@powerlines/engine 0.0.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.
Files changed (70) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +303 -0
  3. package/dist/_internal/worker.cjs +4824 -0
  4. package/dist/_internal/worker.d.cts +38 -0
  5. package/dist/_internal/worker.d.cts.map +1 -0
  6. package/dist/_internal/worker.d.mts +38 -0
  7. package/dist/_internal/worker.d.mts.map +1 -0
  8. package/dist/_internal/worker.mjs +4785 -0
  9. package/dist/_internal/worker.mjs.map +1 -0
  10. package/dist/api.cjs +1265 -0
  11. package/dist/api.d.cts +265 -0
  12. package/dist/api.d.cts.map +1 -0
  13. package/dist/api.d.mts +265 -0
  14. package/dist/api.d.mts.map +1 -0
  15. package/dist/api.mjs +1261 -0
  16. package/dist/api.mjs.map +1 -0
  17. package/dist/base-context-BUnL_9z8.mjs +241 -0
  18. package/dist/base-context-BUnL_9z8.mjs.map +1 -0
  19. package/dist/base-context-CFvO2N9I.cjs +248 -0
  20. package/dist/chunk-C0xms8kb.cjs +34 -0
  21. package/dist/context/index.cjs +11 -0
  22. package/dist/context/index.d.cts +658 -0
  23. package/dist/context/index.d.cts.map +1 -0
  24. package/dist/context/index.d.mts +658 -0
  25. package/dist/context/index.d.mts.map +1 -0
  26. package/dist/context/index.mjs +5 -0
  27. package/dist/engine-context-BuD9AGfd.mjs +41 -0
  28. package/dist/engine-context-BuD9AGfd.mjs.map +1 -0
  29. package/dist/engine-context-NO6enYev.cjs +45 -0
  30. package/dist/execution-context-BxANz9k2.cjs +2600 -0
  31. package/dist/execution-context-CNhvjS52.mjs +2556 -0
  32. package/dist/execution-context-CNhvjS52.mjs.map +1 -0
  33. package/dist/fs-D1nIP45P.mjs +226 -0
  34. package/dist/fs-D1nIP45P.mjs.map +1 -0
  35. package/dist/fs-XogSgMqT.cjs +262 -0
  36. package/dist/index.cjs +569 -0
  37. package/dist/index.d.cts +126 -0
  38. package/dist/index.d.cts.map +1 -0
  39. package/dist/index.d.mts +126 -0
  40. package/dist/index.d.mts.map +1 -0
  41. package/dist/index.mjs +568 -0
  42. package/dist/index.mjs.map +1 -0
  43. package/dist/schemas.cjs +9 -0
  44. package/dist/schemas.d.cts +127 -0
  45. package/dist/schemas.d.cts.map +1 -0
  46. package/dist/schemas.d.mts +127 -0
  47. package/dist/schemas.d.mts.map +1 -0
  48. package/dist/schemas.mjs +3 -0
  49. package/dist/storage/index.cjs +9 -0
  50. package/dist/storage/index.d.cts +419 -0
  51. package/dist/storage/index.d.cts.map +1 -0
  52. package/dist/storage/index.d.mts +419 -0
  53. package/dist/storage/index.d.mts.map +1 -0
  54. package/dist/storage/index.mjs +3 -0
  55. package/dist/ts-morph-BaLPVAdB.cjs +114 -0
  56. package/dist/ts-morph-D0CaA37w.mjs +102 -0
  57. package/dist/ts-morph-D0CaA37w.mjs.map +1 -0
  58. package/dist/tsconfig-Cstsoprg.mjs +155 -0
  59. package/dist/tsconfig-Cstsoprg.mjs.map +1 -0
  60. package/dist/tsconfig-DeyWQC2N.cjs +198 -0
  61. package/dist/typescript/index.cjs +13 -0
  62. package/dist/typescript/index.d.cts +106 -0
  63. package/dist/typescript/index.d.cts.map +1 -0
  64. package/dist/typescript/index.d.mts +106 -0
  65. package/dist/typescript/index.d.mts.map +1 -0
  66. package/dist/typescript/index.mjs +4 -0
  67. package/dist/virtual-BNdKVkRw.cjs +548 -0
  68. package/dist/virtual-gIlTc3Lj.mjs +513 -0
  69. package/dist/virtual-gIlTc3Lj.mjs.map +1 -0
  70. package/package.json +183 -0
