@powerlines/plugin-env 0.13.4 → 0.13.6

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 (63) hide show
  1. package/dist/babel/index.cjs +1 -0
  2. package/dist/babel/index.d.cts +30 -0
  3. package/dist/babel/index.d.ts +30 -0
  4. package/dist/babel/index.js +1 -0
  5. package/dist/babel/plugin.cjs +19 -0
  6. package/dist/babel/plugin.d.cts +33 -0
  7. package/dist/babel/plugin.d.ts +33 -0
  8. package/dist/babel/plugin.js +19 -0
  9. package/dist/chunk-FBBMZ4NC.cjs +7 -0
  10. package/dist/chunk-UCUR73HG.js +7 -0
  11. package/dist/components/env.cjs +40 -0
  12. package/dist/components/env.d.cts +106 -0
  13. package/dist/components/env.d.ts +106 -0
  14. package/dist/components/env.js +40 -0
  15. package/dist/components/index.cjs +1 -0
  16. package/dist/components/index.d.cts +10 -0
  17. package/dist/components/index.d.ts +10 -0
  18. package/dist/components/index.js +1 -0
  19. package/dist/helpers/index.cjs +1 -0
  20. package/dist/helpers/index.d.cts +34 -0
  21. package/dist/helpers/index.d.ts +34 -0
  22. package/dist/helpers/index.js +1 -0
  23. package/dist/helpers/load.cjs +7 -0
  24. package/dist/helpers/load.d.cts +59 -0
  25. package/dist/helpers/load.d.ts +59 -0
  26. package/dist/helpers/load.js +7 -0
  27. package/dist/helpers/persistence.cjs +7 -0
  28. package/dist/helpers/persistence.d.cts +107 -0
  29. package/dist/helpers/persistence.d.ts +107 -0
  30. package/dist/helpers/persistence.js +7 -0
  31. package/dist/helpers/reflect.cjs +7 -0
  32. package/dist/helpers/reflect.d.cts +71 -0
  33. package/dist/helpers/reflect.d.ts +71 -0
  34. package/dist/helpers/reflect.js +7 -0
  35. package/dist/helpers/source-file-env.cjs +7 -0
  36. package/dist/helpers/source-file-env.d.cts +7 -0
  37. package/dist/helpers/source-file-env.d.ts +7 -0
  38. package/dist/helpers/source-file-env.js +7 -0
  39. package/dist/helpers/template-helpers.cjs +7 -0
  40. package/dist/helpers/template-helpers.d.cts +40 -0
  41. package/dist/helpers/template-helpers.d.ts +40 -0
  42. package/dist/helpers/template-helpers.js +7 -0
  43. package/dist/index.cjs +22 -0
  44. package/dist/index.d.cts +70 -0
  45. package/dist/index.d.ts +70 -0
  46. package/dist/index.js +22 -0
  47. package/dist/runtime-CUeIsMV9.d.ts +1753 -0
  48. package/dist/runtime-DEhb6gxi.d.cts +1753 -0
  49. package/dist/types/index.cjs +1 -0
  50. package/dist/types/index.d.cts +29 -0
  51. package/dist/types/index.d.ts +29 -0
  52. package/dist/types/index.js +1 -0
  53. package/dist/types/plugin.cjs +1 -0
  54. package/dist/types/plugin.d.cts +1727 -0
  55. package/dist/types/plugin.d.ts +1727 -0
  56. package/dist/types/plugin.js +0 -0
  57. package/dist/types/runtime.cjs +1 -0
  58. package/dist/types/runtime.d.cts +24 -0
  59. package/dist/types/runtime.d.ts +24 -0
  60. package/dist/types/runtime.js +0 -0
  61. package/dist/vfs-Bl84Hw2V.d.cts +393 -0
  62. package/dist/vfs-Bl84Hw2V.d.ts +393 -0
  63. package/package.json +75 -81
