@powerlines/plugin-env 0.14.21 → 0.14.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +37 -1
  2. package/dist/_virtual/rolldown_runtime.mjs +29 -1
  3. package/dist/babel/index.cjs +1 -1
  4. package/dist/babel/index.mjs +3 -1
  5. package/dist/babel/plugin.cjs +120 -4
  6. package/dist/babel/plugin.d.cts +2 -3
  7. package/dist/babel/plugin.d.mts +3 -2
  8. package/dist/babel/plugin.mjs +118 -4
  9. package/dist/components/docs.cjs +71 -1
  10. package/dist/components/docs.mjs +70 -1
  11. package/dist/components/env.cjs +432 -11
  12. package/dist/components/env.mjs +430 -9
  13. package/dist/components/index.cjs +6 -1
  14. package/dist/components/index.mjs +4 -1
  15. package/dist/deepkit/schemas/reflection.cjs +3940 -1
  16. package/dist/deepkit/schemas/reflection.mjs +3938 -1
  17. package/dist/deepkit/schemas/reflection2.cjs +4112 -1
  18. package/dist/deepkit/schemas/reflection2.mjs +4110 -1
  19. package/dist/deepkit/src/capnp.cjs +913 -1
  20. package/dist/deepkit/src/capnp.mjs +911 -1
  21. package/dist/deepkit/src/esbuild-plugin.cjs +47 -4
  22. package/dist/deepkit/src/esbuild-plugin.mjs +46 -4
  23. package/dist/deepkit/src/reflect-type.cjs +22 -1
  24. package/dist/deepkit/src/reflect-type.mjs +20 -1
  25. package/dist/deepkit/src/resolve-reflections.cjs +16 -1
  26. package/dist/deepkit/src/resolve-reflections.mjs +15 -1
  27. package/dist/deepkit/src/transformer.cjs +52 -1
  28. package/dist/deepkit/src/transformer.mjs +49 -1
  29. package/dist/deepkit/src/transpile.cjs +29 -1
  30. package/dist/deepkit/src/transpile.mjs +27 -1
  31. package/dist/deepkit/src/utilities.cjs +66 -1
  32. package/dist/deepkit/src/utilities.mjs +65 -1
  33. package/dist/deepkit/src/vendor/type-compiler/index.cjs +38 -1
  34. package/dist/deepkit/src/vendor/type-compiler/index.mjs +19 -1
  35. package/dist/deepkit/src/vendor/type.cjs +20 -1
  36. package/dist/deepkit/src/vendor/type.mjs +11 -1
  37. package/dist/helpers/automd-generator.cjs +22 -1
  38. package/dist/helpers/automd-generator.mjs +21 -1
  39. package/dist/helpers/create-reflection-resource.cjs +55 -1
  40. package/dist/helpers/create-reflection-resource.mjs +54 -1
  41. package/dist/helpers/index.cjs +6 -1
  42. package/dist/helpers/index.mjs +8 -1
  43. package/dist/helpers/load.cjs +83 -1
  44. package/dist/helpers/load.d.cts +2 -2
  45. package/dist/helpers/load.d.mts +3 -2
  46. package/dist/helpers/load.mjs +80 -1
  47. package/dist/helpers/persistence.cjs +214 -1
  48. package/dist/helpers/persistence.d.cts +1 -1
  49. package/dist/helpers/persistence.d.mts +1 -1
  50. package/dist/helpers/persistence.mjs +202 -1
  51. package/dist/helpers/reflect.cjs +111 -1
  52. package/dist/helpers/reflect.mjs +103 -1
  53. package/dist/helpers/source-file-env.cjs +28 -1
  54. package/dist/helpers/source-file-env.mjs +26 -1
  55. package/dist/helpers/template-helpers.cjs +42 -1
  56. package/dist/helpers/template-helpers.mjs +41 -1
  57. package/dist/index.cjs +203 -5
  58. package/dist/index.d.cts +1 -3
  59. package/dist/index.d.mts +2 -1
  60. package/dist/index.mjs +170 -5
  61. package/dist/plugin-alloy/src/core/components/output.cjs +45 -1
  62. package/dist/plugin-alloy/src/core/components/output.mjs +44 -1
  63. package/dist/plugin-alloy/src/core/contexts/context.cjs +11 -1
  64. package/dist/plugin-alloy/src/core/contexts/context.mjs +10 -1
  65. package/dist/plugin-alloy/src/index.cjs +93 -1
  66. package/dist/plugin-alloy/src/index.mjs +91 -1
  67. package/dist/plugin-alloy/src/types/plugin.d.cts +2 -2
  68. package/dist/plugin-alloy/src/types/plugin.d.mts +2 -2
  69. package/dist/plugin-automd/src/index.cjs +101 -1
  70. package/dist/plugin-automd/src/index.mjs +98 -1
  71. package/dist/plugin-automd/src/types/plugin.d.mts +2 -2
  72. package/dist/plugin-babel/src/helpers/ast-utils.cjs +10 -1
  73. package/dist/plugin-babel/src/helpers/ast-utils.mjs +9 -1
  74. package/dist/plugin-babel/src/helpers/create-plugin.cjs +41 -1
  75. package/dist/plugin-babel/src/helpers/create-plugin.mjs +39 -1
  76. package/dist/plugin-babel/src/helpers/filters.cjs +23 -1
  77. package/dist/plugin-babel/src/helpers/filters.mjs +21 -1
  78. package/dist/plugin-babel/src/helpers/index.cjs +5 -1
  79. package/dist/plugin-babel/src/helpers/index.mjs +7 -1
  80. package/dist/plugin-babel/src/helpers/module-helpers.cjs +38 -1
  81. package/dist/plugin-babel/src/helpers/module-helpers.mjs +35 -1
  82. package/dist/plugin-babel/src/helpers/options.cjs +50 -1
  83. package/dist/plugin-babel/src/helpers/options.mjs +47 -1
  84. package/dist/plugin-babel/src/index.cjs +91 -1
  85. package/dist/plugin-babel/src/index.mjs +89 -1
  86. package/dist/plugin-babel/src/types/plugin.d.cts +2 -2
  87. package/dist/plugin-babel/src/types/plugin.d.mts +2 -2
  88. package/dist/powerlines/schemas/fs.d.mts +1 -0
  89. package/dist/powerlines/src/api.d.mts +7 -0
  90. package/dist/powerlines/src/index.d.mts +12 -0
  91. package/dist/powerlines/src/internal/helpers/hooks.d.mts +5 -0
  92. package/dist/powerlines/src/lib/build/esbuild.cjs +102 -14
  93. package/dist/powerlines/src/lib/build/esbuild.mjs +100 -14
  94. package/dist/powerlines/src/lib/entry.cjs +12 -1
  95. package/dist/powerlines/src/lib/entry.mjs +14 -1
  96. package/dist/powerlines/src/lib/logger.cjs +41 -1
  97. package/dist/powerlines/src/lib/logger.mjs +39 -1
  98. package/dist/powerlines/src/lib/utilities/bundle.cjs +35 -1
  99. package/dist/powerlines/src/lib/utilities/bundle.mjs +34 -1
  100. package/dist/powerlines/src/lib/utilities/resolve.cjs +30 -1
  101. package/dist/powerlines/src/lib/utilities/resolve.mjs +29 -1
  102. package/dist/powerlines/src/plugin-utils/paths.cjs +1 -1
  103. package/dist/powerlines/src/plugin-utils/paths.mjs +3 -1
  104. package/dist/powerlines/src/types/api.d.mts +5 -0
  105. package/dist/powerlines/src/types/babel.d.cts +3 -2
  106. package/dist/powerlines/src/types/babel.d.mts +3 -2
  107. package/dist/powerlines/src/types/commands.d.cts +1 -1
  108. package/dist/powerlines/src/types/commands.d.mts +2 -2
  109. package/dist/powerlines/src/types/config.d.cts +5 -5
  110. package/dist/powerlines/src/types/config.d.mts +6 -6
  111. package/dist/powerlines/src/types/context.d.cts +28 -4
  112. package/dist/powerlines/src/types/context.d.mts +30 -6
  113. package/dist/powerlines/src/types/fs.d.cts +1 -1
  114. package/dist/powerlines/src/types/fs.d.mts +1 -1
  115. package/dist/powerlines/src/types/index.d.mts +12 -0
  116. package/dist/powerlines/src/types/plugin.d.cts +3 -3
  117. package/dist/powerlines/src/types/plugin.d.mts +4 -4
  118. package/dist/powerlines/src/types/resolved.d.cts +1 -1
  119. package/dist/powerlines/src/types/resolved.d.mts +2 -2
  120. package/dist/powerlines/src/types/tsconfig.d.mts +1 -1
  121. package/dist/powerlines/src/types/unplugin.d.mts +7 -0
  122. package/dist/types/index.mjs +1 -1
  123. package/dist/types/plugin.d.cts +1 -1
  124. package/dist/types/plugin.mjs +1 -1
  125. package/dist/types/runtime.mjs +1 -1
  126. package/package.json +16 -16
  127. package/dist/babel/index.d.cts +0 -1
  128. package/dist/helpers/index.d.cts +0 -6
