@powerlines/plugin-env 0.16.363 → 0.16.365
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/babel/plugin.cjs +4 -26
- package/dist/babel/plugin.mjs +4 -26
- package/dist/components/docs.cjs +4 -47
- package/dist/components/docs.mjs +4 -46
- package/dist/components/env-builtin.cjs +70 -250
- package/dist/components/env-builtin.mjs +70 -248
- package/dist/components/index.cjs +1 -4
- package/dist/components/index.mjs +3 -3
- package/dist/helpers/automd-generator.cjs +4 -12
- package/dist/helpers/automd-generator.mjs +4 -12
- package/dist/helpers/index.cjs +1 -1
- package/dist/helpers/index.d.cts +2 -2
- package/dist/helpers/index.d.mts +2 -2
- package/dist/helpers/index.mjs +2 -2
- package/dist/helpers/load.cjs +7 -59
- package/dist/helpers/load.d.cts +2 -2
- package/dist/helpers/load.d.mts +2 -2
- package/dist/helpers/load.mjs +7 -59
- package/dist/helpers/schema.cjs +35 -154
- package/dist/helpers/schema.d.cts +9 -8
- package/dist/helpers/schema.d.cts.map +1 -1
- package/dist/helpers/schema.d.mts +9 -8
- package/dist/helpers/schema.mjs +35 -154
- package/dist/helpers/source-file-env.cjs +4 -34
- package/dist/helpers/source-file-env.mjs +4 -34
- package/dist/index.cjs +20 -47
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +18 -39
- package/dist/schemas/env.cjs +723 -0
- package/dist/schemas/env.d.cts +230 -0
- package/dist/schemas/env.d.cts.map +1 -0
- package/dist/schemas/env.d.mts +230 -0
- package/dist/{types → schemas}/env.d.mts.map +1 -1
- package/dist/schemas/env.mjs +715 -0
- package/dist/schemas/index.cjs +10 -0
- package/dist/schemas/index.d.cts +2 -0
- package/dist/schemas/index.d.mts +2 -0
- package/dist/schemas/index.mjs +3 -0
- package/dist/types/index.cjs +0 -12
- package/dist/types/index.d.cts +1 -2
- package/dist/types/index.d.mts +1 -2
- package/dist/types/index.mjs +1 -4
- package/dist/types/plugin.cjs +7 -107
- package/dist/types/plugin.d.cts +2 -2
- package/dist/types/plugin.d.mts +2 -2
- package/dist/types/plugin.mjs +7 -100
- package/package.json +50 -35
- package/dist/types/env.cjs +0 -541
- package/dist/types/env.d.cts +0 -938
- package/dist/types/env.d.cts.map +0 -1
- package/dist/types/env.d.mts +0 -938
- package/dist/types/env.mjs +0 -539
- /package/dist/{types → schemas}/env.mjs.map +0 -0
package/dist/helpers/schema.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __ΩEnvSchema } from "../types/plugin.mjs";
|
|
2
1
|
import { loadEnv } from "./load.mjs";
|
|
3
2
|
import { getProperties, getPropertiesList, isSchema, isSchemaObject, merge } from "@power-plant/schema";
|
|
4
3
|
import { extract } from "@powerlines/plugin-power-plant/helpers";
|
|
@@ -8,61 +7,41 @@ import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
|
8
7
|
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
9
8
|
|
|
10
9
|
//#region src/helpers/schema.ts
|
|
11
|
-
function __assignType(fn, args) {
|
|
12
|
-
fn.__type = args;
|
|
13
|
-
return fn;
|
|
14
|
-
}
|
|
15
10
|
/**
|
|
16
|
-
* Resolves the runtime
|
|
11
|
+
* Resolves the runtime Zod schema file for the environment variables.
|
|
17
12
|
*
|
|
18
13
|
* @param context - The plugin context.
|
|
19
|
-
* @returns The runtime
|
|
14
|
+
* @returns The runtime schema file for the environment variables.
|
|
20
15
|
*/
|
|
21
|
-
async function
|
|
22
|
-
const resolved = await context.fs.resolve("@powerlines/plugin-env/
|
|
23
|
-
if (!resolved) throw new Error(`Failed to resolve the runtime
|
|
16
|
+
async function resolveRuntimeSchemaFile(context) {
|
|
17
|
+
const resolved = await context.fs.resolve("@powerlines/plugin-env/schemas/env");
|
|
18
|
+
if (!resolved) throw new Error(`Failed to resolve the runtime schema file for the environment variables. Please ensure that the "@powerlines/plugin-env" package is installed.`);
|
|
24
19
|
return resolved;
|
|
25
20
|
}
|
|
26
|
-
resolveRuntimeTypeFile.__type = [
|
|
27
|
-
"context",
|
|
28
|
-
"resolveRuntimeTypeFile",
|
|
29
|
-
"Resolves the runtime type definition file for the environment variables.",
|
|
30
|
-
"P\"2!&`/\"?#"
|
|
31
|
-
];
|
|
32
21
|
/**
|
|
33
|
-
* Gets the default
|
|
22
|
+
* Gets the default Zod schema reference for the environment variables.
|
|
34
23
|
*
|
|
35
24
|
* @param context - The plugin context.
|
|
36
|
-
* @returns The default
|
|
25
|
+
* @returns The default schema reference for the environment variables.
|
|
37
26
|
*/
|
|
38
27
|
async function getDefaultConfig(context) {
|
|
39
28
|
return {
|
|
40
|
-
file: await
|
|
41
|
-
export: "
|
|
29
|
+
file: await resolveRuntimeSchemaFile(context),
|
|
30
|
+
export: "envSchema"
|
|
42
31
|
};
|
|
43
32
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"getDefaultConfig",
|
|
47
|
-
"Gets the default type definition for the environment variables.",
|
|
48
|
-
"P\"2!!`/\"?#"
|
|
49
|
-
];
|
|
50
|
-
/** Gets the default type definition for the environment secrets.
|
|
33
|
+
/**
|
|
34
|
+
* Gets the default Zod schema reference for the environment secrets.
|
|
51
35
|
*
|
|
52
36
|
* @param context - The plugin context.
|
|
53
|
-
* @returns The default
|
|
37
|
+
* @returns The default schema reference for the environment secrets.
|
|
54
38
|
*/
|
|
55
39
|
async function getDefaultSecrets(context) {
|
|
56
40
|
return {
|
|
57
|
-
file: await
|
|
58
|
-
export: "
|
|
41
|
+
file: await resolveRuntimeSchemaFile(context),
|
|
42
|
+
export: "secretsSchema"
|
|
59
43
|
};
|
|
60
44
|
}
|
|
61
|
-
getDefaultSecrets.__type = [
|
|
62
|
-
"context",
|
|
63
|
-
"getDefaultSecrets",
|
|
64
|
-
"P\"2!!`/\""
|
|
65
|
-
];
|
|
66
45
|
/**
|
|
67
46
|
* A helper function to get the cache directory path for storing schemas. This function takes a context object as input and returns the path to the cache directory where schemas are stored. The cache directory is constructed by joining the `cachePath` property from the context with a subdirectory named "schemas". This function is useful for centralizing the logic for determining where schema files should be cached, ensuring that all schema-related file operations use a consistent location for storing and retrieving cached schemas.
|
|
68
47
|
*
|
|
@@ -72,51 +51,19 @@ getDefaultSecrets.__type = [
|
|
|
72
51
|
function getCacheDirectory(context) {
|
|
73
52
|
return joinPaths(context.cachePath, "env");
|
|
74
53
|
}
|
|
75
|
-
getCacheDirectory.__type = [
|
|
76
|
-
"context",
|
|
77
|
-
"getCacheDirectory",
|
|
78
|
-
"A helper function to get the cache directory path for storing schemas. This function takes a context object as input and returns the path to the cache directory where schemas are stored. The cache directory is constructed by joining the `cachePath` property from the context with a subdirectory named \"schemas\". This function is useful for centralizing the logic for determining where schema files should be cached, ensuring that all schema-related file operations use a consistent location for storing and retrieving cached schemas.",
|
|
79
|
-
"P\"2!&/\"?#"
|
|
80
|
-
];
|
|
81
54
|
function getCacheFilePath(context, variant) {
|
|
82
55
|
return joinPaths(getCacheDirectory(context), `${variant}.json`);
|
|
83
56
|
}
|
|
84
|
-
getCacheFilePath.__type = [
|
|
85
|
-
"context",
|
|
86
|
-
"config",
|
|
87
|
-
"secrets",
|
|
88
|
-
"variant",
|
|
89
|
-
"getCacheFilePath",
|
|
90
|
-
"P\"2!P.\".#J2$&/%"
|
|
91
|
-
];
|
|
92
57
|
async function writeActive(context, variant, schema) {
|
|
93
58
|
if (!isSchema(schema)) throw new Error(`The provided input is not a valid env schema. A valid schema must have a "variant" property indicating the type of the input and a "schema" property containing the parsed JSON Schema object.`);
|
|
94
59
|
await context.fs.write(getCacheFilePath(context, variant), JSON.stringify(schema.schema));
|
|
95
60
|
}
|
|
96
|
-
writeActive.__type = [
|
|
97
|
-
"context",
|
|
98
|
-
"config",
|
|
99
|
-
"secrets",
|
|
100
|
-
"variant",
|
|
101
|
-
() => __ΩEnvSchema,
|
|
102
|
-
"schema",
|
|
103
|
-
"writeActive",
|
|
104
|
-
"P\"2!P.\".#J2$n%2&\"/'"
|
|
105
|
-
];
|
|
106
61
|
async function readActive(context, variant) {
|
|
107
62
|
if (!context.fs.existsSync(getCacheFilePath(context, variant))) return [];
|
|
108
63
|
const data = await context.fs.read(getCacheFilePath(context, variant));
|
|
109
64
|
if (!data) return [];
|
|
110
65
|
return JSON.parse(data);
|
|
111
66
|
}
|
|
112
|
-
readActive.__type = [
|
|
113
|
-
"context",
|
|
114
|
-
"config",
|
|
115
|
-
"secrets",
|
|
116
|
-
"variant",
|
|
117
|
-
"readActive",
|
|
118
|
-
"P\"2!P.\".#J2$&F`/%"
|
|
119
|
-
];
|
|
120
67
|
/**
|
|
121
68
|
* Extracts the environment variables and secrets schema from the provided type definitions in the plugin options, merges them with the default environment variables and secrets schema, and stores the resulting schema in the plugin context for later use during the build process.
|
|
122
69
|
*
|
|
@@ -143,7 +90,7 @@ async function extractEnv(context) {
|
|
|
143
90
|
context.env.secrets.active = await readActive(context, "secrets");
|
|
144
91
|
if (isSetString(context.config.env.secrets) && new RegExp(`${defaultSecrets.file}[:#;@]?${defaultSecrets.export}`).test(context.config.env.secrets) === false || isSetObject(context.config.env.secrets) && (context.config.env.secrets.file !== defaultSecrets.file || context.config.env.secrets.export !== defaultSecrets.export)) context.env.secrets.schema = merge(await extract(context, defaultSecrets), context.env.secrets);
|
|
145
92
|
const properties = getProperties(context.env.config);
|
|
146
|
-
const describeVariant =
|
|
93
|
+
const describeVariant = (variant) => {
|
|
147
94
|
switch (variant) {
|
|
148
95
|
case "json-schema": return "JSON Schema";
|
|
149
96
|
case "standard-schema": return "Standard Schema";
|
|
@@ -151,47 +98,25 @@ async function extractEnv(context) {
|
|
|
151
98
|
case "valibot": return "Valibot schema";
|
|
152
99
|
case "untyped": return "Untyped configuration";
|
|
153
100
|
case "file-reference": return "Typescript exported type";
|
|
101
|
+
case "reflection": return "TypeScript reflection";
|
|
154
102
|
default: return variant;
|
|
155
103
|
}
|
|
156
|
-
}
|
|
157
|
-
() => __ΩEnvSchema,
|
|
158
|
-
"variant",
|
|
159
|
-
"variant",
|
|
160
|
-
"",
|
|
161
|
-
"Pn!.\"f2#\"/$"
|
|
162
|
-
]);
|
|
104
|
+
};
|
|
163
105
|
context.info({
|
|
164
106
|
meta: { category: "env" },
|
|
165
107
|
message: `Environment Variables configuration: ${context.config.env.config ? "" : "Defaulted "}${describeVariant(context.env.config.variant)}${context.config.env.config ? " from plugin options" : ""} provided ${Object.keys(properties).length} parameters\nEnvironment Secret configuration: ${context.config.env.secrets ? "" : "Defaulted "}${describeVariant(context.env.secrets.variant)}${context.config.env.secrets ? " from plugin options" : ""} provided ${context.env.secrets?.schema ? getPropertiesList(context.env.secrets).length : "0"} parameters\nEnvironment variable Prefixes: ${context.config.env.prefix.join(", ")}\nShould inject values: ${context.config.env.inject ? "Yes" : "No"}\nShould validate configuration: ${context.config.env.validate ? "Yes" : "No"}`
|
|
166
108
|
});
|
|
167
|
-
const aliases = Object.fromEntries(Object.entries(properties).flatMap(
|
|
109
|
+
const aliases = Object.fromEntries(Object.entries(properties).flatMap(([key, prop]) => isSetArray(prop.alias) ? prop.alias?.map((alias) => [alias, {
|
|
168
110
|
...prop,
|
|
169
111
|
name: alias,
|
|
170
|
-
alias: [...prop.alias?.filter(
|
|
171
|
-
|
|
172
|
-
"",
|
|
173
|
-
"P\"2!\"/\""
|
|
174
|
-
])) ?? [], key]
|
|
175
|
-
}], [
|
|
176
|
-
"alias",
|
|
177
|
-
"",
|
|
178
|
-
"P\"2!\"/\""
|
|
179
|
-
])) : [], [
|
|
180
|
-
"param0",
|
|
181
|
-
"",
|
|
182
|
-
"P\"2!\"/\""
|
|
183
|
-
])));
|
|
112
|
+
alias: [...prop.alias?.filter((a) => a !== alias) ?? [], key]
|
|
113
|
+
}]) : []));
|
|
184
114
|
context.env.parsed = await loadEnv(context);
|
|
185
115
|
for (const [key, value] of Object.entries(context.env.parsed)) {
|
|
186
|
-
const unprefixedKey = context.config.env.prefix.reduce(
|
|
116
|
+
const unprefixedKey = context.config.env.prefix.reduce((ret, prefix) => {
|
|
187
117
|
if (key.startsWith(prefix)) return key.slice(prefix.length + 1);
|
|
188
118
|
return ret;
|
|
189
|
-
},
|
|
190
|
-
"ret",
|
|
191
|
-
"prefix",
|
|
192
|
-
"",
|
|
193
|
-
"P\"2!\"2\"\"/#"
|
|
194
|
-
]), key);
|
|
119
|
+
}, key);
|
|
195
120
|
if (properties[unprefixedKey]) {
|
|
196
121
|
if (!properties[unprefixedKey]?.runtime) {
|
|
197
122
|
const propertySchema = getProperties(context.env.config.schema)?.[unprefixedKey];
|
|
@@ -206,65 +131,27 @@ async function extractEnv(context) {
|
|
|
206
131
|
}
|
|
207
132
|
}
|
|
208
133
|
if (!isSchemaObject(context.env.config)) throw new Error("Invalid environment variable schema extracted. Please ensure the `env.types` option points to a valid TypeScript type definition file that exports an interface representing the environment variable schema.");
|
|
209
|
-
getPropertiesList(context.env.config).forEach(
|
|
134
|
+
getPropertiesList(context.env.config).forEach((property) => {
|
|
210
135
|
property.alias ??= [];
|
|
211
136
|
const aliases = [...property.alias];
|
|
212
|
-
context.config.env.prefix.forEach(
|
|
137
|
+
context.config.env.prefix.forEach((prefix) => {
|
|
213
138
|
if (!property.alias.includes(`${prefix}_${property.name}`)) property.alias.push(`${prefix}_${property.name}`);
|
|
214
|
-
aliases.map(
|
|
215
|
-
"alias",
|
|
216
|
-
"",
|
|
217
|
-
"P\"2!\"/\""
|
|
218
|
-
])).forEach(__assignType((prefixedAlias) => {
|
|
139
|
+
aliases.map((alias) => `${prefix}_${alias}`).forEach((prefixedAlias) => {
|
|
219
140
|
if (!property.alias.includes(prefixedAlias)) property.alias.push(prefixedAlias);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
]));
|
|
225
|
-
}, [
|
|
226
|
-
"prefix",
|
|
227
|
-
"",
|
|
228
|
-
"P\"2!\"/\""
|
|
229
|
-
]));
|
|
230
|
-
}, [
|
|
231
|
-
"property",
|
|
232
|
-
"",
|
|
233
|
-
"P\"2!\"/\""
|
|
234
|
-
]));
|
|
235
|
-
getPropertiesList(context.env.secrets).forEach(__assignType((property) => {
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
getPropertiesList(context.env.secrets).forEach((property) => {
|
|
236
145
|
property.alias ??= [];
|
|
237
146
|
const aliases = [...property.alias];
|
|
238
|
-
context.config.env.prefix.forEach(
|
|
147
|
+
context.config.env.prefix.forEach((prefix) => {
|
|
239
148
|
if (!property.alias.includes(`${prefix}_${property.name}`)) property.alias.push(`${prefix}_${property.name}`);
|
|
240
|
-
aliases.map(
|
|
241
|
-
"alias",
|
|
242
|
-
"",
|
|
243
|
-
"P\"2!\"/\""
|
|
244
|
-
])).forEach(__assignType((prefixedAlias) => {
|
|
149
|
+
aliases.map((alias) => `${prefix}_${alias}`).forEach((prefixedAlias) => {
|
|
245
150
|
if (!property.alias.includes(prefixedAlias)) property.alias.push(prefixedAlias);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
"P\"2!\"/\""
|
|
250
|
-
]));
|
|
251
|
-
}, [
|
|
252
|
-
"prefix",
|
|
253
|
-
"",
|
|
254
|
-
"P\"2!\"/\""
|
|
255
|
-
]));
|
|
256
|
-
}, [
|
|
257
|
-
"property",
|
|
258
|
-
"",
|
|
259
|
-
"P\"2!\"/\""
|
|
260
|
-
]));
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
261
154
|
}
|
|
262
|
-
extractEnv.__type = [
|
|
263
|
-
"context",
|
|
264
|
-
"extractEnv",
|
|
265
|
-
"Extracts the environment variables and secrets schema from the provided type definitions in the plugin options, merges them with the default environment variables and secrets schema, and stores the resulting schema in the plugin context for later use during the build process.",
|
|
266
|
-
"P\"2!$`/\"?#"
|
|
267
|
-
];
|
|
268
155
|
/**
|
|
269
156
|
* Writes the environment variables and secrets schema stored in the plugin context to the cache directory for later retrieval during the build process. This function should be called during the plugin's `build` hook after the schema has been extracted and stored in the plugin context to ensure that the active environment variables and secrets are persisted across builds and can be accessed during the build process for validation and injection purposes.
|
|
270
157
|
*
|
|
@@ -274,13 +161,7 @@ extractEnv.__type = [
|
|
|
274
161
|
async function writeEnv(context) {
|
|
275
162
|
return Promise.all([writeActive(context, "config", context.env.config), writeActive(context, "secrets", context.env.secrets)]);
|
|
276
163
|
}
|
|
277
|
-
writeEnv.__type = [
|
|
278
|
-
"context",
|
|
279
|
-
"writeEnv",
|
|
280
|
-
"Writes the environment variables and secrets schema stored in the plugin context to the cache directory for later retrieval during the build process. This function should be called during the plugin's `build` hook after the schema has been extracted and stored in the plugin context to ensure that the active environment variables and secrets are persisted across builds and can be accessed during the build process for validation and injection purposes.",
|
|
281
|
-
"P\"2!$F`/\"?#"
|
|
282
|
-
];
|
|
283
164
|
|
|
284
165
|
//#endregion
|
|
285
|
-
export { extractEnv, getCacheDirectory, getCacheFilePath, getDefaultConfig, getDefaultSecrets,
|
|
166
|
+
export { extractEnv, getCacheDirectory, getCacheFilePath, getDefaultConfig, getDefaultSecrets, resolveRuntimeSchemaFile, writeEnv };
|
|
286
167
|
//# sourceMappingURL=schema.mjs.map
|
|
@@ -4,54 +4,24 @@ let _stryke_string_format_camel_case = require("@stryke/string-format/camel-case
|
|
|
4
4
|
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
5
5
|
|
|
6
6
|
//#region src/helpers/source-file-env.ts
|
|
7
|
-
function __assignType(fn, args) {
|
|
8
|
-
fn.__type = args;
|
|
9
|
-
return fn;
|
|
10
|
-
}
|
|
11
|
-
const __ΩTReturned = [
|
|
12
|
-
"TEnv",
|
|
13
|
-
"TReturned",
|
|
14
|
-
"l2&R!RPe#!&qk#%QRb!Pde\"!p'w\"y"
|
|
15
|
-
];
|
|
16
7
|
function removeEnvPrefix(env) {
|
|
17
8
|
if ((0, _stryke_type_checks_is_string.isString)(env)) {
|
|
18
|
-
let name = _stryke_env_types.ENV_PREFIXES.reduce(
|
|
9
|
+
let name = _stryke_env_types.ENV_PREFIXES.reduce((ret, prefix) => {
|
|
19
10
|
if (ret.startsWith(prefix)) ret = ret.slice(prefix.length);
|
|
20
11
|
return ret;
|
|
21
|
-
},
|
|
22
|
-
"ret",
|
|
23
|
-
"prefix",
|
|
24
|
-
"",
|
|
25
|
-
"P\"2!\"2\"\"/#"
|
|
26
|
-
]), env.toUpperCase());
|
|
12
|
+
}, env.toUpperCase());
|
|
27
13
|
while (name.startsWith("_")) name = name.slice(1);
|
|
28
14
|
return name;
|
|
29
15
|
}
|
|
30
|
-
return Object.keys(env).reduce(
|
|
16
|
+
return Object.keys(env).reduce((ret, key) => {
|
|
31
17
|
const name = removeEnvPrefix(key);
|
|
32
18
|
if (name) ret[name] = env[key];
|
|
33
19
|
return ret;
|
|
34
|
-
},
|
|
35
|
-
"ret",
|
|
36
|
-
"key",
|
|
37
|
-
"",
|
|
38
|
-
"P\"2!\"2\"\"/#"
|
|
39
|
-
]), {});
|
|
20
|
+
}, {});
|
|
40
21
|
}
|
|
41
|
-
removeEnvPrefix.__type = [
|
|
42
|
-
"env",
|
|
43
|
-
() => __ΩTReturned,
|
|
44
|
-
"removeEnvPrefix",
|
|
45
|
-
"P\"2!\"o\"\"/#"
|
|
46
|
-
];
|
|
47
22
|
function formatEnvField(key) {
|
|
48
23
|
return (0, _stryke_string_format_camel_case.camelCase)(removeEnvPrefix(key));
|
|
49
24
|
}
|
|
50
|
-
formatEnvField.__type = [
|
|
51
|
-
"key",
|
|
52
|
-
"formatEnvField",
|
|
53
|
-
"P&2!&/\""
|
|
54
|
-
];
|
|
55
25
|
|
|
56
26
|
//#endregion
|
|
57
27
|
exports.formatEnvField = formatEnvField;
|
|
@@ -3,54 +3,24 @@ import { camelCase } from "@stryke/string-format/camel-case";
|
|
|
3
3
|
import { isString } from "@stryke/type-checks/is-string";
|
|
4
4
|
|
|
5
5
|
//#region src/helpers/source-file-env.ts
|
|
6
|
-
function __assignType(fn, args) {
|
|
7
|
-
fn.__type = args;
|
|
8
|
-
return fn;
|
|
9
|
-
}
|
|
10
|
-
const __ΩTReturned = [
|
|
11
|
-
"TEnv",
|
|
12
|
-
"TReturned",
|
|
13
|
-
"l2&R!RPe#!&qk#%QRb!Pde\"!p'w\"y"
|
|
14
|
-
];
|
|
15
6
|
function removeEnvPrefix(env) {
|
|
16
7
|
if (isString(env)) {
|
|
17
|
-
let name = ENV_PREFIXES.reduce(
|
|
8
|
+
let name = ENV_PREFIXES.reduce((ret, prefix) => {
|
|
18
9
|
if (ret.startsWith(prefix)) ret = ret.slice(prefix.length);
|
|
19
10
|
return ret;
|
|
20
|
-
},
|
|
21
|
-
"ret",
|
|
22
|
-
"prefix",
|
|
23
|
-
"",
|
|
24
|
-
"P\"2!\"2\"\"/#"
|
|
25
|
-
]), env.toUpperCase());
|
|
11
|
+
}, env.toUpperCase());
|
|
26
12
|
while (name.startsWith("_")) name = name.slice(1);
|
|
27
13
|
return name;
|
|
28
14
|
}
|
|
29
|
-
return Object.keys(env).reduce(
|
|
15
|
+
return Object.keys(env).reduce((ret, key) => {
|
|
30
16
|
const name = removeEnvPrefix(key);
|
|
31
17
|
if (name) ret[name] = env[key];
|
|
32
18
|
return ret;
|
|
33
|
-
},
|
|
34
|
-
"ret",
|
|
35
|
-
"key",
|
|
36
|
-
"",
|
|
37
|
-
"P\"2!\"2\"\"/#"
|
|
38
|
-
]), {});
|
|
19
|
+
}, {});
|
|
39
20
|
}
|
|
40
|
-
removeEnvPrefix.__type = [
|
|
41
|
-
"env",
|
|
42
|
-
() => __ΩTReturned,
|
|
43
|
-
"removeEnvPrefix",
|
|
44
|
-
"P\"2!\"o\"\"/#"
|
|
45
|
-
];
|
|
46
21
|
function formatEnvField(key) {
|
|
47
22
|
return camelCase(removeEnvPrefix(key));
|
|
48
23
|
}
|
|
49
|
-
formatEnvField.__type = [
|
|
50
|
-
"key",
|
|
51
|
-
"formatEnvField",
|
|
52
|
-
"P&2!&/\""
|
|
53
|
-
];
|
|
54
24
|
|
|
55
25
|
//#endregion
|
|
56
26
|
export { formatEnvField, removeEnvPrefix };
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
2
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const
|
|
4
|
-
const require_types_env = require('./types/env.cjs');
|
|
3
|
+
const require_schemas_env = require('./schemas/env.cjs');
|
|
5
4
|
const require_helpers_schema = require('./helpers/schema.cjs');
|
|
6
5
|
const require_helpers_automd_generator = require('./helpers/automd-generator.cjs');
|
|
7
6
|
const require_components_docs = require('./components/docs.cjs');
|
|
@@ -22,14 +21,10 @@ _powerlines_plugin_babel = require_runtime.__toESM(_powerlines_plugin_babel, 1);
|
|
|
22
21
|
let _stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
|
|
23
22
|
|
|
24
23
|
//#region src/index.tsx
|
|
25
|
-
function __assignType(fn, args) {
|
|
26
|
-
fn.__type = args;
|
|
27
|
-
return fn;
|
|
28
|
-
}
|
|
29
24
|
/**
|
|
30
25
|
* A Powerlines plugin to inject environment variables into the source code.
|
|
31
26
|
*/
|
|
32
|
-
const plugin =
|
|
27
|
+
const plugin = (options = {}) => {
|
|
33
28
|
return [
|
|
34
29
|
(0, _powerlines_plugin_babel.default)(options.babel),
|
|
35
30
|
{
|
|
@@ -50,73 +45,51 @@ const plugin = __assignType((options = {}) => {
|
|
|
50
45
|
};
|
|
51
46
|
config.env.config ??= await require_helpers_schema.getDefaultConfig(this);
|
|
52
47
|
config.env.secrets ??= await require_helpers_schema.getDefaultSecrets(this);
|
|
53
|
-
config.env.prefix = (0, _stryke_helpers_get_unique.getUnique)((0, _stryke_convert_to_array.toArray)(config.env.prefix ?? []).reduce(
|
|
48
|
+
config.env.prefix = (0, _stryke_helpers_get_unique.getUnique)((0, _stryke_convert_to_array.toArray)(config.env.prefix ?? []).reduce((ret, prefix) => {
|
|
54
49
|
const formattedPrefix = (0, _stryke_string_format_constant_case.constantCase)(prefix.replace(/_$/g, ""));
|
|
55
50
|
if (!ret.includes(formattedPrefix)) ret.push(formattedPrefix);
|
|
56
51
|
return ret;
|
|
57
|
-
}, [
|
|
58
|
-
"ret",
|
|
59
|
-
"prefix",
|
|
60
|
-
"",
|
|
61
|
-
"P&F2!&2\"\"/#"
|
|
62
|
-
]), [this.config.framework?.name ? `${(0, _stryke_string_format_constant_case.constantCase)(this.config.framework.name)}` : "POWERLINES"])).toReversed();
|
|
52
|
+
}, [this.config.framework?.name ? `${(0, _stryke_string_format_constant_case.constantCase)(this.config.framework.name)}` : "POWERLINES"])).toReversed();
|
|
63
53
|
return config;
|
|
64
54
|
},
|
|
65
|
-
|
|
55
|
+
async configResolved() {
|
|
66
56
|
this.debug(`Environment plugin configuration has been resolved for the Powerlines project.`);
|
|
67
57
|
await require_helpers_schema.extractEnv(this);
|
|
68
|
-
},
|
|
69
|
-
|
|
58
|
+
},
|
|
59
|
+
async prepare() {
|
|
70
60
|
const _self$ = this;
|
|
71
61
|
this.debug(`Preparing the Environment runtime artifacts for the Powerlines project.`);
|
|
72
62
|
return (0, _powerlines_plugin_alloy_render.render)(this, (0, _alloy_js_core_jsx_runtime.createComponent)(require_components_env_builtin.EnvBuiltin, { get defaultConfig() {
|
|
73
63
|
return _self$.config.env.defaultConfig;
|
|
74
64
|
} }));
|
|
75
|
-
},
|
|
76
|
-
|
|
65
|
+
},
|
|
66
|
+
async docs() {
|
|
77
67
|
this.debug(`Documenting environment variables configuration values in "${(0, _stryke_path_join.joinPaths)((0, powerlines_plugin_utils.getDocsOutputPath)(this.config.root), "env.md")}"`);
|
|
78
68
|
return (0, _powerlines_plugin_alloy_render.render)(this, (0, _alloy_js_core_jsx_runtime.createComponent)(require_components_docs.EnvDocsFile, { levelOffset: 0 }));
|
|
79
|
-
},
|
|
80
|
-
|
|
69
|
+
},
|
|
70
|
+
async buildEnd() {
|
|
81
71
|
this.debug("Writing active environment variables to disk.");
|
|
82
72
|
await require_helpers_schema.writeEnv(this);
|
|
83
|
-
}
|
|
73
|
+
}
|
|
84
74
|
},
|
|
85
75
|
{
|
|
86
76
|
name: "env:automd-generator",
|
|
87
|
-
configResolved
|
|
77
|
+
configResolved() {
|
|
88
78
|
return { automd: (0, defu.default)(options.automd ?? {}, { generators: { env: require_helpers_automd_generator.env(this) } }) };
|
|
89
|
-
}
|
|
79
|
+
}
|
|
90
80
|
},
|
|
91
81
|
{
|
|
92
82
|
name: "env:vite",
|
|
93
|
-
vite: { configResolved
|
|
83
|
+
vite: { configResolved() {
|
|
94
84
|
return { envPrefix: this.config?.env?.prefix };
|
|
95
|
-
}
|
|
96
|
-
"EnvPluginContext",
|
|
97
|
-
"this",
|
|
98
|
-
"configResolved",
|
|
99
|
-
"P\"w!2\"\"/#"
|
|
100
|
-
]) }
|
|
85
|
+
} }
|
|
101
86
|
},
|
|
102
87
|
(0, _powerlines_plugin_automd.default)(options.automd)
|
|
103
88
|
];
|
|
104
|
-
}
|
|
105
|
-
"EnvPluginOptions",
|
|
106
|
-
"options",
|
|
107
|
-
() => ({}),
|
|
108
|
-
"",
|
|
109
|
-
"P\"w!2\">#\"/$"
|
|
110
|
-
]);
|
|
89
|
+
};
|
|
111
90
|
|
|
112
91
|
//#endregion
|
|
113
|
-
exports.__ΩEnvInterface = require_types_env.__ΩEnvInterface;
|
|
114
|
-
exports.__ΩEnvPluginContext = require_types_plugin.__ΩEnvPluginContext;
|
|
115
|
-
exports.__ΩEnvPluginOptions = require_types_plugin.__ΩEnvPluginOptions;
|
|
116
|
-
exports.__ΩEnvPluginResolvedConfig = require_types_plugin.__ΩEnvPluginResolvedConfig;
|
|
117
|
-
exports.__ΩEnvPluginUserConfig = require_types_plugin.__ΩEnvPluginUserConfig;
|
|
118
|
-
exports.__ΩEnvSchema = require_types_plugin.__ΩEnvSchema;
|
|
119
|
-
exports.__ΩEnvType = require_types_plugin.__ΩEnvType;
|
|
120
|
-
exports.__ΩSecretsInterface = require_types_env.__ΩSecretsInterface;
|
|
121
92
|
exports.default = plugin;
|
|
122
|
-
exports.plugin = plugin;
|
|
93
|
+
exports.plugin = plugin;
|
|
94
|
+
exports.envSchema = require_schemas_env.envSchema;
|
|
95
|
+
exports.secretsSchema = require_schemas_env.secretsSchema;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EnvPluginContext, EnvPluginOptions, EnvPluginResolvedConfig, EnvPluginUserConfig, EnvSchema, EnvType } from "./types/plugin.cjs";
|
|
2
|
-
import {
|
|
2
|
+
import { Env, EnvInput, Secrets, SecretsInput, envSchema, secretsSchema } from "./schemas/env.cjs";
|
|
3
3
|
import "./types/index.cjs";
|
|
4
4
|
import { Plugin } from "powerlines";
|
|
5
5
|
//#region src/index.d.ts
|
|
@@ -13,5 +13,5 @@ declare module "powerlines" {
|
|
|
13
13
|
*/
|
|
14
14
|
declare const plugin: <TContext extends EnvPluginContext = EnvPluginContext>(options?: EnvPluginOptions) => Plugin<TContext>[];
|
|
15
15
|
//#endregion
|
|
16
|
-
export {
|
|
16
|
+
export { type Env, type EnvInput, EnvPluginContext, EnvPluginOptions, EnvPluginResolvedConfig, EnvPluginUserConfig, EnvSchema, EnvType, type Secrets, type SecretsInput, plugin as default, plugin, envSchema, secretsSchema };
|
|
17
17
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;YAoDY;IACR,MAAM;;;;;;cAOG,SAAU,iBAAiB,mBAAmB,kBACzD,UAAS,qBAyGJ,OAAO"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EnvPluginContext, EnvPluginOptions, EnvPluginResolvedConfig, EnvPluginUserConfig, EnvSchema, EnvType } from "./types/plugin.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { Env, EnvInput, Secrets, SecretsInput, envSchema, secretsSchema } from "./schemas/env.mjs";
|
|
3
3
|
import "./types/index.mjs";
|
|
4
4
|
import { Plugin } from "powerlines";
|
|
5
5
|
//#region src/index.d.ts
|
|
@@ -13,5 +13,5 @@ declare module "powerlines" {
|
|
|
13
13
|
*/
|
|
14
14
|
declare const plugin: <TContext extends EnvPluginContext = EnvPluginContext>(options?: EnvPluginOptions) => Plugin<TContext>[];
|
|
15
15
|
//#endregion
|
|
16
|
-
export {
|
|
16
|
+
export { type Env, type EnvInput, EnvPluginContext, EnvPluginOptions, EnvPluginResolvedConfig, EnvPluginUserConfig, EnvSchema, EnvType, type Secrets, type SecretsInput, plugin as default, plugin, envSchema, secretsSchema };
|
|
17
17
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { __ΩEnvInterface, __ΩSecretsInterface } from "./types/env.mjs";
|
|
1
|
+
import { envSchema, secretsSchema } from "./schemas/env.mjs";
|
|
3
2
|
import { extractEnv, getDefaultConfig, getDefaultSecrets, writeEnv } from "./helpers/schema.mjs";
|
|
4
3
|
import { env } from "./helpers/automd-generator.mjs";
|
|
5
4
|
import { EnvDocsFile } from "./components/docs.mjs";
|
|
@@ -17,14 +16,10 @@ import babel from "@powerlines/plugin-babel";
|
|
|
17
16
|
import { constantCase } from "@stryke/string-format/constant-case";
|
|
18
17
|
|
|
19
18
|
//#region src/index.tsx
|
|
20
|
-
function __assignType(fn, args) {
|
|
21
|
-
fn.__type = args;
|
|
22
|
-
return fn;
|
|
23
|
-
}
|
|
24
19
|
/**
|
|
25
20
|
* A Powerlines plugin to inject environment variables into the source code.
|
|
26
21
|
*/
|
|
27
|
-
const plugin =
|
|
22
|
+
const plugin = (options = {}) => {
|
|
28
23
|
return [
|
|
29
24
|
babel(options.babel),
|
|
30
25
|
{
|
|
@@ -45,65 +40,49 @@ const plugin = __assignType((options = {}) => {
|
|
|
45
40
|
};
|
|
46
41
|
config.env.config ??= await getDefaultConfig(this);
|
|
47
42
|
config.env.secrets ??= await getDefaultSecrets(this);
|
|
48
|
-
config.env.prefix = getUnique(toArray(config.env.prefix ?? []).reduce(
|
|
43
|
+
config.env.prefix = getUnique(toArray(config.env.prefix ?? []).reduce((ret, prefix) => {
|
|
49
44
|
const formattedPrefix = constantCase(prefix.replace(/_$/g, ""));
|
|
50
45
|
if (!ret.includes(formattedPrefix)) ret.push(formattedPrefix);
|
|
51
46
|
return ret;
|
|
52
|
-
}, [
|
|
53
|
-
"ret",
|
|
54
|
-
"prefix",
|
|
55
|
-
"",
|
|
56
|
-
"P&F2!&2\"\"/#"
|
|
57
|
-
]), [this.config.framework?.name ? `${constantCase(this.config.framework.name)}` : "POWERLINES"])).toReversed();
|
|
47
|
+
}, [this.config.framework?.name ? `${constantCase(this.config.framework.name)}` : "POWERLINES"])).toReversed();
|
|
58
48
|
return config;
|
|
59
49
|
},
|
|
60
|
-
|
|
50
|
+
async configResolved() {
|
|
61
51
|
this.debug(`Environment plugin configuration has been resolved for the Powerlines project.`);
|
|
62
52
|
await extractEnv(this);
|
|
63
|
-
},
|
|
64
|
-
|
|
53
|
+
},
|
|
54
|
+
async prepare() {
|
|
65
55
|
const _self$ = this;
|
|
66
56
|
this.debug(`Preparing the Environment runtime artifacts for the Powerlines project.`);
|
|
67
57
|
return render(this, createComponent(EnvBuiltin, { get defaultConfig() {
|
|
68
58
|
return _self$.config.env.defaultConfig;
|
|
69
59
|
} }));
|
|
70
|
-
},
|
|
71
|
-
|
|
60
|
+
},
|
|
61
|
+
async docs() {
|
|
72
62
|
this.debug(`Documenting environment variables configuration values in "${joinPaths(getDocsOutputPath(this.config.root), "env.md")}"`);
|
|
73
63
|
return render(this, createComponent(EnvDocsFile, { levelOffset: 0 }));
|
|
74
|
-
},
|
|
75
|
-
|
|
64
|
+
},
|
|
65
|
+
async buildEnd() {
|
|
76
66
|
this.debug("Writing active environment variables to disk.");
|
|
77
67
|
await writeEnv(this);
|
|
78
|
-
}
|
|
68
|
+
}
|
|
79
69
|
},
|
|
80
70
|
{
|
|
81
71
|
name: "env:automd-generator",
|
|
82
|
-
configResolved
|
|
72
|
+
configResolved() {
|
|
83
73
|
return { automd: defu(options.automd ?? {}, { generators: { env: env(this) } }) };
|
|
84
|
-
}
|
|
74
|
+
}
|
|
85
75
|
},
|
|
86
76
|
{
|
|
87
77
|
name: "env:vite",
|
|
88
|
-
vite: { configResolved
|
|
78
|
+
vite: { configResolved() {
|
|
89
79
|
return { envPrefix: this.config?.env?.prefix };
|
|
90
|
-
}
|
|
91
|
-
"EnvPluginContext",
|
|
92
|
-
"this",
|
|
93
|
-
"configResolved",
|
|
94
|
-
"P\"w!2\"\"/#"
|
|
95
|
-
]) }
|
|
80
|
+
} }
|
|
96
81
|
},
|
|
97
82
|
automd(options.automd)
|
|
98
83
|
];
|
|
99
|
-
}
|
|
100
|
-
"EnvPluginOptions",
|
|
101
|
-
"options",
|
|
102
|
-
() => ({}),
|
|
103
|
-
"",
|
|
104
|
-
"P\"w!2\">#\"/$"
|
|
105
|
-
]);
|
|
84
|
+
};
|
|
106
85
|
|
|
107
86
|
//#endregion
|
|
108
|
-
export {
|
|
87
|
+
export { plugin as default, plugin, envSchema, secretsSchema };
|
|
109
88
|
//# sourceMappingURL=index.mjs.map
|