storm-config 0.28.143

A crate containing the configuration structure and utilities used by Storm Software monorepos.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
use std::cell::RefCell;
use std::collections::HashMap;
use std::path::Path;
use std::str::FromStr;
use std::{fmt, fs};

use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use storm_workspace::utils::get_workspace_root;

use crate::types::PackageJson;
use crate::{Config, ConfigError, Environment, File, Value};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum WorkspaceMode {
  Development,
  Test,
  Production,
}

impl Default for WorkspaceMode {
  fn default() -> Self {
    WorkspaceMode::Production
  }
}

impl FromStr for WorkspaceMode {
  type Err = ();

  fn from_str(input: &str) -> Result<WorkspaceMode, Self::Err> {
    match input {
      "development" => Ok(WorkspaceMode::Development),
      "test" => Ok(WorkspaceMode::Test),
      "production" => Ok(WorkspaceMode::Production),
      _ => Err(()),
    }
  }
}

impl fmt::Display for WorkspaceMode {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    match *self {
      WorkspaceMode::Development => write!(f, "development"),
      WorkspaceMode::Test => write!(f, "test"),
      WorkspaceMode::Production => write!(f, "production"),
    }
  }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum WorkspaceVariant {
  Minimal,
  Monorepo,
}

impl Default for WorkspaceVariant {
  fn default() -> Self {
    WorkspaceVariant::Monorepo
  }
}

impl FromStr for WorkspaceVariant {
  type Err = ();

  fn from_str(input: &str) -> Result<WorkspaceVariant, Self::Err> {
    match input {
      "minimal" => Ok(WorkspaceVariant::Minimal),
      "monorepo" => Ok(WorkspaceVariant::Monorepo),
      _ => Err(()),
    }
  }
}

impl fmt::Display for WorkspaceVariant {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    match *self {
      WorkspaceVariant::Minimal => write!(f, "minimal"),
      WorkspaceVariant::Monorepo => write!(f, "monorepo"),
    }
  }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum PackageManagerType {
  Npm,
  Yarn,
  Pnpm,
  Bun,
}

impl FromStr for PackageManagerType {
  type Err = ();

  fn from_str(input: &str) -> Result<PackageManagerType, Self::Err> {
    match input {
      "npm" => Ok(PackageManagerType::Npm),
      "yarn" => Ok(PackageManagerType::Yarn),
      "pnpm" => Ok(PackageManagerType::Pnpm),
      "bun" => Ok(PackageManagerType::Bun),
      _ => Err(()),
    }
  }
}

impl fmt::Display for PackageManagerType {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    match *self {
      PackageManagerType::Npm => write!(f, "npm"),
      PackageManagerType::Yarn => write!(f, "yarn"),
      PackageManagerType::Pnpm => write!(f, "pnpm"),
      PackageManagerType::Bun => write!(f, "bun"),
    }
  }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum LogLevel {
  Silent,
  Fatal,
  Error,
  Warn,
  Success,
  Info,
  Debug,
  Trace,
  All,
}

impl FromStr for LogLevel {
  type Err = ();

  fn from_str(input: &str) -> Result<LogLevel, Self::Err> {
    match input {
      "silent" => Ok(LogLevel::Silent),
      "fatal" => Ok(LogLevel::Fatal),
      "error" => Ok(LogLevel::Error),
      "warn" => Ok(LogLevel::Warn),
      "success" => Ok(LogLevel::Success),
      "info" => Ok(LogLevel::Info),
      "debug" => Ok(LogLevel::Debug),
      "trace" => Ok(LogLevel::Trace),
      "all" => Ok(LogLevel::All),
      _ => Err(()),
    }
  }
}

