@powerlines/plugin-webpack 0.5.241 → 0.5.242

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 (114) hide show
  1. package/dist/helpers/unplugin.cjs +2 -3
  2. package/dist/helpers/unplugin.mjs +1 -2
  3. package/dist/index.cjs +2 -2
  4. package/dist/index.d.cts +3 -2
  5. package/dist/index.d.mts +1 -1
  6. package/dist/index.mjs +3 -3
  7. package/dist/types/plugin.d.cts +3 -3
  8. package/dist/types/plugin.d.mts +3 -3
  9. package/package.json +3 -3
  10. package/dist/powerlines/package.cjs +0 -11
  11. package/dist/powerlines/package.mjs +0 -5
  12. package/dist/powerlines/schemas/fs.cjs +0 -226
  13. package/dist/powerlines/schemas/fs.mjs +0 -224
  14. package/dist/powerlines/src/api.cjs +0 -568
  15. package/dist/powerlines/src/api.mjs +0 -566
  16. package/dist/powerlines/src/internal/helpers/environment.cjs +0 -50
  17. package/dist/powerlines/src/internal/helpers/environment.mjs +0 -47
  18. package/dist/powerlines/src/internal/helpers/generate-types.cjs +0 -78
  19. package/dist/powerlines/src/internal/helpers/generate-types.mjs +0 -76
  20. package/dist/powerlines/src/internal/helpers/hooks.cjs +0 -65
  21. package/dist/powerlines/src/internal/helpers/hooks.d.cts +0 -47
  22. package/dist/powerlines/src/internal/helpers/hooks.d.mts +0 -49
  23. package/dist/powerlines/src/internal/helpers/hooks.mjs +0 -63
  24. package/dist/powerlines/src/internal/helpers/install-dependencies.cjs +0 -24
  25. package/dist/powerlines/src/internal/helpers/install-dependencies.mjs +0 -23
  26. package/dist/powerlines/src/internal/helpers/install.cjs +0 -36
  27. package/dist/powerlines/src/internal/helpers/install.mjs +0 -35
  28. package/dist/powerlines/src/internal/helpers/resolve-tsconfig.cjs +0 -97
  29. package/dist/powerlines/src/internal/helpers/resolve-tsconfig.mjs +0 -93
  30. package/dist/powerlines/src/internal/helpers/resolver.cjs +0 -43
  31. package/dist/powerlines/src/internal/helpers/resolver.mjs +0 -41
  32. package/dist/powerlines/src/lib/build/webpack.cjs +0 -38
  33. package/dist/powerlines/src/lib/build/webpack.mjs +0 -36
  34. package/dist/powerlines/src/lib/config-file.cjs +0 -79
  35. package/dist/powerlines/src/lib/config-file.mjs +0 -76
  36. package/dist/powerlines/src/lib/constants/environments.cjs +0 -8
  37. package/dist/powerlines/src/lib/constants/environments.mjs +0 -6
  38. package/dist/powerlines/src/lib/contexts/api-context.cjs +0 -184
  39. package/dist/powerlines/src/lib/contexts/api-context.mjs +0 -182
  40. package/dist/powerlines/src/lib/contexts/context.cjs +0 -951
  41. package/dist/powerlines/src/lib/contexts/context.mjs +0 -949
  42. package/dist/powerlines/src/lib/contexts/environment-context.cjs +0 -195
  43. package/dist/powerlines/src/lib/contexts/environment-context.mjs +0 -194
  44. package/dist/powerlines/src/lib/contexts/plugin-context.cjs +0 -78
  45. package/dist/powerlines/src/lib/contexts/plugin-context.mjs +0 -77
  46. package/dist/powerlines/src/lib/entry.cjs +0 -85
  47. package/dist/powerlines/src/lib/entry.mjs +0 -83
  48. package/dist/powerlines/src/lib/fs/helpers.cjs +0 -85
  49. package/dist/powerlines/src/lib/fs/helpers.mjs +0 -81
  50. package/dist/powerlines/src/lib/fs/storage/base.cjs +0 -196
  51. package/dist/powerlines/src/lib/fs/storage/base.mjs +0 -195
  52. package/dist/powerlines/src/lib/fs/storage/file-system.cjs +0 -170
  53. package/dist/powerlines/src/lib/fs/storage/file-system.mjs +0 -169
  54. package/dist/powerlines/src/lib/fs/storage/virtual.cjs +0 -88
  55. package/dist/powerlines/src/lib/fs/storage/virtual.mjs +0 -87
  56. package/dist/powerlines/src/lib/fs/vfs.cjs +0 -912
  57. package/dist/powerlines/src/lib/fs/vfs.mjs +0 -910
  58. package/dist/powerlines/src/lib/logger.cjs +0 -58
  59. package/dist/powerlines/src/lib/logger.mjs +0 -55
  60. package/dist/powerlines/src/lib/typescript/ts-morph.cjs +0 -103
  61. package/dist/powerlines/src/lib/typescript/ts-morph.mjs +0 -101
  62. package/dist/powerlines/src/lib/typescript/tsconfig.cjs +0 -149
  63. package/dist/powerlines/src/lib/typescript/tsconfig.mjs +0 -144
  64. package/dist/powerlines/src/lib/unplugin/factory.cjs +0 -6
  65. package/dist/powerlines/src/lib/unplugin/factory.mjs +0 -8
  66. package/dist/powerlines/src/lib/unplugin/helpers.cjs +0 -29
  67. package/dist/powerlines/src/lib/unplugin/helpers.mjs +0 -27
  68. package/dist/powerlines/src/lib/unplugin/index.cjs +0 -4
  69. package/dist/powerlines/src/lib/unplugin/index.mjs +0 -6
  70. package/dist/powerlines/src/lib/unplugin/module-resolution.cjs +0 -66
  71. package/dist/powerlines/src/lib/unplugin/module-resolution.mjs +0 -65
  72. package/dist/powerlines/src/lib/unplugin/plugin.cjs +0 -71
  73. package/dist/powerlines/src/lib/unplugin/plugin.mjs +0 -70
  74. package/dist/powerlines/src/lib/utilities/file-header.cjs +0 -22
  75. package/dist/powerlines/src/lib/utilities/file-header.mjs +0 -21
  76. package/dist/powerlines/src/lib/utilities/format.cjs +0 -48
  77. package/dist/powerlines/src/lib/utilities/format.mjs +0 -46
  78. package/dist/powerlines/src/lib/utilities/meta.cjs +0 -44
  79. package/dist/powerlines/src/lib/utilities/meta.mjs +0 -40
  80. package/dist/powerlines/src/lib/utilities/source-file.cjs +0 -22
  81. package/dist/powerlines/src/lib/utilities/source-file.mjs +0 -21
  82. package/dist/powerlines/src/plugin-utils/helpers.cjs +0 -167
  83. package/dist/powerlines/src/plugin-utils/helpers.mjs +0 -156
  84. package/dist/powerlines/src/plugin-utils/paths.cjs +0 -36
  85. package/dist/powerlines/src/plugin-utils/paths.mjs +0 -35
  86. package/dist/powerlines/src/types/api.d.cts +0 -104
  87. package/dist/powerlines/src/types/api.d.mts +0 -104
  88. package/dist/powerlines/src/types/babel.d.mts +0 -2
  89. package/dist/powerlines/src/types/build.cjs +0 -23
  90. package/dist/powerlines/src/types/build.d.cts +0 -185
  91. package/dist/powerlines/src/types/build.d.mts +0 -185
  92. package/dist/powerlines/src/types/build.mjs +0 -21
  93. package/dist/powerlines/src/types/commands.cjs +0 -16
  94. package/dist/powerlines/src/types/commands.d.cts +0 -8
  95. package/dist/powerlines/src/types/commands.d.mts +0 -9
  96. package/dist/powerlines/src/types/commands.mjs +0 -15
  97. package/dist/powerlines/src/types/config.d.cts +0 -424
  98. package/dist/powerlines/src/types/config.d.mts +0 -425
  99. package/dist/powerlines/src/types/context.d.cts +0 -514
  100. package/dist/powerlines/src/types/context.d.mts +0 -514
  101. package/dist/powerlines/src/types/fs.d.cts +0 -486
  102. package/dist/powerlines/src/types/fs.d.mts +0 -486
  103. package/dist/powerlines/src/types/hooks.d.cts +0 -32
  104. package/dist/powerlines/src/types/hooks.d.mts +0 -32
  105. package/dist/powerlines/src/types/plugin.cjs +0 -33
  106. package/dist/powerlines/src/types/plugin.d.cts +0 -205
  107. package/dist/powerlines/src/types/plugin.d.mts +0 -205
  108. package/dist/powerlines/src/types/plugin.mjs +0 -32
  109. package/dist/powerlines/src/types/resolved.d.cts +0 -93
  110. package/dist/powerlines/src/types/resolved.d.mts +0 -93
  111. package/dist/powerlines/src/types/tsconfig.d.cts +0 -69
  112. package/dist/powerlines/src/types/tsconfig.d.mts +0 -69
  113. package/dist/powerlines/src/types/unplugin.d.cts +0 -22
  114. package/dist/powerlines/src/types/unplugin.d.mts +0 -23
