@powerlines/engine 0.45.3 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/_internal/worker.cjs +844 -789
  2. package/dist/_internal/worker.mjs +847 -792
  3. package/dist/_internal/worker.mjs.map +1 -1
  4. package/dist/api.cjs +292 -323
  5. package/dist/api.d.cts +44 -11
  6. package/dist/api.d.cts.map +1 -1
  7. package/dist/api.d.mts +44 -11
  8. package/dist/api.d.mts.map +1 -1
  9. package/dist/api.mjs +292 -323
  10. package/dist/api.mjs.map +1 -1
  11. package/dist/{base-context-Byizvf4F.cjs → base-context-BCG0xN2e.cjs} +70 -64
  12. package/dist/{base-context-BSAC5sO9.mjs → base-context-Cmo6TTh7.mjs} +73 -67
  13. package/dist/base-context-Cmo6TTh7.mjs.map +1 -0
  14. package/dist/context/index.cjs +3 -3
  15. package/dist/context/index.d.cts +44 -617
  16. package/dist/context/index.d.cts.map +1 -1
  17. package/dist/context/index.d.mts +44 -617
  18. package/dist/context/index.d.mts.map +1 -1
  19. package/dist/context/index.mjs +3 -3
  20. package/dist/engine-context-BjFMVQEE.mjs +86 -0
  21. package/dist/engine-context-BjFMVQEE.mjs.map +1 -0
  22. package/dist/engine-context-DOsGtgD9.cjs +91 -0
  23. package/dist/execution-context-BdZt7wWa.d.mts +631 -0
  24. package/dist/execution-context-BdZt7wWa.d.mts.map +1 -0
  25. package/dist/execution-context-CU6iNchD.d.cts +631 -0
  26. package/dist/execution-context-CU6iNchD.d.cts.map +1 -0
  27. package/dist/{execution-context-Bkxp1fML.mjs → execution-context-Cp32TarF.mjs} +421 -364
  28. package/dist/execution-context-Cp32TarF.mjs.map +1 -0
  29. package/dist/{execution-context-BYGFYty0.cjs → execution-context-DgqxcDDx.cjs} +419 -362
  30. package/dist/index.cjs +15 -16
  31. package/dist/index.d.cts +3 -3
  32. package/dist/index.d.cts.map +1 -1
  33. package/dist/index.d.mts +3 -3
  34. package/dist/index.d.mts.map +1 -1
  35. package/dist/index.mjs +15 -16
  36. package/dist/index.mjs.map +1 -1
  37. package/dist/{tsconfig-QMSxSwBD.cjs → tsconfig-BUDqmOaT.cjs} +13 -13
  38. package/dist/{tsconfig-CI6bla4E.mjs → tsconfig-MeFEs21S.mjs} +14 -14
  39. package/dist/tsconfig-MeFEs21S.mjs.map +1 -0
  40. package/dist/typescript/index.cjs +1 -1
  41. package/dist/typescript/index.d.cts +6 -6
  42. package/dist/typescript/index.d.cts.map +1 -1
  43. package/dist/typescript/index.d.mts +6 -6
  44. package/dist/typescript/index.d.mts.map +1 -1
  45. package/dist/typescript/index.mjs +1 -1
  46. package/package.json +17 -17
  47. package/dist/base-context-BSAC5sO9.mjs.map +0 -1
  48. package/dist/engine-context-CI_0NWIk.cjs +0 -73
  49. package/dist/engine-context-_RMFwG4J.mjs +0 -68
  50. package/dist/engine-context-_RMFwG4J.mjs.map +0 -1
  51. package/dist/execution-context-Bkxp1fML.mjs.map +0 -1
  52. package/dist/tsconfig-CI6bla4E.mjs.map +0 -1
package/dist/api.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_chunk = require('./chunk-C0xms8kb.cjs');
3
- const require_execution_context = require('./execution-context-BYGFYty0.cjs');
4
- const require_tsconfig = require('./tsconfig-QMSxSwBD.cjs');
3
+ const require_execution_context = require('./execution-context-DgqxcDDx.cjs');
4
+ const require_tsconfig = require('./tsconfig-BUDqmOaT.cjs');
5
5
  const require_ts_morph = require('./ts-morph-BaLPVAdB.cjs');
6
6
  let _stryke_convert_to_array = require("@stryke/convert/to-array");
7
7
  let _stryke_fs_resolve = require("@stryke/fs/resolve");
@@ -19,7 +19,6 @@ chalk = require_chunk.__toESM(chalk, 1);
19
19
  let defu = require("defu");
20
20
  defu = require_chunk.__toESM(defu, 1);
21
21
  let _stryke_path_join_paths = require("@stryke/path/join-paths");
22
- let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
23
22
  let _powerlines_core_lib_utilities_file_header = require("@powerlines/core/lib/utilities/file-header");
24
23
  let _powerlines_core_lib_utilities_format = require("@powerlines/core/lib/utilities/format");
25
24
  let _storm_software_config_tools_logger_console = require("@storm-software/config-tools/logger/console");
@@ -33,6 +32,7 @@ let _stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
33
32
  let _stryke_helpers_omit = require("@stryke/helpers/omit");
34
33
  let _stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
35
34
  let _stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
35
+ let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
36
36
  let _stryke_type_checks_is_error = require("@stryke/type-checks/is-error");
37
37
  let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
38
38
  let _stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
