@powerlines/engine 0.47.4 โ†’ 0.49.1

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