powerlines 0.42.40 → 0.43.0

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