@powerlines/plugin-nodejs 0.1.0 → 0.1.2
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 +99 -0
- package/dist/plugin-alloy/src/index.mjs +97 -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 +23 -0
- package/dist/plugin-alloy/src/types/components.d.mts +24 -0
- package/dist/plugin-alloy/src/types/index.d.cts +2 -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 +26 -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 +28 -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 +15 -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 +4 -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 +152 -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,54 @@
|
|
|
1
|
+
import { readEnvTypeReflection } from "./persistence.mjs";
|
|
2
|
+
import { loadEnvFromContext } from "./load.mjs";
|
|
3
|
+
import { titleCase } from "@stryke/string-format/title-case";
|
|
4
|
+
import { ReflectionClass, ReflectionKind } from "@powerlines/deepkit/vendor/type";
|
|
5
|
+
import { computed, createResource } from "@alloy-js/core";
|
|
6
|
+
|
|
7
|
+
//#region ../plugin-env/src/helpers/create-reflection-resource.ts
|
|
8
|
+
/**
|
|
9
|
+
* Creates a reflection resource for the environment configuration.
|
|
10
|
+
*
|
|
11
|
+
* @param context - The environment plugin context.
|
|
12
|
+
* @returns A resource that provides the reflection of the environment configuration.
|
|
13
|
+
*/
|
|
14
|
+
function createReflectionResource(context) {
|
|
15
|
+
const defaultValue = computed(() => context && loadEnvFromContext(context, process.env));
|
|
16
|
+
return createResource(async () => {
|
|
17
|
+
if (!context) return new ReflectionClass({
|
|
18
|
+
kind: ReflectionKind.objectLiteral,
|
|
19
|
+
description: `The initial environment configuration state for the Powerlines project.`,
|
|
20
|
+
types: []
|
|
21
|
+
});
|
|
22
|
+
const result = await readEnvTypeReflection(context, "env");
|
|
23
|
+
result.getProperties().forEach((prop) => {
|
|
24
|
+
prop.getAlias().filter(Boolean).forEach((alias) => {
|
|
25
|
+
result.addProperty({
|
|
26
|
+
name: alias,
|
|
27
|
+
optional: prop.isOptional() ? true : void 0,
|
|
28
|
+
readonly: prop.isReadonly() ? true : void 0,
|
|
29
|
+
description: prop.getDescription(),
|
|
30
|
+
visibility: prop.getVisibility(),
|
|
31
|
+
type: prop.getType(),
|
|
32
|
+
default: prop.getDefaultValue(),
|
|
33
|
+
tags: {
|
|
34
|
+
hidden: prop.isHidden(),
|
|
35
|
+
ignore: prop.isIgnored(),
|
|
36
|
+
internal: prop.isInternal(),
|
|
37
|
+
alias: prop.getAlias().filter((a) => a !== alias).concat(prop.name),
|
|
38
|
+
title: prop.getTitle() || titleCase(prop.name),
|
|
39
|
+
readonly: prop.isReadonly(),
|
|
40
|
+
permission: prop.getPermission(),
|
|
41
|
+
domain: prop.getDomain()
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
result.getProperties().forEach((prop) => {
|
|
47
|
+
prop.setDefaultValue(defaultValue.value?.[prop.getNameAsString()] ?? prop.getAlias().reduce((ret, alias) => ret ?? defaultValue.value?.[alias], void 0) ?? prop.getDefaultValue());
|
|
48
|
+
});
|
|
49
|
+
return result;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { createReflectionResource };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const require_reflect = require('./reflect.cjs');
|
|
2
|
+
const require_persistence = require('./persistence.cjs');
|
|
3
|
+
const require_source_file_env = require('./source-file-env.cjs');
|
|
4
|
+
const require_load = require('./load.cjs');
|
|
5
|
+
const require_create_reflection_resource = require('./create-reflection-resource.cjs');
|
|
6
|
+
require('./template-helpers.cjs');
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseEnv, BaseSecrets, createEnvReflection, createSecretsReflection, mergeEnvReflections, mergeSecretsReflections, reflectEnv, reflectSecrets } from "./reflect.mjs";
|
|
2
|
+
import { getEnvDefaultTypeDefinition, getEnvReflectionsPath, getEnvTypeReflectionsPath, getSecretsDefaultTypeDefinition, readEnvReflection, readEnvTypeReflection, readSecretsReflection, resolveRuntimeTypeFile, writeEnvReflection, writeEnvTypeReflection } from "./persistence.mjs";
|
|
3
|
+
import { removeEnvPrefix } from "./source-file-env.mjs";
|
|
4
|
+
import { loadEnv, loadEnvFromContext } from "./load.mjs";
|
|
5
|
+
import { createReflectionResource } from "./create-reflection-resource.mjs";
|
|
6
|
+
import "./template-helpers.mjs";
|
|
7
|
+
|
|
8
|
+
export { };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_source_file_env = require('./source-file-env.cjs');
|
|
3
|
+
let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
4
|
+
let defu = require("defu");
|
|
5
|
+
defu = require_rolldown_runtime.__toESM(defu);
|
|
6
|
+
let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
7
|
+
let __stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
8
|
+
let __stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
9
|
+
let c12 = require("c12");
|
|
10
|
+
let __stryke_env_load_env = require("@stryke/env/load-env");
|
|
11
|
+
|
|
12
|
+
//#region ../plugin-env/src/helpers/load.ts
|
|
13
|
+
async function loadEnvFiles(options, mode, cwd) {
|
|
14
|
+
let env = await (0, __stryke_env_load_env.loadEnv)(cwd, mode);
|
|
15
|
+
if (options.additionalFiles && options.additionalFiles?.length > 0) {
|
|
16
|
+
const additionalEnvFiles = await Promise.all(options.additionalFiles.map(async (additionalEnvFile) => (0, __stryke_env_load_env.loadEnvFile)(additionalEnvFile, cwd)));
|
|
17
|
+
for (const additionalEnvFile of additionalEnvFiles) env = (0, defu.default)(additionalEnvFile, env);
|
|
18
|
+
}
|
|
19
|
+
return require_source_file_env.removeEnvPrefix(env);
|
|
20
|
+
}
|
|
21
|
+
async function loadEnvDirectory(options, directory, mode, cacheDir, packageJson, workspaceConfig) {
|
|
22
|
+
const [envResult, c12Result] = await Promise.all([loadEnvFiles(options, mode, directory), (0, c12.loadConfig)({
|
|
23
|
+
cwd: directory,
|
|
24
|
+
name: "storm",
|
|
25
|
+
envName: mode,
|
|
26
|
+
defaults: {
|
|
27
|
+
NAME: packageJson.name?.replace(`@${workspaceConfig.namespace}/`, ""),
|
|
28
|
+
MODE: mode,
|
|
29
|
+
ORG: workspaceConfig.organization
|
|
30
|
+
},
|
|
31
|
+
globalRc: true,
|
|
32
|
+
packageJson: true,
|
|
33
|
+
dotenv: true,
|
|
34
|
+
jitiOptions: {
|
|
35
|
+
fsCache: (0, __stryke_path_join_paths.joinPaths)(cacheDir, "jiti"),
|
|
36
|
+
moduleCache: true
|
|
37
|
+
}
|
|
38
|
+
})]);
|
|
39
|
+
return (0, defu.default)(envResult, c12Result.config, workspaceConfig);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves various dotenv configuration parameters from the context.
|
|
43
|
+
*
|
|
44
|
+
* @param context - The context to retrieve the dotenv configuration from.
|
|
45
|
+
* @param parsed - The parsed dotenv configuration.
|
|
46
|
+
* @returns An object containing the dotenv configuration.
|
|
47
|
+
*/
|
|
48
|
+
function loadEnvFromContext(context, parsed) {
|
|
49
|
+
return (0, defu.default)({
|
|
50
|
+
APP_NAME: (0, __stryke_string_format_kebab_case.kebabCase)(context.config.name || context.packageJson.name?.replace(`/${context.workspaceConfig.namespace}`, "")),
|
|
51
|
+
APP_VERSION: context.packageJson.version,
|
|
52
|
+
BUILD_ID: context.meta.buildId,
|
|
53
|
+
BUILD_TIMESTAMP: new Date(context.meta.timestamp).toISOString(),
|
|
54
|
+
BUILD_CHECKSUM: context.meta.checksum,
|
|
55
|
+
RELEASE_ID: context.meta.releaseId,
|
|
56
|
+
RELEASE_TAG: `${(0, __stryke_string_format_kebab_case.kebabCase)(context.config.name)}@${context.packageJson.version}`,
|
|
57
|
+
DEFAULT_LOCALE: context.workspaceConfig.locale,
|
|
58
|
+
DEFAULT_TIMEZONE: context.workspaceConfig.timezone,
|
|
59
|
+
LOG_LEVEL: context.config.logLevel,
|
|
60
|
+
ERROR_URL: context.workspaceConfig.error?.url,
|
|
61
|
+
ORGANIZATION: (0, __stryke_type_checks_is_set_string.isSetString)(context.workspaceConfig.organization) ? context.workspaceConfig.organization : context.workspaceConfig.organization?.name,
|
|
62
|
+
PLATFORM: context.config.build.platform,
|
|
63
|
+
MODE: context.workspaceConfig.mode,
|
|
64
|
+
DEBUG: context.workspaceConfig.mode === "development",
|
|
65
|
+
STACKTRACE: context.workspaceConfig.mode === "development",
|
|
66
|
+
ENVIRONMENT: context.environment
|
|
67
|
+
}, (0, __stryke_type_checks_is_set_object.isSetObject)(context?.env?.types?.env) ? context.env.types.env?.getProperties().reduce((ret, prop) => {
|
|
68
|
+
ret[prop.name] = parsed[prop.name] ?? prop.getDefaultValue();
|
|
69
|
+
return ret;
|
|
70
|
+
}, {}) : {});
|
|
71
|
+
}
|
|
72
|
+
async function loadEnv(context, options) {
|
|
73
|
+
const [project, workspace, config] = await Promise.all([
|
|
74
|
+
loadEnvDirectory(options, context.config.projectRoot, context.config.mode, context.cachePath, context.packageJson, context.workspaceConfig),
|
|
75
|
+
loadEnvDirectory(options, context.workspaceConfig.workspaceRoot, context.config.mode, context.cachePath, context.packageJson, context.workspaceConfig),
|
|
76
|
+
loadEnvDirectory(options, context.envPaths.config, context.config.mode, context.cachePath, context.packageJson, context.workspaceConfig)
|
|
77
|
+
]);
|
|
78
|
+
return (0, defu.default)(loadEnvFromContext(context, process.env), project, workspace, config);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
exports.loadEnv = loadEnv;
|
|
83
|
+
exports.loadEnvFromContext = loadEnvFromContext;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { removeEnvPrefix } from "./source-file-env.mjs";
|
|
2
|
+
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
3
|
+
import defu from "defu";
|
|
4
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
5
|
+
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
6
|
+
import { joinPaths } from "@stryke/path/join-paths";
|
|
7
|
+
import { loadConfig } from "c12";
|
|
8
|
+
import { loadEnv, loadEnvFile } from "@stryke/env/load-env";
|
|
9
|
+
|
|
10
|
+
//#region ../plugin-env/src/helpers/load.ts
|
|
11
|
+
async function loadEnvFiles(options, mode, cwd) {
|
|
12
|
+
let env = await loadEnv(cwd, mode);
|
|
13
|
+
if (options.additionalFiles && options.additionalFiles?.length > 0) {
|
|
14
|
+
const additionalEnvFiles = await Promise.all(options.additionalFiles.map(async (additionalEnvFile) => loadEnvFile(additionalEnvFile, cwd)));
|
|
15
|
+
for (const additionalEnvFile of additionalEnvFiles) env = defu(additionalEnvFile, env);
|
|
16
|
+
}
|
|
17
|
+
return removeEnvPrefix(env);
|
|
18
|
+
}
|
|
19
|
+
async function loadEnvDirectory(options, directory, mode, cacheDir, packageJson, workspaceConfig) {
|
|
20
|
+
const [envResult, c12Result] = await Promise.all([loadEnvFiles(options, mode, directory), loadConfig({
|
|
21
|
+
cwd: directory,
|
|
22
|
+
name: "storm",
|
|
23
|
+
envName: mode,
|
|
24
|
+
defaults: {
|
|
25
|
+
NAME: packageJson.name?.replace(`@${workspaceConfig.namespace}/`, ""),
|
|
26
|
+
MODE: mode,
|
|
27
|
+
ORG: workspaceConfig.organization
|
|
28
|
+
},
|
|
29
|
+
globalRc: true,
|
|
30
|
+
packageJson: true,
|
|
31
|
+
dotenv: true,
|
|
32
|
+
jitiOptions: {
|
|
33
|
+
fsCache: joinPaths(cacheDir, "jiti"),
|
|
34
|
+
moduleCache: true
|
|
35
|
+
}
|
|
36
|
+
})]);
|
|
37
|
+
return defu(envResult, c12Result.config, workspaceConfig);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Retrieves various dotenv configuration parameters from the context.
|
|
41
|
+
*
|
|
42
|
+
* @param context - The context to retrieve the dotenv configuration from.
|
|
43
|
+
* @param parsed - The parsed dotenv configuration.
|
|
44
|
+
* @returns An object containing the dotenv configuration.
|
|
45
|
+
*/
|
|
46
|
+
function loadEnvFromContext(context, parsed) {
|
|
47
|
+
return defu({
|
|
48
|
+
APP_NAME: kebabCase(context.config.name || context.packageJson.name?.replace(`/${context.workspaceConfig.namespace}`, "")),
|
|
49
|
+
APP_VERSION: context.packageJson.version,
|
|
50
|
+
BUILD_ID: context.meta.buildId,
|
|
51
|
+
BUILD_TIMESTAMP: new Date(context.meta.timestamp).toISOString(),
|
|
52
|
+
BUILD_CHECKSUM: context.meta.checksum,
|
|
53
|
+
RELEASE_ID: context.meta.releaseId,
|
|
54
|
+
RELEASE_TAG: `${kebabCase(context.config.name)}@${context.packageJson.version}`,
|
|
55
|
+
DEFAULT_LOCALE: context.workspaceConfig.locale,
|
|
56
|
+
DEFAULT_TIMEZONE: context.workspaceConfig.timezone,
|
|
57
|
+
LOG_LEVEL: context.config.logLevel,
|
|
58
|
+
ERROR_URL: context.workspaceConfig.error?.url,
|
|
59
|
+
ORGANIZATION: isSetString(context.workspaceConfig.organization) ? context.workspaceConfig.organization : context.workspaceConfig.organization?.name,
|
|
60
|
+
PLATFORM: context.config.build.platform,
|
|
61
|
+
MODE: context.workspaceConfig.mode,
|
|
62
|
+
DEBUG: context.workspaceConfig.mode === "development",
|
|
63
|
+
STACKTRACE: context.workspaceConfig.mode === "development",
|
|
64
|
+
ENVIRONMENT: context.environment
|
|
65
|
+
}, isSetObject(context?.env?.types?.env) ? context.env.types.env?.getProperties().reduce((ret, prop) => {
|
|
66
|
+
ret[prop.name] = parsed[prop.name] ?? prop.getDefaultValue();
|
|
67
|
+
return ret;
|
|
68
|
+
}, {}) : {});
|
|
69
|
+
}
|
|
70
|
+
async function loadEnv$1(context, options) {
|
|
71
|
+
const [project, workspace, config] = await Promise.all([
|
|
72
|
+
loadEnvDirectory(options, context.config.projectRoot, context.config.mode, context.cachePath, context.packageJson, context.workspaceConfig),
|
|
73
|
+
loadEnvDirectory(options, context.workspaceConfig.workspaceRoot, context.config.mode, context.cachePath, context.packageJson, context.workspaceConfig),
|
|
74
|
+
loadEnvDirectory(options, context.envPaths.config, context.config.mode, context.cachePath, context.packageJson, context.workspaceConfig)
|
|
75
|
+
]);
|
|
76
|
+
return defu(loadEnvFromContext(context, process.env), project, workspace, config);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { loadEnv$1 as loadEnv, loadEnvFromContext };
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_capnp = require('../../../deepkit/src/capnp.cjs');
|
|
3
|
+
const require_reflection = require('../../../deepkit/schemas/reflection2.cjs');
|
|
4
|
+
const require_resolve_reflections = require('../../../deepkit/src/resolve-reflections.cjs');
|
|
5
|
+
const require_reflect = require('./reflect.cjs');
|
|
6
|
+
let __powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
7
|
+
let __stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
8
|
+
let __stryke_capnp = require("@stryke/capnp");
|
|
9
|
+
__stryke_capnp = require_rolldown_runtime.__toESM(__stryke_capnp);
|
|
10
|
+
let __stryke_fs_buffer = require("@stryke/fs/buffer");
|
|
11
|
+
let node_fs = require("node:fs");
|
|
12
|
+
let __stryke_type_checks_is_empty_object = require("@stryke/type-checks/is-empty-object");
|
|
13
|
+
|
|
14
|
+
//#region ../plugin-env/src/helpers/persistence.ts
|
|
15
|
+
/**
|
|
16
|
+
* Resolves the runtime type definition file for the environment variables.
|
|
17
|
+
*
|
|
18
|
+
* @param context - The plugin context.
|
|
19
|
+
* @returns The runtime type definition file for the environment variables.
|
|
20
|
+
*/
|
|
21
|
+
async function resolveRuntimeTypeFile(context) {
|
|
22
|
+
return context.resolver.esmResolve("@powerlines/plugin-env/types/runtime");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Gets the default type definition for the environment variables.
|
|
26
|
+
*
|
|
27
|
+
* @param context - The plugin context.
|
|
28
|
+
* @returns The default type definition for the environment variables.
|
|
29
|
+
*/
|
|
30
|
+
async function getEnvDefaultTypeDefinition(context) {
|
|
31
|
+
return {
|
|
32
|
+
file: await resolveRuntimeTypeFile(context),
|
|
33
|
+
name: "EnvInterface"
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** Gets the default type definition for the environment secrets.
|
|
37
|
+
*
|
|
38
|
+
* @param context - The plugin context.
|
|
39
|
+
* @returns The default type definition for the environment secrets.
|
|
40
|
+
*/
|
|
41
|
+
async function getSecretsDefaultTypeDefinition(context) {
|
|
42
|
+
return {
|
|
43
|
+
file: await resolveRuntimeTypeFile(context),
|
|
44
|
+
name: "SecretsInterface"
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Gets the path to the environment type reflections.
|
|
49
|
+
*
|
|
50
|
+
* @param context - The plugin context.
|
|
51
|
+
* @param name - The name of the type reflections.
|
|
52
|
+
* @returns The path to the environment type reflections.
|
|
53
|
+
*/
|
|
54
|
+
function getEnvTypeReflectionsPath(context, name = "env") {
|
|
55
|
+
return (0, __stryke_path_join_paths.joinPaths)(require_resolve_reflections.getReflectionsPath(context), "env", `${name}-types.bin`);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Reads the environment type reflection from the file system.
|
|
59
|
+
*
|
|
60
|
+
* @param context - The plugin context.
|
|
61
|
+
* @param name - The name of the type reflections.
|
|
62
|
+
* @returns The environment type reflection.
|
|
63
|
+
*/
|
|
64
|
+
async function readEnvTypeReflection(context, name = "env") {
|
|
65
|
+
const filePath = getEnvTypeReflectionsPath(context, name);
|
|
66
|
+
if (!(0, node_fs.existsSync)(filePath)) {
|
|
67
|
+
if (!context.env.types.env || (0, __stryke_type_checks_is_empty_object.isEmptyObject)(context.env.types.env)) {
|
|
68
|
+
const reflection$1 = require_reflect.createEnvReflection(context);
|
|
69
|
+
const message = new __stryke_capnp.Message();
|
|
70
|
+
reflection$1.messageRoot = message.initRoot(require_reflection.SerializedTypes);
|
|
71
|
+
reflection$1.dataBuffer = message.toArrayBuffer();
|
|
72
|
+
context.env.types.env = reflection$1;
|
|
73
|
+
await writeEnvTypeReflection(context, context.env.types.env, name);
|
|
74
|
+
}
|
|
75
|
+
return context.env.types.env;
|
|
76
|
+
}
|
|
77
|
+
const buffer = await (0, __stryke_fs_buffer.readFileBuffer)(filePath);
|
|
78
|
+
const messageRoot = new __stryke_capnp.Message(buffer, false).getRoot(require_reflection.SerializedTypes);
|
|
79
|
+
const reflection = (0, __powerlines_deepkit_vendor_type.resolveClassType)((0, __powerlines_deepkit_vendor_type.deserializeType)(require_capnp.convertFromCapnp(messageRoot.types)));
|
|
80
|
+
context.env.types[name] = reflection;
|
|
81
|
+
context.env.types[name].messageRoot = messageRoot;
|
|
82
|
+
context.env.types[name].dataBuffer = buffer;
|
|
83
|
+
return reflection;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Writes the environment type reflection to the file system.
|
|
87
|
+
*
|
|
88
|
+
* @param context - The plugin context.
|
|
89
|
+
* @param reflection - The environment type reflection to write.
|
|
90
|
+
* @param name - The name of the type reflections.
|
|
91
|
+
*/
|
|
92
|
+
async function writeEnvTypeReflection(context, reflection, name = "env") {
|
|
93
|
+
const serialized = reflection.serializeType();
|
|
94
|
+
const message = new __stryke_capnp.Message();
|
|
95
|
+
require_capnp.convertToCapnp(serialized, message.initRoot(require_reflection.SerializedTypes)._initTypes(serialized.length));
|
|
96
|
+
await (0, __stryke_fs_buffer.writeFileBuffer)(getEnvTypeReflectionsPath(context, name), message.toArrayBuffer());
|
|
97
|
+
}
|
|
98
|
+
function getEnvReflectionsPath(context, name) {
|
|
99
|
+
return (0, __stryke_path_join_paths.joinPaths)(require_resolve_reflections.getReflectionsPath(context), "env", `${name}.bin`);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Reads the environment reflection data from the file system.
|
|
103
|
+
*
|
|
104
|
+
* @param context - The plugin context.
|
|
105
|
+
* @returns The environment reflection data.
|
|
106
|
+
*/
|
|
107
|
+
async function readEnvReflection(context) {
|
|
108
|
+
const filePath = getEnvReflectionsPath(context, "env");
|
|
109
|
+
if (!(0, node_fs.existsSync)(filePath)) {
|
|
110
|
+
if (!context.env.types.env) context.env.types.env = await readEnvTypeReflection(context, "env");
|
|
111
|
+
if (!context.env.used.env || (0, __stryke_type_checks_is_empty_object.isEmptyObject)(context.env.used.env)) {
|
|
112
|
+
const reflection$1 = require_reflect.createEnvReflection(context, {
|
|
113
|
+
type: {
|
|
114
|
+
kind: __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral,
|
|
115
|
+
typeName: "Env",
|
|
116
|
+
description: `An object containing the environment configuration parameters that are used (at least once) by the ${context.config.name ? `${context.config.name} application` : "application"}.`,
|
|
117
|
+
types: []
|
|
118
|
+
},
|
|
119
|
+
superReflection: context.env.types.env
|
|
120
|
+
});
|
|
121
|
+
reflection$1.name = "Env";
|
|
122
|
+
const message = new __stryke_capnp.Message();
|
|
123
|
+
reflection$1.messageRoot = message.initRoot(require_reflection.SerializedTypes);
|
|
124
|
+
reflection$1.dataBuffer = message.toArrayBuffer();
|
|
125
|
+
context.env.used.env = reflection$1;
|
|
126
|
+
await writeEnvReflection(context, context.env.used.env, "env");
|
|
127
|
+
}
|
|
128
|
+
return context.env.used.env;
|
|
129
|
+
}
|
|
130
|
+
const buffer = await (0, __stryke_fs_buffer.readFileBuffer)(filePath);
|
|
131
|
+
const messageRoot = new __stryke_capnp.Message(buffer, false).getRoot(require_reflection.SerializedTypes);
|
|
132
|
+
const reflection = (0, __powerlines_deepkit_vendor_type.resolveClassType)((0, __powerlines_deepkit_vendor_type.deserializeType)(require_capnp.convertFromCapnp(messageRoot.types)));
|
|
133
|
+
context.env.used.env = reflection;
|
|
134
|
+
context.env.used.env.messageRoot = messageRoot;
|
|
135
|
+
context.env.used.env.dataBuffer = buffer;
|
|
136
|
+
return reflection;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Reads the secret environment reflection data from the file system.
|
|
140
|
+
*
|
|
141
|
+
* @param context - The plugin context.
|
|
142
|
+
* @returns The environment reflection data.
|
|
143
|
+
*/
|
|
144
|
+
async function readSecretsReflection(context) {
|
|
145
|
+
const filePath = getEnvReflectionsPath(context, "secrets");
|
|
146
|
+
if (!(0, node_fs.existsSync)(filePath)) {
|
|
147
|
+
if (!context.env.types.secrets) context.env.types.secrets = await readEnvTypeReflection(context, "secrets");
|
|
148
|
+
if (!context.env.used.secrets || (0, __stryke_type_checks_is_empty_object.isEmptyObject)(context.env.used.secrets)) {
|
|
149
|
+
const reflection$1 = require_reflect.createEnvReflection(context, {
|
|
150
|
+
type: {
|
|
151
|
+
kind: __powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral,
|
|
152
|
+
typeName: "Secrets",
|
|
153
|
+
description: `An object containing the secret configuration parameters that are used (at least once) by the ${context.config.name ? `${context.config.name} application` : "application"}.`,
|
|
154
|
+
types: []
|
|
155
|
+
},
|
|
156
|
+
superReflection: context.env.types.secrets
|
|
157
|
+
});
|
|
158
|
+
reflection$1.name = "Secrets";
|
|
159
|
+
const message = new __stryke_capnp.Message();
|
|
160
|
+
reflection$1.messageRoot = message.initRoot(require_reflection.SerializedTypes);
|
|
161
|
+
reflection$1.dataBuffer = message.toArrayBuffer();
|
|
162
|
+
context.env.used.secrets = reflection$1;
|
|
163
|
+
await writeEnvReflection(context, context.env.used.secrets, "secrets");
|
|
164
|
+
}
|
|
165
|
+
return context.env.used.secrets;
|
|
166
|
+
}
|
|
167
|
+
const buffer = await (0, __stryke_fs_buffer.readFileBuffer)(filePath);
|
|
168
|
+
const messageRoot = new __stryke_capnp.Message(buffer, false).getRoot(require_reflection.SerializedTypes);
|
|
169
|
+
const reflection = (0, __powerlines_deepkit_vendor_type.resolveClassType)((0, __powerlines_deepkit_vendor_type.deserializeType)(require_capnp.convertFromCapnp(messageRoot.types)));
|
|
170
|
+
context.env.used.secrets = reflection;
|
|
171
|
+
context.env.used.secrets.messageRoot = messageRoot;
|
|
172
|
+
context.env.used.secrets.dataBuffer = buffer;
|
|
173
|
+
return reflection;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Writes the environment reflection data to the file system.
|
|
177
|
+
*
|
|
178
|
+
* @param context - The plugin context.
|
|
179
|
+
* @param reflection - The reflection data to write.
|
|
180
|
+
* @param name - The name of the reflection (either "env" or "secrets").
|
|
181
|
+
*/
|
|
182
|
+
async function writeEnvReflection(context, reflection, name = "env") {
|
|
183
|
+
const serialized = reflection.serializeType();
|
|
184
|
+
const message = new __stryke_capnp.Message();
|
|
185
|
+
require_capnp.convertToCapnp(serialized, message.initRoot(require_reflection.SerializedTypes)._initTypes(serialized.length));
|
|
186
|
+
await (0, __stryke_fs_buffer.writeFileBuffer)(getEnvReflectionsPath(context, name), message.toArrayBuffer());
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
//#endregion
|
|
190
|
+
exports.getEnvDefaultTypeDefinition = getEnvDefaultTypeDefinition;
|
|
191
|
+
exports.getEnvReflectionsPath = getEnvReflectionsPath;
|
|
192
|
+
exports.getEnvTypeReflectionsPath = getEnvTypeReflectionsPath;
|
|
193
|
+
exports.getSecretsDefaultTypeDefinition = getSecretsDefaultTypeDefinition;
|
|
194
|
+
exports.readEnvReflection = readEnvReflection;
|
|
195
|
+
exports.readEnvTypeReflection = readEnvTypeReflection;
|
|
196
|
+
exports.readSecretsReflection = readSecretsReflection;
|
|
197
|
+
exports.resolveRuntimeTypeFile = resolveRuntimeTypeFile;
|
|
198
|
+
exports.writeEnvReflection = writeEnvReflection;
|
|
199
|
+
exports.writeEnvTypeReflection = writeEnvTypeReflection;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { convertFromCapnp, convertToCapnp } from "../../../deepkit/src/capnp.mjs";
|
|
2
|
+
import { SerializedTypes } from "../../../deepkit/schemas/reflection2.mjs";
|
|
3
|
+
import { getReflectionsPath } from "../../../deepkit/src/resolve-reflections.mjs";
|
|
4
|
+
import { createEnvReflection } from "./reflect.mjs";
|
|
5
|
+
import { ReflectionKind, deserializeType, resolveClassType } from "@powerlines/deepkit/vendor/type";
|
|
6
|
+
import { joinPaths } from "@stryke/path/join-paths";
|
|
7
|
+
import * as capnp from "@stryke/capnp";
|
|
8
|
+
import { readFileBuffer, writeFileBuffer } from "@stryke/fs/buffer";
|
|
9
|
+
import { existsSync } from "node:fs";
|
|
10
|
+
import { isEmptyObject } from "@stryke/type-checks/is-empty-object";
|
|
11
|
+
|
|
12
|
+
//#region ../plugin-env/src/helpers/persistence.ts
|
|
13
|
+
/**
|
|
14
|
+
* Resolves the runtime type definition file for the environment variables.
|
|
15
|
+
*
|
|
16
|
+
* @param context - The plugin context.
|
|
17
|
+
* @returns The runtime type definition file for the environment variables.
|
|
18
|
+
*/
|
|
19
|
+
async function resolveRuntimeTypeFile(context) {
|
|
20
|
+
return context.resolver.esmResolve("@powerlines/plugin-env/types/runtime");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Gets the default type definition for the environment variables.
|
|
24
|
+
*
|
|
25
|
+
* @param context - The plugin context.
|
|
26
|
+
* @returns The default type definition for the environment variables.
|
|
27
|
+
*/
|
|
28
|
+
async function getEnvDefaultTypeDefinition(context) {
|
|
29
|
+
return {
|
|
30
|
+
file: await resolveRuntimeTypeFile(context),
|
|
31
|
+
name: "EnvInterface"
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Gets the default type definition for the environment secrets.
|
|
35
|
+
*
|
|
36
|
+
* @param context - The plugin context.
|
|
37
|
+
* @returns The default type definition for the environment secrets.
|
|
38
|
+
*/
|
|
39
|
+
async function getSecretsDefaultTypeDefinition(context) {
|
|
40
|
+
return {
|
|
41
|
+
file: await resolveRuntimeTypeFile(context),
|
|
42
|
+
name: "SecretsInterface"
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Gets the path to the environment type reflections.
|
|
47
|
+
*
|
|
48
|
+
* @param context - The plugin context.
|
|
49
|
+
* @param name - The name of the type reflections.
|
|
50
|
+
* @returns The path to the environment type reflections.
|
|
51
|
+
*/
|
|
52
|
+
function getEnvTypeReflectionsPath(context, name = "env") {
|
|
53
|
+
return joinPaths(getReflectionsPath(context), "env", `${name}-types.bin`);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Reads the environment type reflection from the file system.
|
|
57
|
+
*
|
|
58
|
+
* @param context - The plugin context.
|
|
59
|
+
* @param name - The name of the type reflections.
|
|
60
|
+
* @returns The environment type reflection.
|
|
61
|
+
*/
|
|
62
|
+
async function readEnvTypeReflection(context, name = "env") {
|
|
63
|
+
const filePath = getEnvTypeReflectionsPath(context, name);
|
|
64
|
+
if (!existsSync(filePath)) {
|
|
65
|
+
if (!context.env.types.env || isEmptyObject(context.env.types.env)) {
|
|
66
|
+
const reflection$1 = createEnvReflection(context);
|
|
67
|
+
const message = new capnp.Message();
|
|
68
|
+
reflection$1.messageRoot = message.initRoot(SerializedTypes);
|
|
69
|
+
reflection$1.dataBuffer = message.toArrayBuffer();
|
|
70
|
+
context.env.types.env = reflection$1;
|
|
71
|
+
await writeEnvTypeReflection(context, context.env.types.env, name);
|
|
72
|
+
}
|
|
73
|
+
return context.env.types.env;
|
|
74
|
+
}
|
|
75
|
+
const buffer = await readFileBuffer(filePath);
|
|
76
|
+
const messageRoot = new capnp.Message(buffer, false).getRoot(SerializedTypes);
|
|
77
|
+
const reflection = resolveClassType(deserializeType(convertFromCapnp(messageRoot.types)));
|
|
78
|
+
context.env.types[name] = reflection;
|
|
79
|
+
context.env.types[name].messageRoot = messageRoot;
|
|
80
|
+
context.env.types[name].dataBuffer = buffer;
|
|
81
|
+
return reflection;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Writes the environment type reflection to the file system.
|
|
85
|
+
*
|
|
86
|
+
* @param context - The plugin context.
|
|
87
|
+
* @param reflection - The environment type reflection to write.
|
|
88
|
+
* @param name - The name of the type reflections.
|
|
89
|
+
*/
|
|
90
|
+
async function writeEnvTypeReflection(context, reflection, name = "env") {
|
|
91
|
+
const serialized = reflection.serializeType();
|
|
92
|
+
const message = new capnp.Message();
|
|
93
|
+
convertToCapnp(serialized, message.initRoot(SerializedTypes)._initTypes(serialized.length));
|
|
94
|
+
await writeFileBuffer(getEnvTypeReflectionsPath(context, name), message.toArrayBuffer());
|
|
95
|
+
}
|
|
96
|
+
function getEnvReflectionsPath(context, name) {
|
|
97
|
+
return joinPaths(getReflectionsPath(context), "env", `${name}.bin`);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Reads the environment reflection data from the file system.
|
|
101
|
+
*
|
|
102
|
+
* @param context - The plugin context.
|
|
103
|
+
* @returns The environment reflection data.
|
|
104
|
+
*/
|
|
105
|
+
async function readEnvReflection(context) {
|
|
106
|
+
const filePath = getEnvReflectionsPath(context, "env");
|
|
107
|
+
if (!existsSync(filePath)) {
|
|
108
|
+
if (!context.env.types.env) context.env.types.env = await readEnvTypeReflection(context, "env");
|
|
109
|
+
if (!context.env.used.env || isEmptyObject(context.env.used.env)) {
|
|
110
|
+
const reflection$1 = createEnvReflection(context, {
|
|
111
|
+
type: {
|
|
112
|
+
kind: ReflectionKind.objectLiteral,
|
|
113
|
+
typeName: "Env",
|
|
114
|
+
description: `An object containing the environment configuration parameters that are used (at least once) by the ${context.config.name ? `${context.config.name} application` : "application"}.`,
|
|
115
|
+
types: []
|
|
116
|
+
},
|
|
117
|
+
superReflection: context.env.types.env
|
|
118
|
+
});
|
|
119
|
+
reflection$1.name = "Env";
|
|
120
|
+
const message = new capnp.Message();
|
|
121
|
+
reflection$1.messageRoot = message.initRoot(SerializedTypes);
|
|
122
|
+
reflection$1.dataBuffer = message.toArrayBuffer();
|
|
123
|
+
context.env.used.env = reflection$1;
|
|
124
|
+
await writeEnvReflection(context, context.env.used.env, "env");
|
|
125
|
+
}
|
|
126
|
+
return context.env.used.env;
|
|
127
|
+
}
|
|
128
|
+
const buffer = await readFileBuffer(filePath);
|
|
129
|
+
const messageRoot = new capnp.Message(buffer, false).getRoot(SerializedTypes);
|
|
130
|
+
const reflection = resolveClassType(deserializeType(convertFromCapnp(messageRoot.types)));
|
|
131
|
+
context.env.used.env = reflection;
|
|
132
|
+
context.env.used.env.messageRoot = messageRoot;
|
|
133
|
+
context.env.used.env.dataBuffer = buffer;
|
|
134
|
+
return reflection;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Reads the secret environment reflection data from the file system.
|
|
138
|
+
*
|
|
139
|
+
* @param context - The plugin context.
|
|
140
|
+
* @returns The environment reflection data.
|
|
141
|
+
*/
|
|
142
|
+
async function readSecretsReflection(context) {
|
|
143
|
+
const filePath = getEnvReflectionsPath(context, "secrets");
|
|
144
|
+
if (!existsSync(filePath)) {
|
|
145
|
+
if (!context.env.types.secrets) context.env.types.secrets = await readEnvTypeReflection(context, "secrets");
|
|
146
|
+
if (!context.env.used.secrets || isEmptyObject(context.env.used.secrets)) {
|
|
147
|
+
const reflection$1 = createEnvReflection(context, {
|
|
148
|
+
type: {
|
|
149
|
+
kind: ReflectionKind.objectLiteral,
|
|
150
|
+
typeName: "Secrets",
|
|
151
|
+
description: `An object containing the secret configuration parameters that are used (at least once) by the ${context.config.name ? `${context.config.name} application` : "application"}.`,
|
|
152
|
+
types: []
|
|
153
|
+
},
|
|
154
|
+
superReflection: context.env.types.secrets
|
|
155
|
+
});
|
|
156
|
+
reflection$1.name = "Secrets";
|
|
157
|
+
const message = new capnp.Message();
|
|
158
|
+
reflection$1.messageRoot = message.initRoot(SerializedTypes);
|
|
159
|
+
reflection$1.dataBuffer = message.toArrayBuffer();
|
|
160
|
+
context.env.used.secrets = reflection$1;
|
|
161
|
+
await writeEnvReflection(context, context.env.used.secrets, "secrets");
|
|
162
|
+
}
|
|
163
|
+
return context.env.used.secrets;
|
|
164
|
+
}
|
|
165
|
+
const buffer = await readFileBuffer(filePath);
|
|
166
|
+
const messageRoot = new capnp.Message(buffer, false).getRoot(SerializedTypes);
|
|
167
|
+
const reflection = resolveClassType(deserializeType(convertFromCapnp(messageRoot.types)));
|
|
168
|
+
context.env.used.secrets = reflection;
|
|
169
|
+
context.env.used.secrets.messageRoot = messageRoot;
|
|
170
|
+
context.env.used.secrets.dataBuffer = buffer;
|
|
171
|
+
return reflection;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Writes the environment reflection data to the file system.
|
|
175
|
+
*
|
|
176
|
+
* @param context - The plugin context.
|
|
177
|
+
* @param reflection - The reflection data to write.
|
|
178
|
+
* @param name - The name of the reflection (either "env" or "secrets").
|
|
179
|
+
*/
|
|
180
|
+
async function writeEnvReflection(context, reflection, name = "env") {
|
|
181
|
+
const serialized = reflection.serializeType();
|
|
182
|
+
const message = new capnp.Message();
|
|
183
|
+
convertToCapnp(serialized, message.initRoot(SerializedTypes)._initTypes(serialized.length));
|
|
184
|
+
await writeFileBuffer(getEnvReflectionsPath(context, name), message.toArrayBuffer());
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
//#endregion
|
|
188
|
+
export { getEnvDefaultTypeDefinition, getEnvReflectionsPath, getEnvTypeReflectionsPath, getSecretsDefaultTypeDefinition, readEnvReflection, readEnvTypeReflection, readSecretsReflection, resolveRuntimeTypeFile, writeEnvReflection, writeEnvTypeReflection };
|