@@ -1,568 +0,0 @@
1
- const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
- const require_package = require('../package.cjs');
3
- const require_generate_types = require('./internal/helpers/generate-types.cjs');
4
- const require_hooks = require('./internal/helpers/hooks.cjs');
5
- const require_install_dependencies = require('./internal/helpers/install-dependencies.cjs');
6
- const require_tsconfig = require('./lib/typescript/tsconfig.cjs');
7
- const require_resolve_tsconfig = require('./internal/helpers/resolve-tsconfig.cjs');
8
- const require_helpers = require('./plugin-utils/helpers.cjs');
9
- const require_format = require('./lib/utilities/format.cjs');
10
- const require_meta = require('./lib/utilities/meta.cjs');
11
- const require_api_context = require('./lib/contexts/api-context.cjs');
12
- const require_file_header = require('./lib/utilities/file-header.cjs');
13
- let __stryke_helpers_omit = require("@stryke/helpers/omit");
14
- let __stryke_path_join_paths = require("@stryke/path/join-paths");
15
- let __storm_software_config_tools_logger_console = require("@storm-software/config-tools/logger/console");
16
- let __stryke_convert_to_array = require("@stryke/convert/to-array");
17
- let __stryke_fs_helpers = require("@stryke/fs/helpers");
18
- let __stryke_fs_install = require("@stryke/fs/install");
19
- let __stryke_fs_list_files = require("@stryke/fs/list-files");
20
- let __stryke_fs_package_fns = require("@stryke/fs/package-fns");
21
- let __stryke_fs_resolve = require("@stryke/fs/resolve");
22
- let __stryke_path_append = require("@stryke/path/append");
23
- let __stryke_path_replace = require("@stryke/path/replace");
24
- let __stryke_type_checks_is_error = require("@stryke/type-checks/is-error");
25
- let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
26
- let __stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
27
- let __stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
28
- let __stryke_type_checks_is_promise = require("@stryke/type-checks/is-promise");
29
- let __stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
30
- let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
31
- let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
32
- let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
33
- let chalk = require("chalk");
34
- chalk = require_rolldown_runtime.__toESM(chalk);
35
- let handlebars = require("handlebars");
36
- handlebars = require_rolldown_runtime.__toESM(handlebars);
37
-
38
- //#region ../powerlines/src/api.ts
39
- /**
40
- * The Powerlines API class
41
- *
42
- * @remarks
43
- * This class is responsible for managing the Powerlines project lifecycle, including initialization, building, and finalization.
44
- *
45
- * @public
46
- */
47
- var PowerlinesAPI = class PowerlinesAPI {
48
- /**
49
- * The Powerlines context
50
- */
51
- #context;
52
- /**
53
- * The Powerlines context
54
- */
55
- get context() {
56
- return this.#context;
57
- }
58
- /**
59
- * Create a new Powerlines API instance
60
- *
61
- * @param context - The Powerlines context
62
- */
63
- constructor(context) {
64
- this.#context = context;
65
- }
66
- /**
67
- * Initialize a Powerlines API instance
68
- *
69
- * @param workspaceRoot - The directory of the underlying workspace the Powerlines project exists in
70
- * @param config - An object containing the configuration required to run Powerlines tasks.
71
- * @returns A new instance of the Powerlines API
72
- */
73
- static async from(workspaceRoot, config) {
74
- const api = new PowerlinesAPI(await require_api_context.PowerlinesAPIContext.from(workspaceRoot, config));
75
- api.#context.$$internal = {
76
- api,
77
- addPlugin: api.#addPlugin.bind(api)
78
- };
79
- api.context.info(`🔌 The Powerlines Engine v${require_package.version} has started`);
80
- for (const plugin of api.context.config.plugins ?? []) await api.#addPlugin(plugin);
81
- if (api.context.plugins.length === 0) api.context.warn("No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended.");
82
- const pluginConfig = await api.callHook("config", {
83
- environment: await api.context.getEnvironment(),
84
- sequential: true,
85
- result: "merge"
86
- });
87
- await api.context.withUserConfig(pluginConfig, { isHighPriority: false });
88
- return api;
89
- }
90
- /**
91
- * Prepare the Powerlines API
92
- *
93
- * @remarks
94
- * This method will prepare the Powerlines API for use, initializing any necessary resources.
95
- *
96
- * @param inlineConfig - The inline configuration for the prepare command
97
- */
98
- async prepare(inlineConfig = { command: "prepare" }) {
99
- this.context.info(" 🏗️ Preparing the Powerlines project");
100
- this.context.debug(" Aggregating configuration options for the Powerlines project");
101
- await this.context.withInlineConfig(inlineConfig);
102
- await this.#executeEnvironments(async (context) => {
103
- context.debug(`Initializing the processing options for the Powerlines project.`);
104
- await this.callHook("configResolved", {
105
- environment: context,
106
- order: "pre"
107
- });
108
- await require_resolve_tsconfig.initializeTsconfig(context);
109
- await this.callHook("configResolved", {
110
- environment: context,
111
- order: "normal"
112
- });
113
- if (context.entry.length > 0) context.debug(`The configuration provided ${(0, __stryke_convert_to_array.toArray)(context.config.entry).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")}` : ""}`);
114
- 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.`);
115
- await require_resolve_tsconfig.resolveTsconfig(context);
116
- await require_install_dependencies.installDependencies(context);
117
- await this.callHook("configResolved", {
118
- environment: context,
119
- order: "post"
120
- });
121
- context.trace(`Powerlines configuration has been resolved: \n\n${(0, __storm_software_config_tools_logger_console.formatLogMessage)({
122
- ...context.config,
123
- userConfig: (0, __stryke_type_checks_is_set_object.isSetObject)(context.config.userConfig) ? (0, __stryke_helpers_omit.omit)(context.config.userConfig, ["plugins"]) : void 0,
124
- inlineConfig: (0, __stryke_type_checks_is_set_object.isSetObject)(context.config.inlineConfig) ? (0, __stryke_helpers_omit.omit)(context.config.inlineConfig, ["plugins"]) : void 0,
125
- plugins: context.plugins.map((plugin) => plugin.plugin.name)
126
- })}`);
127
- if (!context.fs.existsSync(context.cachePath)) await (0, __stryke_fs_helpers.createDirectory)(context.cachePath);
128
- if (!context.fs.existsSync(context.dataPath)) await (0, __stryke_fs_helpers.createDirectory)(context.dataPath);
129
- await this.callHook("prepare", {
130
- environment: context,
131
- order: "pre"
132
- });
133
- await this.callHook("prepare", {
134
- environment: context,
135
- order: "normal"
136
- });
137
- if (context.config.output.dts !== false) {
138
- context.debug(`Preparing the TypeScript definitions for the Powerlines project.`);
139
- if (context.fs.existsSync(context.dtsPath)) await context.fs.remove(context.dtsPath);
140
- if (!await (0, __stryke_fs_resolve.resolvePackage)("typescript")) throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
141
- context.debug("Running TypeScript compiler for built-in runtime module files.");
142
- let types = await require_generate_types.emitBuiltinTypes(context, (await context.getBuiltins()).reduce((ret, builtin) => {
143
- const formatted = (0, __stryke_path_replace.replacePath)(builtin.path, context.workspaceConfig.workspaceRoot);
144
- if (!ret.includes(formatted)) ret.push(formatted);
145
- return ret;
146
- }, []));
147
- context.debug(`Generating TypeScript declaration file ${context.dtsPath}.`);
148
- const directives = [];
149
- const asNextParam = (previousResult) => (0, __stryke_type_checks_is_object.isObject)(previousResult) ? previousResult.code : previousResult;
150
- let result = await this.callHook("types", {
151
- environment: context,
152
- sequential: true,
153
- order: "pre",
154
- result: "merge",
155
- asNextParam
156
- }, types);
157
- if (result) {
158
- if ((0, __stryke_type_checks_is_set_object.isSetObject)(result)) {
159
- types = result.code;
160
- if (Array.isArray(result.directives) && result.directives.length > 0) directives.push(...result.directives);
161
- } else if ((0, __stryke_type_checks_is_set_string.isSetString)(result)) types = result;
162
- }
163
- result = await this.callHook("types", {
164
- environment: context,
165
- sequential: true,
166
- order: "normal",
167
- result: "merge",
168
- asNextParam
169
- }, types);
170
- if (result) {
171
- if ((0, __stryke_type_checks_is_set_object.isSetObject)(result)) {
172
- types = result.code;
173
- if (Array.isArray(result.directives) && result.directives.length > 0) directives.push(...result.directives);
174
- } else if ((0, __stryke_type_checks_is_set_string.isSetString)(result)) types = result;
175
- }
176
- result = await this.callHook("types", {
177
- environment: context,
178
- sequential: true,
179
- order: "post",
180
- result: "merge",
181
- asNextParam
182
- }, types);
183
- if (result) {
184
- if ((0, __stryke_type_checks_is_set_object.isSetObject)(result)) {
185
- types = result.code;
186
- if (Array.isArray(result.directives) && result.directives.length > 0) directives.push(...result.directives);
187
- } else if ((0, __stryke_type_checks_is_set_string.isSetString)(result)) types = result;
188
- }
189
- if ((0, __stryke_type_checks_is_set_string.isSetString)(types?.trim()) || directives.length > 0) await context.fs.write(context.dtsPath, `${directives.length > 0 ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
190
-
191
- ` : ""}${require_file_header.getFileHeader(context, {
192
- directive: null,
193
- prettierIgnore: false
194
- })}
195
-
196
- ${require_generate_types.formatTypes(types)}
197
- `);
198
- else {
199
- const dtsRelativePath = require_resolve_tsconfig.getTsconfigDtsPath(context);
200
- if (context.tsconfig.tsconfigJson.include && require_tsconfig.isIncludeMatchFound(dtsRelativePath, context.tsconfig.tsconfigJson.include)) {
201
- const normalizedDtsRelativePath = dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath;
202
- context.tsconfig.tsconfigJson.include = context.tsconfig.tsconfigJson.include.filter((includeValue) => includeValue?.toString() !== normalizedDtsRelativePath);
203
- await context.fs.write(context.tsconfig.tsconfigFilePath, JSON.stringify(context.tsconfig.tsconfigJson, null, 2));
204
- }
205
- }
206
- }
207
- context.tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
208
- if (!context.tsconfig) throw new Error("Failed to parse the TypeScript configuration file.");
209
- this.context.debug("Formatting files generated during the prepare step.");
210
- await Promise.all([require_format.formatFolder(context, context.builtinsPath), require_format.formatFolder(context, context.entryPath)]);
211
- await this.callHook("prepare", {
212
- environment: context,
213
- order: "post"
214
- });
215
- await require_meta.writeMetaFile(context);
216
- context.persistedMeta = context.meta;
217
- });
218
- this.context.debug("✔ Powerlines preparation has completed successfully");
219
- }
220
- /**
221
- * Create a new Powerlines project
222
- *
223
- * @remarks
224
- * This method will create a new Powerlines project in the current directory.
225
- *
226
- * @param inlineConfig - The inline configuration for the new command
227
- * @returns A promise that resolves when the project has been created
228
- */
229
- async new(inlineConfig) {
230
- this.context.info("🆕 Creating a new Powerlines project");
231
- await this.prepare(inlineConfig);
232
- await this.#executeEnvironments(async (context) => {
233
- context.debug("Initializing the processing options for the Powerlines project.");
234
- await this.callHook("new", {
235
- environment: context,
236
- order: "pre"
237
- });
238
- const files = await (0, __stryke_fs_list_files.listFiles)((0, __stryke_path_join_paths.joinPaths)(context.powerlinesPath, "files/common/**/*.hbs"));
239
- for (const file of files) {
240
- context.trace(`Adding template file to project: ${file}`);
241
- const template = handlebars.default.compile(file);
242
- await context.fs.write((0, __stryke_path_join_paths.joinPaths)(context.config.projectRoot, file.replace(".hbs", "")), template(context));
243
- }
244
- await this.callHook("new", {
245
- environment: context,
246
- order: "normal"
247
- });
248
- if (context.config.projectType === "application") {
249
- const files$1 = await (0, __stryke_fs_list_files.listFiles)((0, __stryke_path_join_paths.joinPaths)(context.powerlinesPath, "files/application/**/*.hbs"));
250
- for (const file of files$1) {
251
- context.trace(`Adding application template file: ${file}`);
252
- const template = handlebars.default.compile(file);
253
- await context.fs.write((0, __stryke_path_join_paths.joinPaths)(context.config.projectRoot, file.replace(".hbs", "")), template(context));
254
- }
255
- } else {
256
- const files$1 = await (0, __stryke_fs_list_files.listFiles)((0, __stryke_path_join_paths.joinPaths)(context.powerlinesPath, "files/library/**/*.hbs"));
257
- for (const file of files$1) {
258
- context.trace(`Adding library template file: ${file}`);
259
- const template = handlebars.default.compile(file);
260
- await context.fs.write((0, __stryke_path_join_paths.joinPaths)(context.config.projectRoot, file.replace(".hbs", "")), template(context));
261
- }
262
- }
263
- await this.callHook("new", {
264
- environment: context,
265
- order: "post"
266
- });
267
- });
268
- this.context.debug("✔ Powerlines new command completed successfully");
269
- }
270
- /**
271
- * Clean any previously prepared artifacts
272
- *
273
- * @remarks
274
- * This method will remove the previous Powerlines artifacts from the project.
275
- *
276
- * @param inlineConfig - The inline configuration for the clean command
277
- * @returns A promise that resolves when the clean command has completed
278
- */
279
- async clean(inlineConfig = { command: "clean" }) {
280
- this.context.info("🧹 Cleaning the previous Powerlines artifacts");
281
- await this.prepare(inlineConfig);
282
- await this.#executeEnvironments(async (context) => {
283
- context.debug("Cleaning the project's dist and artifacts directories.");
284
- await context.fs.remove((0, __stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.output.buildPath));
285
- await context.fs.remove((0, __stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.output.artifactsPath));
286
- await this.callHook("clean", {
287
- environment: context,
288
- sequential: false
289
- });
290
- });
291
- this.context.debug("✔ Powerlines cleaning completed successfully");
292
- }
293
- /**
294
- * Lint the project
295
- *
296
- * @param inlineConfig - The inline configuration for the lint command
297
- * @returns A promise that resolves when the lint command has completed
298
- */
299
- async lint(inlineConfig = { command: "lint" }) {
300
- this.context.info("📋 Linting the Powerlines project");
301
- await this.prepare(inlineConfig);
302
- await this.#executeEnvironments(async (context) => {
303
- if (context.config.lint !== false) await this.callHook("lint", {
304
- environment: context,
305
- sequential: false
306
- });
307
- });
308
- this.context.debug("✔ Powerlines linting completed successfully");
309
- }
310
- /**
311
- * Build the project
312
- *
313
- * @remarks
314
- * This method will build the Powerlines project, generating the necessary artifacts.
315
- *
316
- * @param inlineConfig - The inline configuration for the build command
317
- * @returns A promise that resolves when the build command has completed
318
- */
319
- async build(inlineConfig = { command: "build" }) {
320
- this.context.info("📦 Building the Powerlines project");
321
- await this.prepare(inlineConfig);
322
- if (this.context.config.singleBuild) await this.#handleBuild(await this.#context.toEnvironment());
323
- else await this.#executeEnvironments(async (context) => {
324
- await this.#handleBuild(context);
325
- });
326
- this.context.debug("✔ Powerlines build completed successfully");
327
- }
328
- /**
329
- * Prepare the documentation for the project
330
- *
331
- * @param inlineConfig - The inline configuration for the docs command
332
- * @returns A promise that resolves when the documentation generation has completed
333
- */
334
- async docs(inlineConfig = { command: "docs" }) {
335
- this.context.info("📓 Generating documentation for the Powerlines project");
336
- await this.prepare(inlineConfig);
337
- await this.#executeEnvironments(async (context) => {
338
- context.debug("Writing documentation for the Powerlines project artifacts.");
339
- await this.prepare(inlineConfig);
340
- await this.#executeEnvironments(async (context$1) => {
341
- await this.callHook("docs", { environment: context$1 });
342
- });
343
- });
344
- this.context.debug("✔ Powerlines documentation generation completed successfully");
345
- }
346
- /**
347
- * Deploy the project source code
348
- *
349
- * @remarks
350
- * This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
351
- *
352
- * @param inlineConfig - The inline configuration for the deploy command
353
- */
354
- async deploy(inlineConfig = { command: "deploy" }) {
355
- this.context.info("🚀 Deploying the Powerlines project");
356
- await this.prepare(inlineConfig);
357
- await this.#executeEnvironments(async (context) => {
358
- await this.callHook("deploy", { environment: context });
359
- });
360
- this.context.debug("✔ Powerlines deploy completed successfully");
361
- }
362
- /**
363
- * Finalization process
364
- *
365
- * @remarks
366
- * This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
367
- *
368
- * @returns A promise that resolves when the finalization process has completed
369
- */
370
- async finalize() {
371
- this.context.info("🏁 Powerlines finalization processes started");
372
- await this.#executeEnvironments(async (context) => {
373
- await this.callHook("finalize", { environment: context });
374
- await context.fs.dispose();
375
- });
376
- this.context.debug("✔ Powerlines finalization completed successfully");
377
- }
378
- /**
379
- * Invokes the configured plugin hooks
380
- *
381
- * @remarks
382
- * By default, it will call the `"pre"`, `"normal"`, and `"post"` ordered hooks in sequence
383
- *
384
- * @param hook - The hook to call
385
- * @param options - The options to provide to the hook
386
- * @param args - The arguments to pass to the hook
387
- * @returns The result of the hook call
388
- */
389
- async callHook(hook, options, ...args) {
390
- return require_hooks.callHook((0, __stryke_type_checks_is_set_object.isSetObject)(options?.environment) ? options.environment : await this.#context.getEnvironment(options?.environment), hook, {
391
- sequential: true,
392
- ...options
393
- }, ...args);
394
- }
395
- /**
396
- * Dispose of the Powerlines API instance
397
- *
398
- * @remarks
399
- * This method will finalize the Powerlines API instance, cleaning up any resources used.
400
- */
401
- async [Symbol.asyncDispose]() {
402
- await this.finalize();
403
- }
404
- async #handleBuild(context) {
405
- await this.callHook("build", {
406
- environment: context,
407
- order: "pre"
408
- });
409
- context.debug("Formatting the generated entry files before the build process starts.");
410
- await require_format.formatFolder(context, context.entryPath);
411
- await this.callHook("build", {
412
- environment: context,
413
- order: "normal"
414
- });
415
- if (context.config.output.buildPath !== context.config.output.outputPath) {
416
- const sourcePath = (0, __stryke_path_append.appendPath)(context.config.output.buildPath, context.workspaceConfig.workspaceRoot);
417
- const destinationPath = (0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_append.appendPath)(context.config.output.outputPath, context.workspaceConfig.workspaceRoot), "dist");
418
- if (context.fs.existsSync(sourcePath) && sourcePath !== destinationPath) {
419
- context.debug(`Copying build output files from project's build directory (${context.config.output.buildPath}) to the workspace's output directory (${context.config.output.outputPath}).`);
420
- await context.fs.copy(sourcePath, destinationPath);
421
- }
422
- }
423
- await Promise.all(context.config.output.assets.map(async (asset) => {
424
- context.trace(`Copying asset(s): ${chalk.default.redBright(context.workspaceConfig.workspaceRoot === asset.input ? asset.glob : (0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_replace.replacePath)(asset.input, context.workspaceConfig.workspaceRoot), asset.glob))} -> ${chalk.default.greenBright((0, __stryke_path_join_paths.joinPaths)((0, __stryke_path_replace.replacePath)(asset.output, context.workspaceConfig.workspaceRoot), asset.glob))} ${Array.isArray(asset.ignore) && asset.ignore.length > 0 ? ` (ignoring: ${asset.ignore.map((i) => chalk.default.yellowBright(i)).join(", ")})` : ""}`);
425
- await context.fs.copy(asset, asset.output);
426
- }));
427
- await this.callHook("build", {
428
- environment: context,
429
- order: "post"
430
- });
431
- }
432
- /**
433
- * Get the configured environments
434
- *
435
- * @returns The configured environments
436
- */
437
- async #getEnvironments() {
438
- if (!this.context.config.environments || Object.keys(this.context.config.environments).length <= 1) {
439
- this.context.debug("No environments are configured for this Powerlines project. Using the default environment.");
440
- return [await this.context.getEnvironment()];
441
- }
442
- this.context.debug(`Found ${Object.keys(this.context.config.environments).length} configured environment(s) for this Powerlines project.`);
443
- return (await Promise.all(Object.entries(this.context.config.environments).map(async ([name, config]) => {
444
- if (!await this.context.getEnvironmentSafe(name)) {
445
- const resolvedEnvironment = await this.callHook("configEnvironment", { environment: name }, name, config);
446
- if (resolvedEnvironment) this.context.environments[name] = await this.context.in(resolvedEnvironment);
447
- }
448
- return this.context.environments[name];
449
- }))).filter((context) => (0, __stryke_type_checks_is_set.isSet)(context));
450
- }
451
- /**
452
- * Execute a handler function for each environment
453
- *
454
- * @param handle - The handler function to execute for each environment
455
- */
456
- async #executeEnvironments(handle) {
457
- await Promise.all((await this.#getEnvironments()).map(async (context) => {
458
- return Promise.resolve(handle(context));
459
- }));
460
- }
461
- /**
462
- * Add a Powerlines plugin used in the build process
463
- *
464
- * @param config - The import path of the plugin to add
465
- */
466
- async #addPlugin(config) {
467
- if (config) {
468
- const result = await this.#initPlugin(config);
469
- if (!result) return;
470
- for (const plugin of result) {
471
- this.context.debug(`Successfully initialized the ${chalk.default.bold.cyanBright(plugin.name)} plugin`);
472
- await this.context.addPlugin(plugin);
473
- }
474
- }
475
- }
476
- /**
477
- * Initialize a Powerlines plugin
478
- *
479
- * @param config - The configuration for the plugin
480
- * @returns The initialized plugin instance, or null if the plugin was a duplicate
481
- * @throws Will throw an error if the plugin cannot be found or is invalid
482
- */
483
- async #initPlugin(config) {
484
- let awaited = config;
485
- if ((0, __stryke_type_checks_is_promise.isPromiseLike)(config)) awaited = await Promise.resolve(config);
486
- if (!require_helpers.isPluginConfig(awaited)) {
487
- const invalid = require_helpers.findInvalidPluginConfig(awaited);
488
- 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`);
489
- }
490
- let plugins;
491
- if (require_helpers.isPlugin(awaited)) plugins = [awaited];
492
- else if ((0, __stryke_type_checks_is_function.isFunction)(awaited)) plugins = (0, __stryke_convert_to_array.toArray)(await Promise.resolve(awaited()));
493
- else if ((0, __stryke_type_checks_is_string.isString)(awaited)) {
494
- const resolved = await this.#resolvePlugin(awaited);
495
- if ((0, __stryke_type_checks_is_function.isFunction)(resolved)) plugins = (0, __stryke_convert_to_array.toArray)(await Promise.resolve(resolved()));
496
- else plugins = (0, __stryke_convert_to_array.toArray)(resolved);
497
- } else if (Array.isArray(awaited) && awaited.every(require_helpers.isPlugin)) plugins = awaited;
498
- else if (Array.isArray(awaited) && awaited.every(require_helpers.isPluginConfig)) {
499
- plugins = [];
500
- for (const pluginConfig of awaited) {
501
- const initialized = await this.#initPlugin(pluginConfig);
502
- if (initialized) plugins.push(...initialized);
503
- }
504
- } else if (require_helpers.isPluginConfigTuple(awaited) || require_helpers.isPluginConfigObject(awaited)) {
505
- let pluginConfig;
506
- let pluginOptions;
507
- if (require_helpers.isPluginConfigTuple(awaited)) {
508
- pluginConfig = awaited[0];
509
- pluginOptions = awaited?.length === 2 ? awaited[1] : void 0;
510
- } else {
511
- pluginConfig = awaited.plugin;
512
- pluginOptions = awaited.options;
513
- }
514
- if ((0, __stryke_type_checks_is_set_string.isSetString)(pluginConfig)) {
515
- const resolved = await this.#resolvePlugin(pluginConfig);
516
- if ((0, __stryke_type_checks_is_function.isFunction)(resolved)) plugins = (0, __stryke_convert_to_array.toArray)(await Promise.resolve(pluginOptions ? resolved(pluginOptions) : resolved()));
517
- else plugins = (0, __stryke_convert_to_array.toArray)(resolved);
518
- } else if ((0, __stryke_type_checks_is_function.isFunction)(pluginConfig)) plugins = (0, __stryke_convert_to_array.toArray)(await Promise.resolve(pluginConfig(pluginOptions)));
519
- else if (Array.isArray(pluginConfig) && pluginConfig.every(require_helpers.isPlugin)) plugins = pluginConfig;
520
- else if (require_helpers.isPlugin(pluginConfig)) plugins = (0, __stryke_convert_to_array.toArray)(pluginConfig);
521
- }
522
- if (!plugins) throw new Error(`The plugin configuration ${JSON.stringify(awaited)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
523
- if (plugins.length > 0 && !plugins.every(require_helpers.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.`);
524
- const result = [];
525
- for (const plugin of plugins) if (require_helpers.checkDedupe(plugin, this.context.plugins)) this.context.trace(`Duplicate ${chalk.default.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`);
526
- else {
527
- result.push(plugin);
528
- this.context.trace(`Initializing the ${chalk.default.bold.cyanBright(plugin.name)} plugin...`);
529
- }
530
- return result;
531
- }
532
- async #resolvePlugin(pluginPath) {
533
- if (pluginPath.startsWith("@") && pluginPath.split("/").filter(Boolean).length > 2) {
534
- const splits = pluginPath.split("/").filter(Boolean);
535
- pluginPath = `${splits[0]}/${splits[1]}`;
536
- }
537
- const isInstalled = (0, __stryke_fs_package_fns.isPackageExists)(pluginPath, { paths: [this.context.workspaceConfig.workspaceRoot, this.context.config.projectRoot] });
538
- if (!isInstalled && this.context.config.autoInstall) {
539
- this.#context.warn(`The plugin package "${pluginPath}" is not installed. It will be installed automatically.`);
540
- const result = await (0, __stryke_fs_install.install)(pluginPath, { cwd: this.context.config.projectRoot });
541
- if ((0, __stryke_type_checks_is_number.isNumber)(result.exitCode) && result.exitCode > 0) {
542
- this.#context.error(result.stderr);
543
- throw new Error(`An error occurred while installing the build plugin package "${pluginPath}" `);
544
- }
545
- }
546
- try {
547
- const module$1 = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve((0, __stryke_path_join_paths.joinPaths)(pluginPath, "plugin")));
548
- const result = module$1.plugin ?? module$1.default;
549
- if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
550
- return result;
551
- } catch (error) {
552
- try {
553
- const module$1 = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(pluginPath));
554
- const result = module$1.plugin ?? module$1.default;
555
- if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
556
- return result;
557
- } catch {
558
- if (!isInstalled) throw new Error(`The plugin package "${pluginPath}" is not installed. Please install the package using the command: "npm install ${pluginPath} --save-dev"`);
559
- else throw new Error(`An error occurred while importing the build plugin package "${pluginPath}":
560
- ${(0, __stryke_type_checks_is_error.isError)(error) ? error.message : String(error)}
561
-
562
- 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\`.`);
563
- }
564
- }
565
- }
566
- };
567
-
568
- //#endregion