@@ -0,0 +1,7 @@
1
+ import {a}from'../chunk-UCUR73HG.js';import {ENV_PREFIXES}from'@stryke/env/types';import {camelCase}from'@stryke/string-format/camel-case';import {isString}from'@stryke/type-checks/is-string';/*****************************************
2
+ *
3
+ * ⚡ Built by Storm Software
4
+ *
5
+ *****************************************/
6
+
7
+ function i(r){if(isString(r)){let t=ENV_PREFIXES.reduce((e,n)=>(e.startsWith(n)&&(e=e.slice(n.length)),e),r.toUpperCase());for(;t.startsWith("_");)t=t.slice(1);return t}return Object.keys(r).reduce((t,e)=>{const n=i(e);return n&&(t[n]=r[e]),t},{})}a(i,"removeEnvPrefix");function f(r){return camelCase(i(r))}a(f,"formatEnvField");export{f as formatEnvField,i as removeEnvPrefix};
@@ -0,0 +1,7 @@
1
+ 'use strict';var chunkFBBMZ4NC_cjs=require('../chunk-FBBMZ4NC.cjs'),titleCase=require('@stryke/string-format/title-case'),persistence=require('./persistence');/*****************************************
2
+ *
3
+ * ⚡ Built by Storm Software
4
+ *
5
+ *****************************************/
6
+
7
+ async function P(a,l){const i=await persistence.readEnvTypeReflection(a,l);return i.getProperties().forEach(e=>{e.getAlias().filter(Boolean).forEach(t=>{i.addProperty({name:t,optional:e.isOptional()?true:void 0,readonly:e.isReadonly()?true:void 0,description:e.getDescription(),visibility:e.getVisibility(),type:e.getType(),default:e.getDefaultValue(),tags:{hidden:e.isHidden(),ignore:e.isIgnored(),internal:e.isInternal(),alias:e.getAlias().filter(s=>s!==t).concat(e.name),title:e.getTitle()||titleCase.titleCase(e.name),readonly:e.isReadonly(),permission:e.getPermission(),domain:e.getDomain()}});});}),i}chunkFBBMZ4NC_cjs.a(P,"createTemplateReflection");exports.createTemplateReflection=P;
@@ -0,0 +1,40 @@
1
+ import { ReflectionClass } from '@deepkit/type';
2
+ import { EnvPluginContext, EnvType } from '../types/plugin.cjs';
3
+ import '@alloy-js/core/jsx-runtime';
4
+ import '@stryke/capnp';
5
+ import '../runtime-DEhb6gxi.cjs';
6
+ import '@stryke/env/get-env-paths';
7
+ import '@stryke/types/package-json';
8
+ import 'jiti';
9
+ import 'oxc-parser';
10
+ import 'semver';
11
+ import 'unplugin';
12
+ import '@babel/core';
13
+ import '@storm-software/build-tools/types';
14
+ import '@storm-software/config-tools/types';
15
+ import '@storm-software/config/types';
16
+ import '@stryke/types/base';
17
+ import '@stryke/types/configuration';
18
+ import '@stryke/types/file';
19
+ import 'vite';
20
+ import '@babel/helper-plugin-utils';
21
+ import '@stryke/types/array';
22
+ import '@stryke/types/tsconfig';
23
+ import 'typescript';
24
+ import '../vfs-Bl84Hw2V.cjs';
25
+ import '@stryke/json/types';
26
+ import 'memfs';
27
+ import 'node:fs';
28
+ import 'unionfs';
29
+ import '@stryke/env/types';
30
+
31
+ /**
32
+ * Creates the reflection data used when generating runtime template files.
33
+ *
34
+ * @param context - The context for the configuration plugin.
35
+ * @param name - The name of the configuration template.
36
+ * @returns The reflection for the specified configuration template.
37
+ */
38
+ declare function createTemplateReflection(context: EnvPluginContext, name?: EnvType): Promise<ReflectionClass<any>>;
39
+
40
+ export { createTemplateReflection };
@@ -0,0 +1,40 @@
1
+ import { ReflectionClass } from '@deepkit/type';
2
+ import { EnvPluginContext, EnvType } from '../types/plugin.js';
3
+ import '@alloy-js/core/jsx-runtime';
4
+ import '@stryke/capnp';
5
+ import '../runtime-CUeIsMV9.js';
6
+ import '@stryke/env/get-env-paths';
7
+ import '@stryke/types/package-json';
8
+ import 'jiti';
9
+ import 'oxc-parser';
10
+ import 'semver';
11
+ import 'unplugin';
12
+ import '@babel/core';
13
+ import '@storm-software/build-tools/types';
14
+ import '@storm-software/config-tools/types';
15
+ import '@storm-software/config/types';
16
+ import '@stryke/types/base';
17
+ import '@stryke/types/configuration';
18
+ import '@stryke/types/file';
19
+ import 'vite';
20
+ import '@babel/helper-plugin-utils';
21
+ import '@stryke/types/array';
22
+ import '@stryke/types/tsconfig';
23
+ import 'typescript';
24
+ import '../vfs-Bl84Hw2V.js';
25
+ import '@stryke/json/types';
26
+ import 'memfs';
27
+ import 'node:fs';
28
+ import 'unionfs';
29
+ import '@stryke/env/types';
30
+
31
+ /**
32
+ * Creates the reflection data used when generating runtime template files.
33
+ *
34
+ * @param context - The context for the configuration plugin.
35
+ * @param name - The name of the configuration template.
36
+ * @returns The reflection for the specified configuration template.
37
+ */
38
+ declare function createTemplateReflection(context: EnvPluginContext, name?: EnvType): Promise<ReflectionClass<any>>;
39
+
40
+ export { createTemplateReflection };
@@ -0,0 +1,7 @@
1
+ import {a}from'../chunk-UCUR73HG.js';import {titleCase}from'@stryke/string-format/title-case';import {readEnvTypeReflection}from'./persistence';/*****************************************
2
+ *
3
+ * ⚡ Built by Storm Software
4
+ *
5
+ *****************************************/
6
+
7
+ async function R(a,l){const i=await readEnvTypeReflection(a,l);return i.getProperties().forEach(e=>{e.getAlias().filter(Boolean).forEach(t=>{i.addProperty({name:t,optional:e.isOptional()?true:void 0,readonly:e.isReadonly()?true:void 0,description:e.getDescription(),visibility:e.getVisibility(),type:e.getType(),default:e.getDefaultValue(),tags:{hidden:e.isHidden(),ignore:e.isIgnored(),internal:e.isInternal(),alias:e.getAlias().filter(s=>s!==t).concat(e.name),title:e.getTitle()||titleCase(e.name),readonly:e.isReadonly(),permission:e.getPermission(),domain:e.getDomain()}});});}),i}a(R,"createTemplateReflection");export{R as createTemplateReflection};
package/dist/index.cjs ADDED
@@ -0,0 +1,22 @@
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});require('./chunk-FBBMZ4NC.cjs');var jsxRuntime=require('@alloy-js/core/jsx-runtime'),createPlugin=require('@powerlines/alloy/create-plugin'),type=require('@powerlines/deepkit/vendor/type'),A=require('@powerlines/plugin-babel'),types$1=require('@storm-software/config-tools/types'),parseTypeDefinition=require('@stryke/convert/parse-type-definition'),toArray=require('@stryke/convert/to-array'),types$2=require('@stryke/env/types'),exists=require('@stryke/fs/exists'),helpers$1=require('@stryke/fs/helpers'),isParentPath=require('@stryke/path/is-parent-path'),join=require('@stryke/path/join'),constantCase=require('@stryke/string-format/constant-case'),y=require('defu'),writeFile=require('powerlines/lib/utilities/write-file'),plugin=require('./babel/plugin'),env=require('./components/env'),load=require('./helpers/load'),persistence=require('./helpers/persistence'),reflect=require('./helpers/reflect'),babel=require('./babel'),components=require('./components'),helpers=require('./helpers'),types=require('./types');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var A__default=/*#__PURE__*/_interopDefault(A);var y__default=/*#__PURE__*/_interopDefault(y);/*****************************************
2
+ *
3
+ * ⚡ Built by Storm Software
4
+ *
5
+ *****************************************/
6
+
7
+ const O=createPlugin.createAlloyPlugin(R=>({name:"env",dependsOn:[A__default.default()],async config(){this.log(types$1.LogLevelLabel.TRACE,"Providing default configuration for the Powerlines `env` build plugin.");const e={env:y__default.default(R,{types:{},prefix:[]}),transform:{babel:{plugins:[plugin.envBabelPlugin]}}};if(e.env.types)e.env.types=parseTypeDefinition.parseTypeDefinition(e.env.types);else {this.log(types$1.LogLevelLabel.WARN,"The `env.types` configuration parameter was not provided. Please ensure this is expected.");const t=await persistence.getEnvDefaultTypeDefinition(this);e.env.types=parseTypeDefinition.parseTypeDefinition(`${t.file}#${t.name}`);}if(e.env.secrets)e.env.secrets=parseTypeDefinition.parseTypeDefinition(e.env.secrets);else {const t=await persistence.getSecretsDefaultTypeDefinition(this);e.env.secrets=parseTypeDefinition.parseTypeDefinition(`${t.file}#${t.name}`);}return e.env.prefix=toArray.toArray(e.env.prefix??[]).reduce((t,n)=>{const i=constantCase.constantCase(n);return t.includes(i)||t.push(i),t},[...types$2.ENV_PREFIXES,"POWERLINES_"]),e.env.prefix=e.env.prefix.reduce((t,n)=>(t.includes(n.replace(/_$/g,""))||t.push(n.replace(/_$/g,"")),t),[]),e},async configResolved(){if(this.log(types$1.LogLevelLabel.TRACE,"Environment plugin configuration has been resolved for the Powerlines project."),this.config.env.inject??=this.config.projectType==="application",this.env=y__default.default({parsed:await load.loadEnv(this,this.config.env)},this.env??{},{types:{env:{}},used:{env:{},secrets:{}},parsed:{},injected:{}}),this.config.command!=="prepare"&&this.persistedMeta?.checksum===this.meta.checksum&&exists.existsSync(persistence.getEnvTypeReflectionsPath(this,"env")))this.log(types$1.LogLevelLabel.TRACE,"Skipping reflection initialization as the meta checksum has not changed."),this.env.types.env=await persistence.readEnvTypeReflection(this,"env"),exists.existsSync(persistence.getEnvReflectionsPath(this,"env"))&&(this.env.used.env=await persistence.readEnvReflection(this)),exists.existsSync(persistence.getEnvTypeReflectionsPath(this,"secrets"))&&(this.env.types.secrets=await persistence.readEnvTypeReflection(this,"secrets")),exists.existsSync(persistence.getEnvReflectionsPath(this,"secrets"))&&(this.env.used.secrets=await persistence.readSecretsReflection(this));else {if(this.env.types.env=await reflect.reflectEnv(this,this.config.env.types?.file?isParentPath.isParentPath(this.config.env.types?.file,this.workspaceConfig.workspaceRoot)?this.config.env.types?.file:join.joinPaths(this.config.projectRoot,this.config.env.types?.file):void 0,this.config.env.types?.name),!this.env.types.env)throw new Error("Failed to find the environment configuration type reflection in the context.");if(await persistence.writeEnvTypeReflection(this,this.env.types.env,"env"),this.env.types.secrets=await reflect.reflectSecrets(this,this.config.env.secrets?.file?isParentPath.isParentPath(this.config.env.secrets?.file,this.workspaceConfig.workspaceRoot)?this.config.env.secrets?.file:join.joinPaths(this.config.projectRoot,this.config.env.secrets?.file):void 0,this.config.env.secrets?.name),!this.env.types.secrets)throw new Error("Failed to find the secrets configuration type reflection in the context.");await persistence.writeEnvTypeReflection(this,this.env.types.secrets,"secrets"),this.log(types$1.LogLevelLabel.TRACE,`Resolved ${this.env.types.env.getProperties().length??0} environment configuration parameters and ${this.env.types.secrets?.getProperties().length??0} secret configuration parameters`);const e=this.env.types.env.getProperties().filter(t=>t.getAlias().length>0);Object.entries(await load.loadEnv(this,this.config.env)).forEach(([t,n])=>{const i=this.config.env.prefix.reduce((p,g)=>t.replace(/_$/g,"").startsWith(g)?t.replace(/_$/g,"").slice(g.length):p,t),c=e.find(p=>p?.getAlias().reverse().includes(i));(this.env.types.env?.hasProperty(i)||c)&&this.env.types.env.getProperty(i).setDefaultValue(n);}),this.env.used.env=new type.ReflectionClass({kind:type.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 persistence.writeEnvReflection(this,this.env.used.env,"env"),this.env.types.secrets&&(await persistence.writeEnvTypeReflection(this,this.env.types.secrets,"secrets"),this.env.used.secrets=new type.ReflectionClass({kind:type.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 persistence.writeEnvReflection(this,this.env.used.secrets,"secrets"));}},render(){const e=this;return this.log(types$1.LogLevelLabel.TRACE,"Preparing the Environment runtime artifacts for the Powerlines project."),jsxRuntime.createComponent(env.EnvBuiltin,{get defaultConfig(){return e.config.env.defaultConfig}})},async docs(){this.log(types$1.LogLevelLabel.TRACE,"Writing Environment documentation for the Powerlines project artifacts.");const e=join.joinPaths(this.config.projectRoot,"docs","generated");exists.existsSync(e)||await helpers$1.createDirectory(e);const t=await persistence.readEnvTypeReflection(this,"env"),n=join.joinPaths(e,"env.md");this.log(types$1.LogLevelLabel.TRACE,`Documenting environment variables configuration in "${n}"`),await writeFile.writeFile(this.log,n,`<!-- Generated by Powerlines -->
8
+
9
+ # Environment variables configuration
10
+
11
+ 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.
12
+
13
+ ## Environment Configuration
14
+
15
+ The below list of environment variables 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.
16
+
17
+ | Name | Description | Type | Default Value | Required |
18
+ | ---- | ----------- | ---- | ------------- | :------: |
19
+ ${t.getProperties().filter(i=>i.getNameAsString()!=="__STORM_INJECTED__").sort((i,c)=>i.getNameAsString().localeCompare(c.getNameAsString())).map(i=>`| ${i.getNameAsString().trim()} | ${(i.getDescription()?.replaceAll("\r","")?.replaceAll(`
20
+ `,"")??"").trim()} | ${type.stringifyType(i.getType()).trim().replaceAll(" | ",", or ")} | ${i.hasDefault()?String(i.getDefaultValue())?.includes('"')?i.getDefaultValue():`\`${i.getDefaultValue()}\``:""} | ${i.isValueRequired()?"":"\u2714"} |`).join(`
21
+ `)}
22
+ `);},async buildEnd(){const e=persistence.getEnvReflectionsPath(this,"env");this.log(types$1.LogLevelLabel.TRACE,`Writing env reflection types to ${e}.`),await persistence.writeEnvReflection(this,this.env.used.env,"env");}}));var ae=O;exports.default=ae;exports.plugin=O;Object.keys(babel).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return babel[k]}})});Object.keys(components).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return components[k]}})});Object.keys(helpers).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return helpers[k]}})});Object.keys(types).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return types[k]}})});
@@ -0,0 +1,70 @@
1
+ import { P as PluginContext, b as Plugin } from './runtime-DEhb6gxi.cjs';
2
+ export { E as EnvInterface, S as SecretsInterface } from './runtime-DEhb6gxi.cjs';
3
+ import { Children } from '@alloy-js/core/jsx-runtime';
4
+ import { PrintTreeOptions } from '@alloy-js/core';
5
+ import { EnvPluginContext, EnvPluginResolvedConfig } from './types/plugin.cjs';
6
+ export { EnvPluginOptions, EnvPluginUserConfig, EnvType } from './types/plugin.cjs';
7
+ export { envBabelPlugin } from './babel/plugin.cjs';
8
+ export { EnvBuiltin, EnvBuiltinProps, EnvTypeDefinition } from './components/env.cjs';
9
+ export { loadEnv, loadEnvFromContext } from './helpers/load.cjs';
10
+ export { getEnvDefaultTypeDefinition, getEnvReflectionsPath, getEnvTypeReflectionsPath, getSecretsDefaultTypeDefinition, readEnvReflection, readEnvTypeReflection, readSecretsReflection, resolveRuntimeTypeFile, writeEnvReflection, writeEnvReflectionSync, writeEnvTypeReflection } from './helpers/persistence.cjs';
11
+ export { BaseEnv, BaseSecrets, CreateEnvReflectionOptions, createEnvReflection, createSecretsReflection, mergeEnvReflections, mergeSecretsReflections, reflectEnv, reflectSecrets } from './helpers/reflect.cjs';
12
+ export { formatEnvField, removeEnvPrefix } from './helpers/source-file-env.cjs';
13
+ export { createTemplateReflection } from './helpers/template-helpers.cjs';
14
+ import '@stryke/env/get-env-paths';
15
+ import '@stryke/types/package-json';
16
+ import 'jiti';
17
+ import 'oxc-parser';
18
+ import 'semver';
19
+ import 'unplugin';
20
+ import '@babel/core';
21
+ import '@storm-software/build-tools/types';
22
+ import '@storm-software/config-tools/types';
23
+ import '@storm-software/config/types';
24
+ import '@stryke/types/base';
25
+ import '@stryke/types/configuration';
26
+ import '@stryke/types/file';
27
+ import 'vite';
28
+ import '@babel/helper-plugin-utils';
29
+ import '@stryke/types/array';
30
+ import '@stryke/types/tsconfig';
31
+ import 'typescript';
32
+ import './vfs-Bl84Hw2V.cjs';
33
+ import '@stryke/json/types';
34
+ import 'memfs';
35
+ import 'node:fs';
36
+ import 'unionfs';
37
+ import '@deepkit/type';
38
+ import '@stryke/capnp';
39
+ import '@stryke/env/types';
40
+ import '@alloy-js/typescript';
41
+
42
+ type PluginPluginAlloyOptions = Partial<PrintTreeOptions> & {
43
+ /**
44
+ * If true, the Alloy framework is used to generate JSON output files.
45
+ *
46
+ * @defaultValue false
47
+ */
48
+ generatesJson?: boolean;
49
+ /**
50
+ * If true, the Alloy framework is used to generate Markdown output files.
51
+ *
52
+ * @defaultValue false
53
+ */
54
+ generatesMarkdown?: boolean;
55
+ };
56
+
57
+ interface AlloyPluginOptions {
58
+ alloy?: PluginPluginAlloyOptions;
59
+ }
60
+ type AlloyPluginBuilderResult<TContext extends PluginContext = PluginContext> = Plugin<TContext> & {
61
+ render: (this: TContext) => Children;
62
+ };
63
+ type AlloyPluginBuilder<TContext extends PluginContext = PluginContext, TOptions = any> = (options: TOptions) => AlloyPluginBuilderResult<TContext>;
64
+
65
+ /**
66
+ * A Powerlines plugin to inject environment variables into the source code.
67
+ */
68
+ declare const plugin: (options: Parameters<AlloyPluginBuilder<EnvPluginContext<EnvPluginResolvedConfig>>>[0] & AlloyPluginOptions) => Plugin<EnvPluginContext<EnvPluginResolvedConfig>>;
69
+
70
+ export { EnvPluginContext, EnvPluginResolvedConfig, plugin as default, plugin };
@@ -0,0 +1,70 @@
1
+ import { P as PluginContext, b as Plugin } from './runtime-CUeIsMV9.js';
2
+ export { E as EnvInterface, S as SecretsInterface } from './runtime-CUeIsMV9.js';
3
+ import { Children } from '@alloy-js/core/jsx-runtime';
4
+ import { PrintTreeOptions } from '@alloy-js/core';
5
+ import { EnvPluginContext, EnvPluginResolvedConfig } from './types/plugin.js';
6
+ export { EnvPluginOptions, EnvPluginUserConfig, EnvType } from './types/plugin.js';
7
+ export { envBabelPlugin } from './babel/plugin.js';
8
+ export { EnvBuiltin, EnvBuiltinProps, EnvTypeDefinition } from './components/env.js';
9
+ export { loadEnv, loadEnvFromContext } from './helpers/load.js';
10
+ export { getEnvDefaultTypeDefinition, getEnvReflectionsPath, getEnvTypeReflectionsPath, getSecretsDefaultTypeDefinition, readEnvReflection, readEnvTypeReflection, readSecretsReflection, resolveRuntimeTypeFile, writeEnvReflection, writeEnvReflectionSync, writeEnvTypeReflection } from './helpers/persistence.js';
11
+ export { BaseEnv, BaseSecrets, CreateEnvReflectionOptions, createEnvReflection, createSecretsReflection, mergeEnvReflections, mergeSecretsReflections, reflectEnv, reflectSecrets } from './helpers/reflect.js';
12
+ export { formatEnvField, removeEnvPrefix } from './helpers/source-file-env.js';
13
+ export { createTemplateReflection } from './helpers/template-helpers.js';
14
+ import '@stryke/env/get-env-paths';
15
+ import '@stryke/types/package-json';
16
+ import 'jiti';
17
+ import 'oxc-parser';
18
+ import 'semver';
19
+ import 'unplugin';
20
+ import '@babel/core';
21
+ import '@storm-software/build-tools/types';
22
+ import '@storm-software/config-tools/types';
23
+ import '@storm-software/config/types';
24
+ import '@stryke/types/base';
25
+ import '@stryke/types/configuration';
26
+ import '@stryke/types/file';
27
+ import 'vite';
28
+ import '@babel/helper-plugin-utils';
29
+ import '@stryke/types/array';
30
+ import '@stryke/types/tsconfig';
31
+ import 'typescript';
32
+ import './vfs-Bl84Hw2V.js';
33
+ import '@stryke/json/types';
34
+ import 'memfs';
35
+ import 'node:fs';
36
+ import 'unionfs';
37
+ import '@deepkit/type';
38
+ import '@stryke/capnp';
39
+ import '@stryke/env/types';
40
+ import '@alloy-js/typescript';
41
+
42
+ type PluginPluginAlloyOptions = Partial<PrintTreeOptions> & {
43
+ /**
44
+ * If true, the Alloy framework is used to generate JSON output files.
45
+ *
46
+ * @defaultValue false
47
+ */
48
+ generatesJson?: boolean;
49
+ /**
50
+ * If true, the Alloy framework is used to generate Markdown output files.
51
+ *
52
+ * @defaultValue false
53
+ */
54
+ generatesMarkdown?: boolean;
55
+ };
56
+
57
+ interface AlloyPluginOptions {
58
+ alloy?: PluginPluginAlloyOptions;
59
+ }
60
+ type AlloyPluginBuilderResult<TContext extends PluginContext = PluginContext> = Plugin<TContext> & {
61
+ render: (this: TContext) => Children;
62
+ };
63
+ type AlloyPluginBuilder<TContext extends PluginContext = PluginContext, TOptions = any> = (options: TOptions) => AlloyPluginBuilderResult<TContext>;
64
+
65
+ /**
66
+ * A Powerlines plugin to inject environment variables into the source code.
67
+ */
68
+ declare const plugin: (options: Parameters<AlloyPluginBuilder<EnvPluginContext<EnvPluginResolvedConfig>>>[0] & AlloyPluginOptions) => Plugin<EnvPluginContext<EnvPluginResolvedConfig>>;
69
+
70
+ export { EnvPluginContext, EnvPluginResolvedConfig, plugin as default, plugin };
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ import'./chunk-UCUR73HG.js';import {createComponent}from'@alloy-js/core/jsx-runtime';import {createAlloyPlugin}from'@powerlines/alloy/create-plugin';import {stringifyType,ReflectionClass,ReflectionKind}from'@powerlines/deepkit/vendor/type';import A from'@powerlines/plugin-babel';import {LogLevelLabel}from'@storm-software/config-tools/types';import {parseTypeDefinition}from'@stryke/convert/parse-type-definition';import {toArray}from'@stryke/convert/to-array';import {ENV_PREFIXES}from'@stryke/env/types';import {existsSync}from'@stryke/fs/exists';import {createDirectory}from'@stryke/fs/helpers';import {isParentPath}from'@stryke/path/is-parent-path';import {joinPaths}from'@stryke/path/join';import {constantCase}from'@stryke/string-format/constant-case';import y from'defu';import {writeFile}from'powerlines/lib/utilities/write-file';import {envBabelPlugin}from'./babel/plugin';import {EnvBuiltin}from'./components/env';import {loadEnv}from'./helpers/load';import {getEnvReflectionsPath,writeEnvReflection,readEnvTypeReflection,getEnvTypeReflectionsPath,readEnvReflection,readSecretsReflection,writeEnvTypeReflection,getEnvDefaultTypeDefinition,getSecretsDefaultTypeDefinition}from'./helpers/persistence';import {reflectEnv,reflectSecrets}from'./helpers/reflect';export*from'./babel';export*from'./components';export*from'./helpers';export*from'./types';/*****************************************
2
+ *
3
+ * ⚡ Built by Storm Software
4
+ *
5
+ *****************************************/
6
+
7
+ const O=createAlloyPlugin(R=>({name:"env",dependsOn:[A()],async config(){this.log(LogLevelLabel.TRACE,"Providing default configuration for the Powerlines `env` build plugin.");const e={env:y(R,{types:{},prefix:[]}),transform:{babel:{plugins:[envBabelPlugin]}}};if(e.env.types)e.env.types=parseTypeDefinition(e.env.types);else {this.log(LogLevelLabel.WARN,"The `env.types` configuration parameter was not provided. Please ensure this is expected.");const t=await getEnvDefaultTypeDefinition(this);e.env.types=parseTypeDefinition(`${t.file}#${t.name}`);}if(e.env.secrets)e.env.secrets=parseTypeDefinition(e.env.secrets);else {const t=await getSecretsDefaultTypeDefinition(this);e.env.secrets=parseTypeDefinition(`${t.file}#${t.name}`);}return e.env.prefix=toArray(e.env.prefix??[]).reduce((t,n)=>{const i=constantCase(n);return t.includes(i)||t.push(i),t},[...ENV_PREFIXES,"POWERLINES_"]),e.env.prefix=e.env.prefix.reduce((t,n)=>(t.includes(n.replace(/_$/g,""))||t.push(n.replace(/_$/g,"")),t),[]),e},async configResolved(){if(this.log(LogLevelLabel.TRACE,"Environment plugin configuration has been resolved for the Powerlines project."),this.config.env.inject??=this.config.projectType==="application",this.env=y({parsed:await loadEnv(this,this.config.env)},this.env??{},{types:{env:{}},used:{env:{},secrets:{}},parsed:{},injected:{}}),this.config.command!=="prepare"&&this.persistedMeta?.checksum===this.meta.checksum&&existsSync(getEnvTypeReflectionsPath(this,"env")))this.log(LogLevelLabel.TRACE,"Skipping reflection initialization as the meta checksum has not changed."),this.env.types.env=await readEnvTypeReflection(this,"env"),existsSync(getEnvReflectionsPath(this,"env"))&&(this.env.used.env=await readEnvReflection(this)),existsSync(getEnvTypeReflectionsPath(this,"secrets"))&&(this.env.types.secrets=await readEnvTypeReflection(this,"secrets")),existsSync(getEnvReflectionsPath(this,"secrets"))&&(this.env.used.secrets=await readSecretsReflection(this));else {if(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),!this.env.types.env)throw new Error("Failed to find the environment configuration type reflection in the context.");if(await writeEnvTypeReflection(this,this.env.types.env,"env"),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),!this.env.types.secrets)throw new Error("Failed to find the secrets configuration type reflection in the context.");await writeEnvTypeReflection(this,this.env.types.secrets,"secrets"),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`);const e=this.env.types.env.getProperties().filter(t=>t.getAlias().length>0);Object.entries(await loadEnv(this,this.config.env)).forEach(([t,n])=>{const i=this.config.env.prefix.reduce((p,g)=>t.replace(/_$/g,"").startsWith(g)?t.replace(/_$/g,"").slice(g.length):p,t),c=e.find(p=>p?.getAlias().reverse().includes(i));(this.env.types.env?.hasProperty(i)||c)&&this.env.types.env.getProperty(i).setDefaultValue(n);}),this.env.used.env=new ReflectionClass({kind: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 writeEnvReflection(this,this.env.used.env,"env"),this.env.types.secrets&&(await writeEnvTypeReflection(this,this.env.types.secrets,"secrets"),this.env.used.secrets=new ReflectionClass({kind: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 writeEnvReflection(this,this.env.used.secrets,"secrets"));}},render(){const e=this;return this.log(LogLevelLabel.TRACE,"Preparing the Environment runtime artifacts for the Powerlines project."),createComponent(EnvBuiltin,{get defaultConfig(){return e.config.env.defaultConfig}})},async docs(){this.log(LogLevelLabel.TRACE,"Writing Environment documentation for the Powerlines project artifacts.");const e=joinPaths(this.config.projectRoot,"docs","generated");existsSync(e)||await createDirectory(e);const t=await readEnvTypeReflection(this,"env"),n=joinPaths(e,"env.md");this.log(LogLevelLabel.TRACE,`Documenting environment variables configuration in "${n}"`),await writeFile(this.log,n,`<!-- Generated by Powerlines -->
8
+
9
+ # Environment variables configuration
10
+
11
+ 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.
12
+
13
+ ## Environment Configuration
14
+
15
+ The below list of environment variables 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.
16
+
17
+ | Name | Description | Type | Default Value | Required |
18
+ | ---- | ----------- | ---- | ------------- | :------: |
19
+ ${t.getProperties().filter(i=>i.getNameAsString()!=="__STORM_INJECTED__").sort((i,c)=>i.getNameAsString().localeCompare(c.getNameAsString())).map(i=>`| ${i.getNameAsString().trim()} | ${(i.getDescription()?.replaceAll("\r","")?.replaceAll(`
20
+ `,"")??"").trim()} | ${stringifyType(i.getType()).trim().replaceAll(" | ",", or ")} | ${i.hasDefault()?String(i.getDefaultValue())?.includes('"')?i.getDefaultValue():`\`${i.getDefaultValue()}\``:""} | ${i.isValueRequired()?"":"\u2714"} |`).join(`
21
+ `)}
22
+ `);},async buildEnd(){const e=getEnvReflectionsPath(this,"env");this.log(LogLevelLabel.TRACE,`Writing env reflection types to ${e}.`),await writeEnvReflection(this,this.env.used.env,"env");}}));var ce=O;export{ce as default,O as plugin};