@@ -363,11 +363,11 @@ async function installDependencies(context) {
363
363
  //#endregion
364
364
  //#region src/_internal/helpers/resolve-tsconfig.ts
365
365
  function getTsconfigDtsPath(context) {
366
- return (0, _stryke_path_join_paths.joinPaths)((0, _stryke_path_file_path_fns.relativePath)((0, _stryke_path_join_paths.joinPaths)(context.options.cwd, context.options.root), (0, _stryke_path_file_path_fns.findFilePath)(context.typesPath)), (0, _stryke_path_file_path_fns.findFileName)(context.typesPath));
366
+ return (0, _stryke_path_join_paths.joinPaths)((0, _stryke_path_file_path_fns.relativePath)((0, _stryke_path_join_paths.joinPaths)(context.config.cwd, context.config.root), (0, _stryke_path_file_path_fns.findFilePath)(context.typesPath)), (0, _stryke_path_file_path_fns.findFileName)(context.typesPath));
367
367
  }
368
368
  async function resolveTsconfigChanges(context) {
369
- const tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.options.cwd, context.options.root, context.config.tsconfig, context.config.tsconfigRaw);
370
- const tsconfigJson = await (0, _stryke_fs_json.readJsonFile)(require_tsconfig.getTsconfigFilePath(context.options.cwd, context.options.root, context.config.tsconfig));
369
+ const tsconfig = require_tsconfig.getParsedTypeScriptConfig(context.config.cwd, context.config.root, context.config.tsconfig, context.config.tsconfigRaw);
370
+ const tsconfigJson = await (0, _stryke_fs_json.readJsonFile)(require_tsconfig.getTsconfigFilePath(context.config.cwd, context.config.root, context.config.tsconfig));
371
371
  tsconfigJson.compilerOptions ??= {};
372
372
  if (context.config.output.dts !== false) {
373
373
  const dtsRelativePath = getTsconfigDtsPath(context);
@@ -457,249 +457,15 @@ var PowerlinesExecution = class PowerlinesExecution {
457
457
  * The Powerlines context
458
458
  */
459
459
  #context;
460
- async #handleBuild(context) {
461
- await this.callHook("build", {
462
- environment: context,
463
- order: "pre"
464
- });
465
- context.debug("Formatting the generated entry files before the build process starts.");
466
- await (0, _powerlines_core_lib_utilities_format.formatFolder)(context, context.entryPath);
467
- await this.callHook("build", {
468
- environment: context,
469
- order: "normal"
470
- });
471
- if (context.config.output.copy) {
472
- context.debug("Copying project's files from build output directory.");
473
- const destinationPath = (0, _stryke_path_is_parent_path.isParentPath)((0, _stryke_path_append.appendPath)(context.config.output.path, context.config.cwd), (0, _stryke_path_append.appendPath)(context.config.root, context.config.cwd)) ? (0, _stryke_path_join_paths.joinPaths)(context.config.output.copy.path, (0, _stryke_path_file_path_fns.relativePath)((0, _stryke_path_append.appendPath)(context.config.root, context.config.cwd), (0, _stryke_path_append.appendPath)(context.config.output.path, context.config.cwd))) : (0, _stryke_path_join_paths.joinPaths)(context.config.output.copy.path, "dist");
474
- const sourcePath = context.config.output.path;
475
- if ((0, _stryke_fs_exists.existsSync)(sourcePath) && sourcePath !== destinationPath) {
476
- context.debug(`Copying files from project's build output directory (${context.config.output.path}) to the project's copy/publish directory (${destinationPath}).`);
477
- await (0, _stryke_fs_copy_file.copyFiles)(sourcePath, destinationPath);
478
- } else context.warn(`The source path for the copy operation ${!(0, _stryke_fs_exists.existsSync)(sourcePath) ? "does not exist" : "is the same as the destination path"}. Source: ${sourcePath}, Destination: ${destinationPath}. Skipping copying of build output files.`);
479
- if (context.config.output.copy.assets && Array.isArray(context.config.output.copy.assets)) await Promise.all(context.config.output.copy.assets.map(async (asset) => {
480
- context.trace(`Copying asset(s): ${chalk.default.redBright(context.config.cwd === asset.input ? asset.glob : (0, _stryke_path_append.appendPath)(asset.glob, (0, _stryke_path_replace.replacePath)(asset.input, context.config.cwd)))} -> ${chalk.default.greenBright((0, _stryke_path_append.appendPath)(asset.glob, (0, _stryke_path_replace.replacePath)(asset.output, context.config.cwd)))} ${Array.isArray(asset.ignore) && asset.ignore.length > 0 ? ` (ignoring: ${asset.ignore.map((i) => chalk.default.yellowBright(i)).join(", ")})` : ""}`);
481
- await context.fs.copy(asset, asset.output);
482
- }));
483
- } else context.debug("No copy configuration found for the project output. Skipping the copying of build output files.");
484
- await this.callHook("build", {
485
- environment: context,
486
- order: "post"
487
- });
488
- }
489
- /**
490
- * Get the configured environments
491
- *
492
- * @returns The configured environments
493
- */
494
- async #getEnvironments() {
495
- if (!this.context.config.environments || Object.keys(this.context.config.environments).length <= 1) {
496
- this.context.debug("No environments are configured for this Powerlines project. Using the default environment.");
497
- return [await this.context.getEnvironment()];
498
- }
499
- this.context.debug(`Found ${Object.keys(this.context.config.environments).length} configured environment(s) for this Powerlines project.`);
500
- return (await Promise.all(Object.entries(this.context.config.environments).map(async ([name, config]) => {
501
- if (!await this.context.getEnvironmentSafe(name)) {
502
- const resolvedEnvironment = await this.callHook("configEnvironment", { environment: name }, name, config);
503
- if (resolvedEnvironment) this.context.environments[name] = await this.context.in(resolvedEnvironment);
504
- }
505
- return this.context.environments[name];
506
- }))).filter((context) => (0, _stryke_type_checks_is_set.isSet)(context));
507
- }
508
- /**
509
- * Execute a handler function for each environment
510
- *
511
- * @param handle - The handler function to execute for each environment
512
- */
513
- async #executeEnvironments(handle) {
514
- await Promise.all((await this.#getEnvironments()).map(async (context) => {
515
- return Promise.resolve(handle(context));
516
- }));
517
- }
518
- /**
519
- * Initialize a Powerlines plugin
520
- *
521
- * @param config - The configuration for the plugin
522
- * @returns The initialized plugin instance, or null if the plugin was a duplicate
523
- * @throws Will throw an error if the plugin cannot be found or is invalid
524
- */
525
- async #initPlugin(config) {
526
- let awaited = config;
527
- if ((0, _stryke_type_checks_is_promise.isPromiseLike)(config)) awaited = await Promise.resolve(config);
528
- if (!(0, _powerlines_core_plugin_utils.isPluginConfig)(awaited)) {
529
- const invalid = (0, _powerlines_core_plugin_utils.findInvalidPluginConfig)(awaited);
530
- 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`);
531
- }
532
- let plugins;
533
- if ((0, _powerlines_core_plugin_utils.isPlugin)(awaited)) plugins = [awaited];
534
- else if ((0, _stryke_type_checks_is_function.isFunction)(awaited)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(awaited()));
535
- else if ((0, _stryke_type_checks_is_string.isString)(awaited)) {
536
- const resolved = await this.#resolvePlugin(awaited);
537
- if ((0, _stryke_type_checks_is_function.isFunction)(resolved)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(resolved()));
538
- else plugins = (0, _stryke_convert_to_array.toArray)(resolved);
539
- } else if (Array.isArray(awaited) && awaited.every(_powerlines_core_plugin_utils.isPlugin)) plugins = awaited;
540
- else if (Array.isArray(awaited) && awaited.every(_powerlines_core_plugin_utils.isPluginConfig)) {
541
- plugins = [];
542
- for (const pluginConfig of awaited) {
543
- const initialized = await this.#initPlugin(pluginConfig);
544
- if (initialized) plugins.push(...initialized);
545
- }
546
- } else if ((0, _powerlines_core_plugin_utils.isPluginConfigTuple)(awaited) || (0, _powerlines_core_plugin_utils.isPluginConfigObject)(awaited)) {
547
- let pluginConfig;
548
- let pluginOptions;
549
- if ((0, _powerlines_core_plugin_utils.isPluginConfigTuple)(awaited)) {
550
- pluginConfig = awaited[0];
551
- pluginOptions = awaited?.length === 2 ? awaited[1] : void 0;
552
- } else {
553
- pluginConfig = awaited.plugin;
554
- pluginOptions = awaited.options;
555
- }
556
- if ((0, _stryke_type_checks_is_set_string.isSetString)(pluginConfig)) {
557
- const resolved = await this.#resolvePlugin(pluginConfig);
558
- if ((0, _stryke_type_checks_is_function.isFunction)(resolved)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(pluginOptions ? resolved(pluginOptions) : resolved()));
559
- else plugins = (0, _stryke_convert_to_array.toArray)(resolved);
560
- } else if ((0, _stryke_type_checks_is_function.isFunction)(pluginConfig)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(pluginConfig(pluginOptions)));
561
- else if (Array.isArray(pluginConfig) && pluginConfig.every(_powerlines_core_plugin_utils.isPlugin)) plugins = pluginConfig;
562
- else if ((0, _powerlines_core_plugin_utils.isPlugin)(pluginConfig)) plugins = (0, _stryke_convert_to_array.toArray)(pluginConfig);
563
- }
564
- if (!plugins) throw new Error(`The plugin configuration ${JSON.stringify(awaited)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
565
- if (plugins.length > 0 && !plugins.every(_powerlines_core_plugin_utils.isPlugin)) throw new Error(`The plugin option ${JSON.stringify(plugins)} does not export a valid module. This configuration must point to a valid Powerlines plugin module.`);
566
- const result = [];
567
- for (const plugin of plugins) if ((0, _powerlines_core_plugin_utils.isDuplicate)(plugin, this.context.plugins)) this.context.trace(`Duplicate ${chalk.default.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`);
568
- else {
569
- result.push(plugin);
570
- this.context.trace(`Initializing the ${chalk.default.bold.cyanBright(plugin.name)} plugin...`);
571
- }
572
- return result;
573
- }
574
- async #resolvePlugin(pluginPath) {
575
- if (pluginPath.startsWith("@") && pluginPath.split("/").filter(Boolean).length > 2) {
576
- const splits = pluginPath.split("/").filter(Boolean);
577
- pluginPath = `${splits[0]}/${splits[1]}`;
578
- }
579
- const isInstalled = (0, _stryke_fs_package_fns.isPackageExists)(pluginPath, { paths: [this.context.config.cwd, this.context.config.root] });
580
- if (!isInstalled && this.context.config.autoInstall) {
581
- this.#context.warn(`The plugin package "${pluginPath}" is not installed. It will be installed automatically.`);
582
- const result = await (0, _stryke_fs_install.install)(pluginPath, { cwd: this.context.config.root });
583
- if ((0, _stryke_type_checks_is_number.isNumber)(result.exitCode) && result.exitCode > 0) {
584
- this.#context.error(result.stderr);
585
- throw new Error(`An error occurred while installing the build plugin package "${pluginPath}" `);
586
- }
587
- }
588
- try {
589
- const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve((0, _stryke_path_join_paths.joinPaths)(pluginPath, "plugin")));
590
- const result = module.plugin ?? module.default;
591
- if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
592
- return result;
593
- } catch (error) {
594
- try {
595
- const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(pluginPath));
596
- const result = module.plugin ?? module.default;
597
- if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
598
- return result;
599
- } catch {
600
- if (!isInstalled) throw new Error(`The plugin package "${pluginPath}" is not installed. Please install the package using the command: "npm install ${pluginPath} --save-dev"`);
601
- else throw new Error(`An error occurred while importing the build plugin package "${pluginPath}":
602
- ${(0, _stryke_type_checks_is_error.isError)(error) ? error.message : String(error)}
603
-
604
- 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\`.`);
605
- }
606
- }
607
- }
608
- /**
609
- * Generate the Powerlines TypeScript declaration file
610
- *
611
- * @remarks
612
- * This method will generate the TypeScript declaration file for the Powerlines project, including any types provided by plugins.
613
- *
614
- * @param context - The environment context to use for generating the TypeScript declaration file
615
- * @returns A promise that resolves when the TypeScript declaration file has been generated
616
- */
617
- async #types(context) {
618
- context.debug(`Preparing the TypeScript definitions for the Powerlines project.`);
619
- if (context.fs.existsSync(context.typesPath)) await context.fs.remove(context.typesPath);
620
- if (!await (0, _stryke_fs_resolve.resolvePackage)("typescript")) throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
621
- context.debug("Running TypeScript compiler for built-in runtime module files.");
622
- let { code, directives } = await emitBuiltinTypes(context, (await context.getBuiltins()).reduce((ret, builtin) => {
623
- const formatted = (0, _stryke_path_replace.replacePath)(builtin.path, context.config.cwd);
624
- if (!ret.includes(formatted)) ret.push(formatted);
625
- return ret;
626
- }, []));
627
- context.debug(`Generating TypeScript declaration file ${context.typesPath}.`);
628
- const merge = async (currentResult, previousResult) => {
629
- if (!(0, _stryke_type_checks_is_set_string.isSetString)(currentResult) && !(0, _stryke_type_checks_is_set_object.isSetObject)(currentResult) && !(0, _stryke_type_checks_is_set_string.isSetString)(previousResult) && !(0, _stryke_type_checks_is_set_object.isSetObject)(previousResult)) return {
630
- code,
631
- directives
632
- };
633
- const previous = (await (0, _powerlines_core_lib_utilities_format.format)(context, context.typesPath, (0, _stryke_type_checks_is_set_string.isSetString)(previousResult) ? previousResult : (0, _stryke_type_checks_is_set_object.isSetObject)(previousResult) ? previousResult.code : "")).trim().replace(code, "").trim();
634
- const current = (await (0, _powerlines_core_lib_utilities_format.format)(context, context.typesPath, (0, _stryke_type_checks_is_set_string.isSetString)(currentResult) ? currentResult : (0, _stryke_type_checks_is_set_object.isSetObject)(currentResult) ? currentResult.code : "")).trim().replace(previous, "").trim().replace(code, "").trim();
635
- return {
636
- directives: [...(0, _stryke_type_checks_is_set_object.isSetObject)(currentResult) && currentResult.directives ? currentResult.directives : [], ...(0, _stryke_type_checks_is_set_object.isSetObject)(previousResult) && previousResult.directives ? previousResult.directives : []],
637
- code: await (0, _powerlines_core_lib_utilities_format.format)(context, context.typesPath, `${!previous.includes((0, _powerlines_core_lib_utilities_file_header.getTypescriptFileHeader)(context)) && !current.includes((0, _powerlines_core_lib_utilities_file_header.getTypescriptFileHeader)(context)) ? `${code}\n` : ""}${previous}\n${current}`.trim())
638
- };
639
- };
640
- const asNextParam = (previousResult) => (0, _stryke_type_checks_is_object.isObject)(previousResult) ? previousResult.code : previousResult;
641
- let result = await this.callHook("types", {
642
- environment: context,
643
- sequential: true,
644
- order: "pre",
645
- result: "merge",
646
- merge,
647
- asNextParam
648
- }, code);
649
- if (result) {
650
- if ((0, _stryke_type_checks_is_set_object.isSetObject)(result)) {
651
- code = result.code;
652
- if (Array.isArray(result.directives) && result.directives.length > 0) directives = (0, _stryke_helpers_get_unique.getUnique)([...directives, ...result.directives]).filter(Boolean);
653
- } else if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) code = result;
654
- }
655
- result = await this.callHook("types", {
656
- environment: context,
657
- sequential: true,
658
- order: "normal",
659
- result: "merge",
660
- merge,
661
- asNextParam
662
- }, code);
663
- if (result) {
664
- if ((0, _stryke_type_checks_is_set_object.isSetObject)(result)) {
665
- code = result.code;
666
- if (Array.isArray(result.directives) && result.directives.length > 0) directives = (0, _stryke_helpers_get_unique.getUnique)([...directives, ...result.directives]).filter(Boolean);
667
- } else if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) code = result;
668
- }
669
- result = await this.callHook("types", {
670
- environment: context,
671
- sequential: true,
672
- order: "post",
673
- result: "merge",
674
- merge,
675
- asNextParam
676
- }, code);
677
- if (result) {
678
- if ((0, _stryke_type_checks_is_set_object.isSetObject)(result)) {
679
- code = result.code;
680
- if (Array.isArray(result.directives) && result.directives.length > 0) directives = (0, _stryke_helpers_get_unique.getUnique)([...directives, ...result.directives]).filter(Boolean);
681
- } else if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) code = result;
682
- }
683
- if ((0, _stryke_type_checks_is_set_string.isSetString)(code?.trim()) || directives.length > 0) await context.fs.write(context.typesPath, `${directives.length > 0 ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
684
-
685
- ` : ""}${(0, _powerlines_core_lib_utilities_file_header.getTypescriptFileHeader)(context, {
686
- directive: null,
687
- prettierIgnore: false
688
- })}
689
-
690
- ${formatTypes(code)}
691
- `);
692
- }
693
460
  /**
694
461
  * Initialize a Powerlines API instance
695
462
  *
696
463
  * @param options - The options to initialize the API with
697
464
  * @returns A new instance of the Powerlines API
698
465
  */
699
- static async init(options, initialConfig) {
700
- const api = new PowerlinesExecution(await require_execution_context.PowerlinesExecutionContext.init(options, initialConfig ?? {}));
701
- api.#context.config.initialConfig = initialConfig ?? {};
702
- await api.setup();
466
+ static async from(options, initialConfig) {
467
+ const api = new PowerlinesExecution(await require_execution_context.PowerlinesExecutionContext.fromInitialConfig(options, initialConfig ?? {}));
468
+ await api.init();
703
469
  return api;
704
470
  }
705
471
  /**
@@ -709,37 +475,6 @@ ${formatTypes(code)}
709
475
  return this.#context;
710
476
  }
711
477
  /**
712
- * Initialize the execution API with the provided configuration options
713
- */
714
- async setup() {
715
- await this.#context.setup();
716
- this.#context.$$internal = {
717
- api: this,
718
- addPlugin: this.addPlugin.bind(this)
719
- };
720
- const timer = this.#context.timer("Initialization");
721
- for (const plugin of this.#context.config.plugins.flatMap((p) => (0, _stryke_convert_to_array.toArray)(p)) ?? []) await this.addPlugin(plugin);
722
- if (this.#context.plugins.length === 0) this.#context.warn({
723
- meta: { category: "plugins" },
724
- message: "No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended."
725
- });
726
- else this.#context.info({
727
- meta: { category: "plugins" },
728
- message: `Loaded ${this.#context.plugins.length} ${(0, _stryke_string_format_title_case.titleCase)(this.#context.config.framework)} plugin${this.#context.plugins.length > 1 ? "s" : ""}: \n${this.#context.plugins.map((plugin, index) => ` ${index + 1}. ${(0, _powerlines_core_plugin_utils_logging.colorText)(plugin.name)}`).join("\n")}`
729
- });
730
- const pluginConfig = await this.callHook("config", {
731
- environment: await this.#context.getEnvironment(),
732
- sequential: true,
733
- result: "merge",
734
- merge: require_execution_context.mergeConfigs
735
- });
736
- if (pluginConfig) {
737
- this.#context.config.pluginConfig = pluginConfig;
738
- await this.#context.setup();
739
- }
740
- timer();
741
- }
742
- /**
743
478
  * Generate the Powerlines typescript declaration file
744
479
  *
745
480
  * @remarks
@@ -750,9 +485,8 @@ ${formatTypes(code)}
750
485
  async types(inlineConfig = { command: "types" }) {
751
486
  this.context.debug(" Aggregating configuration options for the Powerlines project");
752
487
  inlineConfig.command ??= "types";
753
- this.context.config.inlineConfig = inlineConfig;
754
- await this.setup();
755
- await this.#executeEnvironments(async (context) => {
488
+ await this.context.setInlineConfig(inlineConfig);
489
+ await this.executeEnvironments(async (context) => {
756
490
  context.debug(`Initializing the processing options for the Powerlines project.`);
757
491
  await this.callHook("configResolved", {
758
492
  environment: context,
@@ -784,7 +518,7 @@ ${formatTypes(code)}
784
518
  context.info(`Running \`prepare\` command as the meta checksum has changed since the last run.`);
785
519
  await this.prepare((0, defu.default)({ output: { types: false } }, inlineConfig));
786
520
  }
787
- await this.#types(context);
521
+ await this.handleTypes(context);
788
522
  this.context.debug("Formatting files generated during the types step.");
789
523
  await (0, _powerlines_core_lib_utilities_format.format)(context, context.typesPath, await context.fs.read(context.typesPath) ?? "");
790
524
  await require_execution_context.writeMetaFile(context);
@@ -801,9 +535,8 @@ ${formatTypes(code)}
801
535
  */
