@powerlines/plugin-nodejs 0.1.0 → 0.1.1
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.
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/components/env.cjs +188 -2
- package/dist/components/env.d.cts +9 -2
- package/dist/components/env.d.mts +9 -2
- package/dist/components/env.mjs +185 -1
- package/dist/components/index.cjs +2 -3
- package/dist/components/index.d.cts +1 -3
- package/dist/components/index.d.mts +1 -3
- package/dist/components/index.mjs +1 -2
- package/dist/deepkit/schemas/reflection.cjs +3940 -0
- package/dist/{plugin-D7kBf19k.d.cts → deepkit/schemas/reflection.d.cts} +1 -1078
- package/dist/{plugin-JL1BtFku.d.mts → deepkit/schemas/reflection.d.mts} +59 -1136
- package/dist/deepkit/schemas/reflection.mjs +3938 -0
- package/dist/deepkit/schemas/reflection2.cjs +4112 -0
- package/dist/deepkit/schemas/reflection2.mjs +4110 -0
- package/dist/deepkit/src/capnp.cjs +913 -0
- package/dist/deepkit/src/capnp.mjs +911 -0
- package/dist/deepkit/src/esbuild-plugin.cjs +47 -0
- package/dist/deepkit/src/esbuild-plugin.mjs +46 -0
- package/dist/deepkit/src/reflect-type.cjs +22 -0
- package/dist/deepkit/src/reflect-type.mjs +20 -0
- package/dist/deepkit/src/resolve-reflections.cjs +16 -0
- package/dist/deepkit/src/resolve-reflections.mjs +15 -0
- package/dist/deepkit/src/transformer.cjs +52 -0
- package/dist/deepkit/src/transformer.mjs +49 -0
- package/dist/deepkit/src/transpile.cjs +29 -0
- package/dist/deepkit/src/transpile.mjs +27 -0
- package/dist/deepkit/src/types.d.cts +10 -0
- package/dist/deepkit/src/types.d.mts +10 -0
- package/dist/deepkit/src/utilities.cjs +66 -0
- package/dist/deepkit/src/utilities.mjs +65 -0
- package/dist/index.cjs +14 -813
- package/dist/index.d.cts +5 -5
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +11 -803
- package/dist/plugin-alloy/src/core/components/output.cjs +45 -0
- package/dist/plugin-alloy/src/core/components/output.mjs +44 -0
- package/dist/plugin-alloy/src/core/components/single-line-comment.cjs +22 -0
- package/dist/plugin-alloy/src/core/components/single-line-comment.mjs +21 -0
- package/dist/plugin-alloy/src/core/components/source-file.cjs +64 -0
- package/dist/plugin-alloy/src/core/components/source-file.d.cts +23 -0
- package/dist/plugin-alloy/src/core/components/source-file.d.mts +23 -0
- package/dist/plugin-alloy/src/core/components/source-file.mjs +62 -0
- package/dist/plugin-alloy/src/core/contexts/context.cjs +60 -0
- package/dist/plugin-alloy/src/core/contexts/context.mjs +54 -0
- package/dist/plugin-alloy/src/core/contexts/index.cjs +2 -0
- package/dist/plugin-alloy/src/core/contexts/index.mjs +4 -0
- package/dist/plugin-alloy/src/core/contexts/reflection.cjs +46 -0
- package/dist/plugin-alloy/src/core/contexts/reflection.mjs +42 -0
- package/dist/plugin-alloy/src/helpers/refkey.cjs +16 -0
- package/dist/plugin-alloy/src/helpers/refkey.mjs +15 -0
- package/dist/plugin-alloy/src/index.cjs +93 -0
- package/dist/plugin-alloy/src/index.mjs +91 -0
- package/dist/plugin-alloy/src/markdown/components/markdown-file.cjs +7 -0
- package/dist/plugin-alloy/src/markdown/components/markdown-file.mjs +9 -0
- package/dist/plugin-alloy/src/markdown/components/markdown-table.cjs +5 -0
- package/dist/plugin-alloy/src/markdown/components/markdown-table.mjs +7 -0
- package/dist/plugin-alloy/src/markdown/contexts/markdown-table.cjs +17 -0
- package/dist/plugin-alloy/src/markdown/contexts/markdown-table.mjs +17 -0
- package/dist/plugin-alloy/src/types/components.d.cts +22 -0
- package/dist/plugin-alloy/src/types/components.d.mts +24 -0
- package/dist/plugin-alloy/src/types/index.d.mts +2 -0
- package/dist/plugin-alloy/src/types/plugin.d.cts +37 -0
- package/dist/plugin-alloy/src/types/plugin.d.mts +37 -0
- package/dist/plugin-alloy/src/typescript/components/builtin-file.cjs +57 -0
- package/dist/plugin-alloy/src/typescript/components/builtin-file.d.cts +25 -0
- package/dist/plugin-alloy/src/typescript/components/builtin-file.d.mts +26 -0
- package/dist/plugin-alloy/src/typescript/components/builtin-file.mjs +56 -0
- package/dist/plugin-alloy/src/typescript/components/tsdoc-reflection.cjs +126 -0
- package/dist/plugin-alloy/src/typescript/components/tsdoc-reflection.mjs +124 -0
- package/dist/plugin-alloy/src/typescript/components/tsdoc.cjs +442 -0
- package/dist/plugin-alloy/src/typescript/components/tsdoc.d.cts +27 -0
- package/dist/plugin-alloy/src/typescript/components/tsdoc.d.mts +28 -0
- package/dist/plugin-alloy/src/typescript/components/tsdoc.mjs +433 -0
- package/dist/plugin-alloy/src/typescript/components/typescript-file.cjs +194 -0
- package/dist/plugin-alloy/src/typescript/components/typescript-file.d.cts +14 -0
- package/dist/plugin-alloy/src/typescript/components/typescript-file.d.mts +15 -0
- package/dist/plugin-alloy/src/typescript/components/typescript-file.mjs +191 -0
- package/dist/plugin-alloy/src/typescript/components/typescript-interface.cjs +68 -0
- package/dist/plugin-alloy/src/typescript/components/typescript-interface.d.cts +1 -0
- package/dist/plugin-alloy/src/typescript/components/typescript-interface.d.mts +4 -0
- package/dist/plugin-alloy/src/typescript/components/typescript-interface.mjs +67 -0
- package/dist/plugin-alloy/src/typescript/components/typescript-object.cjs +124 -0
- package/dist/plugin-alloy/src/typescript/components/typescript-object.mjs +123 -0
- package/dist/plugin-automd/src/index.cjs +101 -0
- package/dist/plugin-automd/src/index.mjs +98 -0
- package/dist/plugin-automd/src/types/plugin.d.cts +38 -0
- package/dist/plugin-automd/src/types/plugin.d.mts +40 -0
- package/dist/plugin-automd/src/types/toc.d.cts +33 -0
- package/dist/plugin-automd/src/types/toc.d.mts +33 -0
- package/dist/plugin-babel/src/helpers/ast-utils.cjs +10 -0
- package/dist/plugin-babel/src/helpers/ast-utils.mjs +9 -0
- package/dist/plugin-babel/src/helpers/create-plugin.cjs +41 -0
- package/dist/plugin-babel/src/helpers/create-plugin.mjs +39 -0
- package/dist/plugin-babel/src/helpers/filters.cjs +23 -0
- package/dist/plugin-babel/src/helpers/filters.mjs +21 -0
- package/dist/plugin-babel/src/helpers/index.cjs +5 -0
- package/dist/plugin-babel/src/helpers/index.mjs +7 -0
- package/dist/plugin-babel/src/helpers/module-helpers.cjs +38 -0
- package/dist/plugin-babel/src/helpers/module-helpers.mjs +35 -0
- package/dist/plugin-babel/src/helpers/options.cjs +50 -0
- package/dist/plugin-babel/src/helpers/options.mjs +47 -0
- package/dist/plugin-babel/src/index.cjs +91 -0
- package/dist/plugin-babel/src/index.mjs +89 -0
- package/dist/plugin-babel/src/types/index.d.mts +1 -0
- package/dist/plugin-babel/src/types/plugin.d.cts +15 -0
- package/dist/plugin-babel/src/types/plugin.d.mts +15 -0
- package/dist/plugin-env/src/babel/index.cjs +1 -0
- package/dist/plugin-env/src/babel/index.mjs +3 -0
- package/dist/plugin-env/src/babel/plugin.cjs +121 -0
- package/dist/plugin-env/src/babel/plugin.mjs +119 -0
- package/dist/plugin-env/src/components/docs.cjs +9 -0
- package/dist/plugin-env/src/components/docs.mjs +11 -0
- package/dist/plugin-env/src/components/env.cjs +575 -0
- package/dist/plugin-env/src/components/env.d.cts +11 -0
- package/dist/plugin-env/src/components/env.d.mts +11 -0
- package/dist/plugin-env/src/components/env.mjs +572 -0
- package/dist/plugin-env/src/components/index.cjs +2 -0
- package/dist/plugin-env/src/components/index.mjs +4 -0
- package/dist/plugin-env/src/helpers/automd-generator.cjs +22 -0
- package/dist/plugin-env/src/helpers/automd-generator.mjs +21 -0
- package/dist/plugin-env/src/helpers/create-reflection-resource.cjs +55 -0
- package/dist/plugin-env/src/helpers/create-reflection-resource.mjs +54 -0
- package/dist/plugin-env/src/helpers/index.cjs +6 -0
- package/dist/plugin-env/src/helpers/index.mjs +8 -0
- package/dist/plugin-env/src/helpers/load.cjs +83 -0
- package/dist/plugin-env/src/helpers/load.mjs +80 -0
- package/dist/plugin-env/src/helpers/persistence.cjs +199 -0
- package/dist/plugin-env/src/helpers/persistence.mjs +188 -0
- package/dist/plugin-env/src/helpers/reflect.cjs +111 -0
- package/dist/plugin-env/src/helpers/reflect.mjs +103 -0
- package/dist/plugin-env/src/helpers/source-file-env.cjs +24 -0
- package/dist/plugin-env/src/helpers/source-file-env.mjs +23 -0
- package/dist/plugin-env/src/helpers/template-helpers.cjs +2 -0
- package/dist/plugin-env/src/helpers/template-helpers.mjs +4 -0
- package/dist/plugin-env/src/index.cjs +175 -0
- package/dist/plugin-env/src/index.mjs +173 -0
- package/dist/plugin-env/src/types/plugin.d.cts +151 -0
- package/dist/plugin-env/src/types/plugin.d.mts +153 -0
- package/dist/plugin-env/src/types/runtime.d.cts +792 -0
- package/dist/plugin-env/src/types/runtime.d.mts +792 -0
- package/dist/powerlines/src/lib/build/esbuild.cjs +102 -0
- package/dist/powerlines/src/lib/build/esbuild.mjs +100 -0
- package/dist/powerlines/src/lib/entry.cjs +12 -0
- package/dist/powerlines/src/lib/entry.mjs +14 -0
- package/dist/powerlines/src/lib/logger.cjs +41 -0
- package/dist/powerlines/src/lib/logger.mjs +39 -0
- package/dist/powerlines/src/lib/typescript/tsconfig.cjs +38 -0
- package/dist/powerlines/src/lib/typescript/tsconfig.mjs +35 -0
- package/dist/powerlines/src/lib/utilities/bundle.cjs +35 -0
- package/dist/powerlines/src/lib/utilities/bundle.mjs +34 -0
- package/dist/powerlines/src/lib/utilities/resolve.cjs +30 -0
- package/dist/powerlines/src/lib/utilities/resolve.mjs +29 -0
- package/dist/powerlines/src/plugin-utils/paths.cjs +1 -0
- package/dist/powerlines/src/plugin-utils/paths.mjs +3 -0
- package/dist/powerlines/src/types/babel.d.cts +22 -0
- package/dist/powerlines/src/types/babel.d.mts +22 -0
- package/dist/powerlines/src/types/build.d.cts +145 -0
- package/dist/powerlines/src/types/build.d.mts +145 -0
- package/dist/powerlines/src/types/commands.d.cts +8 -0
- package/dist/powerlines/src/types/commands.d.mts +9 -0
- package/dist/powerlines/src/types/config.d.cts +387 -0
- package/dist/powerlines/src/types/config.d.mts +388 -0
- package/dist/powerlines/src/types/context.d.cts +414 -0
- package/dist/powerlines/src/types/context.d.mts +416 -0
- package/dist/powerlines/src/types/fs.d.cts +486 -0
- package/dist/powerlines/src/types/fs.d.mts +486 -0
- package/dist/powerlines/src/types/hooks.d.mts +2 -0
- package/dist/powerlines/src/types/plugin.d.cts +231 -0
- package/dist/powerlines/src/types/plugin.d.mts +231 -0
- package/dist/powerlines/src/types/resolved.d.cts +82 -0
- package/dist/powerlines/src/types/resolved.d.mts +82 -0
- package/dist/powerlines/src/types/tsconfig.d.cts +69 -0
- package/dist/powerlines/src/types/tsconfig.d.mts +69 -0
- package/dist/types/index.cjs +0 -2
- package/dist/types/index.d.cts +1 -3
- package/dist/types/index.d.mts +1 -3
- package/dist/types/index.mjs +0 -3
- package/dist/types/plugin.cjs +0 -1
- package/dist/types/plugin.d.cts +22 -2
- package/dist/types/plugin.d.mts +22 -2
- package/dist/types/plugin.mjs +0 -2
- package/package.json +6 -6
- package/dist/components-BWLXb7a2.cjs +0 -0
- package/dist/components-CXZYcH4q.d.mts +0 -1816
- package/dist/components-kh0CpIG2.mjs +0 -1
- package/dist/env-CAhIy_H3.cjs +0 -11713
- package/dist/env-CUyFiniR.d.cts +0 -107
- package/dist/env-IF4XhMjG.mjs +0 -11570
- package/dist/env-sRb-Y8mJ.d.mts +0 -89
- package/dist/index-CUbWeWHc.d.mts +0 -1
- package/dist/index-D6CnpA_r.d.cts +0 -1
- package/dist/index-DL0uimUT.d.mts +0 -1
- package/dist/index-DWPDThxu.d.cts +0 -1
- package/dist/plugin-ifZVa20V.mjs +0 -1
- package/dist/plugin-pBKbb5K9.cjs +0 -0
- package/dist/resolved-zsx09G03.d.cts +0 -1795
- package/dist/types-U3zd8PTP.mjs +0 -1
- package/dist/types-o3zWarRp.cjs +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_reflect_type = require('../../../deepkit/src/reflect-type.cjs');
|
|
3
|
+
const require_persistence = require('./persistence.cjs');
|
|
4
|
+
let __stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
|
|
5
|
+
let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
6
|
+
let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
7
|
+
let __stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
8
|
+
|
|
9
|
+
//#region ../plugin-env/src/helpers/reflect.ts
|
|
10
|
+
function mergeEnvReflections(context, reflections) {
|
|
11
|
+
return createEnvReflection(context, { type: (0, __powerlines_deepkit_vendor_type.merge)(reflections.map((reflection) => reflection.type)) });
|
|
12
|
+
}
|
|
13
|
+
function mergeSecretsReflections(context, reflections) {
|
|
14
|
+
return createSecretsReflection(context, { type: (0, __powerlines_deepkit_vendor_type.merge)(reflections.map((reflection) => reflection.type)) });
|
|
15
|
+
}
|
|
16
|
+
var BaseEnv = class {
|
|
17
|
+
PLATFORM = "neutral";
|
|
18
|
+
MODE = "production";
|
|
19
|
+
DEBUG = false;
|
|
20
|
+
TEST = false;
|
|
21
|
+
MINIMAL = false;
|
|
22
|
+
NO_COLOR = false;
|
|
23
|
+
FORCE_COLOR = false;
|
|
24
|
+
FORCE_HYPERLINK = false;
|
|
25
|
+
STACKTRACE = false;
|
|
26
|
+
INCLUDE_ERROR_DATA = false;
|
|
27
|
+
CI = false;
|
|
28
|
+
};
|
|
29
|
+
var BaseSecrets = class {};
|
|
30
|
+
function createEnvReflection(context, options = {}) {
|
|
31
|
+
const parent = options.superReflection ?? new __powerlines_deepkit_vendor_type.ReflectionClass({
|
|
32
|
+
kind: __powerlines_deepkit_vendor_type.ReflectionKind.class,
|
|
33
|
+
description: `The base environment configuration definition for the ${(0, __stryke_string_format_title_case.titleCase)(context.config.name)} project.`,
|
|
34
|
+
classType: BaseEnv,
|
|
35
|
+
types: [],
|
|
36
|
+
implements: [{
|
|
37
|
+
kind: __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral,
|
|
38
|
+
typeName: "EnvInterface",
|
|
39
|
+
description: `The environment configuration interface definition for the ${(0, __stryke_string_format_title_case.titleCase)(context.config.name)} project.`,
|
|
40
|
+
types: []
|
|
41
|
+
}]
|
|
42
|
+
});
|
|
43
|
+
parent.name = "Env";
|
|
44
|
+
const result = new __powerlines_deepkit_vendor_type.ReflectionClass(options.type ?? {
|
|
45
|
+
kind: __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral,
|
|
46
|
+
typeName: "Env",
|
|
47
|
+
description: `A schema describing the list of available environment variables that can be used by the ${context.config.name ? `${(0, __stryke_string_format_title_case.titleCase)(context.config.name)} application` : "application"}.`,
|
|
48
|
+
types: []
|
|
49
|
+
}, parent);
|
|
50
|
+
result.name = "Env";
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
function createSecretsReflection(context, options = {}) {
|
|
54
|
+
const parent = options.superReflection ?? new __powerlines_deepkit_vendor_type.ReflectionClass({
|
|
55
|
+
kind: __powerlines_deepkit_vendor_type.ReflectionKind.class,
|
|
56
|
+
description: `The base secrets configuration definition for the ${(0, __stryke_string_format_title_case.titleCase)(context.config.name)} project.`,
|
|
57
|
+
classType: BaseSecrets,
|
|
58
|
+
types: [],
|
|
59
|
+
implements: [{
|
|
60
|
+
kind: __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral,
|
|
61
|
+
typeName: "SecretsInterface",
|
|
62
|
+
description: `The secrets configuration interface definition for the ${(0, __stryke_string_format_title_case.titleCase)(context.config.name)} project.`,
|
|
63
|
+
types: []
|
|
64
|
+
}]
|
|
65
|
+
});
|
|
66
|
+
parent.name = "Secrets";
|
|
67
|
+
const result = new __powerlines_deepkit_vendor_type.ReflectionClass(options.type ?? {
|
|
68
|
+
kind: __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral,
|
|
69
|
+
typeName: "Secrets",
|
|
70
|
+
description: `A schema describing the list of available environment secrets that can be used by the ${context.config.name ? `${(0, __stryke_string_format_title_case.titleCase)(context.config.name)} application` : "application"}.`,
|
|
71
|
+
types: []
|
|
72
|
+
}, parent);
|
|
73
|
+
result.name = "Secrets";
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
async function reflectEnv(context, file, name) {
|
|
77
|
+
let config;
|
|
78
|
+
if (file) config = (0, __powerlines_deepkit_vendor_type.resolveClassType)(await require_reflect_type.reflectType(context, {
|
|
79
|
+
file: !(0, __stryke_path_is_parent_path.isParentPath)(file, context.workspaceConfig.workspaceRoot) ? (0, __stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, file) : file,
|
|
80
|
+
name
|
|
81
|
+
}, { skipNodeModulesBundle: true }));
|
|
82
|
+
const defaultConfigType = await require_reflect_type.reflectType(context, await require_persistence.getEnvDefaultTypeDefinition(context));
|
|
83
|
+
return mergeEnvReflections(context, [
|
|
84
|
+
await require_persistence.readEnvTypeReflection(context, "env"),
|
|
85
|
+
config,
|
|
86
|
+
(0, __powerlines_deepkit_vendor_type.resolveClassType)(defaultConfigType)
|
|
87
|
+
].filter(Boolean));
|
|
88
|
+
}
|
|
89
|
+
async function reflectSecrets(context, file, name) {
|
|
90
|
+
let config;
|
|
91
|
+
if (file) config = (0, __powerlines_deepkit_vendor_type.resolveClassType)(await require_reflect_type.reflectType(context, {
|
|
92
|
+
file: !(0, __stryke_path_is_parent_path.isParentPath)(file, context.workspaceConfig.workspaceRoot) ? (0, __stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, file) : file,
|
|
93
|
+
name
|
|
94
|
+
}, { skipNodeModulesBundle: true }));
|
|
95
|
+
const defaultSecretsType = await require_reflect_type.reflectType(context, await require_persistence.getSecretsDefaultTypeDefinition(context));
|
|
96
|
+
return mergeSecretsReflections(context, [
|
|
97
|
+
await require_persistence.readSecretsReflection(context),
|
|
98
|
+
config,
|
|
99
|
+
(0, __powerlines_deepkit_vendor_type.resolveClassType)(defaultSecretsType)
|
|
100
|
+
].filter(Boolean));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
exports.BaseEnv = BaseEnv;
|
|
105
|
+
exports.BaseSecrets = BaseSecrets;
|
|
106
|
+
exports.createEnvReflection = createEnvReflection;
|
|
107
|
+
exports.createSecretsReflection = createSecretsReflection;
|
|
108
|
+
exports.mergeEnvReflections = mergeEnvReflections;
|
|
109
|
+
exports.mergeSecretsReflections = mergeSecretsReflections;
|
|
110
|
+
exports.reflectEnv = reflectEnv;
|
|
111
|
+
exports.reflectSecrets = reflectSecrets;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { reflectType } from "../../../deepkit/src/reflect-type.mjs";
|
|
2
|
+
import { getEnvDefaultTypeDefinition, getSecretsDefaultTypeDefinition, readEnvTypeReflection, readSecretsReflection } from "./persistence.mjs";
|
|
3
|
+
import { isParentPath } from "@stryke/path/is-parent-path";
|
|
4
|
+
import { titleCase } from "@stryke/string-format/title-case";
|
|
5
|
+
import { ReflectionClass, ReflectionKind, merge, resolveClassType } from "@powerlines/deepkit/vendor/type";
|
|
6
|
+
import { joinPaths } from "@stryke/path/join-paths";
|
|
7
|
+
|
|
8
|
+
//#region ../plugin-env/src/helpers/reflect.ts
|
|
9
|
+
function mergeEnvReflections(context, reflections) {
|
|
10
|
+
return createEnvReflection(context, { type: merge(reflections.map((reflection) => reflection.type)) });
|
|
11
|
+
}
|
|
12
|
+
function mergeSecretsReflections(context, reflections) {
|
|
13
|
+
return createSecretsReflection(context, { type: merge(reflections.map((reflection) => reflection.type)) });
|
|
14
|
+
}
|
|
15
|
+
var BaseEnv = class {
|
|
16
|
+
PLATFORM = "neutral";
|
|
17
|
+
MODE = "production";
|
|
18
|
+
DEBUG = false;
|
|
19
|
+
TEST = false;
|
|
20
|
+
MINIMAL = false;
|
|
21
|
+
NO_COLOR = false;
|
|
22
|
+
FORCE_COLOR = false;
|
|
23
|
+
FORCE_HYPERLINK = false;
|
|
24
|
+
STACKTRACE = false;
|
|
25
|
+
INCLUDE_ERROR_DATA = false;
|
|
26
|
+
CI = false;
|
|
27
|
+
};
|
|
28
|
+
var BaseSecrets = class {};
|
|
29
|
+
function createEnvReflection(context, options = {}) {
|
|
30
|
+
const parent = options.superReflection ?? new ReflectionClass({
|
|
31
|
+
kind: ReflectionKind.class,
|
|
32
|
+
description: `The base environment configuration definition for the ${titleCase(context.config.name)} project.`,
|
|
33
|
+
classType: BaseEnv,
|
|
34
|
+
types: [],
|
|
35
|
+
implements: [{
|
|
36
|
+
kind: ReflectionKind.objectLiteral,
|
|
37
|
+
typeName: "EnvInterface",
|
|
38
|
+
description: `The environment configuration interface definition for the ${titleCase(context.config.name)} project.`,
|
|
39
|
+
types: []
|
|
40
|
+
}]
|
|
41
|
+
});
|
|
42
|
+
parent.name = "Env";
|
|
43
|
+
const result = new ReflectionClass(options.type ?? {
|
|
44
|
+
kind: ReflectionKind.objectLiteral,
|
|
45
|
+
typeName: "Env",
|
|
46
|
+
description: `A schema describing the list of available environment variables that can be used by the ${context.config.name ? `${titleCase(context.config.name)} application` : "application"}.`,
|
|
47
|
+
types: []
|
|
48
|
+
}, parent);
|
|
49
|
+
result.name = "Env";
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
function createSecretsReflection(context, options = {}) {
|
|
53
|
+
const parent = options.superReflection ?? new ReflectionClass({
|
|
54
|
+
kind: ReflectionKind.class,
|
|
55
|
+
description: `The base secrets configuration definition for the ${titleCase(context.config.name)} project.`,
|
|
56
|
+
classType: BaseSecrets,
|
|
57
|
+
types: [],
|
|
58
|
+
implements: [{
|
|
59
|
+
kind: ReflectionKind.objectLiteral,
|
|
60
|
+
typeName: "SecretsInterface",
|
|
61
|
+
description: `The secrets configuration interface definition for the ${titleCase(context.config.name)} project.`,
|
|
62
|
+
types: []
|
|
63
|
+
}]
|
|
64
|
+
});
|
|
65
|
+
parent.name = "Secrets";
|
|
66
|
+
const result = new ReflectionClass(options.type ?? {
|
|
67
|
+
kind: ReflectionKind.objectLiteral,
|
|
68
|
+
typeName: "Secrets",
|
|
69
|
+
description: `A schema describing the list of available environment secrets that can be used by the ${context.config.name ? `${titleCase(context.config.name)} application` : "application"}.`,
|
|
70
|
+
types: []
|
|
71
|
+
}, parent);
|
|
72
|
+
result.name = "Secrets";
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
async function reflectEnv(context, file, name) {
|
|
76
|
+
let config;
|
|
77
|
+
if (file) config = resolveClassType(await reflectType(context, {
|
|
78
|
+
file: !isParentPath(file, context.workspaceConfig.workspaceRoot) ? joinPaths(context.workspaceConfig.workspaceRoot, file) : file,
|
|
79
|
+
name
|
|
80
|
+
}, { skipNodeModulesBundle: true }));
|
|
81
|
+
const defaultConfigType = await reflectType(context, await getEnvDefaultTypeDefinition(context));
|
|
82
|
+
return mergeEnvReflections(context, [
|
|
83
|
+
await readEnvTypeReflection(context, "env"),
|
|
84
|
+
config,
|
|
85
|
+
resolveClassType(defaultConfigType)
|
|
86
|
+
].filter(Boolean));
|
|
87
|
+
}
|
|
88
|
+
async function reflectSecrets(context, file, name) {
|
|
89
|
+
let config;
|
|
90
|
+
if (file) config = resolveClassType(await reflectType(context, {
|
|
91
|
+
file: !isParentPath(file, context.workspaceConfig.workspaceRoot) ? joinPaths(context.workspaceConfig.workspaceRoot, file) : file,
|
|
92
|
+
name
|
|
93
|
+
}, { skipNodeModulesBundle: true }));
|
|
94
|
+
const defaultSecretsType = await reflectType(context, await getSecretsDefaultTypeDefinition(context));
|
|
95
|
+
return mergeSecretsReflections(context, [
|
|
96
|
+
await readSecretsReflection(context),
|
|
97
|
+
config,
|
|
98
|
+
resolveClassType(defaultSecretsType)
|
|
99
|
+
].filter(Boolean));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
export { BaseEnv, BaseSecrets, createEnvReflection, createSecretsReflection, mergeEnvReflections, mergeSecretsReflections, reflectEnv, reflectSecrets };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
3
|
+
let __stryke_env_types = require("@stryke/env/types");
|
|
4
|
+
let __stryke_string_format_camel_case = require("@stryke/string-format/camel-case");
|
|
5
|
+
|
|
6
|
+
//#region ../plugin-env/src/helpers/source-file-env.ts
|
|
7
|
+
function removeEnvPrefix(env) {
|
|
8
|
+
if ((0, __stryke_type_checks_is_string.isString)(env)) {
|
|
9
|
+
let name = __stryke_env_types.ENV_PREFIXES.reduce((ret, prefix) => {
|
|
10
|
+
if (ret.startsWith(prefix)) ret = ret.slice(prefix.length);
|
|
11
|
+
return ret;
|
|
12
|
+
}, env.toUpperCase());
|
|
13
|
+
while (name.startsWith("_")) name = name.slice(1);
|
|
14
|
+
return name;
|
|
15
|
+
}
|
|
16
|
+
return Object.keys(env).reduce((ret, key) => {
|
|
17
|
+
const name = removeEnvPrefix(key);
|
|
18
|
+
if (name) ret[name] = env[key];
|
|
19
|
+
return ret;
|
|
20
|
+
}, {});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.removeEnvPrefix = removeEnvPrefix;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isString } from "@stryke/type-checks/is-string";
|
|
2
|
+
import { ENV_PREFIXES } from "@stryke/env/types";
|
|
3
|
+
import { camelCase } from "@stryke/string-format/camel-case";
|
|
4
|
+
|
|
5
|
+
//#region ../plugin-env/src/helpers/source-file-env.ts
|
|
6
|
+
function removeEnvPrefix(env) {
|
|
7
|
+
if (isString(env)) {
|
|
8
|
+
let name = ENV_PREFIXES.reduce((ret, prefix) => {
|
|
9
|
+
if (ret.startsWith(prefix)) ret = ret.slice(prefix.length);
|
|
10
|
+
return ret;
|
|
11
|
+
}, env.toUpperCase());
|
|
12
|
+
while (name.startsWith("_")) name = name.slice(1);
|
|
13
|
+
return name;
|
|
14
|
+
}
|
|
15
|
+
return Object.keys(env).reduce((ret, key) => {
|
|
16
|
+
const name = removeEnvPrefix(key);
|
|
17
|
+
if (name) ret[name] = env[key];
|
|
18
|
+
return ret;
|
|
19
|
+
}, {});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { removeEnvPrefix };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_index = require('../../plugin-babel/src/index.cjs');
|
|
3
|
+
const require_index$1 = require('../../plugin-alloy/src/index.cjs');
|
|
4
|
+
const require_index$2 = require('../../plugin-automd/src/index.cjs');
|
|
5
|
+
const require_reflect = require('./helpers/reflect.cjs');
|
|
6
|
+
const require_persistence = require('./helpers/persistence.cjs');
|
|
7
|
+
const require_plugin = require('./babel/plugin.cjs');
|
|
8
|
+
const require_source_file_env = require('./helpers/source-file-env.cjs');
|
|
9
|
+
const require_load = require('./helpers/load.cjs');
|
|
10
|
+
const require_create_reflection_resource = require('./helpers/create-reflection-resource.cjs');
|
|
11
|
+
const require_env = require('./components/env.cjs');
|
|
12
|
+
const require_automd_generator = require('./helpers/automd-generator.cjs');
|
|
13
|
+
require('./babel/index.cjs');
|
|
14
|
+
require('./components/index.cjs');
|
|
15
|
+
require('./helpers/index.cjs');
|
|
16
|
+
let __alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
17
|
+
let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
|
|
18
|
+
let __stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
|
|
19
|
+
let defu = require("defu");
|
|
20
|
+
defu = require_rolldown_runtime.__toESM(defu);
|
|
21
|
+
let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
22
|
+
let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
23
|
+
let __stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
24
|
+
let __stryke_convert_parse_type_definition = require("@stryke/convert/parse-type-definition");
|
|
25
|
+
let __stryke_env_types = require("@stryke/env/types");
|
|
26
|
+
let __stryke_fs_exists = require("@stryke/fs/exists");
|
|
27
|
+
let __stryke_fs_helpers = require("@stryke/fs/helpers");
|
|
28
|
+
let __stryke_path_join = require("@stryke/path/join");
|
|
29
|
+
let __stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
|
|
30
|
+
|
|
31
|
+
//#region ../plugin-env/src/index.tsx
|
|
32
|
+
/**
|
|
33
|
+
* A Powerlines plugin to inject environment variables into the source code.
|
|
34
|
+
*/
|
|
35
|
+
const plugin = (options = {}) => {
|
|
36
|
+
return [
|
|
37
|
+
require_index$1.default(options.alloy),
|
|
38
|
+
require_index.default(options.babel),
|
|
39
|
+
{
|
|
40
|
+
name: "env",
|
|
41
|
+
async config() {
|
|
42
|
+
this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, "Providing default configuration for the Powerlines `env` build plugin.");
|
|
43
|
+
const config = {
|
|
44
|
+
env: (0, defu.default)(options, {
|
|
45
|
+
types: {},
|
|
46
|
+
prefix: []
|
|
47
|
+
}),
|
|
48
|
+
transform: { babel: { plugins: [require_plugin.envBabelPlugin] } }
|
|
49
|
+
};
|
|
50
|
+
if (config.env.types) config.env.types = (0, __stryke_convert_parse_type_definition.parseTypeDefinition)(config.env.types);
|
|
51
|
+
else {
|
|
52
|
+
this.log(__storm_software_config_tools_types.LogLevelLabel.WARN, "The `env.types` configuration parameter was not provided. Please ensure this is expected.");
|
|
53
|
+
const envDefaultTypeDefinition = await require_persistence.getEnvDefaultTypeDefinition(this);
|
|
54
|
+
config.env.types = (0, __stryke_convert_parse_type_definition.parseTypeDefinition)(`${envDefaultTypeDefinition.file}#${envDefaultTypeDefinition.name}`);
|
|
55
|
+
}
|
|
56
|
+
if (config.env.secrets) config.env.secrets = (0, __stryke_convert_parse_type_definition.parseTypeDefinition)(config.env.secrets);
|
|
57
|
+
else {
|
|
58
|
+
const secretsDefaultTypeDefinition = await require_persistence.getSecretsDefaultTypeDefinition(this);
|
|
59
|
+
config.env.secrets = (0, __stryke_convert_parse_type_definition.parseTypeDefinition)(`${secretsDefaultTypeDefinition.file}#${secretsDefaultTypeDefinition.name}`);
|
|
60
|
+
}
|
|
61
|
+
config.env.prefix = (0, __stryke_convert_to_array.toArray)(config.env.prefix ?? []).reduce((ret, prefix) => {
|
|
62
|
+
const formattedPrefix = (0, __stryke_string_format_constant_case.constantCase)(prefix);
|
|
63
|
+
if (!ret.includes(formattedPrefix)) ret.push(formattedPrefix);
|
|
64
|
+
return ret;
|
|
65
|
+
}, [...__stryke_env_types.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(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Environment plugin configuration has been resolved for the Powerlines project.`);
|
|
74
|
+
this.config.env.inject ??= this.config.projectType === "application";
|
|
75
|
+
this.env = (0, defu.default)({ parsed: await require_load.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 && (0, __stryke_fs_exists.existsSync)(require_persistence.getEnvTypeReflectionsPath(this, "env"))) {
|
|
85
|
+
this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Skipping reflection initialization as the meta checksum has not changed.`);
|
|
86
|
+
this.env.types.env = await require_persistence.readEnvTypeReflection(this, "env");
|
|
87
|
+
if ((0, __stryke_fs_exists.existsSync)(require_persistence.getEnvReflectionsPath(this, "env"))) this.env.used.env = await require_persistence.readEnvReflection(this);
|
|
88
|
+
if ((0, __stryke_fs_exists.existsSync)(require_persistence.getEnvTypeReflectionsPath(this, "secrets"))) this.env.types.secrets = await require_persistence.readEnvTypeReflection(this, "secrets");
|
|
89
|
+
if ((0, __stryke_fs_exists.existsSync)(require_persistence.getEnvReflectionsPath(this, "secrets"))) this.env.used.secrets = await require_persistence.readSecretsReflection(this);
|
|
90
|
+
} else {
|
|
91
|
+
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);
|
|
92
|
+
if (!this.env.types.env) throw new Error("Failed to find the environment configuration type reflection in the context.");
|
|
93
|
+
await require_persistence.writeEnvTypeReflection(this, this.env.types.env, "env");
|
|
94
|
+
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);
|
|
95
|
+
if (!this.env.types.secrets) throw new Error("Failed to find the secrets configuration type reflection in the context.");
|
|
96
|
+
await require_persistence.writeEnvTypeReflection(this, this.env.types.secrets, "secrets");
|
|
97
|
+
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`);
|
|
98
|
+
const envWithAlias = this.env.types.env.getProperties().filter((prop) => prop.getAlias().length > 0);
|
|
99
|
+
Object.entries(await require_load.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 __powerlines_deepkit_vendor_type.ReflectionClass({
|
|
108
|
+
kind: __powerlines_deepkit_vendor_type.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 require_persistence.writeEnvReflection(this, this.env.used.env, "env");
|
|
114
|
+
if (this.env.types.secrets) {
|
|
115
|
+
await require_persistence.writeEnvTypeReflection(this, this.env.types.secrets, "secrets");
|
|
116
|
+
this.env.used.secrets = new __powerlines_deepkit_vendor_type.ReflectionClass({
|
|
117
|
+
kind: __powerlines_deepkit_vendor_type.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 require_persistence.writeEnvReflection(this, this.env.used.secrets, "secrets");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
async prepare() {
|
|
127
|
+
const _self$ = this;
|
|
128
|
+
this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Preparing the Environment runtime artifacts for the Powerlines project.`);
|
|
129
|
+
return this.render((0, __alloy_js_core_jsx_runtime.createComponent)(require_env.EnvBuiltin, { get defaultConfig() {
|
|
130
|
+
return _self$.config.env.defaultConfig;
|
|
131
|
+
} }));
|
|
132
|
+
},
|
|
133
|
+
async docs() {
|
|
134
|
+
this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, "Writing Environment documentation for the Powerlines project artifacts.");
|
|
135
|
+
const outputPath = (0, __stryke_path_join.joinPaths)(this.config.projectRoot, "docs", "generated");
|
|
136
|
+
if (!(0, __stryke_fs_exists.existsSync)(outputPath)) await (0, __stryke_fs_helpers.createDirectory)(outputPath);
|
|
137
|
+
const reflection = await require_persistence.readEnvTypeReflection(this, "env");
|
|
138
|
+
const envDocFile = (0, __stryke_path_join.joinPaths)(outputPath, "env.md");
|
|
139
|
+
this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Documenting environment variables configuration in "${envDocFile}"`);
|
|
140
|
+
await this.fs.write(envDocFile, `<!-- Generated by ${(0, __stryke_string_format_title_case.titleCase)(this.config.framework) || "Powerlines"} -->
|
|
141
|
+
|
|
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.
|
|
143
|
+
|
|
144
|
+
| Name | Description | Type | Default Value | Required |
|
|
145
|
+
| ---- | ----------- | ---- | ------------- | :------: |
|
|
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, __powerlines_deepkit_vendor_type.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 = require_persistence.getEnvReflectionsPath(this, "env");
|
|
153
|
+
this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Writing env reflection types to ${reflectionPath}.`);
|
|
154
|
+
await require_persistence.writeEnvReflection(this, this.env.used.env, "env");
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: "env:automd-generator",
|
|
159
|
+
config() {
|
|
160
|
+
return { automd: (0, defu.default)(options.automd ?? {}, { generators: { "env": require_automd_generator.env(this) } }) };
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: "env:vite",
|
|
165
|
+
vite: { configResolved() {
|
|
166
|
+
return { envPrefix: this.config?.env?.prefix };
|
|
167
|
+
} }
|
|
168
|
+
},
|
|
169
|
+
require_index$2.default(options.automd)
|
|
170
|
+
];
|
|
171
|
+
};
|
|
172
|
+
var src_default$3 = plugin;
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
exports.default = src_default$3;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import src_default$2 from "../../plugin-babel/src/index.mjs";
|
|
2
|
+
import src_default from "../../plugin-alloy/src/index.mjs";
|
|
3
|
+
import src_default$1 from "../../plugin-automd/src/index.mjs";
|
|
4
|
+
import { BaseEnv, BaseSecrets, createEnvReflection, createSecretsReflection, mergeEnvReflections, mergeSecretsReflections, reflectEnv, reflectSecrets } from "./helpers/reflect.mjs";
|
|
5
|
+
import { getEnvDefaultTypeDefinition, getEnvReflectionsPath, getEnvTypeReflectionsPath, getSecretsDefaultTypeDefinition, readEnvReflection, readEnvTypeReflection, readSecretsReflection, resolveRuntimeTypeFile, writeEnvReflection, writeEnvTypeReflection } from "./helpers/persistence.mjs";
|
|
6
|
+
import { envBabelPlugin } from "./babel/plugin.mjs";
|
|
7
|
+
import { removeEnvPrefix } from "./helpers/source-file-env.mjs";
|
|
8
|
+
import { loadEnv, loadEnvFromContext } from "./helpers/load.mjs";
|
|
9
|
+
import { createReflectionResource } from "./helpers/create-reflection-resource.mjs";
|
|
10
|
+
import { EnvBuiltin, EnvTypeDefinition } from "./components/env.mjs";
|
|
11
|
+
import { env } from "./helpers/automd-generator.mjs";
|
|
12
|
+
import "./babel/index.mjs";
|
|
13
|
+
import "./components/index.mjs";
|
|
14
|
+
import "./helpers/index.mjs";
|
|
15
|
+
import { createComponent } from "@alloy-js/core/jsx-runtime";
|
|
16
|
+
import { LogLevelLabel } from "@storm-software/config-tools/types";
|
|
17
|
+
import { isParentPath } from "@stryke/path/is-parent-path";
|
|
18
|
+
import defu from "defu";
|
|
19
|
+
import { titleCase } from "@stryke/string-format/title-case";
|
|
20
|
+
import { ReflectionClass, ReflectionKind, stringifyType } from "@powerlines/deepkit/vendor/type";
|
|
21
|
+
import { toArray } from "@stryke/convert/to-array";
|
|
22
|
+
import { parseTypeDefinition } from "@stryke/convert/parse-type-definition";
|
|
23
|
+
import { ENV_PREFIXES } from "@stryke/env/types";
|
|
24
|
+
import { existsSync } from "@stryke/fs/exists";
|
|
25
|
+
import { createDirectory } from "@stryke/fs/helpers";
|
|
26
|
+
import { joinPaths } from "@stryke/path/join";
|
|
27
|
+
import { constantCase } from "@stryke/string-format/constant-case";
|
|
28
|
+
|
|
29
|
+
//#region ../plugin-env/src/index.tsx
|
|
30
|
+
/**
|
|
31
|
+
* A Powerlines plugin to inject environment variables into the source code.
|
|
32
|
+
*/
|
|
33
|
+
const plugin = (options = {}) => {
|
|
34
|
+
return [
|
|
35
|
+
src_default(options.alloy),
|
|
36
|
+
src_default$2(options.babel),
|
|
37
|
+
{
|
|
38
|
+
name: "env",
|
|
39
|
+
async config() {
|
|
40
|
+
this.log(LogLevelLabel.TRACE, "Providing default configuration for the Powerlines `env` build plugin.");
|
|
41
|
+
const config = {
|
|
42
|
+
env: defu(options, {
|
|
43
|
+
types: {},
|
|
44
|
+
prefix: []
|
|
45
|
+
}),
|
|
46
|
+
transform: { babel: { plugins: [envBabelPlugin] } }
|
|
47
|
+
};
|
|
48
|
+
if (config.env.types) config.env.types = parseTypeDefinition(config.env.types);
|
|
49
|
+
else {
|
|
50
|
+
this.log(LogLevelLabel.WARN, "The `env.types` configuration parameter was not provided. Please ensure this is expected.");
|
|
51
|
+
const envDefaultTypeDefinition = await getEnvDefaultTypeDefinition(this);
|
|
52
|
+
config.env.types = parseTypeDefinition(`${envDefaultTypeDefinition.file}#${envDefaultTypeDefinition.name}`);
|
|
53
|
+
}
|
|
54
|
+
if (config.env.secrets) config.env.secrets = parseTypeDefinition(config.env.secrets);
|
|
55
|
+
else {
|
|
56
|
+
const secretsDefaultTypeDefinition = await getSecretsDefaultTypeDefinition(this);
|
|
57
|
+
config.env.secrets = parseTypeDefinition(`${secretsDefaultTypeDefinition.file}#${secretsDefaultTypeDefinition.name}`);
|
|
58
|
+
}
|
|
59
|
+
config.env.prefix = toArray(config.env.prefix ?? []).reduce((ret, prefix) => {
|
|
60
|
+
const formattedPrefix = constantCase(prefix);
|
|
61
|
+
if (!ret.includes(formattedPrefix)) ret.push(formattedPrefix);
|
|
62
|
+
return ret;
|
|
63
|
+
}, [...ENV_PREFIXES, "POWERLINES_"]);
|
|
64
|
+
config.env.prefix = config.env.prefix.reduce((ret, prefix) => {
|
|
65
|
+
if (!ret.includes(prefix.replace(/_$/g, ""))) ret.push(prefix.replace(/_$/g, ""));
|
|
66
|
+
return ret;
|
|
67
|
+
}, []);
|
|
68
|
+
return config;
|
|
69
|
+
},
|
|
70
|
+
async configResolved() {
|
|
71
|
+
this.log(LogLevelLabel.TRACE, `Environment plugin configuration has been resolved for the Powerlines project.`);
|
|
72
|
+
this.config.env.inject ??= this.config.projectType === "application";
|
|
73
|
+
this.env = defu({ parsed: await loadEnv(this, this.config.env) }, this.env ?? {}, {
|
|
74
|
+
types: { env: {} },
|
|
75
|
+
used: {
|
|
76
|
+
env: {},
|
|
77
|
+
secrets: {}
|
|
78
|
+
},
|
|
79
|
+
parsed: {},
|
|
80
|
+
injected: {}
|
|
81
|
+
});
|
|
82
|
+
if (this.config.command !== "prepare" && this.persistedMeta?.checksum === this.meta.checksum && existsSync(getEnvTypeReflectionsPath(this, "env"))) {
|
|
83
|
+
this.log(LogLevelLabel.TRACE, `Skipping reflection initialization as the meta checksum has not changed.`);
|
|
84
|
+
this.env.types.env = await readEnvTypeReflection(this, "env");
|
|
85
|
+
if (existsSync(getEnvReflectionsPath(this, "env"))) this.env.used.env = await readEnvReflection(this);
|
|
86
|
+
if (existsSync(getEnvTypeReflectionsPath(this, "secrets"))) this.env.types.secrets = await readEnvTypeReflection(this, "secrets");
|
|
87
|
+
if (existsSync(getEnvReflectionsPath(this, "secrets"))) this.env.used.secrets = await readSecretsReflection(this);
|
|
88
|
+
} else {
|
|
89
|
+
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);
|
|
90
|
+
if (!this.env.types.env) throw new Error("Failed to find the environment configuration type reflection in the context.");
|
|
91
|
+
await writeEnvTypeReflection(this, this.env.types.env, "env");
|
|
92
|
+
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);
|
|
93
|
+
if (!this.env.types.secrets) throw new Error("Failed to find the secrets configuration type reflection in the context.");
|
|
94
|
+
await writeEnvTypeReflection(this, this.env.types.secrets, "secrets");
|
|
95
|
+
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`);
|
|
96
|
+
const envWithAlias = this.env.types.env.getProperties().filter((prop) => prop.getAlias().length > 0);
|
|
97
|
+
Object.entries(await loadEnv(this, this.config.env)).forEach(([key, value]) => {
|
|
98
|
+
const unprefixedKey = this.config.env.prefix.reduce((ret, prefix) => {
|
|
99
|
+
if (key.replace(/_$/g, "").startsWith(prefix)) return key.replace(/_$/g, "").slice(prefix.length);
|
|
100
|
+
return ret;
|
|
101
|
+
}, key);
|
|
102
|
+
const aliasKey = envWithAlias.find((prop) => prop?.getAlias().reverse().includes(unprefixedKey));
|
|
103
|
+
if (this.env.types.env?.hasProperty(unprefixedKey) || aliasKey) this.env.types.env.getProperty(unprefixedKey).setDefaultValue(value);
|
|
104
|
+
});
|
|
105
|
+
this.env.used.env = new ReflectionClass({
|
|
106
|
+
kind: ReflectionKind.objectLiteral,
|
|
107
|
+
typeName: "Env",
|
|
108
|
+
description: `An object containing the environment configuration parameters used by the ${this.config.name ? `${this.config.name} application` : "application"}.`,
|
|
109
|
+
types: []
|
|
110
|
+
}, this.env.types.env);
|
|
111
|
+
await writeEnvReflection(this, this.env.used.env, "env");
|
|
112
|
+
if (this.env.types.secrets) {
|
|
113
|
+
await writeEnvTypeReflection(this, this.env.types.secrets, "secrets");
|
|
114
|
+
this.env.used.secrets = new ReflectionClass({
|
|
115
|
+
kind: ReflectionKind.objectLiteral,
|
|
116
|
+
typeName: "Secrets",
|
|
117
|
+
description: `An object containing the secret configuration parameters used by the ${this.config.name ? `${this.config.name} application` : "application"}.`,
|
|
118
|
+
types: []
|
|
119
|
+
}, this.env.types.secrets);
|
|
120
|
+
await writeEnvReflection(this, this.env.used.secrets, "secrets");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
async prepare() {
|
|
125
|
+
const _self$ = this;
|
|
126
|
+
this.log(LogLevelLabel.TRACE, `Preparing the Environment runtime artifacts for the Powerlines project.`);
|
|
127
|
+
return this.render(createComponent(EnvBuiltin, { get defaultConfig() {
|
|
128
|
+
return _self$.config.env.defaultConfig;
|
|
129
|
+
} }));
|
|
130
|
+
},
|
|
131
|
+
async docs() {
|
|
132
|
+
this.log(LogLevelLabel.TRACE, "Writing Environment documentation for the Powerlines project artifacts.");
|
|
133
|
+
const outputPath = joinPaths(this.config.projectRoot, "docs", "generated");
|
|
134
|
+
if (!existsSync(outputPath)) await createDirectory(outputPath);
|
|
135
|
+
const reflection = await readEnvTypeReflection(this, "env");
|
|
136
|
+
const envDocFile = joinPaths(outputPath, "env.md");
|
|
137
|
+
this.log(LogLevelLabel.TRACE, `Documenting environment variables configuration in "${envDocFile}"`);
|
|
138
|
+
await this.fs.write(envDocFile, `<!-- Generated by ${titleCase(this.config.framework) || "Powerlines"} -->
|
|
139
|
+
|
|
140
|
+
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.
|
|
141
|
+
|
|
142
|
+
| Name | Description | Type | Default Value | Required |
|
|
143
|
+
| ---- | ----------- | ---- | ------------- | :------: |
|
|
144
|
+
${reflection.getProperties().filter((property) => property.getNameAsString() !== "__POWERLINES_INJECTED__").sort((a, b) => a.getNameAsString().localeCompare(b.getNameAsString())).map((reflectionProperty) => {
|
|
145
|
+
return `| ${reflectionProperty.getNameAsString().trim()} | ${(reflectionProperty.getDescription()?.replaceAll("\r", "")?.replaceAll("\n", "") ?? "").trim()} | ${stringifyType(reflectionProperty.getType()).trim().replaceAll(" | ", ", or ")} | ${reflectionProperty.hasDefault() ? String(reflectionProperty.getDefaultValue())?.includes("\"") ? reflectionProperty.getDefaultValue() : `\`${reflectionProperty.getDefaultValue()}\`` : ""} | ${reflectionProperty.isValueRequired() ? "" : "✔"} |`;
|
|
146
|
+
}).join("\n")}
|
|
147
|
+
`);
|
|
148
|
+
},
|
|
149
|
+
async buildEnd() {
|
|
150
|
+
const reflectionPath = getEnvReflectionsPath(this, "env");
|
|
151
|
+
this.log(LogLevelLabel.TRACE, `Writing env reflection types to ${reflectionPath}.`);
|
|
152
|
+
await writeEnvReflection(this, this.env.used.env, "env");
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: "env:automd-generator",
|
|
157
|
+
config() {
|
|
158
|
+
return { automd: defu(options.automd ?? {}, { generators: { "env": env(this) } }) };
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: "env:vite",
|
|
163
|
+
vite: { configResolved() {
|
|
164
|
+
return { envPrefix: this.config?.env?.prefix };
|
|
165
|
+
} }
|
|
166
|
+
},
|
|
167
|
+
src_default$1(options.automd)
|
|
168
|
+
];
|
|
169
|
+
};
|
|
170
|
+
var src_default$3 = plugin;
|
|
171
|
+
|
|
172
|
+
//#endregion
|
|
173
|
+
export { src_default$3 as default };
|