@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
package/dist/index.mjs
CHANGED
|
@@ -1,802 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "./
|
|
3
|
-
import "./
|
|
4
|
-
import "./
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import { LogLevelLabel } from "@storm-software/config-tools/types";
|
|
8
|
-
import { findFileExtension, findFileExtensionSafe } from "@stryke/path/file-path-fns";
|
|
9
|
-
import { isParentPath } from "@stryke/path/is-parent-path";
|
|
10
|
-
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
11
|
-
import defu from "defu";
|
|
12
|
-
import { isFunction } from "@stryke/type-checks/is-function";
|
|
13
|
-
import "@stryke/type-checks/is-object";
|
|
14
|
-
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
15
|
-
import chalk from "chalk";
|
|
16
|
-
import _generate from "@babel/generator";
|
|
17
|
-
import "@babel/parser";
|
|
18
|
-
import { declare } from "@babel/helper-plugin-utils";
|
|
19
|
-
import "@storm-software/config-tools/logger";
|
|
20
|
-
import "@storm-software/config-tools/utilities/colors";
|
|
21
|
-
import "@stryke/helpers/noop";
|
|
22
|
-
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
23
|
-
import { titleCase } from "@stryke/string-format/title-case";
|
|
24
|
-
import * as t from "@babel/types";
|
|
25
|
-
import { isString } from "@stryke/type-checks/is-string";
|
|
26
|
-
import { ReflectionClass, ReflectionKind, deserializeType, resolveClassType, stringifyType } from "@powerlines/deepkit/vendor/type";
|
|
27
|
-
import { Output, Prose, Show, code, computed, createContext, createNamedContext, ref, renderAsync, splitProps, traverseOutput, useContext } from "@alloy-js/core";
|
|
28
|
-
import alloy from "@alloy-js/rollup-plugin";
|
|
29
|
-
import { StormJSON } from "@stryke/json/storm-json";
|
|
30
|
-
import { replacePath } from "@stryke/path/replace";
|
|
31
|
-
import { toArray } from "@stryke/convert/to-array";
|
|
32
|
-
import { isDirectory } from "@stryke/fs/is-file";
|
|
33
|
-
import { listFiles } from "@stryke/fs/list-files";
|
|
34
|
-
import { appendPath } from "@stryke/path/append";
|
|
35
|
-
import { isAbsolutePath } from "@stryke/path/is-type";
|
|
36
|
-
import { joinPaths } from "@stryke/path/join-paths";
|
|
37
|
-
import { defineGenerator, loadConfig, resolveConfig, transform } from "automd";
|
|
38
|
-
import { loadConfig as loadConfig$1 } from "c12";
|
|
39
|
-
import toc from "markdown-toc";
|
|
40
|
-
import { parseTypeDefinition } from "@stryke/convert/parse-type-definition";
|
|
41
|
-
import { ENV_PREFIXES } from "@stryke/env/types";
|
|
42
|
-
import { existsSync } from "@stryke/fs/exists";
|
|
43
|
-
import { createDirectory } from "@stryke/fs/helpers";
|
|
44
|
-
import { joinPaths as joinPaths$1 } from "@stryke/path/join";
|
|
45
|
-
import { constantCase } from "@stryke/string-format/constant-case";
|
|
46
|
-
import * as capnp from "@stryke/capnp";
|
|
47
|
-
import { isUndefined } from "@stryke/type-checks/is-undefined";
|
|
48
|
-
import { readFileBufferSync } from "@stryke/fs/buffer";
|
|
49
|
-
import { existsSync as existsSync$1 } from "node:fs";
|
|
50
|
-
import ts from "typescript";
|
|
51
|
-
import "@alloy-js/markdown";
|
|
52
|
-
import "@stryke/fs/json";
|
|
1
|
+
import src_default$1 from "./plugin-babel/src/index.mjs";
|
|
2
|
+
import src_default$2 from "./plugin-env/src/index.mjs";
|
|
3
|
+
import { isMatchFound } from "./powerlines/src/lib/typescript/tsconfig.mjs";
|
|
4
|
+
import { NodeJsEnvBuiltin } from "./components/env.mjs";
|
|
5
|
+
import "./components/index.mjs";
|
|
6
|
+
import { createComponent } from "@alloy-js/core/jsx-runtime";
|
|
53
7
|
|
|
54
|
-
//#region ../plugin-babel/src/helpers/filters.ts
|
|
55
|
-
function getPluginName(plugin$5) {
|
|
56
|
-
return isSetString(plugin$5) ? plugin$5 : Array.isArray(plugin$5) && plugin$5.length > 0 ? getPluginName(plugin$5[0]) : plugin$5.$$name || plugin$5.name ? plugin$5.$$name || plugin$5.name : void 0;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Check if a Babel plugin is a duplicate of another plugin in the list.
|
|
60
|
-
*
|
|
61
|
-
* @param plugins - The list of existing Babel plugins.
|
|
62
|
-
* @param plugin - The Babel plugin to check for duplicates.
|
|
63
|
-
* @returns True if the plugin is a duplicate, false otherwise.
|
|
64
|
-
*/
|
|
65
|
-
function isDuplicatePlugin(plugins, plugin$5) {
|
|
66
|
-
return !!(getPluginName(plugin$5) && plugins.some((existing) => Array.isArray(existing) && getPluginName(existing[0]) === getPluginName(plugin$5)));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region ../plugin-babel/src/helpers/options.ts
|
|
71
|
-
function resolvePluginFunction(context, plugin$5) {
|
|
72
|
-
try {
|
|
73
|
-
return Array.isArray(plugin$5) && plugin$5.length > 0 && plugin$5[0] ? isFunction(plugin$5[0]) ? plugin$5[0](context) : plugin$5[0] : isFunction(plugin$5) ? plugin$5(context) : plugin$5;
|
|
74
|
-
} catch {
|
|
75
|
-
return plugin$5[0];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Resolve the [Babel](https://babeljs.io/) plugin.
|
|
80
|
-
*
|
|
81
|
-
* @param context - The context for the transformation.
|
|
82
|
-
* @param code - The code to be transformed.
|
|
83
|
-
* @param id - The ID of the source file.
|
|
84
|
-
* @param plugin - The Babel plugin to resolve.
|
|
85
|
-
* @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
|
|
86
|
-
*/
|
|
87
|
-
function resolveBabelPlugin(context, code$1, id, plugin$5) {
|
|
88
|
-
if (Array.isArray(plugin$5) && plugin$5.length > 0 && plugin$5[0]) {
|
|
89
|
-
if (plugin$5.length > 2 && plugin$5[2] && isFunction(plugin$5[2]) && !plugin$5[2](code$1, id)) {
|
|
90
|
-
context.log(LogLevelLabel.TRACE, `Skipping filtered Babel plugin ${chalk.bold.cyanBright(getPluginName(plugin$5) || "unnamed")} for ${id}`);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
return plugin$5.length > 2 ? [
|
|
94
|
-
resolvePluginFunction(context, plugin$5),
|
|
95
|
-
plugin$5[1],
|
|
96
|
-
plugin$5[2]
|
|
97
|
-
] : [
|
|
98
|
-
resolvePluginFunction(context, plugin$5),
|
|
99
|
-
plugin$5[1],
|
|
100
|
-
null
|
|
101
|
-
];
|
|
102
|
-
}
|
|
103
|
-
return [
|
|
104
|
-
resolvePluginFunction(context, plugin$5),
|
|
105
|
-
{},
|
|
106
|
-
null
|
|
107
|
-
];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
//#endregion
|
|
111
|
-
//#region ../plugin-babel/src/helpers/ast-utils.ts
|
|
112
|
-
let generate = _generate;
|
|
113
|
-
if ("default" in generate) generate = generate.default;
|
|
114
|
-
|
|
115
|
-
//#endregion
|
|
116
|
-
//#region ../powerlines/src/lib/logger.ts
|
|
117
|
-
const BADGE_COLORS = [
|
|
118
|
-
"#00A0DD",
|
|
119
|
-
"#6FCE4E",
|
|
120
|
-
"#FBBF24",
|
|
121
|
-
"#F43F5E",
|
|
122
|
-
"#3B82F6",
|
|
123
|
-
"#A855F7",
|
|
124
|
-
"#469592",
|
|
125
|
-
"#288EDF",
|
|
126
|
-
"#D8B4FE",
|
|
127
|
-
"#10B981",
|
|
128
|
-
"#EF4444",
|
|
129
|
-
"#F0EC56",
|
|
130
|
-
"#F472B6",
|
|
131
|
-
"#22D3EE",
|
|
132
|
-
"#EAB308",
|
|
133
|
-
"#84CC16",
|
|
134
|
-
"#F87171",
|
|
135
|
-
"#0EA5E9",
|
|
136
|
-
"#D946EF",
|
|
137
|
-
"#FACC15",
|
|
138
|
-
"#34D399",
|
|
139
|
-
"#8B5CF6"
|
|
140
|
-
];
|
|
141
|
-
const extendLog = (logFn, name) => {
|
|
142
|
-
return (type, ...args) => logFn(type, ` ${chalk.inverse.hex(BADGE_COLORS[name.split("").map((char) => char.charCodeAt(0)).reduce((ret, charCode) => ret + charCode, 0) % BADGE_COLORS.length] || BADGE_COLORS[0])(` ${titleCase(name)} `)} ${args.join(" ")} `);
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region ../plugin-babel/src/helpers/create-plugin.ts
|
|
147
|
-
/**
|
|
148
|
-
* Create a Babel plugin using the provided builder function.
|
|
149
|
-
*
|
|
150
|
-
* @param name - The name of the plugin.
|
|
151
|
-
* @param builder - The builder function that defines the plugin behavior.
|
|
152
|
-
* @returns A Babel plugin declaration.
|
|
153
|
-
*/
|
|
154
|
-
function createBabelPlugin(name, builder) {
|
|
155
|
-
const plugin$5 = (context) => {
|
|
156
|
-
return declare((api, options, dirname) => {
|
|
157
|
-
api.cache.using(() => context.meta.checksum);
|
|
158
|
-
api.assertVersion("^7.0.0-0");
|
|
159
|
-
const log = extendLog(context.log, name);
|
|
160
|
-
log(LogLevelLabel.TRACE, `Initializing the ${chalk.bold.cyanBright(name)} Babel plugin`);
|
|
161
|
-
const result = builder({
|
|
162
|
-
log,
|
|
163
|
-
name,
|
|
164
|
-
api,
|
|
165
|
-
options,
|
|
166
|
-
context,
|
|
167
|
-
dirname
|
|
168
|
-
});
|
|
169
|
-
result.name = name;
|
|
170
|
-
log(LogLevelLabel.TRACE, `Completed initialization of the ${chalk.bold.cyanBright(name)} Babel plugin`);
|
|
171
|
-
return result;
|
|
172
|
-
});
|
|
173
|
-
};
|
|
174
|
-
plugin$5.$$name = name;
|
|
175
|
-
return plugin$5;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
//#endregion
|
|
179
|
-
//#region ../plugin-babel/src/helpers/module-helpers.ts
|
|
180
|
-
/**
|
|
181
|
-
* Adds an import to the program if it doesn't already exist.
|
|
182
|
-
*
|
|
183
|
-
* @param path - The current NodePath in the AST.
|
|
184
|
-
* @param specifier - The import specifier.
|
|
185
|
-
*/
|
|
186
|
-
function addImport(path, specifier) {
|
|
187
|
-
addImportsToProgram(path.scope.getProgramParent().path, specifier);
|
|
188
|
-
}
|
|
189
|
-
function isNonNamespacedImport(importDeclPath) {
|
|
190
|
-
return importDeclPath.get("specifiers").filter(Boolean).every((specifier) => specifier?.isImportSpecifier()) && importDeclPath.node.importKind !== "type" && importDeclPath.node.importKind !== "typeof";
|
|
191
|
-
}
|
|
192
|
-
function getExistingImports(program) {
|
|
193
|
-
const existingImports = /* @__PURE__ */ new Map();
|
|
194
|
-
program.traverse({ ImportDeclaration(path) {
|
|
195
|
-
if (isNonNamespacedImport(path)) existingImports.set(path.node.source.value, path);
|
|
196
|
-
} });
|
|
197
|
-
return existingImports;
|
|
198
|
-
}
|
|
199
|
-
function addImportsToProgram(path, specifier) {
|
|
200
|
-
/**
|
|
201
|
-
* If an existing import of this module exists (ie \`import \{ ... \} from
|
|
202
|
-
* '<moduleName>'\`), inject new imported specifiers into the list of
|
|
203
|
-
* destructured variables.
|
|
204
|
-
*/
|
|
205
|
-
if (!getExistingImports(path).get(specifier.module)) path.unshiftContainer("body", t.importDeclaration([t.importSpecifier(t.identifier(specifier.name || specifier.imported), t.identifier(specifier.imported))], t.stringLiteral(specifier.module)));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
//#endregion
|
|
209
|
-
//#region ../plugin-babel/src/index.ts
|
|
210
|
-
/**
|
|
211
|
-
* Babel plugin for Powerlines.
|
|
212
|
-
*
|
|
213
|
-
* @param options - The Babel plugin user configuration options.
|
|
214
|
-
* @returns A Powerlines plugin that integrates Babel transformations.
|
|
215
|
-
*/
|
|
216
|
-
const plugin$4 = (options = {}) => {
|
|
217
|
-
return {
|
|
218
|
-
name: "babel",
|
|
219
|
-
config() {
|
|
220
|
-
if (!isSetObject(options)) return;
|
|
221
|
-
return { transform: { babel: options } };
|
|
222
|
-
},
|
|
223
|
-
configResolved: {
|
|
224
|
-
order: "pre",
|
|
225
|
-
handler() {
|
|
226
|
-
this.devDependencies["@babel/core"] = "^7.28.4";
|
|
227
|
-
this.config.transform.babel = defu(this.config.transform.babel ?? {}, {
|
|
228
|
-
plugins: [],
|
|
229
|
-
presets: []
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
async transform(code$1, id) {
|
|
234
|
-
if (isParentPath(id, this.powerlinesPath) || code$1.includes("/* @storm-ignore */") || code$1.includes("/* @storm-disable */")) {
|
|
235
|
-
this.log(LogLevelLabel.TRACE, `Skipping Babel transformation for: ${id}`);
|
|
236
|
-
return {
|
|
237
|
-
code: code$1,
|
|
238
|
-
id
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
this.log(LogLevelLabel.TRACE, `Babel transforming file: ${id}`);
|
|
242
|
-
const plugins = this.config.transform.babel.plugins.map((plugin$5) => resolveBabelPlugin(this, code$1, id, plugin$5)).filter((plugin$5, _, arr) => plugin$5 && !isDuplicatePlugin(arr, plugin$5));
|
|
243
|
-
const presets = this.config.transform.babel.presets.map((preset) => resolveBabelPlugin(this, code$1, id, preset)).filter((preset, _, arr) => preset && !isDuplicatePlugin(arr, preset));
|
|
244
|
-
if (Array.isArray(plugins) && plugins.length === 0 && Array.isArray(presets) && presets.length === 0) return {
|
|
245
|
-
code: code$1,
|
|
246
|
-
id
|
|
247
|
-
};
|
|
248
|
-
if ([
|
|
249
|
-
"ts",
|
|
250
|
-
"cts",
|
|
251
|
-
"mts",
|
|
252
|
-
"tsx"
|
|
253
|
-
].includes(findFileExtensionSafe(id)) && !isDuplicatePlugin(plugins, "@babel/plugin-syntax-typescript") && !isDuplicatePlugin(presets, "@babel/preset-typescript")) plugins.unshift(["@babel/plugin-syntax-typescript", { isTSX: findFileExtension(id) === ".tsx" }]);
|
|
254
|
-
const result = await transformAsync(code$1, {
|
|
255
|
-
highlightCode: true,
|
|
256
|
-
code: true,
|
|
257
|
-
ast: false,
|
|
258
|
-
cloneInputAst: false,
|
|
259
|
-
comments: true,
|
|
260
|
-
sourceType: "module",
|
|
261
|
-
configFile: false,
|
|
262
|
-
babelrc: false,
|
|
263
|
-
envName: this.config.mode,
|
|
264
|
-
caller: { name: this.config.framework },
|
|
265
|
-
...this.config.transform.babel ?? {},
|
|
266
|
-
filename: id,
|
|
267
|
-
plugins: plugins.map((plugin$5) => {
|
|
268
|
-
return Array.isArray(plugin$5) && plugin$5.length >= 2 ? [plugin$5[0], defu(plugin$5.length > 1 && plugin$5[1] ? plugin$5[1] : {}, { options })] : plugin$5;
|
|
269
|
-
}).filter(Boolean),
|
|
270
|
-
presets: presets.map((preset) => {
|
|
271
|
-
return Array.isArray(preset) && preset.length >= 2 ? [preset[0], defu(preset.length > 1 && preset[1] ? preset[1] : {}, { options })] : preset;
|
|
272
|
-
}).filter(Boolean)
|
|
273
|
-
});
|
|
274
|
-
if (!result?.code) throw new Error(`Powerlines - Babel plugin failed to compile ${id}`);
|
|
275
|
-
return {
|
|
276
|
-
code: result.code,
|
|
277
|
-
id
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
};
|
|
282
|
-
var src_default$1 = plugin$4;
|
|
283
|
-
|
|
284
|
-
//#endregion
|
|
285
|
-
//#region ../plugin-alloy/src/core/components/output.tsx
|
|
286
|
-
/**
|
|
287
|
-
* Output component for rendering the Powerlines plugin's output files via templates.
|
|
288
|
-
*/
|
|
289
|
-
function Output$1(props) {
|
|
290
|
-
const [{ children, context, meta, basePath }, rest] = splitProps(props, [
|
|
291
|
-
"children",
|
|
292
|
-
"context",
|
|
293
|
-
"meta",
|
|
294
|
-
"basePath"
|
|
295
|
-
]);
|
|
296
|
-
const contextRef = ref(context);
|
|
297
|
-
const metaRef = ref(meta ?? {});
|
|
298
|
-
const basePathRef = computed(() => basePath ? replacePath(basePath, contextRef.value.workspaceConfig.workspaceRoot) : contextRef.value.workspaceConfig.workspaceRoot);
|
|
299
|
-
return createComponent(Output, mergeProps(rest, {
|
|
300
|
-
get basePath() {
|
|
301
|
-
return basePathRef.value;
|
|
302
|
-
},
|
|
303
|
-
get children() {
|
|
304
|
-
return createComponent(PowerlinesContext.Provider, {
|
|
305
|
-
value: {
|
|
306
|
-
ref: contextRef,
|
|
307
|
-
meta: metaRef
|
|
308
|
-
},
|
|
309
|
-
get children() {
|
|
310
|
-
return createComponent(Show, {
|
|
311
|
-
get when() {
|
|
312
|
-
return Boolean(contextRef.value);
|
|
313
|
-
},
|
|
314
|
-
children
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
}));
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
//#endregion
|
|
323
|
-
//#region ../plugin-alloy/src/index.tsx
|
|
324
|
-
/**
|
|
325
|
-
* Alloy-js plugin for Powerlines.
|
|
326
|
-
*
|
|
327
|
-
* @param options - The Alloy-js plugin user configuration options.
|
|
328
|
-
* @returns A Powerlines plugin that integrates Alloy-js transformations.
|
|
329
|
-
*/
|
|
330
|
-
const plugin$3 = (options = {}) => {
|
|
331
|
-
return [{
|
|
332
|
-
name: "alloy:config",
|
|
333
|
-
config() {
|
|
334
|
-
return {
|
|
335
|
-
alloy: {
|
|
336
|
-
typescript: true,
|
|
337
|
-
...options
|
|
338
|
-
},
|
|
339
|
-
build: {
|
|
340
|
-
inputOptions: { transform: { jsx: {
|
|
341
|
-
runtime: "classic",
|
|
342
|
-
pragma: "Alloy.createElement",
|
|
343
|
-
importSource: "@alloy-js/core"
|
|
344
|
-
} } },
|
|
345
|
-
plugins: [alloy()]
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
},
|
|
349
|
-
async configResolved() {
|
|
350
|
-
if (this.tsconfig.tsconfigJson.compilerOptions?.jsx !== "preserve" || this.tsconfig.tsconfigJson.compilerOptions?.jsxImportSource !== "@alloy-js/core") {
|
|
351
|
-
this.tsconfig.tsconfigJson.compilerOptions ??= {};
|
|
352
|
-
if (this.tsconfig.tsconfigJson.compilerOptions.jsx !== "preserve") this.tsconfig.tsconfigJson.compilerOptions.jsx = "preserve";
|
|
353
|
-
if (this.tsconfig.tsconfigJson.compilerOptions.jsxImportSource !== "@alloy-js/core") this.tsconfig.tsconfigJson.compilerOptions.jsxImportSource = "@alloy-js/core";
|
|
354
|
-
await this.fs.write(this.tsconfig.tsconfigFilePath, StormJSON.stringify(this.tsconfig.tsconfigJson));
|
|
355
|
-
}
|
|
356
|
-
this.dependencies["@alloy-js/core"] = "^0.22.0";
|
|
357
|
-
if (this.config.alloy?.typescript !== false) this.dependencies["@alloy-js/typescript"] = "^0.22.0";
|
|
358
|
-
if (this.config.alloy?.json === true) this.dependencies["@alloy-js/json"] = "^0.22.0";
|
|
359
|
-
if (this.config.alloy?.markdown === true) this.dependencies["@alloy-js/markdown"] = "^0.22.0";
|
|
360
|
-
}
|
|
361
|
-
}, {
|
|
362
|
-
name: "alloy:update-context",
|
|
363
|
-
configResolved: {
|
|
364
|
-
order: "pre",
|
|
365
|
-
async handler() {
|
|
366
|
-
this.render = async (children) => {
|
|
367
|
-
const _self$ = this;
|
|
368
|
-
const meta = {};
|
|
369
|
-
await traverseOutput(await renderAsync(createComponent(Output$1, {
|
|
370
|
-
context: _self$,
|
|
371
|
-
meta,
|
|
372
|
-
get basePath() {
|
|
373
|
-
return _self$.workspaceConfig.workspaceRoot;
|
|
374
|
-
},
|
|
375
|
-
children
|
|
376
|
-
})), {
|
|
377
|
-
visitDirectory: (directory) => {
|
|
378
|
-
if (this.fs.existsSync(directory.path)) return;
|
|
379
|
-
this.fs.mkdirSync(directory.path);
|
|
380
|
-
},
|
|
381
|
-
visitFile: (file) => {
|
|
382
|
-
if ("contents" in file) {
|
|
383
|
-
const metadata = meta[file.path] ?? {};
|
|
384
|
-
if (metadata.kind === "builtin") {
|
|
385
|
-
if (!metadata.id) throw new Error(`Built-in file "${file.path}" is missing its ID in the render metadata.`);
|
|
386
|
-
this.emitBuiltinSync(file.contents, metadata.id, file.path, {
|
|
387
|
-
skipFormat: metadata.skipFormat,
|
|
388
|
-
storage: metadata.storage
|
|
389
|
-
});
|
|
390
|
-
} else if (metadata.kind === "entry") this.emitEntrySync(file.contents, file.path, {
|
|
391
|
-
skipFormat: metadata.skipFormat,
|
|
392
|
-
storage: metadata.storage,
|
|
393
|
-
...metadata.typeDefinition ?? {}
|
|
394
|
-
});
|
|
395
|
-
else this.emitSync(file.contents, file.path, metadata);
|
|
396
|
-
} else this.fs.copySync(file.sourcePath, file.path);
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}];
|
|
403
|
-
};
|
|
404
|
-
var src_default$3 = plugin$3;
|
|
405
|
-
|
|
406
|
-
//#endregion
|
|
407
|
-
//#region ../plugin-automd/src/index.ts
|
|
408
|
-
/**
|
|
409
|
-
* AutoMD Plugin
|
|
410
|
-
*
|
|
411
|
-
* @remarks
|
|
412
|
-
* A Powerlines plugin to use the AutoMD markdown transformer during the prepare task.
|
|
413
|
-
*
|
|
414
|
-
* @see https://automd.unjs.io/
|
|
415
|
-
*
|
|
416
|
-
* @param options - The plugin options.
|
|
417
|
-
* @returns A Powerlines plugin instance.
|
|
418
|
-
*/
|
|
419
|
-
const plugin$2 = (options = {}) => {
|
|
420
|
-
return {
|
|
421
|
-
name: "automd",
|
|
422
|
-
async config() {
|
|
423
|
-
const config = await loadConfig(joinPaths(this.workspaceConfig.workspaceRoot, this.config.projectRoot), options);
|
|
424
|
-
if (!config.prefix || !Array.isArray(config.prefix)) config.prefix = toArray(config.prefix ?? []);
|
|
425
|
-
if (!config.prefix.includes("automd")) config.prefix.push("automd");
|
|
426
|
-
if (!config.prefix.includes("powerlines")) config.prefix.push("powerlines");
|
|
427
|
-
return { automd: defu(config ?? {}, {
|
|
428
|
-
configFile: options.configFile,
|
|
429
|
-
allowIssues: true,
|
|
430
|
-
dir: this.config.projectRoot,
|
|
431
|
-
watch: false,
|
|
432
|
-
input: "README.md",
|
|
433
|
-
toc: {
|
|
434
|
-
maxDepth: 6,
|
|
435
|
-
bullets: "-"
|
|
436
|
-
}
|
|
437
|
-
}) };
|
|
438
|
-
},
|
|
439
|
-
async configResolved() {
|
|
440
|
-
if (this.config.framework && !toArray(this.config.automd.prefix).includes(this.config.framework)) this.config.automd.prefix = toArray(this.config.automd.prefix).concat(this.config.framework);
|
|
441
|
-
if (this.config.automd.configFile) {
|
|
442
|
-
const { config } = await loadConfig$1({
|
|
443
|
-
cwd: this.config.automd.dir,
|
|
444
|
-
configFile: this.config.automd.configFile,
|
|
445
|
-
defaults: {
|
|
446
|
-
ignore: [
|
|
447
|
-
"**/node_modules",
|
|
448
|
-
"**/dist",
|
|
449
|
-
"**/.*"
|
|
450
|
-
],
|
|
451
|
-
dir: this.config.automd.dir
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
this.config.automd = resolveConfig(defu(this.config.automd, {
|
|
455
|
-
...config,
|
|
456
|
-
prefix: toArray(config.prefix ?? [])
|
|
457
|
-
}));
|
|
458
|
-
}
|
|
459
|
-
this.config.automd.input = (await Promise.all(toArray(this.config.automd.input).map(async (input) => {
|
|
460
|
-
if (input.includes("*")) return listFiles(isAbsolutePath(input) ? input : appendPath(input, this.config.projectRoot), { ignore: this.config.automd.ignore });
|
|
461
|
-
return isAbsolutePath(input) ? input : appendPath(input, this.config.projectRoot);
|
|
462
|
-
}))).flat();
|
|
463
|
-
if (this.config.automd.output && !isAbsolutePath(this.config.automd.output)) this.config.automd.output = appendPath(this.config.automd.output, this.config.projectRoot);
|
|
464
|
-
this.config.automd.generators ??= {};
|
|
465
|
-
if (this.config.automd.toc !== false) this.config.automd.generators.toc ??= {
|
|
466
|
-
name: "toc",
|
|
467
|
-
generate: (ctx) => {
|
|
468
|
-
const opts = this.config.automd.toc ?? {};
|
|
469
|
-
return { contents: toc(ctx.block.md, {
|
|
470
|
-
...opts,
|
|
471
|
-
maxdepth: opts.maxDepth,
|
|
472
|
-
first1: opts.firstH1
|
|
473
|
-
}).content };
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
},
|
|
477
|
-
async docs() {
|
|
478
|
-
await Promise.all(toArray(this.config.automd.input).map(async (input) => {
|
|
479
|
-
const contents = await this.fs.read(input);
|
|
480
|
-
if (contents) {
|
|
481
|
-
const result = await transform(contents, this.config.automd);
|
|
482
|
-
if (result.hasIssues && this.config.automd.allowIssues === false) throw new Error(`AutoMD found issues in file "${input}". Please resolve the issues or set \`allowIssues\` to true in the plugin configuration to ignore them.`);
|
|
483
|
-
if (result.hasChanged) await this.fs.write(appendPath(this.config.automd.output ? isDirectory(this.config.automd.output) ? replacePath(input, this.config.automd.output) : this.config.automd.output : input, this.config.projectRoot), result.contents);
|
|
484
|
-
}
|
|
485
|
-
}));
|
|
486
|
-
}
|
|
487
|
-
};
|
|
488
|
-
};
|
|
489
|
-
var src_default$4 = plugin$2;
|
|
490
|
-
|
|
491
|
-
//#endregion
|
|
492
|
-
//#region ../plugin-env/src/babel/plugin.ts
|
|
493
|
-
const envBabelPlugin = createBabelPlugin("env", ({ log, context }) => {
|
|
494
|
-
function extractEnv(node, pass, isInjectable = false) {
|
|
495
|
-
const envTypesAliasProperties = context.env.types.env?.getProperties().filter((prop) => prop.getAlias().length > 0);
|
|
496
|
-
if (node.name) {
|
|
497
|
-
const prefix = context.config.env.prefix.find((pre) => node.name && node.name.startsWith(pre) && (context.env.types.env?.hasProperty(node.name.replace(`${pre}_`, "")) || envTypesAliasProperties.some((prop) => prop.getAlias().includes(node.name.replace(`${pre}_`, "")))));
|
|
498
|
-
let name = node.name;
|
|
499
|
-
if (prefix) name = node.name.replace(`${prefix}_`, "");
|
|
500
|
-
log(LogLevelLabel.TRACE, `Environment variable ${name} found in ${pass.filename || "unknown file"}.`);
|
|
501
|
-
if (context.env.types.env?.hasProperty(name) || envTypesAliasProperties.some((prop) => prop.getAlias().includes(name))) {
|
|
502
|
-
const envProperty = context.env.types.env.hasProperty(name) ? context.env.types.env.getProperty(name) : envTypesAliasProperties.find((prop) => prop.getAlias().includes(name));
|
|
503
|
-
if (!envProperty || envProperty.isIgnored()) return;
|
|
504
|
-
if (!context.env.used.env.hasProperty(name)) context.env.used.env.addProperty(envProperty.property);
|
|
505
|
-
if (context.config.env.inject && isInjectable) {
|
|
506
|
-
let value = context.env.parsed?.[name];
|
|
507
|
-
if (value === void 0) {
|
|
508
|
-
const prefix$1 = context.config.env.prefix.find((pre) => {
|
|
509
|
-
return context.env.parsed[`${pre.replace(/_$/g, "")}_${name}`];
|
|
510
|
-
});
|
|
511
|
-
if (prefix$1) value = context.env.parsed[`${prefix$1.replace(/_$/g, "")}_${name}`];
|
|
512
|
-
}
|
|
513
|
-
value ??= envProperty.getDefaultValue();
|
|
514
|
-
if (envProperty.isValueRequired() && value === void 0) throw new Error(`Environment variable \`${name}\` is not defined in the .env configuration files`);
|
|
515
|
-
return stringifyDefaultValue(envProperty, value);
|
|
516
|
-
}
|
|
517
|
-
} else throw new Error(`The "${name}" environment variable is not defined in the \`env\` type definition, but is used in the source code file ${pass.filename ? pass.filename : "unknown"}.
|
|
518
|
-
|
|
519
|
-
The following environment configuration names are defined in the \`env\` type definition: \n${context.env.types.env?.getPropertyNames().sort((a, b) => String(a).localeCompare(String(b))).map((typeDef) => ` - ${String(typeDef)} ${envTypesAliasProperties.some((prop) => prop.getNameAsString() === String(typeDef) && prop.getAlias().length > 0) ? `(Alias: ${envTypesAliasProperties?.find((prop) => prop.getNameAsString() === String(typeDef))?.getAlias().join(", ")})` : ""}`).join("\n")} \n\nUsing the following env prefix: \n${context.config.env.prefix.map((prefix$1) => ` - ${prefix$1}`).join("\n")} \n\nPlease check your \`env\` configuration option. If you are using a custom dotenv type definition, please make sure that the configuration names match the ones in the code. \n\n`);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
return {
|
|
523
|
-
visitor: { MemberExpression(path, pass) {
|
|
524
|
-
if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isIdentifier({ name: "$storm" }) && path.get("property")?.isIdentifier()) {
|
|
525
|
-
const identifier = path.get("property")?.node;
|
|
526
|
-
extractEnv(identifier, pass, false);
|
|
527
|
-
path.replaceWithSourceString(`env.${identifier.name}`);
|
|
528
|
-
addImport(path, {
|
|
529
|
-
module: "storm:env",
|
|
530
|
-
name: "env",
|
|
531
|
-
imported: "env"
|
|
532
|
-
});
|
|
533
|
-
} else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isCallExpression({ callee: {
|
|
534
|
-
name: "useStorm",
|
|
535
|
-
type: "Identifier"
|
|
536
|
-
} }) && path.get("property")?.isIdentifier()) {
|
|
537
|
-
const identifier = path.get("property")?.node;
|
|
538
|
-
extractEnv(identifier, pass, false);
|
|
539
|
-
path.replaceWithSourceString(`env.${identifier.name}`);
|
|
540
|
-
addImport(path, {
|
|
541
|
-
module: "storm:env",
|
|
542
|
-
name: "env",
|
|
543
|
-
imported: "env"
|
|
544
|
-
});
|
|
545
|
-
} else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isIdentifier({ name: "process" }) && path.get("property")?.isIdentifier()) {
|
|
546
|
-
const identifier = path.get("property")?.node;
|
|
547
|
-
if (!identifier.name) return;
|
|
548
|
-
extractEnv(identifier, pass, false);
|
|
549
|
-
path.replaceWithSourceString(`env.${identifier.name}`);
|
|
550
|
-
addImport(path, {
|
|
551
|
-
module: "storm:env",
|
|
552
|
-
name: "env",
|
|
553
|
-
imported: "env"
|
|
554
|
-
});
|
|
555
|
-
} else if (path.get("object")?.get("property")?.isIdentifier({ name: "env" }) && path.get("object")?.get("object")?.isMetaProperty() && path.get("property")?.isIdentifier()) {
|
|
556
|
-
const identifier = path.get("property")?.node;
|
|
557
|
-
if (!identifier.name) return;
|
|
558
|
-
extractEnv(identifier, pass, false);
|
|
559
|
-
path.replaceWithSourceString(`env.${identifier.name}`);
|
|
560
|
-
addImport(path, {
|
|
561
|
-
module: "storm:env",
|
|
562
|
-
name: "env",
|
|
563
|
-
imported: "env"
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
} },
|
|
567
|
-
post() {
|
|
568
|
-
log(LogLevelLabel.TRACE, `Adding environment variables from ${this.filename || "unknown file"} to env.json.`);
|
|
569
|
-
let persistedEnv = ReflectionClass.from({
|
|
570
|
-
kind: ReflectionKind.objectLiteral,
|
|
571
|
-
description: `An object containing the environment variables used by the application.`,
|
|
572
|
-
types: []
|
|
573
|
-
});
|
|
574
|
-
const reflectionPath = getEnvReflectionsPath(context, "env");
|
|
575
|
-
if (reflectionPath && existsSync$1(reflectionPath)) {
|
|
576
|
-
log(LogLevelLabel.TRACE, `Environment reflection file found at ${reflectionPath}, reading existing reflection.`);
|
|
577
|
-
persistedEnv = resolveClassType(deserializeType(convertFromCapnp(new capnp.Message(readFileBufferSync(reflectionPath), false).getRoot(SerializedTypes).types)));
|
|
578
|
-
}
|
|
579
|
-
log(LogLevelLabel.TRACE, `Adding new variables to env reflection at ${reflectionPath}.`);
|
|
580
|
-
persistedEnv.getProperties().filter((property) => property.getNameAsString() && !context.env.used.env.hasProperty(property.getNameAsString())).forEach((property) => {
|
|
581
|
-
context.env.used.env.addProperty({
|
|
582
|
-
...property,
|
|
583
|
-
name: property.getNameAsString(),
|
|
584
|
-
description: property.getDescription() ?? `The ${property.getNameAsString()} variable.`,
|
|
585
|
-
default: property.getDefaultValue(),
|
|
586
|
-
optional: property.isOptional() ? true : void 0,
|
|
587
|
-
readonly: property.isReadonly() ? true : void 0,
|
|
588
|
-
visibility: property.getVisibility(),
|
|
589
|
-
type: property.getType(),
|
|
590
|
-
tags: property.getTags()
|
|
591
|
-
});
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
};
|
|
595
|
-
});
|
|
596
|
-
|
|
597
|
-
//#endregion
|
|
598
|
-
//#region ../plugin-env/src/helpers/automd-generator.ts
|
|
599
|
-
/**
|
|
600
|
-
* AutoMD generator to generate environment variable documentation
|
|
601
|
-
*
|
|
602
|
-
* @param context - The generator context.
|
|
603
|
-
* @returns The generated documentation content.
|
|
604
|
-
*/
|
|
605
|
-
const env = (context) => defineGenerator({
|
|
606
|
-
name: "env",
|
|
607
|
-
async generate() {
|
|
608
|
-
const envDocFile = joinPaths(context.config.projectRoot, "docs", "generated", "env.md");
|
|
609
|
-
if (!context.fs.existsSync(envDocFile)) return { contents: "" };
|
|
610
|
-
return { contents: await context.fs.read(envDocFile) || "" };
|
|
611
|
-
}
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
//#endregion
|
|
615
|
-
//#region ../plugin-alloy/src/markdown/contexts/markdown-table.ts
|
|
616
|
-
/**
|
|
617
|
-
* The Powerlines context used in template rendering.
|
|
618
|
-
*/
|
|
619
|
-
const MarkdownTableColumnContext = createNamedContext("markdown-table-column", {});
|
|
620
|
-
/**
|
|
621
|
-
* The Powerlines context used in template rendering.
|
|
622
|
-
*/
|
|
623
|
-
const MarkdownTableContext = createContext({
|
|
624
|
-
columns: [],
|
|
625
|
-
data: []
|
|
626
|
-
});
|
|
627
|
-
|
|
628
|
-
//#endregion
|
|
629
|
-
//#region ../plugin-env/src/index.tsx
|
|
630
|
-
/**
|
|
631
|
-
* A Powerlines plugin to inject environment variables into the source code.
|
|
632
|
-
*/
|
|
633
|
-
const plugin$1 = (options = {}) => {
|
|
634
|
-
return [
|
|
635
|
-
src_default$3(options.alloy),
|
|
636
|
-
src_default$1(options.babel),
|
|
637
|
-
{
|
|
638
|
-
name: "env",
|
|
639
|
-
async config() {
|
|
640
|
-
this.log(LogLevelLabel.TRACE, "Providing default configuration for the Powerlines `env` build plugin.");
|
|
641
|
-
const config = {
|
|
642
|
-
env: defu(options, {
|
|
643
|
-
types: {},
|
|
644
|
-
prefix: []
|
|
645
|
-
}),
|
|
646
|
-
transform: { babel: { plugins: [envBabelPlugin] } }
|
|
647
|
-
};
|
|
648
|
-
if (config.env.types) config.env.types = parseTypeDefinition(config.env.types);
|
|
649
|
-
else {
|
|
650
|
-
this.log(LogLevelLabel.WARN, "The `env.types` configuration parameter was not provided. Please ensure this is expected.");
|
|
651
|
-
const envDefaultTypeDefinition = await getEnvDefaultTypeDefinition(this);
|
|
652
|
-
config.env.types = parseTypeDefinition(`${envDefaultTypeDefinition.file}#${envDefaultTypeDefinition.name}`);
|
|
653
|
-
}
|
|
654
|
-
if (config.env.secrets) config.env.secrets = parseTypeDefinition(config.env.secrets);
|
|
655
|
-
else {
|
|
656
|
-
const secretsDefaultTypeDefinition = await getSecretsDefaultTypeDefinition(this);
|
|
657
|
-
config.env.secrets = parseTypeDefinition(`${secretsDefaultTypeDefinition.file}#${secretsDefaultTypeDefinition.name}`);
|
|
658
|
-
}
|
|
659
|
-
config.env.prefix = toArray(config.env.prefix ?? []).reduce((ret, prefix) => {
|
|
660
|
-
const formattedPrefix = constantCase(prefix);
|
|
661
|
-
if (!ret.includes(formattedPrefix)) ret.push(formattedPrefix);
|
|
662
|
-
return ret;
|
|
663
|
-
}, [...ENV_PREFIXES, "POWERLINES_"]);
|
|
664
|
-
config.env.prefix = config.env.prefix.reduce((ret, prefix) => {
|
|
665
|
-
if (!ret.includes(prefix.replace(/_$/g, ""))) ret.push(prefix.replace(/_$/g, ""));
|
|
666
|
-
return ret;
|
|
667
|
-
}, []);
|
|
668
|
-
return config;
|
|
669
|
-
},
|
|
670
|
-
async configResolved() {
|
|
671
|
-
this.log(LogLevelLabel.TRACE, `Environment plugin configuration has been resolved for the Powerlines project.`);
|
|
672
|
-
this.config.env.inject ??= this.config.projectType === "application";
|
|
673
|
-
this.env = defu({ parsed: await loadEnv(this, this.config.env) }, this.env ?? {}, {
|
|
674
|
-
types: { env: {} },
|
|
675
|
-
used: {
|
|
676
|
-
env: {},
|
|
677
|
-
secrets: {}
|
|
678
|
-
},
|
|
679
|
-
parsed: {},
|
|
680
|
-
injected: {}
|
|
681
|
-
});
|
|
682
|
-
if (this.config.command !== "prepare" && this.persistedMeta?.checksum === this.meta.checksum && existsSync(getEnvTypeReflectionsPath(this, "env"))) {
|
|
683
|
-
this.log(LogLevelLabel.TRACE, `Skipping reflection initialization as the meta checksum has not changed.`);
|
|
684
|
-
this.env.types.env = await readEnvTypeReflection(this, "env");
|
|
685
|
-
if (existsSync(getEnvReflectionsPath(this, "env"))) this.env.used.env = await readEnvReflection(this);
|
|
686
|
-
if (existsSync(getEnvTypeReflectionsPath(this, "secrets"))) this.env.types.secrets = await readEnvTypeReflection(this, "secrets");
|
|
687
|
-
if (existsSync(getEnvReflectionsPath(this, "secrets"))) this.env.used.secrets = await readSecretsReflection(this);
|
|
688
|
-
} else {
|
|
689
|
-
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$1(this.config.projectRoot, this.config.env.types?.file) : void 0, this.config.env.types?.name);
|
|
690
|
-
if (!this.env.types.env) throw new Error("Failed to find the environment configuration type reflection in the context.");
|
|
691
|
-
await writeEnvTypeReflection(this, this.env.types.env, "env");
|
|
692
|
-
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$1(this.config.projectRoot, this.config.env.secrets?.file) : void 0, this.config.env.secrets?.name);
|
|
693
|
-
if (!this.env.types.secrets) throw new Error("Failed to find the secrets configuration type reflection in the context.");
|
|
694
|
-
await writeEnvTypeReflection(this, this.env.types.secrets, "secrets");
|
|
695
|
-
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`);
|
|
696
|
-
const envWithAlias = this.env.types.env.getProperties().filter((prop) => prop.getAlias().length > 0);
|
|
697
|
-
Object.entries(await loadEnv(this, this.config.env)).forEach(([key, value]) => {
|
|
698
|
-
const unprefixedKey = this.config.env.prefix.reduce((ret, prefix) => {
|
|
699
|
-
if (key.replace(/_$/g, "").startsWith(prefix)) return key.replace(/_$/g, "").slice(prefix.length);
|
|
700
|
-
return ret;
|
|
701
|
-
}, key);
|
|
702
|
-
const aliasKey = envWithAlias.find((prop) => prop?.getAlias().reverse().includes(unprefixedKey));
|
|
703
|
-
if (this.env.types.env?.hasProperty(unprefixedKey) || aliasKey) this.env.types.env.getProperty(unprefixedKey).setDefaultValue(value);
|
|
704
|
-
});
|
|
705
|
-
this.env.used.env = new ReflectionClass({
|
|
706
|
-
kind: ReflectionKind.objectLiteral,
|
|
707
|
-
typeName: "Env",
|
|
708
|
-
description: `An object containing the environment configuration parameters used by the ${this.config.name ? `${this.config.name} application` : "application"}.`,
|
|
709
|
-
types: []
|
|
710
|
-
}, this.env.types.env);
|
|
711
|
-
await writeEnvReflection(this, this.env.used.env, "env");
|
|
712
|
-
if (this.env.types.secrets) {
|
|
713
|
-
await writeEnvTypeReflection(this, this.env.types.secrets, "secrets");
|
|
714
|
-
this.env.used.secrets = new ReflectionClass({
|
|
715
|
-
kind: ReflectionKind.objectLiteral,
|
|
716
|
-
typeName: "Secrets",
|
|
717
|
-
description: `An object containing the secret configuration parameters used by the ${this.config.name ? `${this.config.name} application` : "application"}.`,
|
|
718
|
-
types: []
|
|
719
|
-
}, this.env.types.secrets);
|
|
720
|
-
await writeEnvReflection(this, this.env.used.secrets, "secrets");
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
},
|
|
724
|
-
async prepare() {
|
|
725
|
-
const _self$ = this;
|
|
726
|
-
this.log(LogLevelLabel.TRACE, `Preparing the Environment runtime artifacts for the Powerlines project.`);
|
|
727
|
-
return this.render(createComponent(EnvBuiltin, { get defaultConfig() {
|
|
728
|
-
return _self$.config.env.defaultConfig;
|
|
729
|
-
} }));
|
|
730
|
-
},
|
|
731
|
-
async docs() {
|
|
732
|
-
this.log(LogLevelLabel.TRACE, "Writing Environment documentation for the Powerlines project artifacts.");
|
|
733
|
-
const outputPath = joinPaths$1(this.config.projectRoot, "docs", "generated");
|
|
734
|
-
if (!existsSync(outputPath)) await createDirectory(outputPath);
|
|
735
|
-
const reflection = await readEnvTypeReflection(this, "env");
|
|
736
|
-
const envDocFile = joinPaths$1(outputPath, "env.md");
|
|
737
|
-
this.log(LogLevelLabel.TRACE, `Documenting environment variables configuration in "${envDocFile}"`);
|
|
738
|
-
await this.fs.write(envDocFile, `<!-- Generated by ${titleCase(this.config.framework) || "Powerlines"} -->
|
|
739
|
-
|
|
740
|
-
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.
|
|
741
|
-
|
|
742
|
-
| Name | Description | Type | Default Value | Required |
|
|
743
|
-
| ---- | ----------- | ---- | ------------- | :------: |
|
|
744
|
-
${reflection.getProperties().filter((property) => property.getNameAsString() !== "__POWERLINES_INJECTED__").sort((a, b) => a.getNameAsString().localeCompare(b.getNameAsString())).map((reflectionProperty) => {
|
|
745
|
-
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() ? "" : "✔"} |`;
|
|
746
|
-
}).join("\n")}
|
|
747
|
-
`);
|
|
748
|
-
},
|
|
749
|
-
async buildEnd() {
|
|
750
|
-
const reflectionPath = getEnvReflectionsPath(this, "env");
|
|
751
|
-
this.log(LogLevelLabel.TRACE, `Writing env reflection types to ${reflectionPath}.`);
|
|
752
|
-
await writeEnvReflection(this, this.env.used.env, "env");
|
|
753
|
-
}
|
|
754
|
-
},
|
|
755
|
-
{
|
|
756
|
-
name: "env:automd-generator",
|
|
757
|
-
config() {
|
|
758
|
-
return { automd: defu(options.automd ?? {}, { generators: { "env": env(this) } }) };
|
|
759
|
-
}
|
|
760
|
-
},
|
|
761
|
-
{
|
|
762
|
-
name: "env:vite",
|
|
763
|
-
vite: { configResolved() {
|
|
764
|
-
return { envPrefix: this.config?.env?.prefix };
|
|
765
|
-
} }
|
|
766
|
-
},
|
|
767
|
-
src_default$4(options.automd)
|
|
768
|
-
];
|
|
769
|
-
};
|
|
770
|
-
var src_default$2 = plugin$1;
|
|
771
|
-
|
|
772
|
-
//#endregion
|
|
773
|
-
//#region ../powerlines/src/lib/typescript/tsconfig.ts
|
|
774
|
-
/**
|
|
775
|
-
* Check if the TypeScript configuration type matches any of the provided types.
|
|
776
|
-
*
|
|
777
|
-
* @param tsconfigType - The type from the TypeScript configuration.
|
|
778
|
-
* @param types - An array of type names to check against.
|
|
779
|
-
* @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.
|
|
780
|
-
*/
|
|
781
|
-
function findMatch(tsconfigType, types, extensions = [
|
|
782
|
-
".ts",
|
|
783
|
-
".tsx",
|
|
784
|
-
".d.ts"
|
|
785
|
-
]) {
|
|
786
|
-
return types.find((type) => tsconfigType?.toString().toLowerCase() === type?.toString().toLowerCase() || tsconfigType?.toString().toLowerCase() === `./${type?.toString().toLowerCase()}` || `./${tsconfigType?.toString().toLowerCase()}` === type?.toString().toLowerCase() || extensions.some((ext) => `${tsconfigType?.toString().toLowerCase()}${ext}` === type?.toString().toLowerCase() || `${tsconfigType?.toString().toLowerCase()}${ext}` === `./${type?.toString().toLowerCase()}` || `${type?.toString().toLowerCase()}${ext}` === `./${tsconfigType?.toString().toLowerCase()}` || tsconfigType?.toString().toLowerCase() === `${type?.toString().toLowerCase()}${ext}` || tsconfigType?.toString().toLowerCase() === `./${type?.toString().toLowerCase()}${ext}` || type?.toString().toLowerCase() === `./${tsconfigType?.toString().toLowerCase()}${ext}`));
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* Check if the TypeScript configuration type matches any of the provided types.
|
|
790
|
-
*
|
|
791
|
-
* @param tsconfigType - The type from the TypeScript configuration.
|
|
792
|
-
* @param types - An array of type names to check against.
|
|
793
|
-
* @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.
|
|
794
|
-
*/
|
|
795
|
-
function isMatchFound(tsconfigType, types) {
|
|
796
|
-
return findMatch(tsconfigType, types) !== void 0;
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
//#endregion
|
|
800
8
|
//#region src/index.tsx
|
|
801
9
|
/**
|
|
802
10
|
* A package containing a Powerlines plugin for building a NodeJs application.
|
|
@@ -804,12 +12,9 @@ function isMatchFound(tsconfigType, types) {
|
|
|
804
12
|
const plugin = (options = {}) => {
|
|
805
13
|
return [
|
|
806
14
|
src_default$1(options.babel),
|
|
807
|
-
src_default$2(options.env),
|
|
15
|
+
...src_default$2(options.env),
|
|
808
16
|
{
|
|
809
17
|
name: "nodejs",
|
|
810
|
-
config() {
|
|
811
|
-
return defu({ nodejs: options }, { nodejs: { jsxImportSource: this.tsconfig.tsconfigJson.compilerOptions?.jsxImportSource } });
|
|
812
|
-
},
|
|
813
18
|
configResolved() {
|
|
814
19
|
this.devDependencies["@types/node"] = "^22.14.6";
|
|
815
20
|
this.tsconfig.tsconfigJson.compilerOptions ??= {};
|
|
@@ -817,7 +22,10 @@ const plugin = (options = {}) => {
|
|
|
817
22
|
if (!isMatchFound("node", this.tsconfig.tsconfigJson.compilerOptions.types)) this.tsconfig.tsconfigJson.compilerOptions.types.push("node");
|
|
818
23
|
},
|
|
819
24
|
async prepare() {
|
|
820
|
-
|
|
25
|
+
const _self$ = this;
|
|
26
|
+
return this.render(createComponent(NodeJsEnvBuiltin, { get defaultConfig() {
|
|
27
|
+
return _self$.config.env.defaultConfig;
|
|
28
|
+
} }));
|
|
821
29
|
}
|
|
822
30
|
}
|
|
823
31
|
];
|