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