package/dist/index.cjs CHANGED
@@ -1,10 +1,208 @@
1
- Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./deepkit/src/vendor/type.cjs`),n=require(`./plugin-alloy/src/index.cjs`),r=require(`./plugin-automd/src/index.cjs`),i=require(`./plugin-babel/src/index.cjs`),a=require(`./helpers/reflect.cjs`),o=require(`./helpers/persistence.cjs`),s=require(`./babel/plugin.cjs`),c=require(`./helpers/source-file-env.cjs`),l=require(`./helpers/load.cjs`),u=require(`./helpers/create-reflection-resource.cjs`),d=require(`./components/env.cjs`),f=require(`./helpers/automd-generator.cjs`);require(`./babel/index.cjs`);const p=require(`./components/docs.cjs`);require(`./components/index.cjs`);const m=require(`./helpers/template-helpers.cjs`);require(`./helpers/index.cjs`);let h=require(`@alloy-js/core/jsx-runtime`),g=require(`@stryke/convert/to-array`),_=require(`defu`);_=e.__toESM(_);let v=require(`@storm-software/config-tools/types`),y=require(`@stryke/path/is-parent-path`),b=require(`@stryke/string-format/title-case`),x=require(`@stryke/convert/parse-type-definition`),S=require(`@stryke/env/types`),C=require(`@stryke/fs/exists`),w=require(`@stryke/fs/helpers`),T=require(`@stryke/path/join`),E=require(`@stryke/string-format/constant-case`);const D=(e={})=>[n.default(e.alloy),i.default(e.babel),{name:`env`,async config(){this.log(v.LogLevelLabel.TRACE,"Providing default configuration for the Powerlines `env` build plugin.");let t={env:(0,_.default)(e,{types:{},prefix:[]}),transform:{babel:{plugins:[s.envBabelPlugin]}}};if(t.env.types)t.env.types=(0,x.parseTypeDefinition)(t.env.types);else{this.log(v.LogLevelLabel.WARN,"The `env.types` configuration parameter was not provided. Please ensure this is expected.");let e=await o.getEnvDefaultTypeDefinition(this);t.env.types=(0,x.parseTypeDefinition)(`${e.file}#${e.name}`)}if(t.env.secrets)t.env.secrets=(0,x.parseTypeDefinition)(t.env.secrets);else{let e=await o.getSecretsDefaultTypeDefinition(this);t.env.secrets=(0,x.parseTypeDefinition)(`${e.file}#${e.name}`)}return t.env.prefix=(0,g.toArray)(t.env.prefix??[]).reduce((e,t)=>{let n=(0,E.constantCase)(t);return e.includes(n)||e.push(n),e},[...S.ENV_PREFIXES,`POWERLINES_`]),t.env.prefix=t.env.prefix.reduce((e,t)=>(e.includes(t.replace(/_$/g,``))||e.push(t.replace(/_$/g,``)),e),[]),t},async configResolved(){if(this.log(v.LogLevelLabel.TRACE,`Environment plugin configuration has been resolved for the Powerlines project.`),this.config.env.inject??=this.config.projectType===`application`,this.env=(0,_.default)({parsed:await l.loadEnv(this,this.config.env)},this.env??{},{types:{env:{}},used:{env:{},secrets:{}},parsed:{},injected:{}}),this.config.command!==`prepare`&&this.persistedMeta?.checksum===this.meta.checksum&&(0,C.existsSync)(o.getEnvTypeReflectionsPath(this,`env`)))this.log(v.LogLevelLabel.TRACE,`Skipping reflection initialization as the meta checksum has not changed.`),this.env.types.env=await o.readEnvTypeReflection(this,`env`),(0,C.existsSync)(o.getEnvReflectionsPath(this,`env`))&&(this.env.used.env=await o.readEnvReflection(this)),(0,C.existsSync)(o.getEnvTypeReflectionsPath(this,`secrets`))&&(this.env.types.secrets=await o.readEnvTypeReflection(this,`secrets`)),(0,C.existsSync)(o.getEnvReflectionsPath(this,`secrets`))&&(this.env.used.secrets=await o.readSecretsReflection(this));else{if(this.env.types.env=await a.reflectEnv(this,this.config.env.types?.file?(0,y.isParentPath)(this.config.env.types?.file,this.workspaceConfig.workspaceRoot)?this.config.env.types?.file:(0,T.joinPaths)(this.config.projectRoot,this.config.env.types?.file):void 0,this.config.env.types?.name),!this.env.types.env)throw Error(`Failed to find the environment configuration type reflection in the context.`);if(await o.writeEnvTypeReflection(this,this.env.types.env,`env`),this.env.types.secrets=await a.reflectSecrets(this,this.config.env.secrets?.file?(0,y.isParentPath)(this.config.env.secrets?.file,this.workspaceConfig.workspaceRoot)?this.config.env.secrets?.file:(0,T.joinPaths)(this.config.projectRoot,this.config.env.secrets?.file):void 0,this.config.env.secrets?.name),!this.env.types.secrets)throw Error(`Failed to find the secrets configuration type reflection in the context.`);await o.writeEnvTypeReflection(this,this.env.types.secrets,`secrets`),this.log(v.LogLevelLabel.TRACE,`Resolved ${this.env.types.env.getProperties().length??0} environment configuration parameters and ${this.env.types.secrets?.getProperties().length??0} secret configuration parameters`);let e=this.env.types.env.getProperties().filter(e=>e.getAlias().length>0);Object.entries(await l.loadEnv(this,this.config.env)).forEach(([t,n])=>{let r=this.config.env.prefix.reduce((e,n)=>t.replace(/_$/g,``).startsWith(n)?t.replace(/_$/g,``).slice(n.length):e,t),i=e.find(e=>e?.getAlias().reverse().includes(r));(this.env.types.env?.hasProperty(r)||i)&&this.env.types.env.getProperty(r).setDefaultValue(n)}),this.env.used.env=new t.type_exports.ReflectionClass({kind:t.type_exports.ReflectionKind.objectLiteral,typeName:`Env`,description:`An object containing the environment configuration parameters used by the ${this.config.name?`${this.config.name} application`:`application`}.`,types:[]},this.env.types.env),await o.writeEnvReflection(this,this.env.used.env,`env`),this.env.types.secrets&&(await o.writeEnvTypeReflection(this,this.env.types.secrets,`secrets`),this.env.used.secrets=new t.type_exports.ReflectionClass({kind:t.type_exports.ReflectionKind.objectLiteral,typeName:`Secrets`,description:`An object containing the secret configuration parameters used by the ${this.config.name?`${this.config.name} application`:`application`}.`,types:[]},this.env.types.secrets),await o.writeEnvReflection(this,this.env.used.secrets,`secrets`))}},async prepare(){let e=this;return this.log(v.LogLevelLabel.TRACE,`Preparing the Environment runtime artifacts for the Powerlines project.`),this.render((0,h.createComponent)(d.EnvBuiltin,{get defaultConfig(){return e.config.env.defaultConfig}}))},async docs(){this.log(v.LogLevelLabel.TRACE,`Writing Environment documentation for the Powerlines project artifacts.`);let e=(0,T.joinPaths)(this.config.projectRoot,`docs`,`generated`);(0,C.existsSync)(e)||await(0,w.createDirectory)(e);let n=await o.readEnvTypeReflection(this,`env`),r=(0,T.joinPaths)(e,`env.md`);this.log(v.LogLevelLabel.TRACE,`Documenting environment variables configuration in "${r}"`),await this.fs.write(r,`<!-- Generated by ${(0,b.titleCase)(this.config.framework)||`Powerlines`} -->
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
3
+ const require_type = require('./deepkit/src/vendor/type.cjs');
4
+ const require_index = require('./plugin-alloy/src/index.cjs');
5
+ const require_index$1 = require('./plugin-automd/src/index.cjs');
6
+ const require_index$2 = require('./plugin-babel/src/index.cjs');
7
+ const require_reflect = require('./helpers/reflect.cjs');
8
+ const require_persistence = require('./helpers/persistence.cjs');
9
+ const require_plugin = require('./babel/plugin.cjs');
10
+ const require_source_file_env = require('./helpers/source-file-env.cjs');
11
+ const require_load = require('./helpers/load.cjs');
12
+ const require_create_reflection_resource = require('./helpers/create-reflection-resource.cjs');
13
+ const require_components_env = require('./components/env.cjs');
14
+ const require_automd_generator = require('./helpers/automd-generator.cjs');
15
+ require('./babel/index.cjs');
16
+ const require_components_docs = require('./components/docs.cjs');
17
+ require('./components/index.cjs');
18
+ const require_template_helpers = require('./helpers/template-helpers.cjs');
19
+ require('./helpers/index.cjs');
20
+ let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
21
+ let __stryke_convert_to_array = require("@stryke/convert/to-array");
22
+ let defu = require("defu");
23
+ defu = require_rolldown_runtime.__toESM(defu);
24
+ let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
25
+ let __stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
26
+ let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
27
+ let __stryke_convert_parse_type_definition = require("@stryke/convert/parse-type-definition");
28
+ let __stryke_env_types = require("@stryke/env/types");
29
+ let __stryke_fs_exists = require("@stryke/fs/exists");
30
+ let __stryke_fs_helpers = require("@stryke/fs/helpers");
31
+ let __stryke_path_join = require("@stryke/path/join");
32
+ let __stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
33
+
34
+ //#region src/index.tsx
35
+ /**
36
+ * A Powerlines plugin to inject environment variables into the source code.
37
+ */
38
+ const plugin = (options = {}) => {
39
+ return [
40
+ require_index.default(options.alloy),
41
+ require_index$2.default(options.babel),
42
+ {
43
+ name: "env",
44
+ async config() {
45
+ this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, "Providing default configuration for the Powerlines `env` build plugin.");
46
+ const config = {
47
+ env: (0, defu.default)(options, {
48
+ types: {},
49
+ prefix: []
50
+ }),
51
+ transform: { babel: { plugins: [require_plugin.envBabelPlugin] } }
52
+ };
53
+ if (config.env.types) config.env.types = (0, __stryke_convert_parse_type_definition.parseTypeDefinition)(config.env.types);
54
+ else {
55
+ this.log(__storm_software_config_tools_types.LogLevelLabel.WARN, "The `env.types` configuration parameter was not provided. Please ensure this is expected.");
56
+ const envDefaultTypeDefinition = await require_persistence.getEnvDefaultTypeDefinition(this);
57
+ config.env.types = (0, __stryke_convert_parse_type_definition.parseTypeDefinition)(`${envDefaultTypeDefinition.file}#${envDefaultTypeDefinition.name}`);
58
+ }
59
+ if (config.env.secrets) config.env.secrets = (0, __stryke_convert_parse_type_definition.parseTypeDefinition)(config.env.secrets);
60
+ else {
61
+ const secretsDefaultTypeDefinition = await require_persistence.getSecretsDefaultTypeDefinition(this);
62
+ config.env.secrets = (0, __stryke_convert_parse_type_definition.parseTypeDefinition)(`${secretsDefaultTypeDefinition.file}#${secretsDefaultTypeDefinition.name}`);
63
+ }
64
+ config.env.prefix = (0, __stryke_convert_to_array.toArray)(config.env.prefix ?? []).reduce((ret, prefix) => {
65
+ const formattedPrefix = (0, __stryke_string_format_constant_case.constantCase)(prefix);
66
+ if (!ret.includes(formattedPrefix)) ret.push(formattedPrefix);
67
+ return ret;
68
+ }, [...__stryke_env_types.ENV_PREFIXES, "POWERLINES_"]);
69
+ config.env.prefix = config.env.prefix.reduce((ret, prefix) => {
70
+ if (!ret.includes(prefix.replace(/_$/g, ""))) ret.push(prefix.replace(/_$/g, ""));
71
+ return ret;
72
+ }, []);
73
+ return config;
74
+ },
75
+ async configResolved() {
76
+ this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Environment plugin configuration has been resolved for the Powerlines project.`);
77
+ this.config.env.inject ??= this.config.projectType === "application";
78
+ this.env = (0, defu.default)({ parsed: await require_load.loadEnv(this, this.config.env) }, this.env ?? {}, {
79
+ types: { env: {} },
80
+ used: {
81
+ env: {},
82
+ secrets: {}
83
+ },
84
+ parsed: {},
85
+ injected: {}
86
+ });
87
+ if (this.config.command !== "prepare" && this.persistedMeta?.checksum === this.meta.checksum && (0, __stryke_fs_exists.existsSync)(require_persistence.getEnvTypeReflectionsPath(this, "env"))) {
88
+ this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Skipping reflection initialization as the meta checksum has not changed.`);
89
+ this.env.types.env = await require_persistence.readEnvTypeReflection(this, "env");
90
+ if ((0, __stryke_fs_exists.existsSync)(require_persistence.getEnvReflectionsPath(this, "env"))) this.env.used.env = await require_persistence.readEnvReflection(this);
91
+ if ((0, __stryke_fs_exists.existsSync)(require_persistence.getEnvTypeReflectionsPath(this, "secrets"))) this.env.types.secrets = await require_persistence.readEnvTypeReflection(this, "secrets");
92
+ if ((0, __stryke_fs_exists.existsSync)(require_persistence.getEnvReflectionsPath(this, "secrets"))) this.env.used.secrets = await require_persistence.readSecretsReflection(this);
93
+ } else {
94
+ this.env.types.env = await require_reflect.reflectEnv(this, this.config.env.types?.file ? (0, __stryke_path_is_parent_path.isParentPath)(this.config.env.types?.file, this.workspaceConfig.workspaceRoot) ? this.config.env.types?.file : (0, __stryke_path_join.joinPaths)(this.config.projectRoot, this.config.env.types?.file) : void 0, this.config.env.types?.name);
95
+ if (!this.env.types.env) throw new Error("Failed to find the environment configuration type reflection in the context.");
96
+ await require_persistence.writeEnvTypeReflection(this, this.env.types.env, "env");
97
+ this.env.types.secrets = await require_reflect.reflectSecrets(this, this.config.env.secrets?.file ? (0, __stryke_path_is_parent_path.isParentPath)(this.config.env.secrets?.file, this.workspaceConfig.workspaceRoot) ? this.config.env.secrets?.file : (0, __stryke_path_join.joinPaths)(this.config.projectRoot, this.config.env.secrets?.file) : void 0, this.config.env.secrets?.name);
98
+ if (!this.env.types.secrets) throw new Error("Failed to find the secrets configuration type reflection in the context.");
99
+ await require_persistence.writeEnvTypeReflection(this, this.env.types.secrets, "secrets");
100
+ this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Resolved ${this.env.types.env.getProperties().length ?? 0} environment configuration parameters and ${this.env.types.secrets?.getProperties().length ?? 0} secret configuration parameters`);
101
+ const envWithAlias = this.env.types.env.getProperties().filter((prop) => prop.getAlias().length > 0);
102
+ Object.entries(await require_load.loadEnv(this, this.config.env)).forEach(([key, value]) => {
103
+ const unprefixedKey = this.config.env.prefix.reduce((ret, prefix) => {
104
+ if (key.replace(/_$/g, "").startsWith(prefix)) return key.replace(/_$/g, "").slice(prefix.length);
105
+ return ret;
106
+ }, key);
107
+ const aliasKey = envWithAlias.find((prop) => prop?.getAlias().reverse().includes(unprefixedKey));
108
+ if (this.env.types.env?.hasProperty(unprefixedKey) || aliasKey) this.env.types.env.getProperty(unprefixedKey).setDefaultValue(value);
109
+ });
110
+ this.env.used.env = new require_type.type_exports.ReflectionClass({
111
+ kind: require_type.type_exports.ReflectionKind.objectLiteral,
112
+ typeName: "Env",
113
+ description: `An object containing the environment configuration parameters used by the ${this.config.name ? `${this.config.name} application` : "application"}.`,
114
+ types: []
115
+ }, this.env.types.env);
116
+ await require_persistence.writeEnvReflection(this, this.env.used.env, "env");
117
+ if (this.env.types.secrets) {
118
+ await require_persistence.writeEnvTypeReflection(this, this.env.types.secrets, "secrets");
119
+ this.env.used.secrets = new require_type.type_exports.ReflectionClass({
120
+ kind: require_type.type_exports.ReflectionKind.objectLiteral,
121
+ typeName: "Secrets",
122
+ description: `An object containing the secret configuration parameters used by the ${this.config.name ? `${this.config.name} application` : "application"}.`,
123
+ types: []
124
+ }, this.env.types.secrets);
125
+ await require_persistence.writeEnvReflection(this, this.env.used.secrets, "secrets");
126
+ }
127
+ }
128
+ },
129
+ async prepare() {
130
+ const _self$ = this;
131
+ this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Preparing the Environment runtime artifacts for the Powerlines project.`);
132
+ return this.render((0, __alloy_js_core_jsx_runtime.createComponent)(require_components_env.EnvBuiltin, { get defaultConfig() {
133
+ return _self$.config.env.defaultConfig;
134
+ } }));
135
+ },
136
+ async docs() {
137
+ this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, "Writing Environment documentation for the Powerlines project artifacts.");
138
+ const outputPath = (0, __stryke_path_join.joinPaths)(this.config.projectRoot, "docs", "generated");
139
+ if (!(0, __stryke_fs_exists.existsSync)(outputPath)) await (0, __stryke_fs_helpers.createDirectory)(outputPath);
140
+ const reflection = await require_persistence.readEnvTypeReflection(this, "env");
141
+ const envDocFile = (0, __stryke_path_join.joinPaths)(outputPath, "env.md");
142
+ this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Documenting environment variables configuration in "${envDocFile}"`);
143
+ await this.fs.write(envDocFile, `<!-- Generated by ${(0, __stryke_string_format_title_case.titleCase)(this.config.framework) || "Powerlines"} -->
2
144
 