package/dist/api.cjs ADDED
@@ -0,0 +1,1265 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_chunk = require('./chunk-C0xms8kb.cjs');
3
+ const require_execution_context = require('./execution-context-BxANz9k2.cjs');
4
+ const require_tsconfig = require('./tsconfig-DeyWQC2N.cjs');
5
+ const require_ts_morph = require('./ts-morph-BaLPVAdB.cjs');
6
+ let _stryke_fs_resolve = require("@stryke/fs/resolve");
7
+ let _stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
8
+ let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
9
+ let _powerlines_core_lib_logger = require("@powerlines/core/lib/logger");
10
+ let _stryke_json_storm_json = require("@stryke/json/storm-json");
11
+ let chalk = require("chalk");
12
+ chalk = require_chunk.__toESM(chalk, 1);
13
+ let defu = require("defu");
14
+ defu = require_chunk.__toESM(defu, 1);
15
+ let _stryke_path_join_paths = require("@stryke/path/join-paths");
16
+ let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
17
+ let _powerlines_core_lib_utilities_file_header = require("@powerlines/core/lib/utilities/file-header");
18
+ let _powerlines_core_lib_utilities_format = require("@powerlines/core/lib/utilities/format");
19
+ let _powerlines_core_plugin_utils = require("@powerlines/core/plugin-utils");
20
+ let _storm_software_config_tools_logger_console = require("@storm-software/config-tools/logger/console");
21
+ let _stryke_convert_to_array = require("@stryke/convert/to-array");
22
+ let _stryke_fs_copy_file = require("@stryke/fs/copy-file");
23
+ let _stryke_fs_exists = require("@stryke/fs/exists");
24
+ let _stryke_fs_helpers = require("@stryke/fs/helpers");
25
+ let _stryke_fs_install = require("@stryke/fs/install");
26
+ let _stryke_fs_list_files = require("@stryke/fs/list-files");
27
+ let _stryke_fs_package_fns = require("@stryke/fs/package-fns");
28
+ let _stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
29
+ let _stryke_helpers_omit = require("@stryke/helpers/omit");
30
+ let _stryke_path_append = require("@stryke/path/append");
31
+ let _stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
32
+ let _stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
33
+ let _stryke_path_replace = require("@stryke/path/replace");
34
+ let _stryke_type_checks_is_error = require("@stryke/type-checks/is-error");
35
+ let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
36
+ let _stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
37
+ let _stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
38
+ let _stryke_type_checks_is_promise = require("@stryke/type-checks/is-promise");
39
+ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
40
+ let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
41
+ let handlebars = require("handlebars");
42
+ handlebars = require_chunk.__toESM(handlebars, 1);
43
+ let _stryke_fs_json = require("@stryke/fs/json");
44
+ let _stryke_string_format_pretty_bytes = require("@stryke/string-format/pretty-bytes");
45
+ let ts_morph = require("ts-morph");
46
+ let _stryke_string_format_package = require("@stryke/string-format/package");
47
+ let _donedeal0_superdiff = require("@donedeal0/superdiff");
48
+
49
+ //#region src/_internal/helpers/generate-types.ts
50
+ /**
51
+ * Formats the generated TypeScript types source code.
52
+ *
53
+ * @param code - The generated TypeScript code.
54
+ * @returns The formatted TypeScript code.
55
+ */
56
+ function formatTypes(code = "") {
57
+ return code.replaceAll("#private;", "").replace(/__ฮฉ/g, "");
58
+ }
59
+ async function extractModuleDeclarations(ctx, filePath, name, text) {
60
+ const imports = [];
61
+ const exports = [];
62
+ const comment = text.match(new RegExp(`\\/\\*\\*(?s:.)*?@module\\s+${ctx.context.config.framework}:${name}(?s:.)*?\\*\\/\\s+`))?.find((comment) => (0, _stryke_type_checks_is_set_string.isSetString)(comment?.trim()));
63
+ const sourceFile = new ts_morph.Project({ useInMemoryFileSystem: true }).createSourceFile("module.d.ts", text);
64
+ for (const ref of sourceFile.getTypeReferenceDirectives()) if (ref.getFileName() && !ctx.context.builtins.some((builtin) => ref.getFileName().endsWith(builtin))) imports.push({
65
+ name: ref.getFileName(),
66
+ ambient: true
67
+ });
68
+ for (const statement of sourceFile.getStatements()) if (ts_morph.Node.isImportDeclaration(statement)) {
69
+ const moduleSpec = statement.getModuleSpecifierValue();
70
+ if (statement.getNamespaceImport()) imports.push({
71
+ name: moduleSpec,
72
+ specifiers: [{ name: statement.getNamespaceImport().getText() }],
73
+ all: true
74
+ });
75
+ else if (statement.getNamedImports().length > 0 || statement.getDefaultImport()) {
76
+ const specifiers = [];
77
+ if (statement.getDefaultImport()) specifiers.push({
78
+ name: statement.getDefaultImport().getText(),
79
+ default: true,
80
+ type: statement.isTypeOnly()
81
+ });
82
+ statement.getNamedImports().forEach((named) => {
83
+ specifiers.push({
84
+ name: named.getName(),
85
+ alias: named.getAliasNode()?.getText(),
86
+ type: statement.isTypeOnly()
87
+ });
88
+ });
89
+ imports.push({
90
+ name: moduleSpec,
91
+ specifiers
92
+ });
93
+ }
94
+ } else if (ts_morph.Node.isExportDeclaration(statement)) {
95
+ const moduleSpec = statement.getModuleSpecifierValue();
96
+ if (moduleSpec) {
97
+ let resolvedSpec = moduleSpec;
98
+ if (!ctx.context.builtins.includes(moduleSpec)) if (ctx.emitted.has(moduleSpec)) resolvedSpec = ctx.emitted.get(moduleSpec);
99
+ else {
100
+ const resolvedModule = await ctx.context.resolve(moduleSpec, filePath);
101
+ if ((0, _stryke_type_checks_is_set_string.isSetString)(resolvedModule?.id)) resolvedSpec = resolvedModule.id;
102
+ }
103
+ const namedExports = statement.getNamedExports();
104
+ if (namedExports.length > 0) exports.push({
105
+ name: resolvedSpec,
106
+ text: statement.getText(),
107
+ fullText: statement.getFullText(),
108
+ specifiers: namedExports.map((named) => ({
109
+ name: named.getName(),
110
+ alias: named.getAliasNode()?.getText(),
111
+ type: statement.isTypeOnly()
112
+ })),
113
+ comment: statement.getLeadingCommentRanges().filter((c) => (0, _stryke_type_checks_is_set_string.isSetString)(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n").trim()
114
+ });
115
+ else exports.push({
116
+ name: resolvedSpec,
117
+ text: statement.getText(),
118
+ fullText: statement.getFullText(),
119
+ all: true,
120
+ comment: statement.getLeadingCommentRanges().filter((c) => (0, _stryke_type_checks_is_set_string.isSetString)(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n").trim()
121
+ });
122
+ } else {
123
+ const specifiers = statement.getNamedExports().map((named) => ({
124
+ name: named.getName(),
125
+ alias: named.getAliasNode()?.getText(),
126
+ type: statement.isTypeOnly()
127
+ }));
128
+ if (specifiers.length > 0) exports.push({
129
+ text: statement.getText(),
130
+ fullText: statement.getFullText(),
131
+ specifiers,
132
+ comment: statement.getLeadingCommentRanges().filter((c) => (0, _stryke_type_checks_is_set_string.isSetString)(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
133
+ });
134
+ }
135
+ } else if (ts_morph.Node.isExportAssignment(statement)) exports.push({
136
+ text: statement.getText(),
137
+ fullText: statement.getFullText(),
138
+ comment: statement.getLeadingCommentRanges().filter((c) => (0, _stryke_type_checks_is_set_string.isSetString)(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
139
+ });
140
+ else if (ts_morph.Node.isFunctionDeclaration(statement) && statement.isExported() && statement.getNameNode()) exports.push({
141
+ text: statement.getText(),
142
+ fullText: statement.getFullText(),
143
+ specifiers: [{ name: statement.getNameNode().getText() }],
144
+ comment: statement.getLeadingCommentRanges().filter((c) => (0, _stryke_type_checks_is_set_string.isSetString)(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
145
+ });
146
+ else if (ts_morph.Node.isVariableStatement(statement) && statement.isExported()) exports.push({
147
+ text: statement.getText(),
148
+ fullText: statement.getFullText(),
149
+ specifiers: statement.getDeclarationList().getDeclarations().filter((decl) => decl.getNameNode() && ts_morph.Node.isIdentifier(decl.getNameNode())).map((decl) => ({ name: decl.getNameNode().getText() })),
150
+ comment: statement.getLeadingCommentRanges().filter((c) => (0, _stryke_type_checks_is_set_string.isSetString)(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
151
+ });
152
+ else if (ts_morph.Node.isClassDeclaration(statement) && statement.isExported()) {
153
+ const nameNode = statement.getNameNode();
154
+ exports.push({
155
+ text: statement.getText(),
156
+ fullText: statement.getFullText(),
157
+ specifiers: nameNode ? [{ name: nameNode.getText() }] : void 0,
158
+ comment: statement.getLeadingCommentRanges().filter((c) => (0, _stryke_type_checks_is_set_string.isSetString)(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
159
+ });
160
+ } else if (ts_morph.Node.isInterfaceDeclaration(statement) && statement.isExported()) {
161
+ const nameNode = statement.getNameNode();
162
+ exports.push({
163
+ text: statement.getText(),
164
+ fullText: statement.getFullText(),
165
+ specifiers: nameNode ? [{ name: nameNode.getText() }] : void 0,
166
+ comment: statement.getLeadingCommentRanges().filter((c) => (0, _stryke_type_checks_is_set_string.isSetString)(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
167
+ });
168
+ } else if (ts_morph.Node.isTypeAliasDeclaration(statement) && statement.isExported()) {
169
+ const nameNode = statement.getNameNode();
170
+ exports.push({
171
+ text: statement.getText(),
172
+ fullText: statement.getFullText(),
173
+ specifiers: nameNode ? [{ name: nameNode.getText() }] : void 0,
174
+ comment: statement.getLeadingCommentRanges().filter((c) => (0, _stryke_type_checks_is_set_string.isSetString)(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
175
+ });
176
+ } else if (ctx.context.config.output.sourceMap || !statement.getFullText().includes("//# sourceMappingURL=")) exports.push({
177
+ text: statement.getText(),
178
+ fullText: statement.getFullText(),
179
+ comment: statement.getLeadingCommentRanges().filter((c) => (0, _stryke_type_checks_is_set_string.isSetString)(c.getText().trim()) && !c.getText().includes("@module")).map((c) => c.getText().trim()).join("\n")
180
+ });
181
+ return {
182
+ name,
183
+ text,
184
+ sourceFile,
185
+ comment,
186
+ imports,
187
+ exports
188
+ };
189
+ }
190
+ /**
191
+ * Emits TypeScript declaration types for the provided files using the given TypeScript configuration.
192
+ *
193
+ * @param context - The context containing options and environment paths.
194
+ * @param files - The list of files to generate types for.
195
+ * @returns A promise that resolves to the generated TypeScript declaration types.
196
+ */
197
+ async function emitBuiltinTypes(context, files) {
198
+ if (files.length === 0) {
199
+ context.debug("No files provided for TypeScript types generation. Typescript compilation for built-in modules will be skipped.");
200
+ return {
201
+ code: "",
202
+ directives: []
203
+ };
204
+ }
205
+ context.debug(`Running the TypeScript compiler for ${files.length} generated built-in module files.`);
206
+ const program = require_ts_morph.createProgram(context, {
207
+ skipAddingFilesFromTsConfig: true,
208
+ compilerOptions: {
209
+ declaration: true,
210
+ declarationMap: false,
211
+ emitDeclarationOnly: true,
212
+ sourceMap: false,
213
+ outDir: (0, _stryke_path_replace.replacePath)(context.builtinsPath, context.config.cwd),
214
+ composite: false,
215
+ incremental: false,
216
+ tsBuildInfoFile: void 0
217
+ }
218
+ });
219
+ program.addSourceFilesAtPaths(files);
220
+ const emitResult = program.emitToMemory({ emitOnlyDtsFiles: true });
221
+ const diagnostics = emitResult.getDiagnostics();
222
+ 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")}`);
223
+ 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")}`);
224
+ 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")}`);
225
+ const emittedFiles = emitResult.getFiles();
226
+ context.debug(`The TypeScript compiler emitted ${emittedFiles.length} files for built-in types.`);
227
+ if (emittedFiles.length === 0) {
228
+ 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.");
229
+ return {
230
+ code: "",
231
+ directives: []
232
+ };
233
+ }
234
+ const ctx = {
235
+ context,
236
+ modules: [],
237
+ emitted: /* @__PURE__ */ new Map()
238
+ };
239
+ await Promise.all(emittedFiles.map(async (emittedFile) => {
240
+ const filePath = (0, _stryke_path_append.appendPath)(emittedFile.filePath, context.config.cwd);
241
+ if (!filePath.endsWith(".map") && (0, _stryke_path_file_path_fns.findFileName)(filePath) !== "tsconfig.tsbuildinfo" && (0, _stryke_path_is_parent_path.isParentPath)(filePath, context.builtinsPath)) {
242
+ const moduleName = (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.config.cwd)), "", { fullExtension: true });
243
+ if (context.builtins.includes(moduleName)) {
244
+ ctx.emitted.set(filePath, moduleName);
245
+ ctx.modules.push(await extractModuleDeclarations(ctx, filePath, moduleName, emittedFile.text));
246
+ }
247
+ }
248
+ }));
249
+ const commonDeclarations = [];
250
+ for (const mod of ctx.modules) for (const importRef of mod.imports.filter((importRef) => context.builtins.some((builtin) => importRef.name.endsWith(`:${builtin}`)))) {
251
+ const moduleRef = ctx.modules.find((moduleRef) => importRef.name.endsWith(`:${moduleRef.name}`));
252
+ if (moduleRef) {
253
+ let declaration;
254
+ for (const decl of moduleRef.exports.filter((decl) => (0, _stryke_type_checks_is_set_object.isSetObject)(decl))) {
255
+ const specifiers = decl.specifiers?.filter((specifier) => importRef.specifiers?.some((s) => (specifier.alias ? specifier.alias : specifier.name) === (s.alias ? s.alias : s.name)));
256
+ if (specifiers && specifiers.length > 0) {
257
+ importRef.specifiers = importRef.specifiers?.filter((s) => !specifiers.some((specifier) => (specifier.alias ? specifier.alias : specifier.name) === (s.alias ? s.alias : s.name)));
258
+ if (importRef.specifiers && importRef.specifiers.length === 0 && !importRef.all && !importRef.ambient) mod.imports = mod.imports.filter((imp) => imp.name !== importRef.name);
259
+ declaration = decl;
260
+ break;
261
+ }
262
+ }
263
+ if (declaration) {
264
+ for (const decl of moduleRef.exports.filter((decl) => (0, _stryke_type_checks_is_set_object.isSetObject)(decl) && !decl.specifiers?.some((s) => declaration?.specifiers?.some((specifier) => (specifier.alias ? specifier.alias : specifier.name) === (s.alias ? s.alias : s.name))))) {
265
+ const exportModuleRef = decl;
266
+ if ((exportModuleRef.specifiers?.some((s) => s.alias || s.name) || exportModuleRef.name) && new RegExp(`(^|\\s|\\n|\\r\\n|\\(|\\)|<|>|{|}|\\[|\\]|\\!|\\?|\\.|,|\\*|&|:)(${exportModuleRef.specifiers?.map((s) => `${s.alias ? `${s.alias}|` : ""}${s.name}`).join("|") || exportModuleRef.name})($|\\s|\\n|\\r\\n|\\(|\\)|<|>|{|}|\\[|\\]|\\!|\\?|\\.|,|\\*|&|:|;)`).test(declaration.text)) commonDeclarations.push(exportModuleRef);
267
+ }
268
+ commonDeclarations.push(declaration);
269
+ }
270
+ }
271
+ }
272
+ let code = "";
273
+ const directives = [];
274
+ for (const commonDeclaration of commonDeclarations) {
275
+ code += formatTypes(`${commonDeclaration.comment?.trim() ? commonDeclaration.comment.trim() : ""}${commonDeclaration.comment?.trim() ? "\n" : ""}${formatTypes(commonDeclaration.text.replace(/\s*export\s*/, "").replace(/\s*declare\s*interface\s*/, "interface ").replace(/\s*declare\s*type\s*/, "type "))}`);
276
+ code += "\n\n";
277
+ }
278
+ for (const mod of ctx.modules) {
279
+ code += mod.comment ? `${mod.comment.trim()}\n` : "";
280
+ code += `declare module "${context.config.framework}:${mod.name}" { \n`;
281
+ for (const importRef of mod.imports) if (importRef.ambient) code += directives.push(importRef.name);
282
+ else if (importRef.all) code += `\timport * as ${(0, _stryke_path_file_path_fns.findFileName)(importRef.name)} from "${importRef.name}";\n`;
283
+ else if (importRef.specifiers) {
284
+ const typeOnly = importRef.specifiers.every((s) => s.type) ? " type" : "";
285
+ const specifiers = importRef.specifiers.map((s) => s.alias ? `${s.name} as ${s.alias}` : s.name).join(", ");
286
+ code += `\timport${typeOnly} { ${specifiers} } from "${importRef.name}";\n`;
287
+ }
288
+ if (mod.imports.length > 0) code += "\n";
289
+ for (const exportRef of mod.exports.filter((e) => (0, _stryke_type_checks_is_string.isString)(e) || !e.specifiers || !commonDeclarations.some((commonDecl) => commonDecl.specifiers && commonDecl.specifiers.some((specifier) => e.specifiers?.some((s) => (s.alias ? s.alias : s.name) === (specifier.alias ? specifier.alias : specifier.name)))))) if ((0, _stryke_type_checks_is_set_string.isSetString)(exportRef)) code += `${exportRef}\n`;
290
+ else if (exportRef.name) {
291
+ if (exportRef.all) code += `${exportRef.comment?.trim() ? exportRef.comment.trim() : ""}${exportRef.comment?.trim() ? "\n" : ""}export * from "${exportRef.name}";\n`;
292
+ else if (exportRef.specifiers) {
293
+ if (exportRef.comment?.trim()) code += `${exportRef.comment.trim()}\n`;
294
+ code += `\texport${exportRef.specifiers.every((s) => s.type) ? " type" : ""} { ${exportRef.specifiers.map((s) => s.alias ? `${s.name} as ${s.alias}` : s.name).join(", ")} } from "${exportRef.name}";\n`;
295
+ }
296
+ } else code += `${exportRef.comment?.trim() ? exportRef.comment.trim() : ""}${exportRef.comment?.trim() ? "\n" : ""}${formatTypes(exportRef.text.replace(/\s*export\s*declare\s*/, "export ").replace(/\s*declare\s*/, " "))}\n`;
297
+ mod.exports.filter((e) => !(0, _stryke_type_checks_is_string.isString)(e) && e.specifiers && commonDeclarations.some((commonDeclaration) => commonDeclaration.specifiers && commonDeclaration.specifiers.some((specifier) => e.specifiers?.some((s) => (s.alias ? s.alias : s.name) === (specifier.alias ? specifier.alias : specifier.name))))).forEach((e, i, arr) => {
298
+ if (i === 0) code += "\nexport { ";
299
+ else code += ", ";
300
+ code += `${e?.specifiers?.filter((s) => commonDeclarations.some((commonDeclaration) => commonDeclaration.specifiers && commonDeclaration.specifiers.some((specifier) => (s.alias ? s.alias : s.name) === (specifier.alias ? specifier.alias : specifier.name)))).map((s) => s.alias ? `${s.name} as ${s.alias}` : s.name).join(", ") || ""}`;
301
+ if (i === arr.length - 1) code += ` };\n`;
302
+ });
303
+ code += "}";
304
+ code += "\n\n";
305
+ }
306
+ code = await (0, _powerlines_core_lib_utilities_format.format)(context, context.typesPath, code);
307
+ context.debug(`A TypeScript declaration file (size: ${(0, _stryke_string_format_pretty_bytes.prettyBytes)(new Blob((0, _stryke_convert_to_array.toArray)(code)).size)}) emitted for the built-in modules types.`);
308
+ return {
309
+ code,
310
+ directives
311
+ };
312
+ }
313
+
314
+ //#endregion
315
+ //#region src/_internal/helpers/install.ts
316
+ /**
317
+ * Installs a package if it is not already installed.
318
+ *
319
+ * @param context - The resolved options
320
+ * @param packageName - The name of the package to install
321
+ * @param dev - Whether to install the package as a dev dependency
322
+ */
323
+ async function installPackage(context, packageName, dev = false) {
324
+ if (!await (0, _stryke_fs_package_fns.isPackageListed)((0, _stryke_string_format_package.getPackageName)(packageName), { cwd: context.config.root })) if (context.config.autoInstall) {
325
+ context.warn(`The package "${packageName}" is not installed. It will be installed automatically.`);
326
+ const result = await (0, _stryke_fs_install.install)(packageName, {
327
+ cwd: context.config.root,
328
+ dev
329
+ });
330
+ if ((0, _stryke_type_checks_is_number.isNumber)(result.exitCode) && result.exitCode > 0) {
331
+ context.error(result.stderr);
332
+ throw new Error(`An error occurred while installing the package "${packageName}"`);
333
+ }
334
+ } else context.warn(`The package "${packageName}" is not installed. Since the "autoInstall" option is set to false, it will not be installed automatically.`);
335
+ else if ((0, _stryke_string_format_package.hasPackageVersion)(packageName) && !process.env.POWERLINES_SKIP_VERSION_CHECK) {
336
+ 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)) {
337
+ const packageListing = await (0, _stryke_fs_package_fns.getPackageListing)((0, _stryke_string_format_package.getPackageName)(packageName), { cwd: context.config.root });
338
+ 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.`);
339
+ }
340
+ }
341
+ }
342
+
343
+ //#endregion
344
+ //#region src/_internal/helpers/install-dependencies.ts
345
+ /**
346
+ * Install missing project dependencies.
347
+ *
348
+ * @param context - The build context.
349
+ */
350
+ async function installDependencies(context) {
351
+ context.debug(`Checking and installing missing project dependencies.`);
352
+ context.dependencies ??= {};
353
+ context.devDependencies ??= {};
354
+ if (Object.keys(context.dependencies).length === 0 && Object.keys(context.devDependencies).length === 0) {
355
+ context.debug(`No dependencies or devDependencies to install. Skipping installation step.`);
356
+ return;
357
+ }
358
+ 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")}`);
359
+ 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)))]);
360
+ }
361
+
362
+ //#endregion
363
+ //#region src/_internal/helpers/resolve-tsconfig.ts
364
+ function getTsconfigDtsPath(context) {
365
+ return (0, _stryke_path_join_paths.joinPaths)((0, _stryke_path_file_path_fns.relativePath)((0, _stryke_path_join_paths.joinPaths)(context.config.cwd, context.config.root), (0, _stryke_path_file_path_fns.findFilePath)(context.typesPath)), (0, _stryke_path_file_path_fns.findFileName)(context.typesPath));
366
+ }
367
+ async function resolveTsconfigChanges(context) {
368
+ const tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.config.cwd, context.config.root, context.config.tsconfig, context.config.tsconfigRaw);
369
+ const tsconfigJson = await (0, _stryke_fs_json.readJsonFile)(require_tsconfig.getTsconfigFilePath(context.config.cwd, context.config.root, context.config.tsconfig));
370
+ tsconfigJson.compilerOptions ??= {};
371
+ if (context.config.output.dts !== false) {
372
+ const dtsRelativePath = getTsconfigDtsPath(context);
373
+ if (!tsconfigJson.include?.some((filePattern) => require_tsconfig.isIncludeMatchFound(filePattern, [context.typesPath, dtsRelativePath]))) {
374
+ tsconfigJson.include ??= [];
375
+ tsconfigJson.include.push(dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath);
376
+ }
377
+ }
378
+ if (!tsconfig.options.lib?.some((lib) => [
379
+ "lib.esnext.d.ts",
380
+ "lib.es2021.d.ts",
381
+ "lib.es2022.d.ts",
382
+ "lib.es2023.d.ts"
383
+ ].includes(lib.toLowerCase()))) {
384
+ tsconfigJson.compilerOptions.lib ??= [];
385
+ tsconfigJson.compilerOptions.lib.push("esnext");
386
+ }
387
+ if (tsconfig.options.esModuleInterop !== true) tsconfigJson.compilerOptions.esModuleInterop = true;
388
+ if (tsconfig.options.isolatedModules !== true) tsconfigJson.compilerOptions.isolatedModules = true;
389
+ if (context.config.platform === "node") {
390
+ if (!tsconfig.options.types?.some((type) => type.toLowerCase() === "node" || type.toLowerCase() === "@types/node")) {
391
+ tsconfigJson.compilerOptions.types ??= [];
392
+ tsconfigJson.compilerOptions.types.push("node");
393
+ }
394
+ }
395
+ return tsconfigJson;
396
+ }
397
+ async function initializeTsconfig(context) {
398
+ context.debug("Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.");
399
+ 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\"");
400
+ const tsconfigFilePath = require_tsconfig.getTsconfigFilePath(context.config.cwd, context.config.root, context.config.tsconfig);
401
+ context.tsconfig.originalTsconfigJson = await (0, _stryke_fs_json.readJsonFile)(tsconfigFilePath);
402
+ context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
403
+ context.debug("Writing updated TypeScript configuration (tsconfig.json) file to disk.");
404
+ await context.fs.write(tsconfigFilePath, _stryke_json_storm_json.StormJSON.stringify(context.tsconfig.tsconfigJson));
405
+ context.tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.config.cwd, context.config.root, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
406
+ }
407
+ async function resolveTsconfig(context) {
408
+ const updateTsconfigJson = await (0, _stryke_fs_json.readJsonFile)(context.tsconfig.tsconfigFilePath);
409
+ if (updateTsconfigJson?.compilerOptions?.types && Array.isArray(updateTsconfigJson.compilerOptions.types) && !updateTsconfigJson.compilerOptions.types.length) delete updateTsconfigJson.compilerOptions.types;
410
+ const result = (0, _donedeal0_superdiff.getObjectDiff)(context.tsconfig.originalTsconfigJson, updateTsconfigJson, {
411
+ ignoreArrayOrder: true,
412
+ showOnly: {
413
+ statuses: [
414
+ "added",
415
+ "deleted",
416
+ "updated"
417
+ ],
418
+ granularity: "deep"
419
+ }
420
+ });
421
+ const changes = [];
422
+ const getChanges = (difference, property) => {
423
+ 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);
424
+ else changes.push({
425
+ field: property ? `${property}.${difference.property}` : difference.property,
426
+ status: difference.status,
427
+ previous: difference.status === "added" ? "---" : _stryke_json_storm_json.StormJSON.stringify(difference.previousValue),
428
+ current: difference.status === "deleted" ? "---" : _stryke_json_storm_json.StormJSON.stringify(difference.currentValue)
429
+ });
430
+ };
431
+ for (const diff of result.diff) getChanges(diff);
432
+ if (changes.length > 0) context.warn(`Updating the following configuration values in "${context.tsconfig.tsconfigFilePath}" file:
433
+
434
+ ${changes.map((change, i) => `${chalk.default.bold.whiteBright(`${i + 1}. ${(0, _stryke_string_format_title_case.titleCase)(change.status)} the ${change.field} field: `)}
435
+ ${chalk.default.red(` - Previous: ${change.previous} `)}
436
+ ${chalk.default.green(` - Updated: ${change.current} `)}
437
+ `).join("\n")}
438
+ `);
439
+ await context.fs.write(context.tsconfig.tsconfigFilePath, _stryke_json_storm_json.StormJSON.stringify(updateTsconfigJson));
440
+ context.tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.config.cwd, context.config.root, context.config.tsconfig);
441
+ if (!context.tsconfig) throw new Error("Failed to parse the TypeScript configuration file.");
442
+ }
443
+
444
+ //#endregion
445
+ //#region src/_internal/execution.ts
446
+ /**
447
+ * The Powerlines Execution API class
448
+ *
449
+ * @remarks
450
+ * This class is responsible for managing the Powerlines project lifecycle, including initialization, building, and finalization.
451
+ *
452
+ * @internal
453
+ */
454
+ var PowerlinesExecution = class PowerlinesExecution {
455
+ /**
456
+ * The Powerlines context
457
+ */
458
+ #context;
459
+ async #handleBuild(context) {
460
+ await this.callHook("build", {
461
+ environment: context,
462
+ order: "pre"
463
+ });
464
+ context.debug("Formatting the generated entry files before the build process starts.");
465
+ await (0, _powerlines_core_lib_utilities_format.formatFolder)(context, context.entryPath);
466
+ await this.callHook("build", {
467
+ environment: context,
468
+ order: "normal"
469
+ });
470
+ if (context.config.output.copy) {
471
+ context.debug("Copying project's files from build output directory.");
472
+ const destinationPath = (0, _stryke_path_is_parent_path.isParentPath)((0, _stryke_path_append.appendPath)(context.config.output.path, context.config.cwd), (0, _stryke_path_append.appendPath)(context.config.root, context.config.cwd)) ? (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.config.cwd), (0, _stryke_path_append.appendPath)(context.config.output.path, context.config.cwd))) : (0, _stryke_path_join_paths.joinPaths)(context.config.output.copy.path, "dist");
473
+ const sourcePath = context.config.output.path;
474
+ if ((0, _stryke_fs_exists.existsSync)(sourcePath) && sourcePath !== destinationPath) {
475
+ context.debug(`Copying files from project's build output directory (${context.config.output.path}) to the project's copy/publish directory (${destinationPath}).`);
476
+ await (0, _stryke_fs_copy_file.copyFiles)(sourcePath, destinationPath);
477
+ } 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.`);
478
+ if (context.config.output.copy.assets && Array.isArray(context.config.output.copy.assets)) await Promise.all(context.config.output.copy.assets.map(async (asset) => {
479
+ context.trace(`Copying asset(s): ${chalk.default.redBright(context.config.cwd === asset.input ? asset.glob : (0, _stryke_path_append.appendPath)(asset.glob, (0, _stryke_path_replace.replacePath)(asset.input, context.config.cwd)))} -> ${chalk.default.greenBright((0, _stryke_path_append.appendPath)(asset.glob, (0, _stryke_path_replace.replacePath)(asset.output, context.config.cwd)))} ${Array.isArray(asset.ignore) && asset.ignore.length > 0 ? ` (ignoring: ${asset.ignore.map((i) => chalk.default.yellowBright(i)).join(", ")})` : ""}`);
480
+ await context.fs.copy(asset, asset.output);
481
+ }));
482
+ } else context.debug("No copy configuration found for the project output. Skipping the copying of build output files.");
483
+ await this.callHook("build", {
484
+ environment: context,
485
+ order: "post"
486
+ });
487
+ }
488
+ /**
489
+ * Get the configured environments
490
+ *
491
+ * @returns The configured environments
492
+ */
493
+ async #getEnvironments() {
494
+ if (!this.context.config.environments || Object.keys(this.context.config.environments).length <= 1) {
495
+ this.context.debug("No environments are configured for this Powerlines project. Using the default environment.");
496
+ return [await this.context.getEnvironment()];
497
+ }
498
+ this.context.debug(`Found ${Object.keys(this.context.config.environments).length} configured environment(s) for this Powerlines project.`);
499
+ return (await Promise.all(Object.entries(this.context.config.environments).map(async ([name, config]) => {
500
+ if (!await this.context.getEnvironmentSafe(name)) {
501
+ const resolvedEnvironment = await this.callHook("configEnvironment", { environment: name }, name, config);
502
+ if (resolvedEnvironment) this.context.environments[name] = await this.context.in(resolvedEnvironment);
503
+ }
504
+ return this.context.environments[name];
505
+ }))).filter((context) => (0, _stryke_type_checks_is_set.isSet)(context));
506
+ }
507
+ /**
508
+ * Execute a handler function for each environment
509
+ *
510
+ * @param handle - The handler function to execute for each environment
511
+ */
512
+ async #executeEnvironments(handle) {
513
+ await Promise.all((await this.#getEnvironments()).map(async (context) => {
514
+ return Promise.resolve(handle(context));
515
+ }));
516
+ }
517
+ /**
518
+ * Initialize a Powerlines plugin
519
+ *
520
+ * @param config - The configuration for the plugin
521
+ * @returns The initialized plugin instance, or null if the plugin was a duplicate
522
+ * @throws Will throw an error if the plugin cannot be found or is invalid
523
+ */
524
+ async #initPlugin(config) {
525
+ let awaited = config;
526
+ if ((0, _stryke_type_checks_is_promise.isPromiseLike)(config)) awaited = await Promise.resolve(config);
527
+ if (!(0, _powerlines_core_plugin_utils.isPluginConfig)(awaited)) {
528
+ const invalid = (0, _powerlines_core_plugin_utils.findInvalidPluginConfig)(awaited);
529
+ 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`);
530
+ }
531
+ let plugins;
532
+ if ((0, _powerlines_core_plugin_utils.isPlugin)(awaited)) plugins = [awaited];
533
+ else if ((0, _stryke_type_checks_is_function.isFunction)(awaited)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(awaited()));
534
+ else if ((0, _stryke_type_checks_is_string.isString)(awaited)) {
535
+ const resolved = await this.#resolvePlugin(awaited);
536
+ if ((0, _stryke_type_checks_is_function.isFunction)(resolved)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(resolved()));
537
+ else plugins = (0, _stryke_convert_to_array.toArray)(resolved);
538
+ } else if (Array.isArray(awaited) && awaited.every(_powerlines_core_plugin_utils.isPlugin)) plugins = awaited;
539
+ else if (Array.isArray(awaited) && awaited.every(_powerlines_core_plugin_utils.isPluginConfig)) {
540
+ plugins = [];
541
+ for (const pluginConfig of awaited) {
542
+ const initialized = await this.#initPlugin(pluginConfig);
543
+ if (initialized) plugins.push(...initialized);
544
+ }
545
+ } else if ((0, _powerlines_core_plugin_utils.isPluginConfigTuple)(awaited) || (0, _powerlines_core_plugin_utils.isPluginConfigObject)(awaited)) {
546
+ let pluginConfig;
547
+ let pluginOptions;
548
+ if ((0, _powerlines_core_plugin_utils.isPluginConfigTuple)(awaited)) {
549
+ pluginConfig = awaited[0];
550
+ pluginOptions = awaited?.length === 2 ? awaited[1] : void 0;
551
+ } else {
552
+ pluginConfig = awaited.plugin;
553
+ pluginOptions = awaited.options;
554
+ }
555
+ if ((0, _stryke_type_checks_is_set_string.isSetString)(pluginConfig)) {
556
+ const resolved = await this.#resolvePlugin(pluginConfig);
557
+ if ((0, _stryke_type_checks_is_function.isFunction)(resolved)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(pluginOptions ? resolved(pluginOptions) : resolved()));
558
+ else plugins = (0, _stryke_convert_to_array.toArray)(resolved);
559
+ } else if ((0, _stryke_type_checks_is_function.isFunction)(pluginConfig)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(pluginConfig(pluginOptions)));
560
+ else if (Array.isArray(pluginConfig) && pluginConfig.every(_powerlines_core_plugin_utils.isPlugin)) plugins = pluginConfig;
561
+ else if ((0, _powerlines_core_plugin_utils.isPlugin)(pluginConfig)) plugins = (0, _stryke_convert_to_array.toArray)(pluginConfig);
562
+ }
563
+ if (!plugins) throw new Error(`The plugin configuration ${JSON.stringify(awaited)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
564
+ if (plugins.length > 0 && !plugins.every(_powerlines_core_plugin_utils.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.`);
565
+ const result = [];
566
+ for (const plugin of plugins) if ((0, _powerlines_core_plugin_utils.isDuplicate)(plugin, this.context.plugins)) this.context.trace(`Duplicate ${chalk.default.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`);
567
+ else {
568
+ result.push(plugin);
569
+ this.context.trace(`Initializing the ${chalk.default.bold.cyanBright(plugin.name)} plugin...`);
570
+ }
571
+ return result;
572
+ }
573
+ async #resolvePlugin(pluginPath) {
574
+ if (pluginPath.startsWith("@") && pluginPath.split("/").filter(Boolean).length > 2) {
575
+ const splits = pluginPath.split("/").filter(Boolean);
576
+ pluginPath = `${splits[0]}/${splits[1]}`;
577
+ }
578
+ const isInstalled = (0, _stryke_fs_package_fns.isPackageExists)(pluginPath, { paths: [this.context.config.cwd, this.context.config.root] });
579
+ if (!isInstalled && this.context.config.autoInstall) {
580
+ this.#context.warn(`The plugin package "${pluginPath}" is not installed. It will be installed automatically.`);
581
+ const result = await (0, _stryke_fs_install.install)(pluginPath, { cwd: this.context.config.root });
582
+ if ((0, _stryke_type_checks_is_number.isNumber)(result.exitCode) && result.exitCode > 0) {
583
+ this.#context.error(result.stderr);
584
+ throw new Error(`An error occurred while installing the build plugin package "${pluginPath}" `);
585
+ }
586
+ }
587
+ try {
588
+ const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve((0, _stryke_path_join_paths.joinPaths)(pluginPath, "plugin")));
589
+ const result = module.plugin ?? module.default;
590
+ if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
591
+ return result;
592
+ } catch (error) {
593
+ try {
594
+ const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(pluginPath));
595
+ const result = module.plugin ?? module.default;
596
+ if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
597
+ return result;
598
+ } catch {
599
+ if (!isInstalled) throw new Error(`The plugin package "${pluginPath}" is not installed. Please install the package using the command: "npm install ${pluginPath} --save-dev"`);
600
+ else throw new Error(`An error occurred while importing the build plugin package "${pluginPath}":
601
+ ${(0, _stryke_type_checks_is_error.isError)(error) ? error.message : String(error)}
602
+
603
+ 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\`.`);
604
+ }
605
+ }
606
+ }
607
+ /**
608
+ * Generate the Powerlines TypeScript declaration file
609
+ *
610
+ * @remarks
611
+ * This method will generate the TypeScript declaration file for the Powerlines project, including any types provided by plugins.
612
+ *
613
+ * @param context - The environment context to use for generating the TypeScript declaration file
614
+ * @returns A promise that resolves when the TypeScript declaration file has been generated
615
+ */
616
+ async #types(context) {
617
+ context.debug(`Preparing the TypeScript definitions for the Powerlines project.`);
618
+ if (context.fs.existsSync(context.typesPath)) await context.fs.remove(context.typesPath);
619
+ if (!await (0, _stryke_fs_resolve.resolvePackage)("typescript")) throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
620
+ context.debug("Running TypeScript compiler for built-in runtime module files.");
621
+ let { code, directives } = await emitBuiltinTypes(context, (await context.getBuiltins()).reduce((ret, builtin) => {
622
+ const formatted = (0, _stryke_path_replace.replacePath)(builtin.path, context.config.cwd);
623
+ if (!ret.includes(formatted)) ret.push(formatted);
624
+ return ret;
625
+ }, []));
626
+ context.debug(`Generating TypeScript declaration file ${context.typesPath}.`);
627
+ const merge = async (currentResult, previousResult) => {
628
+ 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 {
629
+ code,
630
+ directives
631
+ };
632
+ const previous = (await (0, _powerlines_core_lib_utilities_format.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();
633
+ const current = (await (0, _powerlines_core_lib_utilities_format.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();
634
+ return {
635
+ 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 : []],
636
+ code: await (0, _powerlines_core_lib_utilities_format.format)(context, context.typesPath, `${!previous.includes((0, _powerlines_core_lib_utilities_file_header.getTypescriptFileHeader)(context)) && !current.includes((0, _powerlines_core_lib_utilities_file_header.getTypescriptFileHeader)(context)) ? `${code}\n` : ""}${previous}\n${current}`.trim())
637
+ };
638
+ };
639
+ const asNextParam = (previousResult) => (0, _stryke_type_checks_is_object.isObject)(previousResult) ? previousResult.code : previousResult;
640
+ let result = await this.callHook("types", {
641
+ environment: context,
642
+ sequential: true,
643
+ order: "pre",
644
+ result: "merge",
645
+ merge,
646
+ asNextParam
647
+ }, code);
648
+ if (result) {
649
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(result)) {
650
+ code = result.code;
651
+ if (Array.isArray(result.directives) && result.directives.length > 0) directives = (0, _stryke_helpers_get_unique.getUnique)([...directives, ...result.directives]).filter(Boolean);
652
+ } else if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) code = result;
653
+ }
654
+ result = await this.callHook("types", {
655
+ environment: context,
656
+ sequential: true,
657
+ order: "normal",
658
+ result: "merge",
659
+ merge,
660
+ asNextParam
661
+ }, code);
662
+ if (result) {
663
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(result)) {
664
+ code = result.code;
665
+ if (Array.isArray(result.directives) && result.directives.length > 0) directives = (0, _stryke_helpers_get_unique.getUnique)([...directives, ...result.directives]).filter(Boolean);
666
+ } else if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) code = result;
667
+ }
668
+ result = await this.callHook("types", {
669
+ environment: context,
670
+ sequential: true,
671
+ order: "post",
672
+ result: "merge",
673
+ merge,
674
+ asNextParam
675
+ }, code);
676
+ if (result) {
677
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(result)) {
678
+ code = result.code;
679
+ if (Array.isArray(result.directives) && result.directives.length > 0) directives = (0, _stryke_helpers_get_unique.getUnique)([...directives, ...result.directives]).filter(Boolean);
680
+ } else if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) code = result;
681
+ }
682
+ 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")}
683
+
684
+ ` : ""}${(0, _powerlines_core_lib_utilities_file_header.getTypescriptFileHeader)(context, {
685
+ directive: null,
686
+ prettierIgnore: false
687
+ })}
688
+
689
+ ${formatTypes(code)}
690
+ `);
691
+ }
692
+ /**
693
+ * The Powerlines context
694
+ */
695
+ get context() {
696
+ return this.#context;
697
+ }
698
+ /**
699
+ * Initialize a Powerlines API instance
700
+ *
701
+ * @param options - The options to initialize the API with
702
+ * @returns A new instance of the Powerlines API
703
+ */
704
+ static async fromConfig(options, config) {
705
+ const api = new PowerlinesExecution(await require_execution_context.PowerlinesExecutionContext.fromOptions(options));
706
+ api.#context.config.inlineConfig = config;
707
+ await api.#context.setup(config);
708
+ api.#context.$$internal = {
709
+ api,
710
+ addPlugin: api.addPlugin.bind(api)
711
+ };
712
+ const timer = api.context.timer("Initialization");
713
+ for (const plugin of api.context.config.plugins.flat(10) ?? []) await api.addPlugin(plugin);
714
+ 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.");
715
+ 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${api.context.plugins.map((plugin, index) => ` ${index + 1}. ${(0, _powerlines_core_lib_logger.colorText)(plugin.name)}`).join("\n")}`);
716
+ const pluginConfig = await api.callHook("config", {
717
+ environment: await api.context.getEnvironment(),
718
+ sequential: true,
719
+ result: "merge",
720
+ merge: require_execution_context.mergeConfigs
721
+ });
722
+ if (pluginConfig) {
723
+ api.#context.config.pluginConfig = pluginConfig;
724
+ await api.#context.setup(pluginConfig);
725
+ }
726
+ timer();
727
+ return api;
728
+ }
729
+ /**
730
+ * Generate the Powerlines typescript declaration file
731
+ *
732
+ * @remarks
733
+ * 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.
734
+ *
735
+ * @param inlineConfig - The inline configuration for the types command
736
+ */
737
+ async types(inlineConfig = { command: "types" }) {
738
+ this.context.debug(" Aggregating configuration options for the Powerlines project");
739
+ inlineConfig.command ??= "types";
740
+ await this.context.setup(inlineConfig);
741
+ await this.#executeEnvironments(async (context) => {
742
+ context.debug(`Initializing the processing options for the Powerlines project.`);
743
+ await this.callHook("configResolved", {
744
+ environment: context,
745
+ order: "pre"
746
+ });
747
+ await initializeTsconfig(context);
748
+ await this.callHook("configResolved", {
749
+ environment: context,
750
+ order: "normal"
751
+ });
752
+ 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")}` : ""}`);
753
+ 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.`);
754
+ await resolveTsconfig(context);
755
+ await installDependencies(context);
756
+ await this.callHook("configResolved", {
757
+ environment: context,
758
+ order: "post"
759
+ });
760
+ context.trace(`Powerlines configuration has been resolved: \n\n${(0, _storm_software_config_tools_logger_console.formatLogMessage)({
761
+ ...context.config,
762
+ userConfig: (0, _stryke_type_checks_is_set_object.isSetObject)(context.config.userConfig) ? (0, _stryke_helpers_omit.omit)(context.config.userConfig, ["plugins"]) : void 0,
763
+ inlineConfig: (0, _stryke_type_checks_is_set_object.isSetObject)(context.config.inlineConfig) ? (0, _stryke_helpers_omit.omit)(context.config.inlineConfig, ["plugins"]) : void 0,
764
+ plugins: context.plugins.map((plugin) => plugin.plugin.name)
765
+ })}`);
766
+ if (!context.fs.existsSync(context.cachePath)) await (0, _stryke_fs_helpers.createDirectory)(context.cachePath);
767
+ if (!context.fs.existsSync(context.dataPath)) await (0, _stryke_fs_helpers.createDirectory)(context.dataPath);
768
+ if (context.config.skipCache === true || context.persistedMeta?.checksum !== context.meta.checksum) context.debug(`Using previously prepared files as the meta checksum has not changed.`);
769
+ else {
770
+ context.info(`Running \`prepare\` command as the meta checksum has changed since the last run.`);
771
+ await this.prepare((0, defu.default)({ output: { types: false } }, inlineConfig));
772
+ }
773
+ await this.#types(context);
774
+ this.context.debug("Formatting files generated during the types step.");
775
+ await (0, _powerlines_core_lib_utilities_format.format)(context, context.typesPath, await context.fs.read(context.typesPath) ?? "");
776
+ await require_execution_context.writeMetaFile(context);
777
+ context.persistedMeta = context.meta;
778
+ });
779
+ }
780
+ /**
781
+ * Prepare the Powerlines API
782
+ *
783
+ * @remarks
784
+ * This method will prepare the Powerlines API for use, initializing any necessary resources.
785
+ *
786
+ * @param inlineConfig - The inline configuration for the prepare command
787
+ */
788
+ async prepare(inlineConfig = { command: "prepare" }) {
789
+ inlineConfig.command ??= "prepare";
790
+ await this.context.setup(inlineConfig);
791
+ await this.#executeEnvironments(async (context) => {
792
+ context.debug(`Initializing the processing options for the Powerlines project.`);
793
+ await this.callHook("configResolved", {
794
+ environment: context,
795
+ order: "pre"
796
+ });
797
+ await initializeTsconfig(context);
798
+ await this.callHook("configResolved", {
799
+ environment: context,
800
+ order: "normal"
801
+ });
802
+ 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")}` : ""}`);
803
+ 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.`);
804
+ await resolveTsconfig(context);
805
+ await installDependencies(context);
806
+ await this.callHook("configResolved", {
807
+ environment: context,
808
+ order: "post"
809
+ });
810
+ context.trace(`Powerlines configuration has been resolved: \n\n${(0, _storm_software_config_tools_logger_console.formatLogMessage)({
811
+ ...context.config,
812
+ userConfig: (0, _stryke_type_checks_is_set_object.isSetObject)(context.config.userConfig) ? (0, _stryke_helpers_omit.omit)(context.config.userConfig, ["plugins"]) : void 0,
813
+ inlineConfig: (0, _stryke_type_checks_is_set_object.isSetObject)(context.config.inlineConfig) ? (0, _stryke_helpers_omit.omit)(context.config.inlineConfig, ["plugins"]) : void 0,
814
+ plugins: context.plugins.map((plugin) => plugin.plugin.name)
815
+ })}`);
816
+ if (!context.fs.existsSync(context.cachePath)) await (0, _stryke_fs_helpers.createDirectory)(context.cachePath);
817
+ if (!context.fs.existsSync(context.dataPath)) await (0, _stryke_fs_helpers.createDirectory)(context.dataPath);
818
+ await this.callHook("prepare", {
819
+ environment: context,
820
+ order: "pre"
821
+ });
822
+ await this.callHook("prepare", {
823
+ environment: context,
824
+ order: "normal"
825
+ });
826
+ await this.callHook("prepare", {
827
+ environment: context,
828
+ order: "post"
829
+ });
830
+ if (context.config.output.types !== false) await this.#types(context);
831
+ this.context.debug("Formatting files generated during the prepare step.");
832
+ await Promise.all([(0, _powerlines_core_lib_utilities_format.formatFolder)(context, context.builtinsPath), (0, _powerlines_core_lib_utilities_format.formatFolder)(context, context.entryPath)]);
833
+ await require_execution_context.writeMetaFile(context);
834
+ context.persistedMeta = context.meta;
835
+ });
836
+ }
837
+ /**
838
+ * Create a new Powerlines project
839
+ *
840
+ * @remarks
841
+ * This method will create a new Powerlines project in the current directory.
842
+ *
843
+ * @param inlineConfig - The inline configuration for the new command
844
+ * @returns A promise that resolves when the project has been created
845
+ */
846
+ async new(inlineConfig) {
847
+ inlineConfig.command ??= "new";
848
+ await this.prepare(inlineConfig);
849
+ await this.#executeEnvironments(async (context) => {
850
+ context.debug("Initializing the processing options for the Powerlines project.");
851
+ await this.callHook("new", {
852
+ environment: context,
853
+ order: "pre"
854
+ });
855
+ const files = await (0, _stryke_fs_list_files.listFiles)((0, _stryke_path_join_paths.joinPaths)(context.powerlinesPath, "files/common/**/*.hbs"));
856
+ for (const file of files) {
857
+ context.trace(`Adding template file to project: ${file}`);
858
+ const template = handlebars.default.compile(file);
859
+ await context.fs.write((0, _stryke_path_join_paths.joinPaths)(context.config.root, file.replace(".hbs", "")), template(context));
860
+ }
861
+ await this.callHook("new", {
862
+ environment: context,
863
+ order: "normal"
864
+ });
865
+ if (context.config.projectType === "application") {
866
+ const files = await (0, _stryke_fs_list_files.listFiles)((0, _stryke_path_join_paths.joinPaths)(context.powerlinesPath, "files/application/**/*.hbs"));
867
+ for (const file of files) {
868
+ context.trace(`Adding application template file: ${file}`);
869
+ const template = handlebars.default.compile(file);
870
+ await context.fs.write((0, _stryke_path_join_paths.joinPaths)(context.config.root, file.replace(".hbs", "")), template(context));
871
+ }
872
+ } else {
873
+ const files = await (0, _stryke_fs_list_files.listFiles)((0, _stryke_path_join_paths.joinPaths)(context.powerlinesPath, "files/library/**/*.hbs"));
874
+ for (const file of files) {
875
+ context.trace(`Adding library template file: ${file}`);
876
+ const template = handlebars.default.compile(file);
877
+ await context.fs.write((0, _stryke_path_join_paths.joinPaths)(context.config.root, file.replace(".hbs", "")), template(context));
878
+ }
879
+ }
880
+ await this.callHook("new", {
881
+ environment: context,
882
+ order: "post"
883
+ });
884
+ });
885
+ }
886
+ /**
887
+ * Clean any previously prepared artifacts
888
+ *
889
+ * @remarks
890
+ * This method will remove the previous Powerlines artifacts from the project.
891
+ *
892
+ * @param inlineConfig - The inline configuration for the clean command
893
+ * @returns A promise that resolves when the clean command has completed
894
+ */
895
+ async clean(inlineConfig = { command: "clean" }) {
896
+ inlineConfig.command ??= "clean";
897
+ await this.prepare(inlineConfig);
898
+ await this.#executeEnvironments(async (context) => {
899
+ context.debug("Cleaning the project's dist and artifacts directories.");
900
+ await context.fs.remove((0, _stryke_path_join_paths.joinPaths)(context.config.cwd, context.config.output.path));
901
+ await context.fs.remove((0, _stryke_path_join_paths.joinPaths)(context.config.cwd, context.config.root, context.config.output.artifactsPath));
902
+ await this.callHook("clean", {
903
+ environment: context,
904
+ sequential: false
905
+ });
906
+ });
907
+ }
908
+ /**
909
+ * Lint the project
910
+ *
911
+ * @param inlineConfig - The inline configuration for the lint command
912
+ * @returns A promise that resolves when the lint command has completed
913
+ */
914
+ async lint(inlineConfig = { command: "lint" }) {
915
+ inlineConfig.command ??= "lint";
916
+ await this.prepare(inlineConfig);
917
+ await this.#executeEnvironments(async (context) => {
918
+ await this.callHook("lint", {
919
+ environment: context,
920
+ sequential: false
921
+ });
922
+ });
923
+ }
924
+ /**
925
+ * Test the project source code
926
+ *
927
+ * @param inlineConfig - The inline configuration for the test command
928
+ * @returns A promise that resolves when the test command has completed
929
+ */
930
+ async test(inlineConfig = { command: "test" }) {
931
+ inlineConfig.command ??= "test";
932
+ await this.prepare(inlineConfig);
933
+ await this.#executeEnvironments(async (context) => {
934
+ await this.callHook("test", {
935
+ environment: context,
936
+ sequential: false
937
+ });
938
+ });
939
+ }
940
+ /**
941
+ * Build the project
942
+ *
943
+ * @remarks
944
+ * This method will build the Powerlines project, generating the necessary artifacts.
945
+ *
946
+ * @param inlineConfig - The inline configuration for the build command
947
+ * @returns A promise that resolves when the build command has completed
948
+ */
949
+ async build(inlineConfig = { command: "build" }) {
950
+ await this.context.generateChecksum();
951
+ if (this.context.meta.checksum !== this.context.persistedMeta?.checksum || this.context.config.skipCache) {
952
+ 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.");
953
+ inlineConfig.command ??= "build";
954
+ await this.prepare(inlineConfig);
955
+ }
956
+ if (this.context.config.singleBuild) await this.#handleBuild(await this.#context.toEnvironment());
957
+ else await this.#executeEnvironments(async (context) => {
958
+ await this.#handleBuild(context);
959
+ });
960
+ }
961
+ /**
962
+ * Prepare the documentation for the project
963
+ *
964
+ * @param inlineConfig - The inline configuration for the docs command
965
+ * @returns A promise that resolves when the documentation generation has completed
966
+ */
967
+ async docs(inlineConfig = { command: "docs" }) {
968
+ inlineConfig.command ??= "docs";
969
+ await this.prepare(inlineConfig);
970
+ await this.#executeEnvironments(async (context) => {
971
+ context.debug("Writing documentation for the Powerlines project artifacts.");
972
+ await this.callHook("docs", { environment: context });
973
+ });
974
+ }
975
+ /**
976
+ * Deploy the project source code
977
+ *
978
+ * @remarks
979
+ * This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
980
+ *
981
+ * @param inlineConfig - The inline configuration for the deploy command
982
+ */
983
+ async deploy(inlineConfig = { command: "deploy" }) {
984
+ inlineConfig.command ??= "deploy";
985
+ await this.prepare(inlineConfig);
986
+ await this.#executeEnvironments(async (context) => {
987
+ await this.callHook("deploy", { environment: context });
988
+ });
989
+ }
990
+ /**
991
+ * Finalization/cleanup processing for the Powerlines API
992
+ *
993
+ * @remarks
994
+ * This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
995
+ *
996
+ * @returns A promise that resolves when the finalization process has completed
997
+ */
998
+ async finalize() {
999
+ await this.#executeEnvironments(async (context) => {
1000
+ await this.callHook("finalize", { environment: context });
1001
+ await context.fs.dispose();
1002
+ 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);
1003
+ });
1004
+ }
1005
+ /**
1006
+ * Invokes the configured plugin hooks
1007
+ *
1008
+ * @remarks
1009
+ * By default, it will call the `"pre"`, `"normal"`, and `"post"` ordered hooks in sequence
1010
+ *
1011
+ * @param hook - The hook to call
1012
+ * @param options - The options to provide to the hook
1013
+ * @param args - The arguments to pass to the hook
1014
+ * @returns The result of the hook call
1015
+ */
1016
+ async callHook(hook, options, ...args) {
1017
+ return require_execution_context.callHook((0, _stryke_type_checks_is_set_object.isSetObject)(options?.environment) ? options.environment : await this.#context.getEnvironment(options?.environment), hook, {
1018
+ sequential: true,
1019
+ ...options
1020
+ }, ...args);
1021
+ }
1022
+ /**
1023
+ * Create a new Powerlines API instance
1024
+ *
1025
+ * @param context - The Powerlines context
1026
+ */
1027
+ constructor(context) {
1028
+ this.#context = context;
1029
+ }
1030
+ /**
1031
+ * Add a Powerlines plugin used in the build process
1032
+ *
1033
+ * @param config - The import path of the plugin to add
1034
+ */
1035
+ async addPlugin(config) {
1036
+ if (config) {
1037
+ const result = await this.#initPlugin(config);
1038
+ if (!result) return;
1039
+ for (const plugin of result) {
1040
+ this.context.debug(`Successfully initialized the ${chalk.default.bold.cyanBright(plugin.name)} plugin`);
1041
+ await this.context.addPlugin(plugin);
1042
+ }
1043
+ }
1044
+ }
1045
+ };
1046
+
1047
+ //#endregion
1048
+ //#region src/api.ts
1049
+ /**
1050
+ * The Powerlines API class
1051
+ *
1052
+ * @remarks
1053
+ * This class is responsible for managing the Powerlines project lifecycle, including initialization, building, and finalization.
1054
+ *
1055
+ * @public
1056
+ */
1057
+ var PowerlinesAPI = class PowerlinesAPI extends PowerlinesExecution {
1058
+ /**
1059
+ * Create a new Powerlines API instance
1060
+ *
1061
+ * @param context - The Powerlines context
1062
+ */
1063
+ constructor(context) {
1064
+ super(context);
1065
+ }
1066
+ /**
1067
+ * Initialize a Powerlines API instance
1068
+ *
1069
+ * @param options - The options to initialize the API with
1070
+ * @returns A new instance of the Powerlines API
1071
+ */
1072
+ static async fromOptions(options, override) {
1073
+ const api = new PowerlinesAPI(await require_execution_context.PowerlinesExecutionContext.fromOptions({
1074
+ cwd: process.cwd(),
1075
+ mode: "production",
1076
+ framework: "powerlines",
1077
+ ...options,
1078
+ configIndex: 0
1079
+ }));
1080
+ if (override) await api.context.setup(override);
1081
+ api.context.$$internal = {
1082
+ api,
1083
+ addPlugin: api.addPlugin.bind(api)
1084
+ };
1085
+ const timer = api.context.timer("Initialization");
1086
+ for (const plugin of api.context.config.plugins.flat(10) ?? []) await api.addPlugin(plugin);
1087
+ 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.");
1088
+ 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${api.context.plugins.map((plugin, index) => ` ${index + 1}. ${(0, _powerlines_core_lib_logger.colorText)(plugin.name)}`).join("\n")}`);
1089
+ const pluginConfig = await api.callHook("config", {
1090
+ environment: await api.context.getEnvironment(),
1091
+ sequential: true,
1092
+ result: "merge",
1093
+ merge: require_execution_context.mergeConfigs
1094
+ });
1095
+ if (pluginConfig) {
1096
+ api.context.config.pluginConfig = pluginConfig;
1097
+ await api.context.setup(pluginConfig);
1098
+ }
1099
+ timer();
1100
+ return api;
1101
+ }
1102
+ /**
1103
+ * Generate the Powerlines typescript declaration file
1104
+ *
1105
+ * @remarks
1106
+ * 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.
1107
+ *
1108
+ * @param inlineConfig - The inline configuration for the types command
1109
+ */
1110
+ async types(inlineConfig = { command: "types" }) {
1111
+ const timer = this.context.timer("Types");
1112
+ this.context.info(" ๐Ÿ—๏ธ Generating typescript declarations for the Powerlines project");
1113
+ await super.types(inlineConfig);
1114
+ this.context.debug("โœ” Powerlines types generation has completed successfully");
1115
+ timer();
1116
+ }
1117
+ /**
1118
+ * Prepare the Powerlines API
1119
+ *
1120
+ * @remarks
1121
+ * This method will prepare the Powerlines API for use, initializing any necessary resources.
1122
+ *
1123
+ * @param inlineConfig - The inline configuration for the prepare command
1124
+ */
1125
+ async prepare(inlineConfig = { command: "prepare" }) {
1126
+ const timer = this.context.timer("Prepare");
1127
+ this.context.info(" ๐Ÿ—๏ธ Preparing the Powerlines project");
1128
+ this.context.debug(" Aggregating configuration options for the Powerlines project");
1129
+ await super.prepare(inlineConfig);
1130
+ this.context.debug("โœ” Powerlines preparation has completed successfully");
1131
+ timer();
1132
+ }
1133
+ /**
1134
+ * Create a new Powerlines project
1135
+ *
1136
+ * @remarks
1137
+ * This method will create a new Powerlines project in the current directory.
1138
+ *
1139
+ * @param inlineConfig - The inline configuration for the new command
1140
+ * @returns A promise that resolves when the project has been created
1141
+ */
1142
+ async new(inlineConfig) {
1143
+ const timer = this.context.timer("New");
1144
+ this.context.info(" ๐Ÿ†• Creating a new Powerlines project");
1145
+ await super.new(inlineConfig);
1146
+ this.context.debug("โœ” Powerlines new command completed successfully");
1147
+ timer();
1148
+ }
1149
+ /**
1150
+ * Clean any previously prepared artifacts
1151
+ *
1152
+ * @remarks
1153
+ * This method will remove the previous Powerlines artifacts from the project.
1154
+ *
1155
+ * @param inlineConfig - The inline configuration for the clean command
1156
+ * @returns A promise that resolves when the clean command has completed
1157
+ */
1158
+ async clean(inlineConfig = { command: "clean" }) {
1159
+ const timer = this.context.timer("Clean");
1160
+ this.context.info(" ๐Ÿงน Cleaning the previous Powerlines artifacts");
1161
+ await super.clean(inlineConfig);
1162
+ this.context.debug("โœ” Powerlines cleaning completed successfully");
1163
+ timer();
1164
+ }
1165
+ /**
1166
+ * Lint the project
1167
+ *
1168
+ * @param inlineConfig - The inline configuration for the lint command
1169
+ * @returns A promise that resolves when the lint command has completed
1170
+ */
1171
+ async lint(inlineConfig = { command: "lint" }) {
1172
+ const timer = this.context.timer("Lint");
1173
+ this.context.info(" ๐Ÿ“ Linting the Powerlines project");
1174
+ await super.lint(inlineConfig);
1175
+ this.context.debug("โœ” Powerlines linting completed successfully");
1176
+ timer();
1177
+ }
1178
+ /**
1179
+ * Test the project
1180
+ *
1181
+ * @remarks
1182
+ * This method will run the tests for the Powerlines project.
1183
+ *
1184
+ * @param inlineConfig - The inline configuration for the test command
1185
+ * @returns A promise that resolves when the test command has completed
1186
+ */
1187
+ async test(inlineConfig = { command: "test" }) {
1188
+ const timer = this.context.timer("Test");
1189
+ this.context.info(" ๐Ÿงช Running tests for the Powerlines project");
1190
+ await super.test(inlineConfig);
1191
+ this.context.debug("โœ” Powerlines testing completed successfully");
1192
+ timer();
1193
+ }
1194
+ /**
1195
+ * Build the project
1196
+ *
1197
+ * @remarks
1198
+ * This method will build the Powerlines project, generating the necessary artifacts.
1199
+ *
1200
+ * @param inlineConfig - The inline configuration for the build command
1201
+ * @returns A promise that resolves when the build command has completed
1202
+ */
1203
+ async build(inlineConfig = { command: "build" }) {
1204
+ const timer = this.context.timer("Build");
1205
+ this.context.info(" ๐Ÿ“ฆ Building the Powerlines project");
1206
+ await super.build(inlineConfig);
1207
+ this.context.debug("โœ” Powerlines build completed successfully");
1208
+ timer();
1209
+ }
1210
+ /**
1211
+ * Prepare the documentation for the project
1212
+ *
1213
+ * @param inlineConfig - The inline configuration for the docs command
1214
+ * @returns A promise that resolves when the documentation generation has completed
1215
+ */
1216
+ async docs(inlineConfig = { command: "docs" }) {
1217
+ const timer = this.context.timer("Docs");
1218
+ this.context.info(" ๐Ÿ““ Generating documentation for the Powerlines project");
1219
+ await super.docs(inlineConfig);
1220
+ this.context.debug("โœ” Powerlines documentation generation completed successfully");
1221
+ timer();
1222
+ }
1223
+ /**
1224
+ * Deploy the project source code
1225
+ *
1226
+ * @remarks
1227
+ * This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
1228
+ *
1229
+ * @param inlineConfig - The inline configuration for the deploy command
1230
+ */
1231
+ async deploy(inlineConfig = { command: "deploy" }) {
1232
+ const timer = this.context.timer("Deploy");
1233
+ this.context.info(" ๐Ÿš€ Deploying the Powerlines project");
1234
+ await super.deploy(inlineConfig);
1235
+ this.context.debug("โœ” Powerlines deploy completed successfully");
1236
+ timer();
1237
+ }
1238
+ /**
1239
+ * Finalization/cleanup processing for the Powerlines API
1240
+ *
1241
+ * @remarks
1242
+ * This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
1243
+ *
1244
+ * @returns A promise that resolves when the finalization process has completed
1245
+ */
1246
+ async finalize() {
1247
+ const timer = this.context.timer("Finalization");
1248
+ this.context.info(" ๐Ÿ Powerlines finalization processes started");
1249
+ await super.finalize();
1250
+ this.context.debug("โœ” Powerlines finalization completed successfully");
1251
+ timer();
1252
+ }
1253
+ /**
1254
+ * Dispose of the Powerlines API instance
1255
+ *
1256
+ * @remarks
1257
+ * This method will finalize the Powerlines API instance, cleaning up any resources used.
1258
+ */
1259
+ async [Symbol.asyncDispose]() {
1260
+ await this.finalize();
1261
+ }
1262
+ };
1263
+
1264
+ //#endregion
1265
+ exports.PowerlinesAPI = PowerlinesAPI;