powerlines 0.42.32 → 0.42.33
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/api-CIDAmydP.cjs +917 -0
- package/dist/api-KqyZ6kMY.mjs +897 -0
- package/dist/api-KqyZ6kMY.mjs.map +1 -0
- package/dist/{api-context-k3dnn5KR.cjs → api-context-Ck0P2lLD.cjs} +9 -425
- package/dist/{api-context-BQi9M07D.mjs → api-context-DiZCovj6.mjs} +6 -414
- package/dist/api-context-DiZCovj6.mjs.map +1 -0
- package/dist/astro.mjs.map +1 -1
- package/dist/{chunk-7azAqIA9.cjs → chunk-AIJqnxB6.cjs} +0 -7
- package/dist/{chunk-WJdhOJK3.mjs → chunk-CtajNgzt.mjs} +1 -10
- package/dist/config.cjs +1 -1
- package/dist/config.mjs +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/context/index.cjs +1 -1
- package/dist/context/index.d.cts +1 -260
- package/dist/context/index.d.cts.map +1 -1
- package/dist/context/index.d.mts +2 -261
- package/dist/context/index.d.mts.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/esbuild.cjs +9 -4
- package/dist/esbuild.d.cts +2 -2
- package/dist/esbuild.d.cts.map +1 -1
- package/dist/esbuild.d.mts +2 -2
- package/dist/esbuild.d.mts.map +1 -1
- package/dist/esbuild.mjs +2 -2
- package/dist/esbuild.mjs.map +1 -1
- package/dist/farm.cjs +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/next.mjs.map +1 -1
- package/dist/nuxt.cjs +2 -2
- package/dist/nuxt.d.mts +1 -1
- package/dist/nuxt.mjs +1 -1
- package/dist/nuxt.mjs.map +1 -1
- package/dist/plugin-utils.cjs +1 -1
- package/dist/plugin-utils.mjs +1 -1
- package/dist/rolldown.cjs +7 -2
- package/dist/rolldown.d.cts +2 -2
- package/dist/rolldown.d.cts.map +1 -1
- package/dist/rolldown.d.mts +2 -2
- package/dist/rolldown.d.mts.map +1 -1
- package/dist/rolldown.mjs +2 -2
- package/dist/rolldown.mjs.map +1 -1
- package/dist/rollup.cjs +7 -2
- package/dist/rollup.d.cts +2 -2
- package/dist/rollup.d.cts.map +1 -1
- package/dist/rollup.d.mts +2 -2
- package/dist/rollup.d.mts.map +1 -1
- package/dist/rollup.mjs +2 -2
- package/dist/rollup.mjs.map +1 -1
- package/dist/rspack.cjs +7 -2
- package/dist/rspack.d.cts +2 -2
- package/dist/rspack.d.cts.map +1 -1
- package/dist/rspack.d.mts +2 -2
- package/dist/rspack.d.mts.map +1 -1
- package/dist/rspack.mjs +2 -2
- package/dist/rspack.mjs.map +1 -1
- package/dist/storage/index.cjs +1 -1
- package/dist/storage/index.d.cts +1 -1
- package/dist/storage/index.d.mts +2 -2
- package/dist/storage/index.mjs +1 -1
- package/dist/ts-morph-B85ZbV1Q.mjs +102 -0
- package/dist/ts-morph-B85ZbV1Q.mjs.map +1 -0
- package/dist/ts-morph-Cf4wz3E0.cjs +114 -0
- package/dist/{tsconfig-BhVGZ2DK.cjs → tsconfig-ChmbpAO7.cjs} +2 -2
- package/dist/{tsconfig-CzYPBpDS.mjs → tsconfig-DoV1dUYg.mjs} +2 -2
- package/dist/{tsconfig-CzYPBpDS.mjs.map → tsconfig-DoV1dUYg.mjs.map} +1 -1
- package/dist/tsdown.cjs +8 -3
- package/dist/tsdown.d.cts +2 -2
- package/dist/tsdown.d.cts.map +1 -1
- package/dist/tsdown.d.mts +2 -2
- package/dist/tsdown.d.mts.map +1 -1
- package/dist/tsdown.mjs +3 -3
- package/dist/tsdown.mjs.map +1 -1
- package/dist/tsup.cjs +8 -3
- package/dist/tsup.d.cts +3 -547
- package/dist/tsup.d.cts.map +1 -1
- package/dist/tsup.d.mts +3 -547
- package/dist/tsup.d.mts.map +1 -1
- package/dist/tsup.mjs +3 -3
- package/dist/tsup.mjs.map +1 -1
- package/dist/{types-hdziyQIH.d.mts → types-9O-s0Fpu.d.mts} +1 -1
- package/dist/types-9O-s0Fpu.d.mts.map +1 -0
- package/dist/typescript/index.cjs +4 -104
- package/dist/typescript/index.d.cts +1 -6
- package/dist/typescript/index.d.cts.map +1 -1
- package/dist/typescript/index.d.mts +2 -7
- package/dist/typescript/index.d.mts.map +1 -1
- package/dist/typescript/index.mjs +3 -102
- package/dist/unloader.cjs +1 -1
- package/dist/unplugin.cjs +2 -2
- package/dist/unplugin.mjs +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.mjs +1 -1
- package/dist/{virtual-BHb4iMd_.cjs → virtual-BNy8T32w.cjs} +3 -3
- package/dist/{virtual-OEHgBu0s.mjs → virtual-PaZGNIrj.mjs} +3 -3
- package/dist/{virtual-OEHgBu0s.mjs.map → virtual-PaZGNIrj.mjs.map} +1 -1
- package/dist/vite.cjs +7 -2
- package/dist/vite.d.cts +2 -2
- package/dist/vite.d.mts +2 -2
- package/dist/vite.mjs +2 -2
- package/dist/vite.mjs.map +1 -1
- package/dist/webpack.cjs +7 -2
- package/dist/webpack.d.cts +2 -2
- package/dist/webpack.d.cts.map +1 -1
- package/dist/webpack.d.mts +2 -2
- package/dist/webpack.d.mts.map +1 -1
- package/dist/webpack.mjs +2 -2
- package/dist/webpack.mjs.map +1 -1
- package/package.json +3 -4
- package/dist/api-D6i8MmbC.mjs +0 -6063
- package/dist/api-D6i8MmbC.mjs.map +0 -1
- package/dist/api-DZoRNTY7.cjs +0 -6083
- package/dist/api-context-BQi9M07D.mjs.map +0 -1
- package/dist/base-Bl_AMAlI.d.cts +0 -12
- package/dist/base-Bl_AMAlI.d.cts.map +0 -1
- package/dist/base-hjCHfNY6.d.mts +0 -12
- package/dist/base-hjCHfNY6.d.mts.map +0 -1
- package/dist/types-hdziyQIH.d.mts.map +0 -1
- package/dist/typescript/index.mjs.map +0 -1
|
@@ -0,0 +1,917 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-AIJqnxB6.cjs');
|
|
2
|
+
const require_ts_morph = require('./ts-morph-Cf4wz3E0.cjs');
|
|
3
|
+
const require_utils = require('./utils.cjs');
|
|
4
|
+
const require_plugin_utils = require('./plugin-utils.cjs');
|
|
5
|
+
const require_api_context = require('./api-context-Ck0P2lLD.cjs');
|
|
6
|
+
const require_tsconfig = require('./tsconfig-ChmbpAO7.cjs');
|
|
7
|
+
let _storm_software_config_tools_logger_console = require("@storm-software/config-tools/logger/console");
|
|
8
|
+
let _stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
9
|
+
let _stryke_fs_copy_file = require("@stryke/fs/copy-file");
|
|
10
|
+
let _stryke_fs_exists = require("@stryke/fs/exists");
|
|
11
|
+
let _stryke_fs_helpers = require("@stryke/fs/helpers");
|
|
12
|
+
let _stryke_fs_install = require("@stryke/fs/install");
|
|
13
|
+
let _stryke_fs_list_files = require("@stryke/fs/list-files");
|
|
14
|
+
let _stryke_fs_package_fns = require("@stryke/fs/package-fns");
|
|
15
|
+
let _stryke_fs_resolve = require("@stryke/fs/resolve");
|
|
16
|
+
let _stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
17
|
+
let _stryke_helpers_omit = require("@stryke/helpers/omit");
|
|
18
|
+
let _stryke_path_append = require("@stryke/path/append");
|
|
19
|
+
let _stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
|
|
20
|
+
let _stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
|
|
21
|
+
let _stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
22
|
+
let _stryke_path_replace = require("@stryke/path/replace");
|
|
23
|
+
let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
24
|
+
let _stryke_type_checks_is_error = require("@stryke/type-checks/is-error");
|
|
25
|
+
let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
26
|
+
let _stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
|
|
27
|
+
let _stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
|
|
28
|
+
let _stryke_type_checks_is_promise = require("@stryke/type-checks/is-promise");
|
|
29
|
+
let _stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
|
|
30
|
+
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
31
|
+
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
32
|
+
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
33
|
+
let chalk = require("chalk");
|
|
34
|
+
chalk = require_chunk.__toESM(chalk);
|
|
35
|
+
let defu = require("defu");
|
|
36
|
+
defu = require_chunk.__toESM(defu);
|
|
37
|
+
let handlebars = require("handlebars");
|
|
38
|
+
handlebars = require_chunk.__toESM(handlebars);
|
|
39
|
+
let _stryke_string_format_pretty_bytes = require("@stryke/string-format/pretty-bytes");
|
|
40
|
+
let bundle_require = require("bundle-require");
|
|
41
|
+
let ts_morph = require("ts-morph");
|
|
42
|
+
let _stryke_string_format_package = require("@stryke/string-format/package");
|
|
43
|
+
let _stryke_fs_json = require("@stryke/fs/json");
|
|
44
|
+
let _donedeal0_superdiff = require("@donedeal0/superdiff");
|
|
45
|
+
let _stryke_json_storm_json = require("@stryke/json/storm-json");
|
|
46
|
+
|
|
47
|
+
//#region package.json
|
|
48
|
+
var name = "powerlines";
|
|
49
|
+
var version = "0.42.33";
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/_internal/helpers/generate-types.ts
|
|
53
|
+
/**
|
|
54
|
+
* Formats the generated TypeScript types source code.
|
|
55
|
+
*
|
|
56
|
+
* @param code - The generated TypeScript code.
|
|
57
|
+
* @returns The formatted TypeScript code.
|
|
58
|
+
*/
|
|
59
|
+
function formatTypes(code = "") {
|
|
60
|
+
return code.replaceAll("#private;", "").replace(/__Ω/g, "");
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Formats a generated TypeScript module in the types source code.
|
|
64
|
+
*
|
|
65
|
+
* @param context - The Powerlines context.
|
|
66
|
+
* @param id - The module ID for the generated TypeScript module.
|
|
67
|
+
* @param code - The generated TypeScript module code.
|
|
68
|
+
* @returns The formatted TypeScript module code.
|
|
69
|
+
*/
|
|
70
|
+
async function formatTypesModule(context, id, code) {
|
|
71
|
+
const moduleComment = code.match(new RegExp(`\\/\\*\\*(?s:.)*?@module\\s+${context.config.framework}:${id}(?s:.)*?\\*\\/\\s+`))?.find((comment) => (0, _stryke_type_checks_is_set_string.isSetString)(comment?.trim()));
|
|
72
|
+
const ast = await context.parse(code, {
|
|
73
|
+
lang: "dts",
|
|
74
|
+
astType: "ts"
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
code: `${moduleComment ? `
|
|
78
|
+
${moduleComment.trim()}` : ""}
|
|
79
|
+
declare module "${context.config.framework}:${id}" {
|
|
80
|
+
${ast.module.staticImports.filter((staticImport) => !(0, bundle_require.match)(staticImport.moduleRequest.value, context.config.resolve.external) && !staticImport.moduleRequest.value.startsWith("node:")).reduce((ret, staticImport) => {
|
|
81
|
+
return ret.replaceAll(new RegExp(`^import.*from\\s+['"]${staticImport.moduleRequest.value}['"]\\s*;?$`, "gm"), "");
|
|
82
|
+
}, code).replace(moduleComment ?? "", "").replaceAll(/^\s*export\s*declare\s*/gm, "export ").replaceAll(/^\s*declare\s*/gm, "").replaceAll(/^\s*export\s*\{\s*\}/gm, "").replaceAll(/^\s*export\s*=\s*/gm, "export default ").replaceAll(/^\s*export\s*\{/gm, "export {").replaceAll(/^\s*export\s*default\s*\{/gm, "export default {").replaceAll(/^\s*export\s*function\s*/gm, "export function ").replaceAll(/^\s*export\s*class\s*/gm, "export class ").replaceAll(/^\s*export\s*interface\s*/gm, "export interface ").replaceAll(/^\s*export\s*type\s*/gm, "export type ").replaceAll(/^\s*export\s*enum\s*/gm, "export enum ").replaceAll(/^\s*export\s*namespace\s*/gm, "export namespace ")}${ast.module.staticExports.length === 0 ? `
|
|
83
|
+
export {};` : ""}
|
|
84
|
+
}
|
|
85
|
+
`,
|
|
86
|
+
directives: ast.module.staticImports.filter((staticImport) => (0, bundle_require.match)(staticImport.moduleRequest.value, context.config.resolve.external) || staticImport.moduleRequest.value.startsWith("node:")).map((staticImport) => staticImport.moduleRequest.value.startsWith("node:") ? "node" : Object.keys(context.packageJson.dependencies ?? {}).find((dependency) => staticImport.moduleRequest.value.startsWith(dependency) || staticImport.moduleRequest.value.startsWith(dependency.replace(/^@types\//, ""))) || Object.keys(context.packageJson.devDependencies ?? {}).find((dependency) => staticImport.moduleRequest.value.startsWith(dependency) || staticImport.moduleRequest.value.startsWith(dependency.replace(/^@types\//, ""))) || Object.keys(context.packageJson.peerDependencies ?? {}).find((dependency) => staticImport.moduleRequest.value.startsWith(dependency) || staticImport.moduleRequest.value.startsWith(dependency.replace(/^@types\//, ""))) || staticImport.moduleRequest.value).filter(Boolean).map((dependency) => dependency.replace(/^@types\//, ""))
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Emits TypeScript declaration types for the provided files using the given TypeScript configuration.
|
|
91
|
+
*
|
|
92
|
+
* @param context - The context containing options and environment paths.
|
|
93
|
+
* @param files - The list of files to generate types for.
|
|
94
|
+
* @returns A promise that resolves to the generated TypeScript declaration types.
|
|
95
|
+
*/
|
|
96
|
+
async function emitBuiltinTypes(context, files) {
|
|
97
|
+
if (files.length === 0) {
|
|
98
|
+
context.debug("No files provided for TypeScript types generation. Typescript compilation for built-in modules will be skipped.");
|
|
99
|
+
return {
|
|
100
|
+
code: "",
|
|
101
|
+
directives: []
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
context.debug(`Running the TypeScript compiler for ${files.length} generated built-in module files.`);
|
|
105
|
+
const program = require_ts_morph.createProgram(context, {
|
|
106
|
+
skipAddingFilesFromTsConfig: true,
|
|
107
|
+
compilerOptions: {
|
|
108
|
+
declaration: true,
|
|
109
|
+
declarationMap: false,
|
|
110
|
+
emitDeclarationOnly: true,
|
|
111
|
+
sourceMap: false,
|
|
112
|
+
outDir: (0, _stryke_path_replace.replacePath)(context.builtinsPath, context.workspaceConfig.workspaceRoot),
|
|
113
|
+
composite: false,
|
|
114
|
+
incremental: false,
|
|
115
|
+
tsBuildInfoFile: void 0
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
program.addSourceFilesAtPaths(files);
|
|
119
|
+
const emitResult = program.emitToMemory({ emitOnlyDtsFiles: true });
|
|
120
|
+
const diagnostics = emitResult.getDiagnostics();
|
|
121
|
+
if (diagnostics && diagnostics.length > 0) if (diagnostics.some((d) => d.getCategory() === ts_morph.DiagnosticCategory.Error)) throw new Error(`The Typescript emit process failed while generating built-in types: \n ${diagnostics.filter((d) => d.getCategory() === ts_morph.DiagnosticCategory.Error).map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
|
|
122
|
+
else if (diagnostics.some((d) => d.getCategory() === ts_morph.DiagnosticCategory.Warning)) context.warn(`The Typescript emit process completed with warnings while generating built-in types: \n ${diagnostics.filter((d) => d.getCategory() === ts_morph.DiagnosticCategory.Warning).map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
|
|
123
|
+
else context.debug(`The Typescript emit process completed with diagnostic messages while generating built-in types: \n ${diagnostics.map((d) => `-${d.getSourceFile() ? `${d.getSourceFile()?.getFilePath()}:` : ""} ${String(d.getMessageText())} (at ${d.getStart()}:${d.getLength()})`).join("\n")}`);
|
|
124
|
+
const emittedFiles = emitResult.getFiles();
|
|
125
|
+
context.debug(`The TypeScript compiler emitted ${emittedFiles.length} files for built-in types.`);
|
|
126
|
+
if (emittedFiles.length === 0) {
|
|
127
|
+
context.warn("The TypeScript compiler did not emit any files for built-in types. This may indicate an issue with the TypeScript configuration or the provided files.");
|
|
128
|
+
return {
|
|
129
|
+
code: "",
|
|
130
|
+
directives: []
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
let result = "";
|
|
134
|
+
const directives = [];
|
|
135
|
+
for (const emittedFile of emittedFiles) {
|
|
136
|
+
context.trace(`Processing emitted type declaration file: ${emittedFile.filePath}`);
|
|
137
|
+
const filePath = (0, _stryke_path_append.appendPath)(emittedFile.filePath, context.workspaceConfig.workspaceRoot);
|
|
138
|
+
if (!filePath.endsWith(".map") && (0, _stryke_path_file_path_fns.findFileName)(filePath) !== "tsconfig.tsbuildinfo" && (0, _stryke_path_is_parent_path.isParentPath)(filePath, context.builtinsPath)) {
|
|
139
|
+
const moduleId = (0, _stryke_path_replace.replaceExtension)((0, _stryke_path_replace.replacePath)((0, _stryke_path_replace.replacePath)(filePath, context.builtinsPath), (0, _stryke_path_replace.replacePath)(context.builtinsPath, context.workspaceConfig.workspaceRoot)), "", { fullExtension: true });
|
|
140
|
+
if (context.builtins.includes(moduleId)) {
|
|
141
|
+
const formatted = await formatTypesModule(context, moduleId, emittedFile.text);
|
|
142
|
+
result += formatted.code;
|
|
143
|
+
directives.push(...formatted.directives);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
result = await (0, require_utils.utils_exports.format)(context, context.typesPath, formatTypes(result));
|
|
148
|
+
context.debug(`A TypeScript declaration file (size: ${(0, _stryke_string_format_pretty_bytes.prettyBytes)(new Blob((0, _stryke_convert_to_array.toArray)(result)).size)}) emitted for the built-in modules types.`);
|
|
149
|
+
return {
|
|
150
|
+
code: result,
|
|
151
|
+
directives
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/_internal/helpers/install.ts
|
|
157
|
+
/**
|
|
158
|
+
* Installs a package if it is not already installed.
|
|
159
|
+
*
|
|
160
|
+
* @param context - The resolved options
|
|
161
|
+
* @param packageName - The name of the package to install
|
|
162
|
+
* @param dev - Whether to install the package as a dev dependency
|
|
163
|
+
*/
|
|
164
|
+
async function installPackage(context, packageName, dev = false) {
|
|
165
|
+
if (!await (0, _stryke_fs_package_fns.isPackageListed)((0, _stryke_string_format_package.getPackageName)(packageName), { cwd: context.config.root })) if (context.config.autoInstall) {
|
|
166
|
+
context.warn(`The package "${packageName}" is not installed. It will be installed automatically.`);
|
|
167
|
+
const result = await (0, _stryke_fs_install.install)(packageName, {
|
|
168
|
+
cwd: context.config.root,
|
|
169
|
+
dev
|
|
170
|
+
});
|
|
171
|
+
if ((0, _stryke_type_checks_is_number.isNumber)(result.exitCode) && result.exitCode > 0) {
|
|
172
|
+
context.error(result.stderr);
|
|
173
|
+
throw new Error(`An error occurred while installing the package "${packageName}"`);
|
|
174
|
+
}
|
|
175
|
+
} else context.warn(`The package "${packageName}" is not installed. Since the "autoInstall" option is set to false, it will not be installed automatically.`);
|
|
176
|
+
else if ((0, _stryke_string_format_package.hasPackageVersion)(packageName) && !process.env.POWERLINES_SKIP_VERSION_CHECK) {
|
|
177
|
+
if (!await (0, _stryke_fs_package_fns.doesPackageMatch)((0, _stryke_string_format_package.getPackageName)(packageName), (0, _stryke_string_format_package.getPackageVersion)(packageName), context.config.root)) {
|
|
178
|
+
const packageListing = await (0, _stryke_fs_package_fns.getPackageListing)((0, _stryke_string_format_package.getPackageName)(packageName), { cwd: context.config.root });
|
|
179
|
+
if (!packageListing?.version.startsWith("catalog:") && !packageListing?.version.startsWith("workspace:")) context.warn(`The package "${(0, _stryke_string_format_package.getPackageName)(packageName)}" is installed but does not match the expected version ${(0, _stryke_string_format_package.getPackageVersion)(packageName)} (installed version: ${packageListing?.version || "<Unknown>"}). Please ensure this is intentional before proceeding. Note: You can skip this validation with the "STORM_STACK_SKIP_VERSION_CHECK" environment variable.`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/_internal/helpers/install-dependencies.ts
|
|
186
|
+
/**
|
|
187
|
+
* Install missing project dependencies.
|
|
188
|
+
*
|
|
189
|
+
* @param context - The build context.
|
|
190
|
+
*/
|
|
191
|
+
async function installDependencies(context) {
|
|
192
|
+
context.debug(`Checking and installing missing project dependencies.`);
|
|
193
|
+
context.dependencies ??= {};
|
|
194
|
+
context.devDependencies ??= {};
|
|
195
|
+
if (Object.keys(context.dependencies).length === 0 && Object.keys(context.devDependencies).length === 0) {
|
|
196
|
+
context.debug(`No dependencies or devDependencies to install. Skipping installation step.`);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
context.debug(`The following packages are required: \nDependencies: \n${Object.entries(context.dependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}\n\nDevDependencies: \n${Object.entries(context.devDependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}`);
|
|
200
|
+
await Promise.all([Promise.all(Object.entries(context.dependencies).map(async ([name, version]) => installPackage(context, `${(0, _stryke_string_format_package.getPackageName)(name)}@${String(version)}`, false))), Promise.all(Object.entries(context.devDependencies).map(async ([name, version]) => installPackage(context, `${(0, _stryke_string_format_package.getPackageName)(name)}@${String(version)}`, true)))]);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/_internal/helpers/resolve-tsconfig.ts
|
|
205
|
+
function getTsconfigDtsPath(context) {
|
|
206
|
+
return (0, _stryke_path_join_paths.joinPaths)((0, _stryke_path_file_path_fns.relativePath)((0, _stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.root), (0, _stryke_path_file_path_fns.findFilePath)(context.typesPath)), (0, _stryke_path_file_path_fns.findFileName)(context.typesPath));
|
|
207
|
+
}
|
|
208
|
+
async function resolveTsconfigChanges(context) {
|
|
209
|
+
const tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig, context.config.tsconfigRaw);
|
|
210
|
+
const tsconfigJson = await (0, _stryke_fs_json.readJsonFile)(require_tsconfig.getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig));
|
|
211
|
+
tsconfigJson.compilerOptions ??= {};
|
|
212
|
+
if (context.config.output.dts !== false) {
|
|
213
|
+
const dtsRelativePath = getTsconfigDtsPath(context);
|
|
214
|
+
if (!tsconfigJson.include?.some((filePattern) => require_tsconfig.isIncludeMatchFound(filePattern, [context.typesPath, dtsRelativePath]))) {
|
|
215
|
+
tsconfigJson.include ??= [];
|
|
216
|
+
tsconfigJson.include.push(dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (!tsconfig.options.lib?.some((lib) => [
|
|
220
|
+
"lib.esnext.d.ts",
|
|
221
|
+
"lib.es2021.d.ts",
|
|
222
|
+
"lib.es2022.d.ts",
|
|
223
|
+
"lib.es2023.d.ts"
|
|
224
|
+
].includes(lib.toLowerCase()))) {
|
|
225
|
+
tsconfigJson.compilerOptions.lib ??= [];
|
|
226
|
+
tsconfigJson.compilerOptions.lib.push("esnext");
|
|
227
|
+
}
|
|
228
|
+
if (tsconfig.options.esModuleInterop !== true) tsconfigJson.compilerOptions.esModuleInterop = true;
|
|
229
|
+
if (tsconfig.options.isolatedModules !== true) tsconfigJson.compilerOptions.isolatedModules = true;
|
|
230
|
+
if (context.config.platform === "node") {
|
|
231
|
+
if (!tsconfig.options.types?.some((type) => type.toLowerCase() === "node" || type.toLowerCase() === "@types/node")) {
|
|
232
|
+
tsconfigJson.compilerOptions.types ??= [];
|
|
233
|
+
tsconfigJson.compilerOptions.types.push("node");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return tsconfigJson;
|
|
237
|
+
}
|
|
238
|
+
async function initializeTsconfig(context) {
|
|
239
|
+
context.debug("Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.");
|
|
240
|
+
if (!(0, _stryke_fs_package_fns.isPackageExists)("typescript")) throw new Error("The TypeScript package is not installed. Please install the package using the command: \"npm install typescript --save-dev\"");
|
|
241
|
+
const tsconfigFilePath = require_tsconfig.getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig);
|
|
242
|
+
context.tsconfig.originalTsconfigJson = await (0, _stryke_fs_json.readJsonFile)(tsconfigFilePath);
|
|
243
|
+
context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
|
|
244
|
+
context.debug("Writing updated TypeScript configuration (tsconfig.json) file to disk.");
|
|
245
|
+
await context.fs.write(tsconfigFilePath, _stryke_json_storm_json.StormJSON.stringify(context.tsconfig.tsconfigJson));
|
|
246
|
+
context.tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
|
|
247
|
+
}
|
|
248
|
+
async function resolveTsconfig(context) {
|
|
249
|
+
const updateTsconfigJson = await (0, _stryke_fs_json.readJsonFile)(context.tsconfig.tsconfigFilePath);
|
|
250
|
+
if (updateTsconfigJson?.compilerOptions?.types && Array.isArray(updateTsconfigJson.compilerOptions.types) && !updateTsconfigJson.compilerOptions.types.length) delete updateTsconfigJson.compilerOptions.types;
|
|
251
|
+
const result = (0, _donedeal0_superdiff.getObjectDiff)(context.tsconfig.originalTsconfigJson, updateTsconfigJson, {
|
|
252
|
+
ignoreArrayOrder: true,
|
|
253
|
+
showOnly: {
|
|
254
|
+
statuses: [
|
|
255
|
+
"added",
|
|
256
|
+
"deleted",
|
|
257
|
+
"updated"
|
|
258
|
+
],
|
|
259
|
+
granularity: "deep"
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
const changes = [];
|
|
263
|
+
const getChanges = (difference, property) => {
|
|
264
|
+
if (difference.status === "added" || difference.status === "deleted" || difference.status === "updated") if (difference.diff) for (const diff of difference.diff) getChanges(diff, property ? `${property}.${difference.property}` : difference.property);
|
|
265
|
+
else changes.push({
|
|
266
|
+
field: property ? `${property}.${difference.property}` : difference.property,
|
|
267
|
+
status: difference.status,
|
|
268
|
+
previous: difference.status === "added" ? "---" : _stryke_json_storm_json.StormJSON.stringify(difference.previousValue),
|
|
269
|
+
current: difference.status === "deleted" ? "---" : _stryke_json_storm_json.StormJSON.stringify(difference.currentValue)
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
for (const diff of result.diff) getChanges(diff);
|
|
273
|
+
if (changes.length > 0) context.warn(`Updating the following configuration values in "${context.tsconfig.tsconfigFilePath}" file:
|
|
274
|
+
|
|
275
|
+
${changes.map((change, i) => `${chalk.default.bold.whiteBright(`${i + 1}. ${(0, _stryke_string_format_title_case.titleCase)(change.status)} the ${change.field} field: `)}
|
|
276
|
+
${chalk.default.red(` - Previous: ${change.previous} `)}
|
|
277
|
+
${chalk.default.green(` - Updated: ${change.current} `)}
|
|
278
|
+
`).join("\n")}
|
|
279
|
+
`);
|
|
280
|
+
await context.fs.write(context.tsconfig.tsconfigFilePath, _stryke_json_storm_json.StormJSON.stringify(updateTsconfigJson));
|
|
281
|
+
context.tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.root, context.config.tsconfig);
|
|
282
|
+
if (!context.tsconfig) throw new Error("Failed to parse the TypeScript configuration file.");
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/api.ts
|
|
287
|
+
/**
|
|
288
|
+
* The Powerlines API class
|
|
289
|
+
*
|
|
290
|
+
* @remarks
|
|
291
|
+
* This class is responsible for managing the Powerlines project lifecycle, including initialization, building, and finalization.
|
|
292
|
+
*
|
|
293
|
+
* @public
|
|
294
|
+
*/
|
|
295
|
+
var PowerlinesAPI = class PowerlinesAPI {
|
|
296
|
+
/**
|
|
297
|
+
* The Powerlines context
|
|
298
|
+
*/
|
|
299
|
+
#context;
|
|
300
|
+
/**
|
|
301
|
+
* The Powerlines context
|
|
302
|
+
*/
|
|
303
|
+
get context() {
|
|
304
|
+
return this.#context;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Create a new Powerlines API instance
|
|
308
|
+
*
|
|
309
|
+
* @param context - The Powerlines context
|
|
310
|
+
*/
|
|
311
|
+
constructor(context) {
|
|
312
|
+
this.#context = context;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Initialize a Powerlines API instance
|
|
316
|
+
*
|
|
317
|
+
* @param workspaceRoot - The directory of the underlying workspace the Powerlines project exists in
|
|
318
|
+
* @param config - An object containing the configuration required to run Powerlines tasks.
|
|
319
|
+
* @returns A new instance of the Powerlines API
|
|
320
|
+
*/
|
|
321
|
+
static async from(workspaceRoot, config) {
|
|
322
|
+
const api = new PowerlinesAPI(await require_api_context.PowerlinesAPIContext.from(workspaceRoot, config));
|
|
323
|
+
api.#context.$$internal = {
|
|
324
|
+
api,
|
|
325
|
+
addPlugin: api.#addPlugin.bind(api)
|
|
326
|
+
};
|
|
327
|
+
api.context.info(`🔌 The Powerlines Engine v${version} has started`);
|
|
328
|
+
for (const plugin of api.context.config.plugins.flat(10) ?? []) await api.#addPlugin(plugin);
|
|
329
|
+
if (api.context.plugins.length === 0) api.context.warn("No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended.");
|
|
330
|
+
else api.context.info(`🔌 Loaded ${api.context.plugins.length} ${(0, _stryke_string_format_title_case.titleCase)(api.context.config.framework)} plugin${api.context.plugins.length > 1 ? "s" : ""}: \n\n${api.context.plugins.map((plugin, index) => ` ${index + 1}. ${(0, require_utils.utils_exports.colorText)(plugin.name)}`).join("\n")}`);
|
|
331
|
+
const pluginConfig = await api.callHook("config", {
|
|
332
|
+
environment: await api.context.getEnvironment(),
|
|
333
|
+
sequential: true,
|
|
334
|
+
result: "merge",
|
|
335
|
+
merge: require_api_context.mergeConfigs
|
|
336
|
+
});
|
|
337
|
+
await api.context.withUserConfig(pluginConfig, { isHighPriority: false });
|
|
338
|
+
return api;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Generate the Powerlines typescript declaration file
|
|
342
|
+
*
|
|
343
|
+
* @remarks
|
|
344
|
+
* This method will only generate the typescript declaration file for the Powerlines project. It is generally recommended to run the full `prepare` command, which will run this method as part of its process.
|
|
345
|
+
*
|
|
346
|
+
* @param inlineConfig - The inline configuration for the types command
|
|
347
|
+
*/
|
|
348
|
+
async types(inlineConfig = { command: "types" }) {
|
|
349
|
+
this.context.info(" 🏗️ Generating typescript declarations for the Powerlines project");
|
|
350
|
+
this.context.debug(" Aggregating configuration options for the Powerlines project");
|
|
351
|
+
inlineConfig.command ??= "types";
|
|
352
|
+
await this.context.withInlineConfig(inlineConfig);
|
|
353
|
+
await this.#executeEnvironments(async (context) => {
|
|
354
|
+
context.debug(`Initializing the processing options for the Powerlines project.`);
|
|
355
|
+
await this.callHook("configResolved", {
|
|
356
|
+
environment: context,
|
|
357
|
+
order: "pre"
|
|
358
|
+
});
|
|
359
|
+
await initializeTsconfig(context);
|
|
360
|
+
await this.callHook("configResolved", {
|
|
361
|
+
environment: context,
|
|
362
|
+
order: "normal"
|
|
363
|
+
});
|
|
364
|
+
if (context.entry.length > 0) context.debug(`The configuration provided ${(0, _stryke_type_checks_is_object.isObject)(context.config.input) ? Object.keys(context.config.input).length : (0, _stryke_convert_to_array.toArray)(context.config.input).length} entry point(s), Powerlines has found ${context.entry.length} entry files(s) for the ${context.config.title} project${context.entry.length > 0 && context.entry.length < 10 ? `: \n${context.entry.map((entry) => `- ${entry.file}${entry.output ? ` -> ${entry.output}` : ""}`).join(" \n")}` : ""}`);
|
|
365
|
+
else context.warn(`No entry files were found for the ${context.config.title} project. Please ensure this is correct. Powerlines plugins generally require at least one entry point to function properly.`);
|
|
366
|
+
await resolveTsconfig(context);
|
|
367
|
+
await installDependencies(context);
|
|
368
|
+
await this.callHook("configResolved", {
|
|
369
|
+
environment: context,
|
|
370
|
+
order: "post"
|
|
371
|
+
});
|
|
372
|
+
context.trace(`Powerlines configuration has been resolved: \n\n${(0, _storm_software_config_tools_logger_console.formatLogMessage)({
|
|
373
|
+
...context.config,
|
|
374
|
+
userConfig: (0, _stryke_type_checks_is_set_object.isSetObject)(context.config.userConfig) ? (0, _stryke_helpers_omit.omit)(context.config.userConfig, ["plugins"]) : void 0,
|
|
375
|
+
inlineConfig: (0, _stryke_type_checks_is_set_object.isSetObject)(context.config.inlineConfig) ? (0, _stryke_helpers_omit.omit)(context.config.inlineConfig, ["plugins"]) : void 0,
|
|
376
|
+
plugins: context.plugins.map((plugin) => plugin.plugin.name)
|
|
377
|
+
})}`);
|
|
378
|
+
if (!context.fs.existsSync(context.cachePath)) await (0, _stryke_fs_helpers.createDirectory)(context.cachePath);
|
|
379
|
+
if (!context.fs.existsSync(context.dataPath)) await (0, _stryke_fs_helpers.createDirectory)(context.dataPath);
|
|
380
|
+
if (context.config.skipCache === true || context.persistedMeta?.checksum !== context.meta.checksum) context.debug(`Using previously prepared files as the meta checksum has not changed.`);
|
|
381
|
+
else {
|
|
382
|
+
context.info(`Running \`prepare\` command as the meta checksum has changed since the last run.`);
|
|
383
|
+
await this.prepare((0, defu.default)({ output: { types: false } }, inlineConfig));
|
|
384
|
+
}
|
|
385
|
+
await this.#types(context);
|
|
386
|
+
this.context.debug("Formatting files generated during the types step.");
|
|
387
|
+
await (0, require_utils.utils_exports.format)(context, context.typesPath, await context.fs.read(context.typesPath) ?? "");
|
|
388
|
+
await require_api_context.writeMetaFile(context);
|
|
389
|
+
context.persistedMeta = context.meta;
|
|
390
|
+
});
|
|
391
|
+
this.context.debug("✔ Powerlines types generation has completed successfully");
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Prepare the Powerlines API
|
|
395
|
+
*
|
|
396
|
+
* @remarks
|
|
397
|
+
* This method will prepare the Powerlines API for use, initializing any necessary resources.
|
|
398
|
+
*
|
|
399
|
+
* @param inlineConfig - The inline configuration for the prepare command
|
|
400
|
+
*/
|
|
401
|
+
async prepare(inlineConfig = { command: "prepare" }) {
|
|
402
|
+
this.context.info(" 🏗️ Preparing the Powerlines project");
|
|
403
|
+
this.context.debug(" Aggregating configuration options for the Powerlines project");
|
|
404
|
+
inlineConfig.command ??= "prepare";
|
|
405
|
+
await this.context.withInlineConfig(inlineConfig);
|
|
406
|
+
await this.#executeEnvironments(async (context) => {
|
|
407
|
+
context.debug(`Initializing the processing options for the Powerlines project.`);
|
|
408
|
+
await this.callHook("configResolved", {
|
|
409
|
+
environment: context,
|
|
410
|
+
order: "pre"
|
|
411
|
+
});
|
|
412
|
+
await initializeTsconfig(context);
|
|
413
|
+
await this.callHook("configResolved", {
|
|
414
|
+
environment: context,
|
|
415
|
+
order: "normal"
|
|
416
|
+
});
|
|
417
|
+
if (context.entry.length > 0) context.debug(`The configuration provided ${(0, _stryke_type_checks_is_object.isObject)(context.config.input) ? Object.keys(context.config.input).length : (0, _stryke_convert_to_array.toArray)(context.config.input).length} entry point(s), Powerlines has found ${context.entry.length} entry files(s) for the ${context.config.title} project${context.entry.length > 0 && context.entry.length < 10 ? `: \n${context.entry.map((entry) => `- ${entry.file}${entry.output ? ` -> ${entry.output}` : ""}`).join(" \n")}` : ""}`);
|
|
418
|
+
else context.warn(`No entry files were found for the ${context.config.title} project. Please ensure this is correct. Powerlines plugins generally require at least one entry point to function properly.`);
|
|
419
|
+
await resolveTsconfig(context);
|
|
420
|
+
await installDependencies(context);
|
|
421
|
+
await this.callHook("configResolved", {
|
|
422
|
+
environment: context,
|
|
423
|
+
order: "post"
|
|
424
|
+
});
|
|
425
|
+
context.trace(`Powerlines configuration has been resolved: \n\n${(0, _storm_software_config_tools_logger_console.formatLogMessage)({
|
|
426
|
+
...context.config,
|
|
427
|
+
userConfig: (0, _stryke_type_checks_is_set_object.isSetObject)(context.config.userConfig) ? (0, _stryke_helpers_omit.omit)(context.config.userConfig, ["plugins"]) : void 0,
|
|
428
|
+
inlineConfig: (0, _stryke_type_checks_is_set_object.isSetObject)(context.config.inlineConfig) ? (0, _stryke_helpers_omit.omit)(context.config.inlineConfig, ["plugins"]) : void 0,
|
|
429
|
+
plugins: context.plugins.map((plugin) => plugin.plugin.name)
|
|
430
|
+
})}`);
|
|
431
|
+
if (!context.fs.existsSync(context.cachePath)) await (0, _stryke_fs_helpers.createDirectory)(context.cachePath);
|
|
432
|
+
if (!context.fs.existsSync(context.dataPath)) await (0, _stryke_fs_helpers.createDirectory)(context.dataPath);
|
|
433
|
+
await this.callHook("prepare", {
|
|
434
|
+
environment: context,
|
|
435
|
+
order: "pre"
|
|
436
|
+
});
|
|
437
|
+
await this.callHook("prepare", {
|
|
438
|
+
environment: context,
|
|
439
|
+
order: "normal"
|
|
440
|
+
});
|
|
441
|
+
await this.callHook("prepare", {
|
|
442
|
+
environment: context,
|
|
443
|
+
order: "post"
|
|
444
|
+
});
|
|
445
|
+
if (context.config.output.types !== false) await this.#types(context);
|
|
446
|
+
this.context.debug("Formatting files generated during the prepare step.");
|
|
447
|
+
await Promise.all([(0, require_utils.utils_exports.formatFolder)(context, context.builtinsPath), (0, require_utils.utils_exports.formatFolder)(context, context.entryPath)]);
|
|
448
|
+
await require_api_context.writeMetaFile(context);
|
|
449
|
+
context.persistedMeta = context.meta;
|
|
450
|
+
});
|
|
451
|
+
this.context.debug("✔ Powerlines preparation has completed successfully");
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Create a new Powerlines project
|
|
455
|
+
*
|
|
456
|
+
* @remarks
|
|
457
|
+
* This method will create a new Powerlines project in the current directory.
|
|
458
|
+
*
|
|
459
|
+
* @param inlineConfig - The inline configuration for the new command
|
|
460
|
+
* @returns A promise that resolves when the project has been created
|
|
461
|
+
*/
|
|
462
|
+
async new(inlineConfig) {
|
|
463
|
+
this.context.info(" 🆕 Creating a new Powerlines project");
|
|
464
|
+
inlineConfig.command ??= "new";
|
|
465
|
+
await this.prepare(inlineConfig);
|
|
466
|
+
await this.#executeEnvironments(async (context) => {
|
|
467
|
+
context.debug("Initializing the processing options for the Powerlines project.");
|
|
468
|
+
await this.callHook("new", {
|
|
469
|
+
environment: context,
|
|
470
|
+
order: "pre"
|
|
471
|
+
});
|
|
472
|
+
const files = await (0, _stryke_fs_list_files.listFiles)((0, _stryke_path_join_paths.joinPaths)(context.powerlinesPath, "files/common/**/*.hbs"));
|
|
473
|
+
for (const file of files) {
|
|
474
|
+
context.trace(`Adding template file to project: ${file}`);
|
|
475
|
+
const template = handlebars.default.compile(file);
|
|
476
|
+
await context.fs.write((0, _stryke_path_join_paths.joinPaths)(context.config.root, file.replace(".hbs", "")), template(context));
|
|
477
|
+
}
|
|
478
|
+
await this.callHook("new", {
|
|
479
|
+
environment: context,
|
|
480
|
+
order: "normal"
|
|
481
|
+
});
|
|
482
|
+
if (context.config.projectType === "application") {
|
|
483
|
+
const files = await (0, _stryke_fs_list_files.listFiles)((0, _stryke_path_join_paths.joinPaths)(context.powerlinesPath, "files/application/**/*.hbs"));
|
|
484
|
+
for (const file of files) {
|
|
485
|
+
context.trace(`Adding application template file: ${file}`);
|
|
486
|
+
const template = handlebars.default.compile(file);
|
|
487
|
+
await context.fs.write((0, _stryke_path_join_paths.joinPaths)(context.config.root, file.replace(".hbs", "")), template(context));
|
|
488
|
+
}
|
|
489
|
+
} else {
|
|
490
|
+
const files = await (0, _stryke_fs_list_files.listFiles)((0, _stryke_path_join_paths.joinPaths)(context.powerlinesPath, "files/library/**/*.hbs"));
|
|
491
|
+
for (const file of files) {
|
|
492
|
+
context.trace(`Adding library template file: ${file}`);
|
|
493
|
+
const template = handlebars.default.compile(file);
|
|
494
|
+
await context.fs.write((0, _stryke_path_join_paths.joinPaths)(context.config.root, file.replace(".hbs", "")), template(context));
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
await this.callHook("new", {
|
|
498
|
+
environment: context,
|
|
499
|
+
order: "post"
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
this.context.debug("✔ Powerlines new command completed successfully");
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Clean any previously prepared artifacts
|
|
506
|
+
*
|
|
507
|
+
* @remarks
|
|
508
|
+
* This method will remove the previous Powerlines artifacts from the project.
|
|
509
|
+
*
|
|
510
|
+
* @param inlineConfig - The inline configuration for the clean command
|
|
511
|
+
* @returns A promise that resolves when the clean command has completed
|
|
512
|
+
*/
|
|
513
|
+
async clean(inlineConfig = { command: "clean" }) {
|
|
514
|
+
this.context.info(" 🧹 Cleaning the previous Powerlines artifacts");
|
|
515
|
+
inlineConfig.command ??= "clean";
|
|
516
|
+
await this.prepare(inlineConfig);
|
|
517
|
+
await this.#executeEnvironments(async (context) => {
|
|
518
|
+
context.debug("Cleaning the project's dist and artifacts directories.");
|
|
519
|
+
await context.fs.remove((0, _stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.output.path));
|
|
520
|
+
await context.fs.remove((0, _stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.root, context.config.output.artifactsPath));
|
|
521
|
+
await this.callHook("clean", {
|
|
522
|
+
environment: context,
|
|
523
|
+
sequential: false
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
this.context.debug("✔ Powerlines cleaning completed successfully");
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Lint the project
|
|
530
|
+
*
|
|
531
|
+
* @param inlineConfig - The inline configuration for the lint command
|
|
532
|
+
* @returns A promise that resolves when the lint command has completed
|
|
533
|
+
*/
|
|
534
|
+
async lint(inlineConfig = { command: "lint" }) {
|
|
535
|
+
this.context.info(" 📝 Linting the Powerlines project");
|
|
536
|
+
inlineConfig.command ??= "lint";
|
|
537
|
+
await this.prepare(inlineConfig);
|
|
538
|
+
await this.#executeEnvironments(async (context) => {
|
|
539
|
+
await this.callHook("lint", {
|
|
540
|
+
environment: context,
|
|
541
|
+
sequential: false
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
this.context.debug("✔ Powerlines linting completed successfully");
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Build the project
|
|
548
|
+
*
|
|
549
|
+
* @remarks
|
|
550
|
+
* This method will build the Powerlines project, generating the necessary artifacts.
|
|
551
|
+
*
|
|
552
|
+
* @param inlineConfig - The inline configuration for the build command
|
|
553
|
+
* @returns A promise that resolves when the build command has completed
|
|
554
|
+
*/
|
|
555
|
+
async build(inlineConfig = { command: "build" }) {
|
|
556
|
+
this.context.info(" 📦 Building the Powerlines project");
|
|
557
|
+
await this.context.generateChecksum();
|
|
558
|
+
if (this.context.meta.checksum !== this.context.persistedMeta?.checksum || this.context.config.skipCache) {
|
|
559
|
+
this.context.info(!this.context.persistedMeta?.checksum ? "No previous build cache found. Preparing the project for the initial build." : this.context.meta.checksum !== this.context.persistedMeta.checksum ? "The project has been modified since the last time `prepare` was ran. Re-preparing the project." : "The project is configured to skip cache. Re-preparing the project.");
|
|
560
|
+
inlineConfig.command ??= "build";
|
|
561
|
+
await this.prepare(inlineConfig);
|
|
562
|
+
}
|
|
563
|
+
if (this.context.config.singleBuild) await this.#handleBuild(await this.#context.toEnvironment());
|
|
564
|
+
else await this.#executeEnvironments(async (context) => {
|
|
565
|
+
await this.#handleBuild(context);
|
|
566
|
+
});
|
|
567
|
+
this.context.debug("✔ Powerlines build completed successfully");
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Prepare the documentation for the project
|
|
571
|
+
*
|
|
572
|
+
* @param inlineConfig - The inline configuration for the docs command
|
|
573
|
+
* @returns A promise that resolves when the documentation generation has completed
|
|
574
|
+
*/
|
|
575
|
+
async docs(inlineConfig = { command: "docs" }) {
|
|
576
|
+
this.context.info(" 📓 Generating documentation for the Powerlines project");
|
|
577
|
+
inlineConfig.command ??= "docs";
|
|
578
|
+
await this.prepare(inlineConfig);
|
|
579
|
+
await this.#executeEnvironments(async (context) => {
|
|
580
|
+
context.debug("Writing documentation for the Powerlines project artifacts.");
|
|
581
|
+
inlineConfig.command ??= "docs";
|
|
582
|
+
await this.prepare(inlineConfig);
|
|
583
|
+
await this.#executeEnvironments(async (context) => {
|
|
584
|
+
await this.callHook("docs", { environment: context });
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
this.context.debug("✔ Powerlines documentation generation completed successfully");
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Deploy the project source code
|
|
591
|
+
*
|
|
592
|
+
* @remarks
|
|
593
|
+
* This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
|
|
594
|
+
*
|
|
595
|
+
* @param inlineConfig - The inline configuration for the deploy command
|
|
596
|
+
*/
|
|
597
|
+
async deploy(inlineConfig = { command: "deploy" }) {
|
|
598
|
+
this.context.info(" 🚀 Deploying the Powerlines project");
|
|
599
|
+
inlineConfig.command ??= "deploy";
|
|
600
|
+
await this.prepare(inlineConfig);
|
|
601
|
+
await this.#executeEnvironments(async (context) => {
|
|
602
|
+
await this.callHook("deploy", { environment: context });
|
|
603
|
+
});
|
|
604
|
+
this.context.debug("✔ Powerlines deploy completed successfully");
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Finalization process
|
|
608
|
+
*
|
|
609
|
+
* @remarks
|
|
610
|
+
* This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
|
|
611
|
+
*
|
|
612
|
+
* @returns A promise that resolves when the finalization process has completed
|
|
613
|
+
*/
|
|
614
|
+
async finalize() {
|
|
615
|
+
this.context.info(" 🏁 Powerlines finalization processes started");
|
|
616
|
+
await this.#executeEnvironments(async (context) => {
|
|
617
|
+
await this.callHook("finalize", { environment: context });
|
|
618
|
+
await context.fs.dispose();
|
|
619
|
+
if ((0, _stryke_fs_exists.existsSync)(context.cachePath) && !(await (0, _stryke_fs_list_files.listFiles)((0, _stryke_path_join_paths.joinPaths)(context.cachePath, "**/*")))?.length) await (0, _stryke_fs_helpers.removeDirectory)(context.cachePath);
|
|
620
|
+
});
|
|
621
|
+
this.context.debug("✔ Powerlines finalization completed successfully");
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Invokes the configured plugin hooks
|
|
625
|
+
*
|
|
626
|
+
* @remarks
|
|
627
|
+
* By default, it will call the `"pre"`, `"normal"`, and `"post"` ordered hooks in sequence
|
|
628
|
+
*
|
|
629
|
+
* @param hook - The hook to call
|
|
630
|
+
* @param options - The options to provide to the hook
|
|
631
|
+
* @param args - The arguments to pass to the hook
|
|
632
|
+
* @returns The result of the hook call
|
|
633
|
+
*/
|
|
634
|
+
async callHook(hook, options, ...args) {
|
|
635
|
+
return require_api_context.callHook((0, _stryke_type_checks_is_set_object.isSetObject)(options?.environment) ? options.environment : await this.#context.getEnvironment(options?.environment), hook, {
|
|
636
|
+
sequential: true,
|
|
637
|
+
...options
|
|
638
|
+
}, ...args);
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Dispose of the Powerlines API instance
|
|
642
|
+
*
|
|
643
|
+
* @remarks
|
|
644
|
+
* This method will finalize the Powerlines API instance, cleaning up any resources used.
|
|
645
|
+
*/
|
|
646
|
+
async [Symbol.asyncDispose]() {
|
|
647
|
+
await this.finalize();
|
|
648
|
+
}
|
|
649
|
+
async #handleBuild(context) {
|
|
650
|
+
await this.callHook("build", {
|
|
651
|
+
environment: context,
|
|
652
|
+
order: "pre"
|
|
653
|
+
});
|
|
654
|
+
context.debug("Formatting the generated entry files before the build process starts.");
|
|
655
|
+
await (0, require_utils.utils_exports.formatFolder)(context, context.entryPath);
|
|
656
|
+
await this.callHook("build", {
|
|
657
|
+
environment: context,
|
|
658
|
+
order: "normal"
|
|
659
|
+
});
|
|
660
|
+
if (context.config.output.copy) {
|
|
661
|
+
context.debug("Copying project's files from build output directory.");
|
|
662
|
+
const destinationPath = (0, _stryke_path_is_parent_path.isParentPath)((0, _stryke_path_append.appendPath)(context.config.output.path, context.workspaceConfig.workspaceRoot), (0, _stryke_path_append.appendPath)(context.config.root, context.workspaceConfig.workspaceRoot)) ? (0, _stryke_path_join_paths.joinPaths)(context.config.output.copy.path, (0, _stryke_path_file_path_fns.relativePath)((0, _stryke_path_append.appendPath)(context.config.root, context.workspaceConfig.workspaceRoot), (0, _stryke_path_append.appendPath)(context.config.output.path, context.workspaceConfig.workspaceRoot))) : (0, _stryke_path_join_paths.joinPaths)(context.config.output.copy.path, "dist");
|
|
663
|
+
const sourcePath = (0, _stryke_path_append.appendPath)(context.config.output.path, context.workspaceConfig.workspaceRoot);
|
|
664
|
+
if ((0, _stryke_fs_exists.existsSync)(sourcePath) && sourcePath !== destinationPath) {
|
|
665
|
+
context.debug(`Copying files from project's build output directory (${context.config.output.path}) to the project's copy/publish directory (${destinationPath}).`);
|
|
666
|
+
await (0, _stryke_fs_copy_file.copyFiles)(sourcePath, destinationPath);
|
|
667
|
+
} else context.warn(`The source path for the copy operation ${!(0, _stryke_fs_exists.existsSync)(sourcePath) ? "does not exist" : "is the same as the destination path"}. Source: ${sourcePath}, Destination: ${destinationPath}. Skipping copying of build output files.`);
|
|
668
|
+
if (context.config.output.copy.assets && Array.isArray(context.config.output.copy.assets)) await Promise.all(context.config.output.copy.assets.map(async (asset) => {
|
|
669
|
+
context.trace(`Copying asset(s): ${chalk.default.redBright(context.workspaceConfig.workspaceRoot === asset.input ? asset.glob : (0, _stryke_path_append.appendPath)(asset.glob, (0, _stryke_path_replace.replacePath)(asset.input, context.workspaceConfig.workspaceRoot)))} -> ${chalk.default.greenBright((0, _stryke_path_append.appendPath)(asset.glob, (0, _stryke_path_replace.replacePath)(asset.output, context.workspaceConfig.workspaceRoot)))} ${Array.isArray(asset.ignore) && asset.ignore.length > 0 ? ` (ignoring: ${asset.ignore.map((i) => chalk.default.yellowBright(i)).join(", ")})` : ""}`);
|
|
670
|
+
await context.fs.copy(asset, asset.output);
|
|
671
|
+
}));
|
|
672
|
+
} else context.debug("No copy configuration found for the project output. Skipping the copying of build output files.");
|
|
673
|
+
await this.callHook("build", {
|
|
674
|
+
environment: context,
|
|
675
|
+
order: "post"
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Get the configured environments
|
|
680
|
+
*
|
|
681
|
+
* @returns The configured environments
|
|
682
|
+
*/
|
|
683
|
+
async #getEnvironments() {
|
|
684
|
+
if (!this.context.config.environments || Object.keys(this.context.config.environments).length <= 1) {
|
|
685
|
+
this.context.debug("No environments are configured for this Powerlines project. Using the default environment.");
|
|
686
|
+
return [await this.context.getEnvironment()];
|
|
687
|
+
}
|
|
688
|
+
this.context.debug(`Found ${Object.keys(this.context.config.environments).length} configured environment(s) for this Powerlines project.`);
|
|
689
|
+
return (await Promise.all(Object.entries(this.context.config.environments).map(async ([name, config]) => {
|
|
690
|
+
if (!await this.context.getEnvironmentSafe(name)) {
|
|
691
|
+
const resolvedEnvironment = await this.callHook("configEnvironment", { environment: name }, name, config);
|
|
692
|
+
if (resolvedEnvironment) this.context.environments[name] = await this.context.in(resolvedEnvironment);
|
|
693
|
+
}
|
|
694
|
+
return this.context.environments[name];
|
|
695
|
+
}))).filter((context) => (0, _stryke_type_checks_is_set.isSet)(context));
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Execute a handler function for each environment
|
|
699
|
+
*
|
|
700
|
+
* @param handle - The handler function to execute for each environment
|
|
701
|
+
*/
|
|
702
|
+
async #executeEnvironments(handle) {
|
|
703
|
+
await Promise.all((await this.#getEnvironments()).map(async (context) => {
|
|
704
|
+
return Promise.resolve(handle(context));
|
|
705
|
+
}));
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Add a Powerlines plugin used in the build process
|
|
709
|
+
*
|
|
710
|
+
* @param config - The import path of the plugin to add
|
|
711
|
+
*/
|
|
712
|
+
async #addPlugin(config) {
|
|
713
|
+
if (config) {
|
|
714
|
+
const result = await this.#initPlugin(config);
|
|
715
|
+
if (!result) return;
|
|
716
|
+
for (const plugin of result) {
|
|
717
|
+
this.context.debug(`Successfully initialized the ${chalk.default.bold.cyanBright(plugin.name)} plugin`);
|
|
718
|
+
await this.context.addPlugin(plugin);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Initialize a Powerlines plugin
|
|
724
|
+
*
|
|
725
|
+
* @param config - The configuration for the plugin
|
|
726
|
+
* @returns The initialized plugin instance, or null if the plugin was a duplicate
|
|
727
|
+
* @throws Will throw an error if the plugin cannot be found or is invalid
|
|
728
|
+
*/
|
|
729
|
+
async #initPlugin(config) {
|
|
730
|
+
let awaited = config;
|
|
731
|
+
if ((0, _stryke_type_checks_is_promise.isPromiseLike)(config)) awaited = await Promise.resolve(config);
|
|
732
|
+
if (!(0, require_plugin_utils.plugin_utils_exports.isPluginConfig)(awaited)) {
|
|
733
|
+
const invalid = (0, require_plugin_utils.plugin_utils_exports.findInvalidPluginConfig)(awaited);
|
|
734
|
+
throw new Error(`Invalid ${invalid && invalid.length > 1 ? "plugins" : "plugin"} specified in the configuration - ${invalid && invalid.length > 0 ? JSON.stringify(awaited) : invalid?.join("\n\n")} \n\nPlease ensure the value is one of the following: \n - an instance of \`Plugin\` \n - a plugin name \n - an object with the \`plugin\` and \`options\` properties \n - a tuple array with the plugin and options \n - a factory function that returns a plugin or array of plugins \n - an array of plugins or plugin configurations`);
|
|
735
|
+
}
|
|
736
|
+
let plugins;
|
|
737
|
+
if ((0, require_plugin_utils.plugin_utils_exports.isPlugin)(awaited)) plugins = [awaited];
|
|
738
|
+
else if ((0, _stryke_type_checks_is_function.isFunction)(awaited)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(awaited()));
|
|
739
|
+
else if ((0, _stryke_type_checks_is_string.isString)(awaited)) {
|
|
740
|
+
const resolved = await this.#resolvePlugin(awaited);
|
|
741
|
+
if ((0, _stryke_type_checks_is_function.isFunction)(resolved)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(resolved()));
|
|
742
|
+
else plugins = (0, _stryke_convert_to_array.toArray)(resolved);
|
|
743
|
+
} else if (Array.isArray(awaited) && awaited.every(require_plugin_utils.plugin_utils_exports.isPlugin)) plugins = awaited;
|
|
744
|
+
else if (Array.isArray(awaited) && awaited.every(require_plugin_utils.plugin_utils_exports.isPluginConfig)) {
|
|
745
|
+
plugins = [];
|
|
746
|
+
for (const pluginConfig of awaited) {
|
|
747
|
+
const initialized = await this.#initPlugin(pluginConfig);
|
|
748
|
+
if (initialized) plugins.push(...initialized);
|
|
749
|
+
}
|
|
750
|
+
} else if ((0, require_plugin_utils.plugin_utils_exports.isPluginConfigTuple)(awaited) || (0, require_plugin_utils.plugin_utils_exports.isPluginConfigObject)(awaited)) {
|
|
751
|
+
let pluginConfig;
|
|
752
|
+
let pluginOptions;
|
|
753
|
+
if ((0, require_plugin_utils.plugin_utils_exports.isPluginConfigTuple)(awaited)) {
|
|
754
|
+
pluginConfig = awaited[0];
|
|
755
|
+
pluginOptions = awaited?.length === 2 ? awaited[1] : void 0;
|
|
756
|
+
} else {
|
|
757
|
+
pluginConfig = awaited.plugin;
|
|
758
|
+
pluginOptions = awaited.options;
|
|
759
|
+
}
|
|
760
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(pluginConfig)) {
|
|
761
|
+
const resolved = await this.#resolvePlugin(pluginConfig);
|
|
762
|
+
if ((0, _stryke_type_checks_is_function.isFunction)(resolved)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(pluginOptions ? resolved(pluginOptions) : resolved()));
|
|
763
|
+
else plugins = (0, _stryke_convert_to_array.toArray)(resolved);
|
|
764
|
+
} else if ((0, _stryke_type_checks_is_function.isFunction)(pluginConfig)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(pluginConfig(pluginOptions)));
|
|
765
|
+
else if (Array.isArray(pluginConfig) && pluginConfig.every(require_plugin_utils.plugin_utils_exports.isPlugin)) plugins = pluginConfig;
|
|
766
|
+
else if ((0, require_plugin_utils.plugin_utils_exports.isPlugin)(pluginConfig)) plugins = (0, _stryke_convert_to_array.toArray)(pluginConfig);
|
|
767
|
+
}
|
|
768
|
+
if (!plugins) throw new Error(`The plugin configuration ${JSON.stringify(awaited)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
|
|
769
|
+
if (plugins.length > 0 && !plugins.every(require_plugin_utils.plugin_utils_exports.isPlugin)) throw new Error(`The plugin option ${JSON.stringify(plugins)} does not export a valid module. This configuration must point to a valid Powerlines plugin module.`);
|
|
770
|
+
const result = [];
|
|
771
|
+
for (const plugin of plugins) if ((0, require_plugin_utils.plugin_utils_exports.checkDedupe)(plugin, this.context.plugins)) this.context.trace(`Duplicate ${chalk.default.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`);
|
|
772
|
+
else {
|
|
773
|
+
result.push(plugin);
|
|
774
|
+
this.context.trace(`Initializing the ${chalk.default.bold.cyanBright(plugin.name)} plugin...`);
|
|
775
|
+
}
|
|
776
|
+
return result;
|
|
777
|
+
}
|
|
778
|
+
async #resolvePlugin(pluginPath) {
|
|
779
|
+
if (pluginPath.startsWith("@") && pluginPath.split("/").filter(Boolean).length > 2) {
|
|
780
|
+
const splits = pluginPath.split("/").filter(Boolean);
|
|
781
|
+
pluginPath = `${splits[0]}/${splits[1]}`;
|
|
782
|
+
}
|
|
783
|
+
const isInstalled = (0, _stryke_fs_package_fns.isPackageExists)(pluginPath, { paths: [this.context.workspaceConfig.workspaceRoot, this.context.config.root] });
|
|
784
|
+
if (!isInstalled && this.context.config.autoInstall) {
|
|
785
|
+
this.#context.warn(`The plugin package "${pluginPath}" is not installed. It will be installed automatically.`);
|
|
786
|
+
const result = await (0, _stryke_fs_install.install)(pluginPath, { cwd: this.context.config.root });
|
|
787
|
+
if ((0, _stryke_type_checks_is_number.isNumber)(result.exitCode) && result.exitCode > 0) {
|
|
788
|
+
this.#context.error(result.stderr);
|
|
789
|
+
throw new Error(`An error occurred while installing the build plugin package "${pluginPath}" `);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
try {
|
|
793
|
+
const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve((0, _stryke_path_join_paths.joinPaths)(pluginPath, "plugin")));
|
|
794
|
+
const result = module.plugin ?? module.default;
|
|
795
|
+
if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
|
|
796
|
+
return result;
|
|
797
|
+
} catch (error) {
|
|
798
|
+
try {
|
|
799
|
+
const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(pluginPath));
|
|
800
|
+
const result = module.plugin ?? module.default;
|
|
801
|
+
if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
|
|
802
|
+
return result;
|
|
803
|
+
} catch {
|
|
804
|
+
if (!isInstalled) throw new Error(`The plugin package "${pluginPath}" is not installed. Please install the package using the command: "npm install ${pluginPath} --save-dev"`);
|
|
805
|
+
else throw new Error(`An error occurred while importing the build plugin package "${pluginPath}":
|
|
806
|
+
${(0, _stryke_type_checks_is_error.isError)(error) ? error.message : String(error)}
|
|
807
|
+
|
|
808
|
+
Note: Please ensure the plugin package's default export is a class that extends \`Plugin\` with a constructor that excepts a single arguments of type \`PluginOptions\`.`);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Generate the Powerlines TypeScript declaration file
|
|
814
|
+
*
|
|
815
|
+
* @remarks
|
|
816
|
+
* This method will generate the TypeScript declaration file for the Powerlines project, including any types provided by plugins.
|
|
817
|
+
*
|
|
818
|
+
* @param context - The environment context to use for generating the TypeScript declaration file
|
|
819
|
+
* @returns A promise that resolves when the TypeScript declaration file has been generated
|
|
820
|
+
*/
|
|
821
|
+
async #types(context) {
|
|
822
|
+
context.debug(`Preparing the TypeScript definitions for the Powerlines project.`);
|
|
823
|
+
if (context.fs.existsSync(context.typesPath)) await context.fs.remove(context.typesPath);
|
|
824
|
+
if (!await (0, _stryke_fs_resolve.resolvePackage)("typescript")) throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
|
|
825
|
+
context.debug("Running TypeScript compiler for built-in runtime module files.");
|
|
826
|
+
let { code, directives } = await emitBuiltinTypes(context, (await context.getBuiltins()).reduce((ret, builtin) => {
|
|
827
|
+
const formatted = (0, _stryke_path_replace.replacePath)(builtin.path, context.workspaceConfig.workspaceRoot);
|
|
828
|
+
if (!ret.includes(formatted)) ret.push(formatted);
|
|
829
|
+
return ret;
|
|
830
|
+
}, []));
|
|
831
|
+
context.debug(`Generating TypeScript declaration file ${context.typesPath}.`);
|
|
832
|
+
const merge = async (currentResult, previousResult) => {
|
|
833
|
+
if (!(0, _stryke_type_checks_is_set_string.isSetString)(currentResult) && !(0, _stryke_type_checks_is_set_object.isSetObject)(currentResult) && !(0, _stryke_type_checks_is_set_string.isSetString)(previousResult) && !(0, _stryke_type_checks_is_set_object.isSetObject)(previousResult)) return {
|
|
834
|
+
code,
|
|
835
|
+
directives
|
|
836
|
+
};
|
|
837
|
+
const previous = (await (0, require_utils.utils_exports.format)(context, context.typesPath, (0, _stryke_type_checks_is_set_string.isSetString)(previousResult) ? previousResult : (0, _stryke_type_checks_is_set_object.isSetObject)(previousResult) ? previousResult.code : "")).trim().replace(code, "").trim();
|
|
838
|
+
const current = (await (0, require_utils.utils_exports.format)(context, context.typesPath, (0, _stryke_type_checks_is_set_string.isSetString)(currentResult) ? currentResult : (0, _stryke_type_checks_is_set_object.isSetObject)(currentResult) ? currentResult.code : "")).trim().replace(previous, "").trim().replace(code, "").trim();
|
|
839
|
+
return {
|
|
840
|
+
directives: [...(0, _stryke_type_checks_is_set_object.isSetObject)(currentResult) && currentResult.directives ? currentResult.directives : [], ...(0, _stryke_type_checks_is_set_object.isSetObject)(previousResult) && previousResult.directives ? previousResult.directives : []],
|
|
841
|
+
code: await (0, require_utils.utils_exports.format)(context, context.typesPath, `${!previous.includes((0, require_utils.utils_exports.getTypescriptFileHeader)(context)) && !current.includes((0, require_utils.utils_exports.getTypescriptFileHeader)(context)) ? `${code}\n` : ""}${previous}\n${current}`.trim())
|
|
842
|
+
};
|
|
843
|
+
};
|
|
844
|
+
const asNextParam = (previousResult) => (0, _stryke_type_checks_is_object.isObject)(previousResult) ? previousResult.code : previousResult;
|
|
845
|
+
let result = await this.callHook("types", {
|
|
846
|
+
environment: context,
|
|
847
|
+
sequential: true,
|
|
848
|
+
order: "pre",
|
|
849
|
+
result: "merge",
|
|
850
|
+
merge,
|
|
851
|
+
asNextParam
|
|
852
|
+
}, code);
|
|
853
|
+
if (result) {
|
|
854
|
+
if ((0, _stryke_type_checks_is_set_object.isSetObject)(result)) {
|
|
855
|
+
code = result.code;
|
|
856
|
+
if (Array.isArray(result.directives) && result.directives.length > 0) directives = (0, _stryke_helpers_get_unique.getUnique)([...directives, ...result.directives]).filter(Boolean);
|
|
857
|
+
} else if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) code = result;
|
|
858
|
+
}
|
|
859
|
+
result = await this.callHook("types", {
|
|
860
|
+
environment: context,
|
|
861
|
+
sequential: true,
|
|
862
|
+
order: "normal",
|
|
863
|
+
result: "merge",
|
|
864
|
+
merge,
|
|
865
|
+
asNextParam
|
|
866
|
+
}, code);
|
|
867
|
+
if (result) {
|
|
868
|
+
if ((0, _stryke_type_checks_is_set_object.isSetObject)(result)) {
|
|
869
|
+
code = result.code;
|
|
870
|
+
if (Array.isArray(result.directives) && result.directives.length > 0) directives = (0, _stryke_helpers_get_unique.getUnique)([...directives, ...result.directives]).filter(Boolean);
|
|
871
|
+
} else if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) code = result;
|
|
872
|
+
}
|
|
873
|
+
result = await this.callHook("types", {
|
|
874
|
+
environment: context,
|
|
875
|
+
sequential: true,
|
|
876
|
+
order: "post",
|
|
877
|
+
result: "merge",
|
|
878
|
+
merge,
|
|
879
|
+
asNextParam
|
|
880
|
+
}, code);
|
|
881
|
+
if (result) {
|
|
882
|
+
if ((0, _stryke_type_checks_is_set_object.isSetObject)(result)) {
|
|
883
|
+
code = result.code;
|
|
884
|
+
if (Array.isArray(result.directives) && result.directives.length > 0) directives = (0, _stryke_helpers_get_unique.getUnique)([...directives, ...result.directives]).filter(Boolean);
|
|
885
|
+
} else if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) code = result;
|
|
886
|
+
}
|
|
887
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(code?.trim()) || directives.length > 0) await context.fs.write(context.typesPath, `${directives.length > 0 ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
|
|
888
|
+
|
|
889
|
+
` : ""}${(0, require_utils.utils_exports.getTypescriptFileHeader)(context, {
|
|
890
|
+
directive: null,
|
|
891
|
+
prettierIgnore: false
|
|
892
|
+
})}
|
|
893
|
+
|
|
894
|
+
${formatTypes(code)}
|
|
895
|
+
`);
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
|
|
899
|
+
//#endregion
|
|
900
|
+
Object.defineProperty(exports, 'PowerlinesAPI', {
|
|
901
|
+
enumerable: true,
|
|
902
|
+
get: function () {
|
|
903
|
+
return PowerlinesAPI;
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
Object.defineProperty(exports, 'name', {
|
|
907
|
+
enumerable: true,
|
|
908
|
+
get: function () {
|
|
909
|
+
return name;
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
Object.defineProperty(exports, 'version', {
|
|
913
|
+
enumerable: true,
|
|
914
|
+
get: function () {
|
|
915
|
+
return version;
|
|
916
|
+
}
|
|
917
|
+
});
|