impl fmt::Display for LogLevel {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    match *self {
      LogLevel::Silent => write!(f, "silent"),
      LogLevel::Fatal => write!(f, "fatal"),
      LogLevel::Error => write!(f, "error"),
      LogLevel::Warn => write!(f, "warn"),
      LogLevel::Success => write!(f, "success"),
      LogLevel::Info => write!(f, "info"),
      LogLevel::Debug => write!(f, "debug"),
      LogLevel::Trace => write!(f, "trace"),
      LogLevel::All => write!(f, "all"),
    }
  }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum ExtendsConfig {
  Single(String),
  Multiple(Vec<String>),
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct OrganizationDetails {
  /// The name of the organization
  pub name: Option<String>,
  /// A description of the organization
  pub description: Option<String>,
  /// A URL to the organization's logo image
  pub logo: Option<String>,
  /// A URL to the organization's icon image
  pub icon: Option<String>,
  /// A URL to a page that provides more information about the organization
  pub url: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum WorkspaceOrganizationConfig {
  Details(OrganizationDetails),
  Name(String),
}

impl Default for WorkspaceOrganizationConfig {
  fn default() -> Self {
    WorkspaceOrganizationConfig::Name("storm-software".to_string())
  }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ColorPaletteConfig {
  /// The dark background color of the workspace
  pub dark: String,
  /// The light background color of the workspace
  pub light: String,
  /// The primary brand specific color of the workspace
  pub brand: String,
  /// The alternate brand specific color of the workspace
  pub alternate: Option<String>,
  /// The secondary brand specific color of the workspace
  pub accent: Option<String>,
  /// The color used to display hyperlink text
  pub link: String,
  /// The help color of the workspace
  pub help: String,
  /// The success color of the workspace
  pub success: String,
  /// The info color of the workspace
  pub info: String,
  /// The warning color of the workspace
  pub warning: String,
  /// The danger color of the workspace
  pub danger: String,
  /// The fatal color of the workspace
  pub fatal: Option<String>,
  /// The positive color of the workspace
  pub positive: String,
  /// The negative color of the workspace
  pub negative: String,
  /// The gradient color stops of the workspace
  pub gradient: Option<Vec<String>>,
}

impl Default for ColorPaletteConfig {
  fn default() -> Self {
    Self {
      dark: "#151718".to_string(),
      light: "#cbd5e1".to_string(),
      brand: "#1fb2a6".to_string(),
      alternate: None,
      accent: None,
      link: "#3fa6ff".to_string(),
      help: "#818cf8".to_string(),
      success: "#45b27e".to_string(),
      info: "#38bdf8".to_string(),
      warning: "#f3d371".to_string(),
      danger: "#d8314a".to_string(),
      fatal: None,
      positive: "#4ade80".to_string(),
      negative: "#ef4444".to_string(),
      gradient: None,
    }
  }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ColorSchemaConfig {
  /// The foreground color of the workspace
  pub foreground: String,
  /// The background color of the workspace
  pub background: String,
  /// The primary brand specific color of the workspace
  pub brand: String,
  /// The alternate brand specific color of the workspace
  pub alternate: Option<String>,
  /// The secondary brand specific color of the workspace
  pub accent: Option<String>,
  /// The color used to display hyperlink text
  pub link: String,
  /// The help color of the workspace
  pub help: String,
  /// The success color of the workspace
  pub success: String,
  /// The info color of the workspace
  pub info: String,
  /// The warning color of the workspace
  pub warning: String,
  /// The danger color of the workspace
  pub danger: String,
  /// The fatal color of the workspace
  pub fatal: Option<String>,
  /// The positive color of the workspace
  pub positive: String,
  /// The negative color of the workspace
  pub negative: String,
  /// The gradient color stops of the workspace
  pub gradient: Option<Vec<String>>,
}

impl ColorSchemaConfig {
  fn default_dark() -> Self {
    Self {
      foreground: "#cbd5e1".to_string(),
      background: "#151718".to_string(),
      brand: "#1fb2a6".to_string(),
      alternate: None,
      accent: None,
      link: "#3fa6ff".to_string(),
      help: "#818cf8".to_string(),
      success: "#45b27e".to_string(),
      info: "#38bdf8".to_string(),
      warning: "#f3d371".to_string(),
      danger: "#d8314a".to_string(),
      fatal: None,
      positive: "#4ade80".to_string(),
      negative: "#ef4444".to_string(),
      gradient: None,
    }
  }

  fn default_light() -> Self {
    Self {
      foreground: "#151718".to_string(),
      background: "#cbd5e1".to_string(),
      brand: "#1fb2a6".to_string(),
      alternate: None,
      accent: None,
      link: "#3fa6ff".to_string(),
      help: "#818cf8".to_string(),
      success: "#45b27e".to_string(),
      info: "#38bdf8".to_string(),
      warning: "#f3d371".to_string(),
      danger: "#d8314a".to_string(),
      fatal: None,
      positive: "#4ade80".to_string(),
      negative: "#ef4444".to_string(),
      gradient: None,
    }
  }
}

impl Default for ColorSchemaConfig {
  fn default() -> Self {
    ColorSchemaConfig::default_dark()
  }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ColorThemeConfig {
  /// The light color schema of the workspace
  pub light: ColorSchemaConfig,
  /// The dark color schema of the workspace
  pub dark: ColorSchemaConfig,
}

impl Default for ColorThemeConfig {
  fn default() -> Self {
    Self { light: ColorSchemaConfig::default_light(), dark: ColorSchemaConfig::default_dark() }
  }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum ColorThemeEntry {
  Palette(ColorPaletteConfig),
  Theme(ColorThemeConfig),
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum WorkspaceColorsConfig {
  Palette(ColorPaletteConfig),
  Theme(ColorThemeConfig),
  Collection(HashMap<String, ColorThemeEntry>),
}

impl Default for WorkspaceColorsConfig {
  fn default() -> Self {
    WorkspaceColorsConfig::Palette(ColorPaletteConfig::default())
  }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceRegistryUrlConfig {
  /// A remote registry URL used to publish distributable packages to GitHub
  pub github: Option<String>,
  /// A remote registry URL used to publish distributable packages to npm
  pub npm: Option<String>,
  /// A remote registry URL used to publish distributable packages to crates.io
  pub cargo: Option<String>,
  /// A remote registry URL used to publish distributable packages to Cyclone
  pub cyclone: Option<String>,
  /// A remote registry URL used to publish container images
  pub container: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceBotConfig {
  /// The workspace bot user's name (this is the bot that will be used to perform various tasks)
  pub name: String,
  /// The email of the workspace bot
  pub email: String,
}

impl Default for WorkspaceBotConfig {
  fn default() -> Self {
    Self { name: "stormie-bot".to_string(), email: "stormie-bot@stormsoftware.com".to_string() }
  }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceReleaseBannerConfig {
  /// The URL for the workspace's release banner image
  pub url: Option<String>,
  /// The alt text for the workspace's release banner image
  pub alt: String,
}

impl Default for WorkspaceReleaseBannerConfig {
  fn default() -> Self {
    Self { url: None, alt: "The workspace's banner image".to_string() }
  }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum ReleaseBannerConfig {
  Url(String),
  Details(WorkspaceReleaseBannerConfig),
}

impl Default for ReleaseBannerConfig {
  fn default() -> Self {
    ReleaseBannerConfig::Details(WorkspaceReleaseBannerConfig::default())
  }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceReleaseConfig {
  /// The workspace's release banner details or URL
  pub banner: ReleaseBannerConfig,
  /// A header message appended to the start of the release notes
  pub header: Option<String>,
  /// A footer message appended to the end of the release notes
  pub footer: Option<String>,
}

impl Default for WorkspaceReleaseConfig {
  fn default() -> Self {
    Self { banner: ReleaseBannerConfig::default(), header: None, footer: None }
  }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceSocialsConfig {
  /// A Twitter/X account associated with the organization/project
  pub twitter: Option<String>,
  /// A Discord account associated with the organization/project
  pub discord: Option<String>,
  /// A Telegram account associated with the organization/project
  pub telegram: Option<String>,
  /// A Slack account associated with the organization/project
  pub slack: Option<String>,
  /// A Medium account associated with the organization/project
  pub medium: Option<String>,
  /// A GitHub account associated with the organization/project
  pub github: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceErrorConfig {
  /// The path to the workspace's error codes JSON file
  pub codes_file: String,
  /// A URL to a page that looks up the workspace's error messages given a specific error code
  pub url: Option<String>,
}

impl Default for WorkspaceErrorConfig {
  fn default() -> Self {
    Self { codes_file: "tools/errors/codes.json".to_string(), url: None }
  }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct WorkspaceDirectoriesConfig {
  /// The directory used to store the environment's cached file data
  pub cache: Option<String>,
  /// The directory used to store the environment's data files
  pub data: Option<String>,
  /// The directory used to store the environment's configuration files
  pub config: Option<String>,
  /// The directory used to store the environment's temp files
  pub temp: Option<String>,
  /// The directory used to store the environment's log files
  pub log: Option<String>,
  /// The directory used to store the workspace's distributable files after a build
  pub build: String,
}

impl Default for WorkspaceDirectoriesConfig {
  fn default() -> Self {
    Self { cache: None, data: None, config: None, temp: None, log: None, build: "dist".to_string() }
  }
}

/// Storm Workspace config values used during various development processes.
/// It represents the shared config of the entire monorepo.
#[derive(Debug, Clone)]
pub struct WorkspaceConfig {
  /// The JSON schema reference describing the workspace configuration
  pub schema: String,
  /// The configuration values parsed from the file
  pub config: Option<Config>,
  /// The filepath of the Storm config. When this field is null, no config file was found in the current workspace.
  pub config_file: Option<String>,
  /// Optional configuration presets to extend from
  pub extends: Option<ExtendsConfig>,
  /// The root directory of the package
  pub workspace_root: String,
  /// The name of the package
  pub name: String,
  /// The namespace of the package
  pub namespace: String,
  /// The configured workspace variant
  pub variant: WorkspaceVariant,
  /// The organization configuration backing the workspace
  pub organization: WorkspaceOrganizationConfig,
  /// The repo URL of the workspace (i.e. GitHub)
  pub repository: String,
  /// The license used by the package
  pub license: String,
  /// The homepage of the workspace
  pub homepage: String,
  /// The documentation site for the workspace
  pub docs: Option<String>,
  /// The development portal site for the workspace
  pub portal: Option<String>,
  /// The licensing site for the workspace
  pub licensing: Option<String>,
  /// The contact site for the workspace
  pub contact: Option<String>,
  /// The support site for the workspace
  pub support: Option<String>,
  /// The branch of the workspace
  pub branch: String,
  /// A tag specifying the version pre-release identifier
  pub preid: Option<String>,
  /// The owner of the package
  pub owner: String,
  /// The workspace bot configuration used to automate tasks
  pub bot: WorkspaceBotConfig,
  /// The current workspace runtime mode (development/test/production)
  pub mode: WorkspaceMode,
  /// Configured color settings for the workspace
  pub colors: WorkspaceColorsConfig,
  /// The workspace release configuration
  pub release: WorkspaceReleaseConfig,
  /// The workspace socials configuration
  pub socials: WorkspaceSocialsConfig,
  /// The workspace error configuration
  pub error: WorkspaceErrorConfig,
  /// Should all known types of workspace caching be skipped?
  pub skip_cache: bool,
  /// The registry configuration for the workspace
  pub registry: WorkspaceRegistryUrlConfig,
  /// The directories configuration for the workspace
  pub directories: WorkspaceDirectoriesConfig,
  /// The package manager used by the repository
  pub package_manager: PackageManagerType,
  /// The default timezone of the workspace
  pub timezone: String,
  /// The default locale of the workspace
  pub locale: String,
  /// The log level used to filter out lower priority log messages. If not provided, this is defaulted using the `environment` config value (if `environment` is set to `production` then `level` is `error`, else `level` is `debug`).
  pub log_level: LogLevel,
  /// Should the logging of the current Storm Workspace configuration be skipped?
  pub skip_config_logging: bool,
  /// Configuration of each used extension
  pub extensions: RefCell<HashMap<String, HashMap<String, Value>>>,
}

impl WorkspaceConfig {
  pub fn new() -> Result<Self, ConfigError> {
    let workspace_root = get_workspace_root().expect("No workspace root could be found");
    let workspace_config = Self::from_workspace_root(&workspace_root)?;

    Ok(workspace_config)
  }

  pub fn from_workspace_root(workspace_root: &Path) -> Result<Self, ConfigError> {
    let mut workspace_config = Self::default();
    workspace_config.workspace_root = workspace_root.to_str().unwrap().to_string();

    match fs::metadata(format!("{}/package.json", workspace_root.to_string_lossy())) {
      Ok(_) => {
        let package_json_path = format!("{}/package.json", workspace_root.to_string_lossy());

        let package_json: PackageJson = serde_json::from_reader(
          std::fs::File::open(Path::new(&package_json_path))
            .expect("Unable to read package.json file"),
        )
        .expect("error while reading or parsing");

        workspace_config.config = Some(
          Config::builder()
            .set_default("name", package_json.name)?
            .set_default("namespace", package_json.namespace)?
            .set_default("repository", package_json.repository.get("url").unwrap().to_string())?
            .set_default("license", package_json.license)?
            .set_default("homepage", package_json.homepage)?
            .set_default("workspace_root", workspace_root.to_str().unwrap().to_string())?
            .add_source(
              File::with_name(&format!(
                "{}/storm-workspace.json",
                workspace_root.to_string_lossy()
              ))
              .required(false),
            )
            .add_source(
              File::with_name(&format!(
                "{}/storm-workspace.jsonc",
                workspace_root.to_string_lossy()
              ))
              .required(false),
            )
            .add_source(
              File::with_name(&format!("{}/.storm/config.json", workspace_root.to_string_lossy()))
                .required(false),
            )
            .add_source(
              File::with_name(&format!(
                "{}/.storm-workspace/config.json",
                workspace_root.to_string_lossy()
              ))
              .required(false),
            )
            .add_source(
              File::with_name(&format!(
                "{}/storm-workspace.toml",
                workspace_root.to_string_lossy()
              ))
              .required(false),
            )
            .add_source(
              File::with_name(&format!("{}/.storm/config.toml", workspace_root.to_string_lossy()))
                .required(false),
            )
            .add_source(
              File::with_name(&format!(
                "{}/.storm-workspace/config.toml",
                workspace_root.to_string_lossy()
              ))
              .required(false),
            )
            .add_source(
              File::with_name(&format!(
                "{}/storm-workspace.yaml",
                workspace_root.to_string_lossy()
              ))
              .required(false),
            )
            .add_source(
              File::with_name(&format!("{}/.storm/config.yaml", workspace_root.to_string_lossy()))
                .required(false),
            )
            .add_source(
              File::with_name(&format!(
                "{}/.storm-workspace/config.yaml",
                workspace_root.to_string_lossy()
              ))
              .required(false),
            )
            .add_source(
              File::with_name(&format!("{}/storm-workspace.yml", workspace_root.to_string_lossy()))
                .required(false),
            )
            .add_source(
              File::with_name(&format!("{}/.storm/config.yml", workspace_root.to_string_lossy()))
                .required(false),
            )
            .add_source(
              File::with_name(&format!(
                "{}/.storm-workspace/config.yml",
                workspace_root.to_string_lossy()
              ))
              .required(false),
            )
            .add_source(Environment::with_prefix("storm"))
            .build()?,
        );

        let config = workspace_config.config.as_ref().unwrap();
        if let Ok(found) = config.get_string("config_file") {
          workspace_config.config_file = Some(found);
        }
        if let Ok(found) = config.get_string("schema") {
          workspace_config.schema = found;
        }
        if let Ok(found) = config.get::<ExtendsConfig>("extends") {
          workspace_config.extends = Some(found);
        }
        if let Ok(found) = config.get_string("workspace_root") {
          workspace_config.workspace_root = found;
        }
        if let Ok(found) = config.get_string("name") {
          workspace_config.name = found;
        }
        if let Ok(found) = config.get_string("namespace") {
          workspace_config.namespace = found;
        }
        if let Ok(found) = config.get::<WorkspaceVariant>("variant") {
          workspace_config.variant = found;
        }
        if let Ok(found) = config.get::<WorkspaceOrganizationConfig>("organization") {
          workspace_config.organization = found;
        } else if let Ok(found) = config.get::<WorkspaceOrganizationConfig>("org") {
          workspace_config.organization = found;
        } else if let Ok(found) = config.get::<WorkspaceOrganizationConfig>("organization_config") {
          workspace_config.organization = found;
        }
        if let Ok(found) = config.get_string("repository") {
          workspace_config.repository = found;
        }
        if let Ok(found) = config.get_string("license") {
          workspace_config.license = found;
        }
        if let Ok(found) = config.get_string("homepage") {
          workspace_config.homepage = found;
        }
        if let Ok(found) = config.get_string("docs") {
          workspace_config.docs = Some(found);
        }
        if let Ok(found) = config.get_string("portal") {
          workspace_config.portal = Some(found);
        }
        if let Ok(found) = config.get_string("licensing") {
          workspace_config.licensing = Some(found);
        }
        if let Ok(found) = config.get_string("contact") {
          workspace_config.contact = Some(found);
        }
        if let Ok(found) = config.get_string("support") {
          workspace_config.support = Some(found);
        }
        if let Ok(found) = config.get_string("branch") {
          workspace_config.branch = found;
        }
        if let Ok(found) = config.get_string("preid") {
          workspace_config.preid = Some(found);
        }
        if let Ok(found) = config.get_string("owner") {
          workspace_config.owner = found;
        }
        if let Ok(found) = config.get_string("mode") {
          workspace_config.mode = WorkspaceMode::from_str(&found).unwrap();
        }
        if let Ok(found) = config.get_bool("skip_cache") {
          workspace_config.skip_cache = found;
        }
        if let Ok(found) = config.get_string("package_manager") {
          workspace_config.package_manager = PackageManagerType::from_str(&found).unwrap();
        }
        if let Ok(found) = config.get_string("timezone") {
          workspace_config.timezone = found;
        }
        if let Ok(found) = config.get_string("locale") {
          workspace_config.locale = found;
        }
        if let Ok(found) = config.get_string("log_level") {
          workspace_config.log_level = LogLevel::from_str(&found).unwrap();
        }
        if let Ok(found) = config.get_bool("skip_config_logging") {
          workspace_config.skip_config_logging = found;
        }
        if let Ok(found) = config.get::<WorkspaceReleaseConfig>("release") {
          workspace_config.release = found;
        }
        if let Ok(found) = config.get::<WorkspaceColorsConfig>("colors") {
          workspace_config.colors = found;
        }
        if let Ok(found) = config.get::<WorkspaceBotConfig>("bot") {
          workspace_config.bot = found;
        } else if let Ok(found) = config.get::<WorkspaceBotConfig>("bot_config") {
          workspace_config.bot = found;
        } else if let Ok(found) = config.get::<WorkspaceBotConfig>("workspaceBot") {
          workspace_config.bot = found;
        }
        if let Ok(found) = config.get::<WorkspaceSocialsConfig>("socials") {
          workspace_config.socials = found;
        }
        if let Ok(found) = config.get::<WorkspaceErrorConfig>("error") {
          workspace_config.error = found;
        }
        if let Ok(found) = config.get::<WorkspaceRegistryUrlConfig>("registry") {
          workspace_config.registry = found;
        } else if let Ok(found) = config.get::<WorkspaceRegistryUrlConfig>("registry_urls") {
          workspace_config.registry = found;
        } else if let Ok(found) = config.get::<WorkspaceRegistryUrlConfig>("registryUrls") {
          workspace_config.registry = found;
        }
        if let Ok(found) = config.get::<WorkspaceDirectoriesConfig>("directories") {
          workspace_config.directories = found;
        }
        if let Ok(found) = config.get_string("package_manager") {
          workspace_config.package_manager = PackageManagerType::from_str(&found).unwrap();
        }

        Ok(workspace_config)
      }
      Err(_) => {
        return Err(ConfigError::NotFound(format!(
          "{}/package.json",
          workspace_root.to_string_lossy()
        )));
      }
    }
  }

  pub fn get_extension(&self, name: &str) -> Option<HashMap<String, Value>> {
    if let Some(existing) = self.extensions.borrow().get(name) {
      return Some(existing.clone());
    }

    let extension = self.config.as_ref().expect("Config value must be determined").get_table(name);
    match extension.is_ok() {
      true => {
        self.extensions.borrow_mut().insert(name.to_string(), extension.ok().unwrap());
        return self.extensions.borrow().get(name).cloned();
      }
      false => None,
    }
  }
}

impl Default for WorkspaceConfig {
  fn default() -> Self {
    WorkspaceConfig {
      schema: "https://stormsoftware.com/schemas/storm-workspace.json".to_string(),
      config: None,
      config_file: None,
      extends: None,
      workspace_root: get_workspace_root().unwrap().to_str().unwrap().to_string(),
      mode: WorkspaceMode::Production,
      variant: WorkspaceVariant::Monorepo,
      name: "storm-monorepo".to_string(),
      namespace: "storm-software".to_string(),
      organization: WorkspaceOrganizationConfig::default(),
      repository: "https://github.com/storm-software/storm-monorepo".to_string(),
      license: "Apache-2.0".to_string(),
      homepage: "https://stormsoftware.com".to_string(),
      branch: "main".to_string(),
      preid: None,
      docs: None,
      portal: None,
      licensing: None,
      contact: None,
      support: None,
      release: WorkspaceReleaseConfig::default(),
      socials: WorkspaceSocialsConfig::default(),
      error: WorkspaceErrorConfig::default(),
      directories: WorkspaceDirectoriesConfig::default(),
      owner: "@storm-software/admin".to_string(),
      bot: WorkspaceBotConfig::default(),
      log_level: LogLevel::Info,
      skip_config_logging: true,
      skip_cache: false,
      package_manager: PackageManagerType::Npm,
      registry: WorkspaceRegistryUrlConfig::default(),
      timezone: "America/New_York".to_string(),
      locale: "en-US".to_string(),
      colors: WorkspaceColorsConfig::default(),
      extensions: HashMap::new().into(),
    }
  }
}

impl FromStr for WorkspaceConfig {
  type Err = ();

  fn from_str(input: &str) -> Result<WorkspaceConfig, Self::Err> {
    let workspace_root = Path::new(input);
    WorkspaceConfig::from_workspace_root(workspace_root).map_err(|_| ())
  }
}