3
145
  Below is a list of environment variables used by the [${this.packageJson.name}](https://www.npmjs.com/package/${this.packageJson.name}) package. These values can be updated in the \`.env\` file in the root of the project. The variables in the list below are used as configuration parameters to drive the processing of the application. The data contained in these variables are **not** considered sensitive or confidential. Any values provided in these variables will be available in plain text to the public.
4
146
 
5
147
  | Name | Description | Type | Default Value | Required |
6
148
  | ---- | ----------- | ---- | ------------- | :------: |
7
- ${n.getProperties().filter(e=>e.getNameAsString()!==`__POWERLINES_INJECTED__`).sort((e,t)=>e.getNameAsString().localeCompare(t.getNameAsString())).map(e=>`| ${e.getNameAsString().trim()} | ${(e.getDescription()?.replaceAll(`\r`,``)?.replaceAll(`
8
- `,``)??``).trim()} | ${(0,t.type_exports.stringifyType)(e.getType()).trim().replaceAll(` | `,`, or `)} | ${e.hasDefault()?String(e.getDefaultValue())?.includes(`"`)?e.getDefaultValue():`\`${e.getDefaultValue()}\``:``} | ${e.isValueRequired()?``:`✔`} |`).join(`
9
- `)}
10
- `)},async buildEnd(){let e=o.getEnvReflectionsPath(this,`env`);this.log(v.LogLevelLabel.TRACE,`Writing env reflection types to ${e}.`),await o.writeEnvReflection(this,this.env.used.env,`env`)}},{name:`env:automd-generator`,config(){return{automd:(0,_.default)(e.automd??{},{generators:{env:f.env(this)}})}}},{name:`env:vite`,vite:{configResolved(){return{envPrefix:this.config?.env?.prefix}}}},r.default(e.automd)];var O=D;exports.BaseEnv=a.BaseEnv,exports.BaseSecrets=a.BaseSecrets,exports.EnvBuiltin=d.EnvBuiltin,exports.EnvDocs=p.EnvDocs,exports.EnvTypeDefinition=d.EnvTypeDefinition,exports.createEnvReflection=a.createEnvReflection,exports.createReflectionResource=u.createReflectionResource,exports.createSecretsReflection=a.createSecretsReflection,exports.createTemplateReflection=m.createTemplateReflection,exports.default=O,exports.envBabelPlugin=s.envBabelPlugin,exports.formatEnvField=c.formatEnvField,exports.getEnvDefaultTypeDefinition=o.getEnvDefaultTypeDefinition,exports.getEnvReflectionsPath=o.getEnvReflectionsPath,exports.getEnvTypeReflectionsPath=o.getEnvTypeReflectionsPath,exports.getSecretsDefaultTypeDefinition=o.getSecretsDefaultTypeDefinition,exports.loadEnv=l.loadEnv,exports.loadEnvFromContext=l.loadEnvFromContext,exports.mergeEnvReflections=a.mergeEnvReflections,exports.mergeSecretsReflections=a.mergeSecretsReflections,exports.plugin=D,exports.readEnvReflection=o.readEnvReflection,exports.readEnvTypeReflection=o.readEnvTypeReflection,exports.readSecretsReflection=o.readSecretsReflection,exports.reflectEnv=a.reflectEnv,exports.reflectSecrets=a.reflectSecrets,exports.removeEnvPrefix=c.removeEnvPrefix,exports.resolveRuntimeTypeFile=o.resolveRuntimeTypeFile,exports.writeEnvReflection=o.writeEnvReflection,exports.writeEnvReflectionSync=o.writeEnvReflectionSync,exports.writeEnvTypeReflection=o.writeEnvTypeReflection;
149
+ ${reflection.getProperties().filter((property) => property.getNameAsString() !== "__POWERLINES_INJECTED__").sort((a, b) => a.getNameAsString().localeCompare(b.getNameAsString())).map((reflectionProperty) => {
150
+ return `| ${reflectionProperty.getNameAsString().trim()} | ${(reflectionProperty.getDescription()?.replaceAll("\r", "")?.replaceAll("\n", "") ?? "").trim()} | ${(0, require_type.type_exports.stringifyType)(reflectionProperty.getType()).trim().replaceAll(" | ", ", or ")} | ${reflectionProperty.hasDefault() ? String(reflectionProperty.getDefaultValue())?.includes("\"") ? reflectionProperty.getDefaultValue() : `\`${reflectionProperty.getDefaultValue()}\`` : ""} | ${reflectionProperty.isValueRequired() ? "" : "✔"} |`;
151
+ }).join("\n")}
152
+ `);
153
+ },
154
+ async buildEnd() {
155
+ const reflectionPath = require_persistence.getEnvReflectionsPath(this, "env");
156
+ this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Writing env reflection types to ${reflectionPath}.`);
157
+ await require_persistence.writeEnvReflection(this, this.env.used.env, "env");
158
+ }
159
+ },
160
+ {
161
+ name: "env:automd-generator",
162
+ config() {
163
+ return { automd: (0, defu.default)(options.automd ?? {}, { generators: { "env": require_automd_generator.env(this) } }) };
164
+ }
165
+ },
166
+ {
167
+ name: "env:vite",
168
+ vite: { configResolved() {
169
+ return { envPrefix: this.config?.env?.prefix };
170
+ } }
171
+ },
172
+ require_index$1.default(options.automd)
173
+ ];
174
+ };
175
+ var src_default = plugin;
176
+
177
+ //#endregion
178
+ exports.BaseEnv = require_reflect.BaseEnv;
179
+ exports.BaseSecrets = require_reflect.BaseSecrets;
180
+ exports.EnvBuiltin = require_components_env.EnvBuiltin;
181
+ exports.EnvDocs = require_components_docs.EnvDocs;
182
+ exports.EnvTypeDefinition = require_components_env.EnvTypeDefinition;
183
+ exports.createEnvReflection = require_reflect.createEnvReflection;
184
+ exports.createReflectionResource = require_create_reflection_resource.createReflectionResource;
185
+ exports.createSecretsReflection = require_reflect.createSecretsReflection;
186
+ exports.createTemplateReflection = require_template_helpers.createTemplateReflection;
187
+ exports.default = src_default;
188
+ exports.envBabelPlugin = require_plugin.envBabelPlugin;
189
+ exports.formatEnvField = require_source_file_env.formatEnvField;
190
+ exports.getEnvDefaultTypeDefinition = require_persistence.getEnvDefaultTypeDefinition;
191
+ exports.getEnvReflectionsPath = require_persistence.getEnvReflectionsPath;
192
+ exports.getEnvTypeReflectionsPath = require_persistence.getEnvTypeReflectionsPath;
193
+ exports.getSecretsDefaultTypeDefinition = require_persistence.getSecretsDefaultTypeDefinition;
194
+ exports.loadEnv = require_load.loadEnv;
195
+ exports.loadEnvFromContext = require_load.loadEnvFromContext;
196
+ exports.mergeEnvReflections = require_reflect.mergeEnvReflections;
197
+ exports.mergeSecretsReflections = require_reflect.mergeSecretsReflections;
198
+ exports.plugin = plugin;
199
+ exports.readEnvReflection = require_persistence.readEnvReflection;
200
+ exports.readEnvTypeReflection = require_persistence.readEnvTypeReflection;
201
+ exports.readSecretsReflection = require_persistence.readSecretsReflection;
202
+ exports.reflectEnv = require_reflect.reflectEnv;
203
+ exports.reflectSecrets = require_reflect.reflectSecrets;
204
+ exports.removeEnvPrefix = require_source_file_env.removeEnvPrefix;
205
+ exports.resolveRuntimeTypeFile = require_persistence.resolveRuntimeTypeFile;
206
+ exports.writeEnvReflection = require_persistence.writeEnvReflection;
207
+ exports.writeEnvReflectionSync = require_persistence.writeEnvReflectionSync;
208
+ exports.writeEnvTypeReflection = require_persistence.writeEnvTypeReflection;
package/dist/index.d.cts CHANGED
@@ -1,17 +1,15 @@
1
1
  import { EnvDocs } from "./components/docs.cjs";
2
2
  import { EnvBuiltin, EnvBuiltinProps, EnvTypeDefinition, __ΩEnvBuiltinProps } from "./components/env.cjs";
3
+ import { Plugin } from "./powerlines/src/types/plugin.cjs";
3
4
  import { EnvInterface, SecretsInterface, __ΩEnvInterface, __ΩSecretsInterface } from "./types/runtime.cjs";
4
5
  import { EnvPluginContext, EnvPluginOptions, EnvPluginResolvedConfig, EnvPluginUserConfig, EnvType, __ΩEnvPluginContext, __ΩEnvPluginOptions, __ΩEnvPluginResolvedConfig, __ΩEnvPluginUserConfig, __ΩEnvType } from "./types/plugin.cjs";
5
6
  import { envBabelPlugin } from "./babel/plugin.cjs";
6
- import "./babel/index.cjs";
7
7
  import { createReflectionResource } from "./helpers/create-reflection-resource.cjs";
8
8
  import { loadEnv, loadEnvFromContext } from "./helpers/load.cjs";
9
9
  import { getEnvDefaultTypeDefinition, getEnvReflectionsPath, getEnvTypeReflectionsPath, getSecretsDefaultTypeDefinition, readEnvReflection, readEnvTypeReflection, readSecretsReflection, resolveRuntimeTypeFile, writeEnvReflection, writeEnvReflectionSync, writeEnvTypeReflection } from "./helpers/persistence.cjs";
10
10
  import { BaseEnv, BaseSecrets, CreateEnvReflectionOptions, __ΩCreateEnvReflectionOptions, createEnvReflection, createSecretsReflection, mergeEnvReflections, mergeSecretsReflections, reflectEnv, reflectSecrets } from "./helpers/reflect.cjs";
11
11
  import { formatEnvField, removeEnvPrefix } from "./helpers/source-file-env.cjs";
12
12
  import { createTemplateReflection } from "./helpers/template-helpers.cjs";
13
- import "./helpers/index.cjs";
14
- import { Plugin } from "powerlines";
15
13
 
16
14
  //#region src/index.d.ts
17
15
  /**
package/dist/index.d.mts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { EnvDocs } from "./components/docs.mjs";
2
2
  import { EnvBuiltin, EnvBuiltinProps, EnvTypeDefinition, __ΩEnvBuiltinProps } from "./components/env.mjs";
3
3
  import "./components/index.mjs";
4
+ import { Plugin } from "./powerlines/src/types/plugin.mjs";
5
+ import "./powerlines/src/index.mjs";
4
6
  import { EnvInterface, SecretsInterface, __ΩEnvInterface, __ΩSecretsInterface } from "./types/runtime.mjs";
5
7
  import { EnvPluginContext, EnvPluginOptions, EnvPluginResolvedConfig, EnvPluginUserConfig, EnvType, __ΩEnvPluginContext, __ΩEnvPluginOptions, __ΩEnvPluginResolvedConfig, __ΩEnvPluginUserConfig, __ΩEnvType } from "./types/plugin.mjs";
6
8
  import { envBabelPlugin } from "./babel/plugin.mjs";
@@ -13,7 +15,6 @@ import { formatEnvField, removeEnvPrefix } from "./helpers/source-file-env.mjs";
13
15
  import { createTemplateReflection } from "./helpers/template-helpers.mjs";
14
16
  import "./helpers/index.mjs";
15
17
  import "./types/index.mjs";
16
- import { Plugin } from "powerlines";
17
18
 
18
19
  //#region src/index.d.ts
19
20
  /**
package/dist/index.mjs CHANGED
@@ -1,10 +1,175 @@
1
- import{type_exports as e}from"./deepkit/src/vendor/type.mjs";import t from"./plugin-alloy/src/index.mjs";import n from"./plugin-automd/src/index.mjs";import r from"./plugin-babel/src/index.mjs";import{BaseEnv as i,BaseSecrets as a,createEnvReflection as o,createSecretsReflection as s,mergeEnvReflections as c,mergeSecretsReflections as l,reflectEnv as u,reflectSecrets as d}from"./helpers/reflect.mjs";import{getEnvDefaultTypeDefinition as f,getEnvReflectionsPath as p,getEnvTypeReflectionsPath as m,getSecretsDefaultTypeDefinition as h,readEnvReflection as g,readEnvTypeReflection as _,readSecretsReflection as v,resolveRuntimeTypeFile as y,writeEnvReflection as b,writeEnvReflectionSync as x,writeEnvTypeReflection as S}from"./helpers/persistence.mjs";import{envBabelPlugin as C}from"./babel/plugin.mjs";import{formatEnvField as w,removeEnvPrefix as T}from"./helpers/source-file-env.mjs";import{loadEnv as E,loadEnvFromContext as D}from"./helpers/load.mjs";import{createReflectionResource as O}from"./helpers/create-reflection-resource.mjs";import{EnvBuiltin as k,EnvTypeDefinition as A}from"./components/env.mjs";import{env as j}from"./helpers/automd-generator.mjs";import"./babel/index.mjs";import{EnvDocs as M}from"./components/docs.mjs";import"./components/index.mjs";import{createTemplateReflection as N}from"./helpers/template-helpers.mjs";import"./helpers/index.mjs";import{createComponent as P}from"@alloy-js/core/jsx-runtime";import{toArray as F}from"@stryke/convert/to-array";import I from"defu";import{LogLevelLabel as L}from"@storm-software/config-tools/types";import{isParentPath as R}from"@stryke/path/is-parent-path";import{titleCase as z}from"@stryke/string-format/title-case";import{parseTypeDefinition as B}from"@stryke/convert/parse-type-definition";import{ENV_PREFIXES as V}from"@stryke/env/types";import{existsSync as H}from"@stryke/fs/exists";import{createDirectory as U}from"@stryke/fs/helpers";import{joinPaths as W}from"@stryke/path/join";import{constantCase as G}from"@stryke/string-format/constant-case";const K=(i={})=>[t(i.alloy),r(i.babel),{name:`env`,async config(){this.log(L.TRACE,"Providing default configuration for the Powerlines `env` build plugin.");let e={env:I(i,{types:{},prefix:[]}),transform:{babel:{plugins:[C]}}};if(e.env.types)e.env.types=B(e.env.types);else{this.log(L.WARN,"The `env.types` configuration parameter was not provided. Please ensure this is expected.");let t=await f(this);e.env.types=B(`${t.file}#${t.name}`)}if(e.env.secrets)e.env.secrets=B(e.env.secrets);else{let t=await h(this);e.env.secrets=B(`${t.file}#${t.name}`)}return e.env.prefix=F(e.env.prefix??[]).reduce((e,t)=>{let n=G(t);return e.includes(n)||e.push(n),e},[...V,`POWERLINES_`]),e.env.prefix=e.env.prefix.reduce((e,t)=>(e.includes(t.replace(/_$/g,``))||e.push(t.replace(/_$/g,``)),e),[]),e},async configResolved(){if(this.log(L.TRACE,`Environment plugin configuration has been resolved for the Powerlines project.`),this.config.env.inject??=this.config.projectType===`application`,this.env=I({parsed:await E(this,this.config.env)},this.env??{},{types:{env:{}},used:{env:{},secrets:{}},parsed:{},injected:{}}),this.config.command!==`prepare`&&this.persistedMeta?.checksum===this.meta.checksum&&H(m(this,`env`)))this.log(L.TRACE,`Skipping reflection initialization as the meta checksum has not changed.`),this.env.types.env=await _(this,`env`),H(p(this,`env`))&&(this.env.used.env=await g(this)),H(m(this,`secrets`))&&(this.env.types.secrets=await _(this,`secrets`)),H(p(this,`secrets`))&&(this.env.used.secrets=await v(this));else{if(this.env.types.env=await u(this,this.config.env.types?.file?R(this.config.env.types?.file,this.workspaceConfig.workspaceRoot)?this.config.env.types?.file:W(this.config.projectRoot,this.config.env.types?.file):void 0,this.config.env.types?.name),!this.env.types.env)throw Error(`Failed to find the environment configuration type reflection in the context.`);if(await S(this,this.env.types.env,`env`),this.env.types.secrets=await d(this,this.config.env.secrets?.file?R(this.config.env.secrets?.file,this.workspaceConfig.workspaceRoot)?this.config.env.secrets?.file:W(this.config.projectRoot,this.config.env.secrets?.file):void 0,this.config.env.secrets?.name),!this.env.types.secrets)throw Error(`Failed to find the secrets configuration type reflection in the context.`);await S(this,this.env.types.secrets,`secrets`),this.log(L.TRACE,`Resolved ${this.env.types.env.getProperties().length??0} environment configuration parameters and ${this.env.types.secrets?.getProperties().length??0} secret configuration parameters`);let t=this.env.types.env.getProperties().filter(e=>e.getAlias().length>0);Object.entries(await E(this,this.config.env)).forEach(([e,n])=>{let r=this.config.env.prefix.reduce((t,n)=>e.replace(/_$/g,``).startsWith(n)?e.replace(/_$/g,``).slice(n.length):t,e),i=t.find(e=>e?.getAlias().reverse().includes(r));(this.env.types.env?.hasProperty(r)||i)&&this.env.types.env.getProperty(r).setDefaultValue(n)}),this.env.used.env=new e.ReflectionClass({kind:e.ReflectionKind.objectLiteral,typeName:`Env`,description:`An object containing the environment configuration parameters used by the ${this.config.name?`${this.config.name} application`:`application`}.`,types:[]},this.env.types.env),await b(this,this.env.used.env,`env`),this.env.types.secrets&&(await S(this,this.env.types.secrets,`secrets`),this.env.used.secrets=new e.ReflectionClass({kind:e.ReflectionKind.objectLiteral,typeName:`Secrets`,description:`An object containing the secret configuration parameters used by the ${this.config.name?`${this.config.name} application`:`application`}.`,types:[]},this.env.types.secrets),await b(this,this.env.used.secrets,`secrets`))}},async prepare(){let e=this;return this.log(L.TRACE,`Preparing the Environment runtime artifacts for the Powerlines project.`),this.render(P(k,{get defaultConfig(){return e.config.env.defaultConfig}}))},async docs(){this.log(L.TRACE,`Writing Environment documentation for the Powerlines project artifacts.`);let t=W(this.config.projectRoot,`docs`,`generated`);H(t)||await U(t);let n=await _(this,`env`),r=W(t,`env.md`);this.log(L.TRACE,`Documenting environment variables configuration in "${r}"`),await this.fs.write(r,`<!-- Generated by ${z(this.config.framework)||`Powerlines`} -->
1
+ import { type_exports } from "./deepkit/src/vendor/type.mjs";
2
+ import src_default$1 from "./plugin-alloy/src/index.mjs";
3
+ import src_default$2 from "./plugin-automd/src/index.mjs";
4
+ import src_default$3 from "./plugin-babel/src/index.mjs";
5
+ import { BaseEnv, BaseSecrets, createEnvReflection, createSecretsReflection, mergeEnvReflections, mergeSecretsReflections, reflectEnv, reflectSecrets } from "./helpers/reflect.mjs";
6
+ import { getEnvDefaultTypeDefinition, getEnvReflectionsPath, getEnvTypeReflectionsPath, getSecretsDefaultTypeDefinition, readEnvReflection, readEnvTypeReflection, readSecretsReflection, resolveRuntimeTypeFile, writeEnvReflection, writeEnvReflectionSync, writeEnvTypeReflection } from "./helpers/persistence.mjs";
7
+ import { envBabelPlugin } from "./babel/plugin.mjs";
8
+ import { formatEnvField, removeEnvPrefix } from "./helpers/source-file-env.mjs";
9
+ import { loadEnv, loadEnvFromContext } from "./helpers/load.mjs";
10
+ import { createReflectionResource } from "./helpers/create-reflection-resource.mjs";
11
+ import { EnvBuiltin, EnvTypeDefinition } from "./components/env.mjs";
12
+ import { env } from "./helpers/automd-generator.mjs";
13
+ import "./babel/index.mjs";
14
+ import { EnvDocs } from "./components/docs.mjs";
15
+ import "./components/index.mjs";
16
+ import { createTemplateReflection } from "./helpers/template-helpers.mjs";
17
+ import "./helpers/index.mjs";
18
+ import { createComponent } from "@alloy-js/core/jsx-runtime";
19
+ import { toArray } from "@stryke/convert/to-array";
20
+ import defu from "defu";
21
+ import { LogLevelLabel } from "@storm-software/config-tools/types";
22
+ import { isParentPath } from "@stryke/path/is-parent-path";
23
+ import { titleCase } from "@stryke/string-format/title-case";
24
+ import { parseTypeDefinition } from "@stryke/convert/parse-type-definition";
25
+ import { ENV_PREFIXES } from "@stryke/env/types";
26
+ import { existsSync } from "@stryke/fs/exists";
27
+ import { createDirectory } from "@stryke/fs/helpers";
28
+ import { joinPaths } from "@stryke/path/join";
29
+ import { constantCase } from "@stryke/string-format/constant-case";
30
+
31
+ //#region src/index.tsx
32
+ /**
33
+ * A Powerlines plugin to inject environment variables into the source code.
34
+ */
35
+ const plugin = (options = {}) => {
36
+ return [
37
+ src_default$1(options.alloy),
38
+ src_default$3(options.babel),
39
+ {
40
+ name: "env",
41
+ async config() {
42
+ this.log(LogLevelLabel.TRACE, "Providing default configuration for the Powerlines `env` build plugin.");
43
+ const config = {
44
+ env: defu(options, {
45
+ types: {},
46
+ prefix: []
47
+ }),
48
+ transform: { babel: { plugins: [envBabelPlugin] } }
49
+ };
50
+ if (config.env.types) config.env.types = parseTypeDefinition(config.env.types);
51
+ else {
52
+ this.log(LogLevelLabel.WARN, "The `env.types` configuration parameter was not provided. Please ensure this is expected.");
53
+ const envDefaultTypeDefinition = await getEnvDefaultTypeDefinition(this);
54
+ config.env.types = parseTypeDefinition(`${envDefaultTypeDefinition.file}#${envDefaultTypeDefinition.name}`);
55
+ }
56
+ if (config.env.secrets) config.env.secrets = parseTypeDefinition(config.env.secrets);
57
+ else {
58
+ const secretsDefaultTypeDefinition = await getSecretsDefaultTypeDefinition(this);
59
+ config.env.secrets = parseTypeDefinition(`${secretsDefaultTypeDefinition.file}#${secretsDefaultTypeDefinition.name}`);
60
+ }
61
+ config.env.prefix = toArray(config.env.prefix ?? []).reduce((ret, prefix) => {
62
+ const formattedPrefix = constantCase(prefix);
63
+ if (!ret.includes(formattedPrefix)) ret.push(formattedPrefix);
64
+ return ret;
65
+ }, [...ENV_PREFIXES, "POWERLINES_"]);
66
+ config.env.prefix = config.env.prefix.reduce((ret, prefix) => {
67
+ if (!ret.includes(prefix.replace(/_$/g, ""))) ret.push(prefix.replace(/_$/g, ""));
68
+ return ret;
69
+ }, []);
70
+ return config;
71
+ },
72
+ async configResolved() {
73
+ this.log(LogLevelLabel.TRACE, `Environment plugin configuration has been resolved for the Powerlines project.`);
74
+ this.config.env.inject ??= this.config.projectType === "application";
75
+ this.env = defu({ parsed: await loadEnv(this, this.config.env) }, this.env ?? {}, {
76
+ types: { env: {} },
77
+ used: {
78
+ env: {},
79
+ secrets: {}
80
+ },
81
+ parsed: {},
82
+ injected: {}
83
+ });
84
+ if (this.config.command !== "prepare" && this.persistedMeta?.checksum === this.meta.checksum && existsSync(getEnvTypeReflectionsPath(this, "env"))) {
85
+ this.log(LogLevelLabel.TRACE, `Skipping reflection initialization as the meta checksum has not changed.`);
86
+ this.env.types.env = await readEnvTypeReflection(this, "env");
87
+ if (existsSync(getEnvReflectionsPath(this, "env"))) this.env.used.env = await readEnvReflection(this);
88
+ if (existsSync(getEnvTypeReflectionsPath(this, "secrets"))) this.env.types.secrets = await readEnvTypeReflection(this, "secrets");
89
+ if (existsSync(getEnvReflectionsPath(this, "secrets"))) this.env.used.secrets = await readSecretsReflection(this);
90
+ } else {
91
+ this.env.types.env = await reflectEnv(this, this.config.env.types?.file ? isParentPath(this.config.env.types?.file, this.workspaceConfig.workspaceRoot) ? this.config.env.types?.file : joinPaths(this.config.projectRoot, this.config.env.types?.file) : void 0, this.config.env.types?.name);
92
+ if (!this.env.types.env) throw new Error("Failed to find the environment configuration type reflection in the context.");
93
+ await writeEnvTypeReflection(this, this.env.types.env, "env");
94
+ this.env.types.secrets = await reflectSecrets(this, this.config.env.secrets?.file ? isParentPath(this.config.env.secrets?.file, this.workspaceConfig.workspaceRoot) ? this.config.env.secrets?.file : joinPaths(this.config.projectRoot, this.config.env.secrets?.file) : void 0, this.config.env.secrets?.name);
95
+ if (!this.env.types.secrets) throw new Error("Failed to find the secrets configuration type reflection in the context.");
96
+ await writeEnvTypeReflection(this, this.env.types.secrets, "secrets");
97
+ this.log(LogLevelLabel.TRACE, `Resolved ${this.env.types.env.getProperties().length ?? 0} environment configuration parameters and ${this.env.types.secrets?.getProperties().length ?? 0} secret configuration parameters`);
98
+ const envWithAlias = this.env.types.env.getProperties().filter((prop) => prop.getAlias().length > 0);
99
+ Object.entries(await loadEnv(this, this.config.env)).forEach(([key, value]) => {
100
+ const unprefixedKey = this.config.env.prefix.reduce((ret, prefix) => {
101
+ if (key.replace(/_$/g, "").startsWith(prefix)) return key.replace(/_$/g, "").slice(prefix.length);
102
+ return ret;
103
+ }, key);
104
+ const aliasKey = envWithAlias.find((prop) => prop?.getAlias().reverse().includes(unprefixedKey));
105
+ if (this.env.types.env?.hasProperty(unprefixedKey) || aliasKey) this.env.types.env.getProperty(unprefixedKey).setDefaultValue(value);
106
+ });
107
+ this.env.used.env = new type_exports.ReflectionClass({
108
+ kind: type_exports.ReflectionKind.objectLiteral,
109
+ typeName: "Env",
110
+ description: `An object containing the environment configuration parameters used by the ${this.config.name ? `${this.config.name} application` : "application"}.`,
111
+ types: []
112
+ }, this.env.types.env);
113
+ await writeEnvReflection(this, this.env.used.env, "env");
114
+ if (this.env.types.secrets) {
115
+ await writeEnvTypeReflection(this, this.env.types.secrets, "secrets");
116
+ this.env.used.secrets = new type_exports.ReflectionClass({
117
+ kind: type_exports.ReflectionKind.objectLiteral,
118
+ typeName: "Secrets",
119
+ description: `An object containing the secret configuration parameters used by the ${this.config.name ? `${this.config.name} application` : "application"}.`,
120
+ types: []
121
+ }, this.env.types.secrets);
122
+ await writeEnvReflection(this, this.env.used.secrets, "secrets");
123
+ }
124
+ }
125
+ },
126
+ async prepare() {
127
+ const _self$ = this;
128
+ this.log(LogLevelLabel.TRACE, `Preparing the Environment runtime artifacts for the Powerlines project.`);
129
+ return this.render(createComponent(EnvBuiltin, { get defaultConfig() {
130
+ return _self$.config.env.defaultConfig;
131
+ } }));
132
+ },
133
+ async docs() {
134
+ this.log(LogLevelLabel.TRACE, "Writing Environment documentation for the Powerlines project artifacts.");
135
+ const outputPath = joinPaths(this.config.projectRoot, "docs", "generated");
136
+ if (!existsSync(outputPath)) await createDirectory(outputPath);
137
+ const reflection = await readEnvTypeReflection(this, "env");
138
+ const envDocFile = joinPaths(outputPath, "env.md");
139
+ this.log(LogLevelLabel.TRACE, `Documenting environment variables configuration in "${envDocFile}"`);
140
+ await this.fs.write(envDocFile, `<!-- Generated by ${titleCase(this.config.framework) || "Powerlines"} -->
2
141
 
3
142
  Below is a list of environment variables used by the [${this.packageJson.name}](https://www.npmjs.com/package/${this.packageJson.name}) package. These values can be updated in the \`.env\` file in the root of the project. The variables in the list below are used as configuration parameters to drive the processing of the application. The data contained in these variables are **not** considered sensitive or confidential. Any values provided in these variables will be available in plain text to the public.
4
143
 
5
144
  | Name | Description | Type | Default Value | Required |
6
145
  | ---- | ----------- | ---- | ------------- | :------: |
7
- ${n.getProperties().filter(e=>e.getNameAsString()!==`__POWERLINES_INJECTED__`).sort((e,t)=>e.getNameAsString().localeCompare(t.getNameAsString())).map(t=>`| ${t.getNameAsString().trim()} | ${(t.getDescription()?.replaceAll(`\r`,``)?.replaceAll(`
8
- `,``)??``).trim()} | ${(0,e.stringifyType)(t.getType()).trim().replaceAll(` | `,`, or `)} | ${t.hasDefault()?String(t.getDefaultValue())?.includes(`"`)?t.getDefaultValue():`\`${t.getDefaultValue()}\``:``} | ${t.isValueRequired()?``:`✔`} |`).join(`
9
- `)}
10
- `)},async buildEnd(){let e=p(this,`env`);this.log(L.TRACE,`Writing env reflection types to ${e}.`),await b(this,this.env.used.env,`env`)}},{name:`env:automd-generator`,config(){return{automd:I(i.automd??{},{generators:{env:j(this)}})}}},{name:`env:vite`,vite:{configResolved(){return{envPrefix:this.config?.env?.prefix}}}},n(i.automd)];var q=K;export{i as BaseEnv,a as BaseSecrets,k as EnvBuiltin,M as EnvDocs,A as EnvTypeDefinition,o as createEnvReflection,O as createReflectionResource,s as createSecretsReflection,N as createTemplateReflection,q as default,C as envBabelPlugin,w as formatEnvField,f as getEnvDefaultTypeDefinition,p as getEnvReflectionsPath,m as getEnvTypeReflectionsPath,h as getSecretsDefaultTypeDefinition,E as loadEnv,D as loadEnvFromContext,c as mergeEnvReflections,l as mergeSecretsReflections,K as plugin,g as readEnvReflection,_ as readEnvTypeReflection,v as readSecretsReflection,u as reflectEnv,d as reflectSecrets,T as removeEnvPrefix,y as resolveRuntimeTypeFile,b as writeEnvReflection,x as writeEnvReflectionSync,S as writeEnvTypeReflection};
146
+ ${reflection.getProperties().filter((property) => property.getNameAsString() !== "__POWERLINES_INJECTED__").sort((a, b) => a.getNameAsString().localeCompare(b.getNameAsString())).map((reflectionProperty) => {
147
+ return `| ${reflectionProperty.getNameAsString().trim()} | ${(reflectionProperty.getDescription()?.replaceAll("\r", "")?.replaceAll("\n", "") ?? "").trim()} | ${(0, type_exports.stringifyType)(reflectionProperty.getType()).trim().replaceAll(" | ", ", or ")} | ${reflectionProperty.hasDefault() ? String(reflectionProperty.getDefaultValue())?.includes("\"") ? reflectionProperty.getDefaultValue() : `\`${reflectionProperty.getDefaultValue()}\`` : ""} | ${reflectionProperty.isValueRequired() ? "" : "✔"} |`;
148
+ }).join("\n")}
149
+ `);
150
+ },
151
+ async buildEnd() {
152
+ const reflectionPath = getEnvReflectionsPath(this, "env");
153
+ this.log(LogLevelLabel.TRACE, `Writing env reflection types to ${reflectionPath}.`);
154
+ await writeEnvReflection(this, this.env.used.env, "env");
155
+ }
156
+ },
157
+ {
158
+ name: "env:automd-generator",
159
+ config() {
160
+ return { automd: defu(options.automd ?? {}, { generators: { "env": env(this) } }) };
161
+ }
162
+ },
163
+ {
164
+ name: "env:vite",
165
+ vite: { configResolved() {
166
+ return { envPrefix: this.config?.env?.prefix };
167
+ } }
168
+ },
169
+ src_default$2(options.automd)
170
+ ];
171
+ };
172
+ var src_default = plugin;
173
+
174
+ //#endregion
175
+ export { BaseEnv, BaseSecrets, EnvBuiltin, EnvDocs, EnvTypeDefinition, createEnvReflection, createReflectionResource, createSecretsReflection, createTemplateReflection, src_default as default, envBabelPlugin, formatEnvField, getEnvDefaultTypeDefinition, getEnvReflectionsPath, getEnvTypeReflectionsPath, getSecretsDefaultTypeDefinition, loadEnv, loadEnvFromContext, mergeEnvReflections, mergeSecretsReflections, plugin, readEnvReflection, readEnvTypeReflection, readSecretsReflection, reflectEnv, reflectSecrets, removeEnvPrefix, resolveRuntimeTypeFile, writeEnvReflection, writeEnvReflectionSync, writeEnvTypeReflection };
@@ -1 +1,45 @@
1
- const e=require(`../../../../_virtual/rolldown_runtime.cjs`),t=require(`../contexts/context.cjs`);let n=require(`@alloy-js/core/jsx-runtime`),r=require(`@alloy-js/core`),i=require(`@stryke/path/replace`);function a(e){let[{children:a,context:o,meta:s,basePath:c},l]=(0,r.splitProps)(e,[`children`,`context`,`meta`,`basePath`]),u=(0,r.ref)(o),d=(0,r.ref)(s??{}),f=(0,r.computed)(()=>c?(0,i.replacePath)(c,u.value.workspaceConfig.workspaceRoot):u.value.workspaceConfig.workspaceRoot);return(0,n.createComponent)(r.Output,(0,n.mergeProps)(l,{get basePath(){return f.value},get children(){return(0,n.createComponent)(t.PowerlinesContext.Provider,{value:{ref:u,meta:d},get children(){return(0,n.createComponent)(r.Show,{get when(){return!!u.value},children:a})}})}}))}exports.Output=a;
1
+ const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
+ const require_context = require('../contexts/context.cjs');
3
+ let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
4
+ let __alloy_js_core = require("@alloy-js/core");
5
+ let __stryke_path_replace = require("@stryke/path/replace");
6
+
7
+ //#region ../plugin-alloy/src/core/components/output.tsx
8
+ /**
9
+ * Output component for rendering the Powerlines plugin's output files via templates.
10
+ */
11
+ function Output(props) {
12
+ const [{ children, context, meta, basePath }, rest] = (0, __alloy_js_core.splitProps)(props, [
13
+ "children",
14
+ "context",
15
+ "meta",
16
+ "basePath"
17
+ ]);
18
+ const contextRef = (0, __alloy_js_core.ref)(context);
19
+ const metaRef = (0, __alloy_js_core.ref)(meta ?? {});
20
+ const basePathRef = (0, __alloy_js_core.computed)(() => basePath ? (0, __stryke_path_replace.replacePath)(basePath, contextRef.value.workspaceConfig.workspaceRoot) : contextRef.value.workspaceConfig.workspaceRoot);
21
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Output, (0, __alloy_js_core_jsx_runtime.mergeProps)(rest, {
22
+ get basePath() {
23
+ return basePathRef.value;
24
+ },
25
+ get children() {
26
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(require_context.PowerlinesContext.Provider, {
27
+ value: {
28
+ ref: contextRef,
29
+ meta: metaRef
30
+ },
31
+ get children() {
32
+ return (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
33
+ get when() {
34
+ return Boolean(contextRef.value);
35
+ },
36
+ children
37
+ });
38
+ }
39
+ });
40
+ }
41
+ }));
42
+ }
43
+
44
+ //#endregion
45
+ exports.Output = Output;
@@ -1 +1,44 @@
1
- import{PowerlinesContext as e}from"../contexts/context.mjs";import{createComponent as t,mergeProps as n}from"@alloy-js/core/jsx-runtime";import{Output as r,Show as i,computed as a,ref as o,splitProps as s}from"@alloy-js/core";import{replacePath as c}from"@stryke/path/replace";function l(l){let[{children:u,context:d,meta:f,basePath:p},m]=s(l,[`children`,`context`,`meta`,`basePath`]),h=o(d),g=o(f??{}),_=a(()=>p?c(p,h.value.workspaceConfig.workspaceRoot):h.value.workspaceConfig.workspaceRoot);return t(r,n(m,{get basePath(){return _.value},get children(){return t(e.Provider,{value:{ref:h,meta:g},get children(){return t(i,{get when(){return!!h.value},children:u})}})}}))}export{l as Output};
1
+ import { PowerlinesContext } from "../contexts/context.mjs";
2
+ import { createComponent, mergeProps } from "@alloy-js/core/jsx-runtime";
3
+ import { Output, Show, computed, ref, splitProps } from "@alloy-js/core";
4
+ import { replacePath } from "@stryke/path/replace";
5
+
6
+ //#region ../plugin-alloy/src/core/components/output.tsx
7
+ /**
8
+ * Output component for rendering the Powerlines plugin's output files via templates.
9
+ */
10
+ function Output$1(props) {
11
+ const [{ children, context, meta, basePath }, rest] = splitProps(props, [
12
+ "children",
13
+ "context",
14
+ "meta",
15
+ "basePath"
16
+ ]);
17
+ const contextRef = ref(context);
18
+ const metaRef = ref(meta ?? {});
19
+ const basePathRef = computed(() => basePath ? replacePath(basePath, contextRef.value.workspaceConfig.workspaceRoot) : contextRef.value.workspaceConfig.workspaceRoot);
20
+ return createComponent(Output, mergeProps(rest, {
21
+ get basePath() {
22
+ return basePathRef.value;
23
+ },
24
+ get children() {
25
+ return createComponent(PowerlinesContext.Provider, {
26
+ value: {
27
+ ref: contextRef,
28
+ meta: metaRef
29
+ },
30
+ get children() {
31
+ return createComponent(Show, {
32
+ get when() {
33
+ return Boolean(contextRef.value);
34
+ },
35
+ children
36
+ });
37
+ }
38
+ });
39
+ }
40
+ }));
41
+ }
42
+
43
+ //#endregion
44
+ export { Output$1 as Output };
@@ -1 +1,11 @@
1
- const e=require(`../../../../_virtual/rolldown_runtime.cjs`);let t=require(`@alloy-js/core`);const n=(0,t.createNamedContext)(`powerlines`);exports.PowerlinesContext=n;
1
+ const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
2
+ let __alloy_js_core = require("@alloy-js/core");
3
+
4
+ //#region ../plugin-alloy/src/core/contexts/context.ts
5
+ /**
6
+ * The Powerlines context used in template rendering.
7
+ */
8
+ const PowerlinesContext = (0, __alloy_js_core.createNamedContext)("powerlines");
9
+
10
+ //#endregion
11
+ exports.PowerlinesContext = PowerlinesContext;
@@ -1 +1,10 @@
1
- import{createNamedContext as e}from"@alloy-js/core";const t=e(`powerlines`);export{t as PowerlinesContext};
1
+ import { createNamedContext } from "@alloy-js/core";
2
+
3
+ //#region ../plugin-alloy/src/core/contexts/context.ts
4
+ /**
5
+ * The Powerlines context used in template rendering.
6
+ */
7
+ const PowerlinesContext = createNamedContext("powerlines");
8
+
9
+ //#endregion
10
+ export { PowerlinesContext };