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