802
536
  async prepare(inlineConfig = { command: "prepare" }) {
803
537
  inlineConfig.command ??= "prepare";
804
- this.context.config.inlineConfig = inlineConfig;
805
- await this.setup();
806
- await this.#executeEnvironments(async (context) => {
538
+ await this.context.setInlineConfig(inlineConfig);
539
+ await this.executeEnvironments(async (context) => {
807
540
  context.debug(`Initializing the processing options for the Powerlines project.`);
808
541
  await this.callHook("configResolved", {
809
542
  environment: context,
@@ -853,7 +586,7 @@ ${formatTypes(code)}
853
586
  environment: context,
854
587
  order: "post"
855
588
  });
856
- if (context.config.output.types !== false) await this.#types(context);
589
+ if (context.config.output.types !== false) await this.handleTypes(context);
857
590
  this.context.debug("Formatting files generated during the prepare step.");
858
591
  await Promise.all([(0, _powerlines_core_lib_utilities_format.formatFolder)(context, context.builtinsPath), (0, _powerlines_core_lib_utilities_format.formatFolder)(context, context.entryPath)]);
859
592
  await require_execution_context.writeMetaFile(context);
@@ -872,7 +605,7 @@ ${formatTypes(code)}
872
605
  async new(inlineConfig) {
873
606
  inlineConfig.command ??= "new";
874
607
  await this.prepare(inlineConfig);
875
- await this.#executeEnvironments(async (context) => {
608
+ await this.executeEnvironments(async (context) => {
876
609
  context.debug("Initializing the processing options for the Powerlines project.");
877
610
  await this.callHook("new", {
878
611
  environment: context,
@@ -921,7 +654,7 @@ ${formatTypes(code)}
921
654
  async clean(inlineConfig = { command: "clean" }) {
922
655
  inlineConfig.command ??= "clean";
923
656
  await this.prepare(inlineConfig);
924
- await this.#executeEnvironments(async (context) => {
657
+ await this.executeEnvironments(async (context) => {
925
658
  context.debug("Cleaning the project's dist and artifacts directories.");
926
659
  await context.fs.remove((0, _stryke_path_join_paths.joinPaths)(context.config.cwd, context.config.output.path));
927
660
  await context.fs.remove((0, _stryke_path_join_paths.joinPaths)(context.config.cwd, context.config.root, context.config.output.artifactsPath));
@@ -940,7 +673,7 @@ ${formatTypes(code)}
940
673
  async lint(inlineConfig = { command: "lint" }) {
941
674
  inlineConfig.command ??= "lint";
942
675
  await this.prepare(inlineConfig);
943
- await this.#executeEnvironments(async (context) => {
676
+ await this.executeEnvironments(async (context) => {
944
677
  await this.callHook("lint", {
945
678
  environment: context,
946
679
  sequential: false
@@ -956,7 +689,7 @@ ${formatTypes(code)}
956
689
  async test(inlineConfig = { command: "test" }) {
957
690
  inlineConfig.command ??= "test";
958
691
  await this.prepare(inlineConfig);
959
- await this.#executeEnvironments(async (context) => {
692
+ await this.executeEnvironments(async (context) => {
960
693
  await this.callHook("test", {
961
694
  environment: context,
962
695
  sequential: false
@@ -974,17 +707,15 @@ ${formatTypes(code)}
974
707
  */
975
708
  async build(inlineConfig = { command: "build" }) {
976
709
  inlineConfig.command ??= "build";
710
+ await this.context.setInlineConfig(inlineConfig);
977
711
  await this.context.generateChecksum();
978
712
  if (this.context.meta.checksum !== this.context.persistedMeta?.checksum || this.context.config.skipCache) {
979
713
  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.");
980
714
  await this.prepare(inlineConfig);
981
- } else {
982
- this.context.config.inlineConfig = inlineConfig;
983
- await this.context.setup();
984
715
  }
985
- if (this.context.config.singleBuild) await this.#handleBuild(await this.#context.toEnvironment());
986
- else await this.#executeEnvironments(async (context) => {
987
- await this.#handleBuild(context);
716
+ if (this.context.config.singleBuild) await this.handleBuild(await this.#context.toEnvironment());
717
+ else await this.executeEnvironments(async (context) => {
718
+ await this.handleBuild(context);
988
719
  });
989
720
  }
990
721
  /**
@@ -995,8 +726,9 @@ ${formatTypes(code)}
995
726
  */
996
727
  async docs(inlineConfig = { command: "docs" }) {
997
728
  inlineConfig.command ??= "docs";
729
+ await this.context.setInlineConfig(inlineConfig);
998
730
  await this.prepare(inlineConfig);
999
- await this.#executeEnvironments(async (context) => {
731
+ await this.executeEnvironments(async (context) => {
1000
732
  context.debug("Writing documentation for the Powerlines project artifacts.");
1001
733
  await this.callHook("docs", { environment: context });
1002
734
  });
@@ -1011,8 +743,9 @@ ${formatTypes(code)}
1011
743
  */
1012
744
  async deploy(inlineConfig = { command: "deploy" }) {
1013
745
  inlineConfig.command ??= "deploy";
746
+ await this.context.setInlineConfig(inlineConfig);
1014
747
  await this.prepare(inlineConfig);
1015
- await this.#executeEnvironments(async (context) => {
748
+ await this.executeEnvironments(async (context) => {
1016
749
  await this.callHook("deploy", { environment: context });
1017
750
  });
1018
751
  }
@@ -1025,7 +758,7 @@ ${formatTypes(code)}
1025
758
  * @returns A promise that resolves when the finalization process has completed
1026
759
  */
1027
760
  async finalize() {
1028
- await this.#executeEnvironments(async (context) => {
761
+ await this.executeEnvironments(async (context) => {
1029
762
  await this.callHook("finalize", { environment: context });
1030
763
  await context.fs.dispose();
1031
764
  if ((0, _stryke_fs_exists.existsSync)(context.cachePath) && !(await (0, _stryke_fs_list_files.listFiles)((0, _stryke_path_join_paths.joinPaths)(context.cachePath, "**/*")))?.length) await (0, _stryke_fs_helpers.removeDirectory)(context.cachePath);
@@ -1057,13 +790,40 @@ ${formatTypes(code)}
1057
790
  this.#context = context;
1058
791
  }
1059
792
  /**
793
+ * Initialize the execution API with the provided configuration options
794
+ */
795
+ async init() {
796
+ this.#context.$$internal = {
797
+ api: this,
798
+ addPlugin: this.addPlugin.bind(this)
799
+ };
800
+ const timer = this.#context.timer("Initialization");
801
+ for (const plugin of this.#context.config.plugins.flatMap((p) => (0, _stryke_convert_to_array.toArray)(p)) ?? []) await this.addPlugin(plugin);
802
+ if (this.#context.plugins.length === 0) this.#context.warn({
803
+ meta: { category: "plugins" },
804
+ message: "No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended."
805
+ });
806
+ else this.#context.info({
807
+ meta: { category: "plugins" },
808
+ message: `Loaded ${this.#context.plugins.length} ${(0, _stryke_string_format_title_case.titleCase)(this.#context.config.framework)} plugin${this.#context.plugins.length > 1 ? "s" : ""}: \n${this.#context.plugins.map((plugin, index) => ` ${index + 1}. ${(0, _powerlines_core_plugin_utils_logging.colorText)(plugin.name)}`).join("\n")}`
809
+ });
810
+ const pluginConfig = await this.callHook("config", {
811
+ environment: await this.#context.getEnvironment(),
812
+ sequential: true,
813
+ result: "merge",
814
+ merge: require_execution_context.mergeConfigs
815
+ });
816
+ if (pluginConfig) await this.context.setPluginConfig(pluginConfig);
817
+ timer();
818
+ }
819
+ /**
1060
820
  * Add a Powerlines plugin used in the build process
1061
821
  *
1062
822
  * @param config - The import path of the plugin to add
1063
823
  */
1064
824
  async addPlugin(config) {
1065
825
  if (config) {
1066
- const result = await this.#initPlugin(config);
826
+ const result = await this.initPlugin(config);
1067
827
  if (!result) return;
1068
828
  for (const plugin of result) {
1069
829
  this.context.debug({
@@ -1074,6 +834,239 @@ ${formatTypes(code)}
1074
834
  }
1075
835
  }
1076
836
  }
837
+ /**
838
+ * Get the configured environments
839
+ *
840
+ * @returns The configured environments
841
+ */
842
+ async getEnvironments() {
843
+ if (!this.context.config.environments || Object.keys(this.context.config.environments).length <= 1) {
844
+ this.context.debug("No environments are configured for this Powerlines project. Using the default environment.");
845
+ return [await this.context.getEnvironment()];
846
+ }
847
+ this.context.debug(`Found ${Object.keys(this.context.config.environments).length} configured environment(s) for this Powerlines project.`);
848
+ return (await Promise.all(Object.entries(this.context.config.environments).map(async ([name, config]) => {
849
+ if (!await this.context.getEnvironmentSafe(name)) {
850
+ const resolvedEnvironment = await this.callHook("configEnvironment", { environment: name }, name, config);
851
+ if (resolvedEnvironment) this.context.environments[name] = await this.context.createEnvironment(resolvedEnvironment);
852
+ }
853
+ return this.context.environments[name];
854
+ }))).filter((context) => (0, _stryke_type_checks_is_set.isSet)(context));
855
+ }
856
+ /**
857
+ * Execute a handler function for each environment
858
+ *
859
+ * @param handle - The handler function to execute for each environment
860
+ */
861
+ async executeEnvironments(handle) {
862
+ await Promise.all((await this.getEnvironments()).map(async (context) => {
863
+ return Promise.resolve(handle(context));
864
+ }));
865
+ }
866
+ /**
867
+ * Initialize a Powerlines plugin
868
+ *
869
+ * @param config - The configuration for the plugin
870
+ * @returns The initialized plugin instance, or null if the plugin was a duplicate
871
+ * @throws Will throw an error if the plugin cannot be found or is invalid
872
+ */
873
+ async initPlugin(config) {
874
+ let awaited = config;
875
+ if ((0, _stryke_type_checks_is_promise.isPromiseLike)(config)) awaited = await Promise.resolve(config);
876
+ if (!(0, _powerlines_core_plugin_utils.isPluginConfig)(awaited)) {
877
+ const invalid = (0, _powerlines_core_plugin_utils.findInvalidPluginConfig)(awaited);
878
+ 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`);
879
+ }
880
+ let plugins;
881
+ if ((0, _powerlines_core_plugin_utils.isPlugin)(awaited)) plugins = [awaited];
882
+ else if ((0, _stryke_type_checks_is_function.isFunction)(awaited)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(awaited()));
883
+ else if ((0, _stryke_type_checks_is_string.isString)(awaited)) {
884
+ const resolved = await this.resolvePlugin(awaited);
885
+ if ((0, _stryke_type_checks_is_function.isFunction)(resolved)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(resolved()));
886
+ else plugins = (0, _stryke_convert_to_array.toArray)(resolved);
887
+ } else if (Array.isArray(awaited) && awaited.every(_powerlines_core_plugin_utils.isPlugin)) plugins = awaited;
888
+ else if (Array.isArray(awaited) && awaited.every(_powerlines_core_plugin_utils.isPluginConfig)) {
889
+ plugins = [];
890
+ for (const pluginConfig of awaited) {
891
+ const initialized = await this.initPlugin(pluginConfig);
892
+ if (initialized) plugins.push(...initialized);
893
+ }
894
+ } else if ((0, _powerlines_core_plugin_utils.isPluginConfigTuple)(awaited) || (0, _powerlines_core_plugin_utils.isPluginConfigObject)(awaited)) {
895
+ let pluginConfig;
896
+ let pluginOptions;
897
+ if ((0, _powerlines_core_plugin_utils.isPluginConfigTuple)(awaited)) {
898
+ pluginConfig = awaited[0];
899
+ pluginOptions = awaited?.length === 2 ? awaited[1] : void 0;
900
+ } else {
901
+ pluginConfig = awaited.plugin;
902
+ pluginOptions = awaited.options;
903
+ }
904
+ if ((0, _stryke_type_checks_is_set_string.isSetString)(pluginConfig)) {
905
+ const resolved = await this.resolvePlugin(pluginConfig);
906
+ if ((0, _stryke_type_checks_is_function.isFunction)(resolved)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(pluginOptions ? resolved(pluginOptions) : resolved()));
907
+ else plugins = (0, _stryke_convert_to_array.toArray)(resolved);
908
+ } else if ((0, _stryke_type_checks_is_function.isFunction)(pluginConfig)) plugins = (0, _stryke_convert_to_array.toArray)(await Promise.resolve(pluginConfig(pluginOptions)));
909
+ else if (Array.isArray(pluginConfig) && pluginConfig.every(_powerlines_core_plugin_utils.isPlugin)) plugins = pluginConfig;
910
+ else if ((0, _powerlines_core_plugin_utils.isPlugin)(pluginConfig)) plugins = (0, _stryke_convert_to_array.toArray)(pluginConfig);
911
+ }
912
+ if (!plugins) throw new Error(`The plugin configuration ${JSON.stringify(awaited)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
913
+ if (plugins.length > 0 && !plugins.every(_powerlines_core_plugin_utils.isPlugin)) throw new Error(`The plugin option ${JSON.stringify(plugins)} does not export a valid module. This configuration must point to a valid Powerlines plugin module.`);
914
+ const result = [];
915
+ for (const plugin of plugins) if ((0, _powerlines_core_plugin_utils.isDuplicate)(plugin, this.context.plugins)) this.context.trace(`Duplicate ${chalk.default.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`);
916
+ else {
917
+ result.push(plugin);
918
+ this.context.trace(`Initializing the ${chalk.default.bold.cyanBright(plugin.name)} plugin...`);
919
+ }
920
+ return result;
921
+ }
922
+ async resolvePlugin(pluginPath) {
923
+ if (pluginPath.startsWith("@") && pluginPath.split("/").filter(Boolean).length > 2) {
924
+ const splits = pluginPath.split("/").filter(Boolean);
925
+ pluginPath = `${splits[0]}/${splits[1]}`;
926
+ }
927
+ const isInstalled = (0, _stryke_fs_package_fns.isPackageExists)(pluginPath, { paths: [this.context.config.cwd, this.context.config.root] });
928
+ if (!isInstalled && this.context.config.autoInstall) {
929
+ this.#context.warn(`The plugin package "${pluginPath}" is not installed. It will be installed automatically.`);
930
+ const result = await (0, _stryke_fs_install.install)(pluginPath, { cwd: this.context.config.root });
931
+ if ((0, _stryke_type_checks_is_number.isNumber)(result.exitCode) && result.exitCode > 0) {
932
+ this.#context.error(result.stderr);
933
+ throw new Error(`An error occurred while installing the build plugin package "${pluginPath}" `);
934
+ }
935
+ }
936
+ try {
937
+ const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve((0, _stryke_path_join_paths.joinPaths)(pluginPath, "plugin")));
938
+ const result = module.plugin ?? module.default;
939
+ if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
940
+ return result;
941
+ } catch (error) {
942
+ try {
943
+ const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(pluginPath));
944
+ const result = module.plugin ?? module.default;
945
+ if (!result) throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
946
+ return result;
947
+ } catch {
948
+ if (!isInstalled) throw new Error(`The plugin package "${pluginPath}" is not installed. Please install the package using the command: "npm install ${pluginPath} --save-dev"`);
949
+ else throw new Error(`An error occurred while importing the build plugin package "${pluginPath}":
950
+ ${(0, _stryke_type_checks_is_error.isError)(error) ? error.message : String(error)}
951
+
952
+ 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\`.`);
953
+ }
954
+ }
955
+ }
956
+ async handleBuild(context) {
957
+ await this.callHook("build", {
958
+ environment: context,
959
+ order: "pre"
960
+ });
961
+ context.debug("Formatting the generated entry files before the build process starts.");
962
+ await (0, _powerlines_core_lib_utilities_format.formatFolder)(context, context.entryPath);
963
+ await this.callHook("build", {
964
+ environment: context,
965
+ order: "normal"
966
+ });
967
+ if (context.config.output.copy) {
968
+ context.debug("Copying project's files from build output directory.");
969
+ const destinationPath = (0, _stryke_path_is_parent_path.isParentPath)((0, _stryke_path_append.appendPath)(context.config.output.path, context.config.cwd), (0, _stryke_path_append.appendPath)(context.config.root, context.config.cwd)) ? (0, _stryke_path_join_paths.joinPaths)(context.config.output.copy.path, (0, _stryke_path_file_path_fns.relativePath)((0, _stryke_path_append.appendPath)(context.config.root, context.config.cwd), (0, _stryke_path_append.appendPath)(context.config.output.path, context.config.cwd))) : (0, _stryke_path_join_paths.joinPaths)(context.config.output.copy.path, "dist");
970
+ const sourcePath = context.config.output.path;
971
+ if ((0, _stryke_fs_exists.existsSync)(sourcePath) && sourcePath !== destinationPath) {
972
+ context.debug(`Copying files from project's build output directory (${context.config.output.path}) to the project's copy/publish directory (${destinationPath}).`);
973
+ await (0, _stryke_fs_copy_file.copyFiles)(sourcePath, destinationPath);
974
+ } else context.warn(`The source path for the copy operation ${!(0, _stryke_fs_exists.existsSync)(sourcePath) ? "does not exist" : "is the same as the destination path"}. Source: ${sourcePath}, Destination: ${destinationPath}. Skipping copying of build output files.`);
975
+ if (context.config.output.copy.assets && Array.isArray(context.config.output.copy.assets)) await Promise.all(context.config.output.copy.assets.map(async (asset) => {
976
+ context.trace(`Copying asset(s): ${chalk.default.redBright(context.config.cwd === asset.input ? asset.glob : (0, _stryke_path_append.appendPath)(asset.glob, (0, _stryke_path_replace.replacePath)(asset.input, context.config.cwd)))} -> ${chalk.default.greenBright((0, _stryke_path_append.appendPath)(asset.glob, (0, _stryke_path_replace.replacePath)(asset.output, context.config.cwd)))} ${Array.isArray(asset.ignore) && asset.ignore.length > 0 ? ` (ignoring: ${asset.ignore.map((i) => chalk.default.yellowBright(i)).join(", ")})` : ""}`);
977
+ await context.fs.copy(asset, asset.output);
978
+ }));
979
+ } else context.debug("No copy configuration found for the project output. Skipping the copying of build output files.");
980
+ await this.callHook("build", {
981
+ environment: context,
982
+ order: "post"
983
+ });
984
+ }
985
+ /**
986
+ * Generate the Powerlines TypeScript declaration file
987
+ *
988
+ * @remarks
989
+ * This method will generate the TypeScript declaration file for the Powerlines project, including any types provided by plugins.
990
+ *
991
+ * @param context - The environment context to use for generating the TypeScript declaration file
992
+ * @returns A promise that resolves when the TypeScript declaration file has been generated
993
+ */
994
+ async handleTypes(context) {
995
+ context.debug(`Preparing the TypeScript definitions for the Powerlines project.`);
996
+ if (context.fs.existsSync(context.typesPath)) await context.fs.remove(context.typesPath);
997
+ if (!await (0, _stryke_fs_resolve.resolvePackage)("typescript")) throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
998
+ context.debug("Running TypeScript compiler for built-in runtime module files.");
999
+ let { code, directives } = await emitBuiltinTypes(context, (await context.getBuiltins()).reduce((ret, builtin) => {
1000
+ const formatted = (0, _stryke_path_replace.replacePath)(builtin.path, context.config.cwd);
1001
+ if (!ret.includes(formatted)) ret.push(formatted);
1002
+ return ret;
1003
+ }, []));
1004
+ context.debug(`Generating TypeScript declaration file ${context.typesPath}.`);
1005
+ const merge = async (currentResult, previousResult) => {
1006
+ if (!(0, _stryke_type_checks_is_set_string.isSetString)(currentResult) && !(0, _stryke_type_checks_is_set_object.isSetObject)(currentResult) && !(0, _stryke_type_checks_is_set_string.isSetString)(previousResult) && !(0, _stryke_type_checks_is_set_object.isSetObject)(previousResult)) return {
1007
+ code,
1008
+ directives
1009
+ };
1010
+ const previous = (await (0, _powerlines_core_lib_utilities_format.format)(context, context.typesPath, (0, _stryke_type_checks_is_set_string.isSetString)(previousResult) ? previousResult : (0, _stryke_type_checks_is_set_object.isSetObject)(previousResult) ? previousResult.code : "")).trim().replace(code, "").trim();
1011
+ const current = (await (0, _powerlines_core_lib_utilities_format.format)(context, context.typesPath, (0, _stryke_type_checks_is_set_string.isSetString)(currentResult) ? currentResult : (0, _stryke_type_checks_is_set_object.isSetObject)(currentResult) ? currentResult.code : "")).trim().replace(previous, "").trim().replace(code, "").trim();
1012
+ return {
1013
+ directives: [...(0, _stryke_type_checks_is_set_object.isSetObject)(currentResult) && currentResult.directives ? currentResult.directives : [], ...(0, _stryke_type_checks_is_set_object.isSetObject)(previousResult) && previousResult.directives ? previousResult.directives : []],
1014
+ code: await (0, _powerlines_core_lib_utilities_format.format)(context, context.typesPath, `${!previous.includes((0, _powerlines_core_lib_utilities_file_header.getTypescriptFileHeader)(context)) && !current.includes((0, _powerlines_core_lib_utilities_file_header.getTypescriptFileHeader)(context)) ? `${code}\n` : ""}${previous}\n${current}`.trim())
1015
+ };
1016
+ };
1017
+ const asNextParam = (previousResult) => (0, _stryke_type_checks_is_object.isObject)(previousResult) ? previousResult.code : previousResult;
1018
+ let result = await this.callHook("types", {
1019
+ environment: context,
1020
+ sequential: true,
1021
+ order: "pre",
1022
+ result: "merge",
1023
+ merge,
1024
+ asNextParam
1025
+ }, code);
1026
+ if (result) {
1027
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(result)) {
1028
+ code = result.code;
1029
+ if (Array.isArray(result.directives) && result.directives.length > 0) directives = (0, _stryke_helpers_get_unique.getUnique)([...directives, ...result.directives]).filter(Boolean);
1030
+ } else if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) code = result;
1031
+ }
1032
+ result = await this.callHook("types", {
1033
+ environment: context,
1034
+ sequential: true,
1035
+ order: "normal",
1036
+ result: "merge",
1037
+ merge,
1038
+ asNextParam
1039
+ }, code);
1040
+ if (result) {
1041
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(result)) {
1042
+ code = result.code;
1043
+ if (Array.isArray(result.directives) && result.directives.length > 0) directives = (0, _stryke_helpers_get_unique.getUnique)([...directives, ...result.directives]).filter(Boolean);
1044
+ } else if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) code = result;
1045
+ }
1046
+ result = await this.callHook("types", {
1047
+ environment: context,
1048
+ sequential: true,
1049
+ order: "post",
1050
+ result: "merge",
1051
+ merge,
1052
+ asNextParam
1053
+ }, code);
1054
+ if (result) {
1055
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(result)) {
1056
+ code = result.code;
1057
+ if (Array.isArray(result.directives) && result.directives.length > 0) directives = (0, _stryke_helpers_get_unique.getUnique)([...directives, ...result.directives]).filter(Boolean);
1058
+ } else if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) code = result;
1059
+ }
1060
+ if ((0, _stryke_type_checks_is_set_string.isSetString)(code?.trim()) || directives.length > 0) await context.fs.write(context.typesPath, `${directives.length > 0 ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
1061
+
1062
+ ` : ""}${(0, _powerlines_core_lib_utilities_file_header.getTypescriptFileHeader)(context, {
1063
+ directive: null,
1064
+ prettierIgnore: false
1065
+ })}
1066
+
1067
+ ${formatTypes(code)}
1068
+ `);
1069
+ }
1077
1070
  };
1078
1071
 
1079
1072
  //#endregion
@@ -1094,37 +1087,13 @@ var PowerlinesAPI = class PowerlinesAPI extends PowerlinesExecution {
1094
1087
  * @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.
1095
1088
  * @returns A new instance of the Powerlines API
1096
1089
  */
1097
- static async init(options, initialConfig) {
1098
- const api = new PowerlinesAPI(await require_execution_context.PowerlinesExecutionContext.init({
1090
+ static async from(options, initialConfig) {
1091
+ const api = new PowerlinesAPI(await require_execution_context.PowerlinesExecutionContext.fromInitialConfig({
1099
1092
  executionId: (0, _stryke_unique_id_uuid.uuid)(),
1100
1093
  executionIndex: 0,
1101
1094
  ...options
1102
1095
  }, initialConfig ?? {}));
1103
- api.context.$$internal = {
1104
- api,
1105
- addPlugin: api.addPlugin.bind(api)
1106
- };
1107
- const timer = api.context.timer("Initialization");
1108
- for (const plugin of api.context.config.plugins.flatMap((p) => (0, _stryke_convert_to_array.toArray)(p)) ?? []) await api.addPlugin(plugin);
1109
- if (api.context.plugins.length === 0) api.context.warn({
1110
- meta: { category: "plugins" },
1111
- message: "No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended."
1112
- });
1113
- else api.context.info({
1114
- meta: { category: "plugins" },
1115
- message: `Loaded ${api.context.plugins.length} ${(0, _stryke_string_format_title_case.titleCase)(api.context.config.framework)} plugin${api.context.plugins.length > 1 ? "s" : ""}: \n${api.context.plugins.map((plugin, index) => ` ${index + 1}. ${(0, _powerlines_core_plugin_utils_logging.colorText)(plugin.name)}`).join("\n")}`
1116
- });
1117
- const pluginConfig = await api.callHook("config", {
1118
- environment: await api.context.getEnvironment(),
1119
- sequential: true,
1120
- result: "merge",
1121
- merge: require_execution_context.mergeConfigs
1122
- });
1123
- if ((0, _stryke_type_checks_is_set_object.isSetObject)(pluginConfig)) {
1124
- api.context.config.pluginConfig = pluginConfig;
1125
- await api.context.setup();
1126
- }
1127
- timer();
1096
+ await api.init();
1128
1097
  return api;
1129
1098
  }
1130
1099
  /**