@powerlines/nx 0.13.124 → 0.13.126
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.
- package/dist/src/base/base-executor.d.mts +34 -4
- package/dist/src/base/base-executor.d.mts.map +1 -1
- package/dist/src/base/base-executor.d.ts +34 -4
- package/dist/src/base/base-executor.d.ts.map +1 -1
- package/dist/src/base/base-executor.js +15 -13
- package/dist/src/base/base-executor.mjs +15 -13
- package/dist/src/base/base-executor.mjs.map +1 -1
- package/dist/src/base/index.d.mts +2 -2
- package/dist/src/base/index.d.ts +2 -2
- package/dist/src/{base-executor-0AtMZrSx.mjs → base-executor-B1RffQX6.mjs} +16 -14
- package/dist/src/base-executor-B1RffQX6.mjs.map +1 -0
- package/dist/src/{base-executor-BIhn6u5E.js → base-executor-CHEFLBQ-.js} +15 -13
- package/dist/src/executors/build/executor.js +1 -1
- package/dist/src/executors/build/executor.mjs +1 -1
- package/dist/src/executors/clean/executor.js +1 -1
- package/dist/src/executors/clean/executor.mjs +1 -1
- package/dist/src/executors/docs/executor.js +1 -1
- package/dist/src/executors/docs/executor.mjs +1 -1
- package/dist/src/executors/lint/executor.js +1 -1
- package/dist/src/executors/lint/executor.mjs +1 -1
- package/dist/src/executors/prepare/executor.js +1 -1
- package/dist/src/executors/prepare/executor.mjs +1 -1
- package/dist/src/helpers/plugin-utilities.js +1 -1
- package/dist/src/helpers/plugin-utilities.mjs +1 -1
- package/dist/src/index.d.mts +2 -2
- package/dist/src/index.d.ts +2 -2
- package/package.json +10 -10
- package/dist/src/base-executor-0AtMZrSx.mjs.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import __tsdown_shims_path from 'node:path';
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
3
|
import { BaseExecutorSchema } from "./base-executor.schema.mjs";
|
|
4
|
+
import { ExecutionOptions, FrameworkOptions, InlineConfig } from "powerlines";
|
|
4
5
|
import { ExecutorContext, PromiseExecutor } from "@nx/devkit";
|
|
5
6
|
import { StormWorkspaceConfig } from "@storm-software/config/types";
|
|
6
7
|
import { BaseExecutorResult } from "@storm-software/workspace-tools/types";
|
|
7
8
|
import { DeepPartial } from "@stryke/types/base";
|
|
8
|
-
import { ExecutionOptions, InlineConfig } from "powerlines";
|
|
9
9
|
|
|
10
10
|
//#region src/base/base-executor.d.ts
|
|
11
11
|
type PowerlinesExecutorContext<TExecutorSchema extends BaseExecutorSchema = BaseExecutorSchema> = ExecutorContext & {
|
|
@@ -16,6 +16,36 @@ type PowerlinesExecutorContext<TExecutorSchema extends BaseExecutorSchema = Base
|
|
|
16
16
|
workspaceConfig: StormWorkspaceConfig;
|
|
17
17
|
};
|
|
18
18
|
type PowerlinesExecutorApi = (inlineConfig: InlineConfig) => Promise<void>;
|
|
19
|
+
interface WithExecutorOptions {
|
|
20
|
+
/**
|
|
21
|
+
* The import path for the executor API module, which is used to dynamically import the API function that will be called during execution. This value should be a string representing the module path, and it defaults to "powerlines/api" if not provided. The specified module should export a default function that matches the expected signature for the executor API, which will be invoked with the execution parameters when the executor is run.
|
|
22
|
+
*
|
|
23
|
+
* @defaultValue "powerlines/api"
|
|
24
|
+
*/
|
|
25
|
+
importPath?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Default options to be merged with the execution options, which can be used to provide default values for certain execution parameters or to override specific options for all executions of the executor. This value should be an object that matches the shape of the `ExecutionOptions` type, and it will be merged with the options provided during execution to create the final set of options that will be passed to the executor API function.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* This can be useful for setting default values for options that are commonly used across multiple executions, or for providing a consistent set of options for all executions of the executor without requiring the caller to specify them each time.
|
|
31
|
+
*/
|
|
32
|
+
defaultOptions?: DeepPartial<ExecutionOptions>;
|
|
33
|
+
/**
|
|
34
|
+
* Details about the framework being used in the current execution, which can be used by plugins and other parts of the system to customize behavior based on the framework.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* This should only be used by framework plugins to ensure the correct framework name is applied
|
|
38
|
+
*
|
|
39
|
+
* @defaultValue
|
|
40
|
+
* ```ts
|
|
41
|
+
* {
|
|
42
|
+
* name: "powerlines",
|
|
43
|
+
* orgId: "storm-software"
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
framework?: FrameworkOptions;
|
|
48
|
+
}
|
|
19
49
|
/**
|
|
20
50
|
* A utility function to create a Powerlines executor that can be used with the `withRunExecutor` function.
|
|
21
51
|
*
|
|
@@ -24,10 +54,10 @@ type PowerlinesExecutorApi = (inlineConfig: InlineConfig) => Promise<void>;
|
|
|
24
54
|
*
|
|
25
55
|
* @param command - The command that the executor will handle (e.g., "new", "prepare", "build", etc.).
|
|
26
56
|
* @param executorFn - The function that will be executed when the command is run.
|
|
27
|
-
* @param
|
|
57
|
+
* @param options - Additional options for configuring the executor, such as the import path for the API module and default execution options.
|
|
28
58
|
* @returns A Promise that resolves to the result of the executor function.
|
|
29
59
|
*/
|
|
30
|
-
declare function withExecutor<TExecutorSchema extends BaseExecutorSchema = BaseExecutorSchema>(command: string, executorFn: (context: PowerlinesExecutorContext<TExecutorSchema>, api: PowerlinesExecutorApi) => Promise<BaseExecutorResult | null | undefined> | BaseExecutorResult | null | undefined,
|
|
60
|
+
declare function withExecutor<TExecutorSchema extends BaseExecutorSchema = BaseExecutorSchema>(command: string, executorFn: (context: PowerlinesExecutorContext<TExecutorSchema>, api: PowerlinesExecutorApi) => Promise<BaseExecutorResult | null | undefined> | BaseExecutorResult | null | undefined, options?: WithExecutorOptions): PromiseExecutor<TExecutorSchema>;
|
|
31
61
|
//#endregion
|
|
32
|
-
export { PowerlinesExecutorApi, PowerlinesExecutorContext, withExecutor };
|
|
62
|
+
export { PowerlinesExecutorApi, PowerlinesExecutorContext, WithExecutorOptions, withExecutor };
|
|
33
63
|
//# sourceMappingURL=base-executor.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-executor.d.mts","names":[],"sources":["../../../src/base/base-executor.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"base-executor.d.mts","names":[],"sources":["../../../src/base/base-executor.ts"],"mappings":";;;;;;;;;;KA6CY,yBAAA,yBACc,kBAAA,GAAqB,kBAAA,IAC3C,eAAA;EACF,WAAA;EACA,OAAA;EACA,OAAA,EAAS,eAAA;EACT,YAAA,EAAc,YAAA;EACd,eAAA,EAAiB,oBAAA;AAAA;AAAA,KAGP,qBAAA,IACV,YAAA,EAAc,YAAA,KACX,OAAO;AAAA,UAEK,mBAAA;;AAdjB;;;;EAoBE,UAAA;EAlBE;;;;;;EA0BF,cAAA,GAAiB,WAAA,CAAY,gBAAA;EA3BL;;;;;;;;;;;;AAMa;AAGvC;EAkCE,SAAA,GAAY,gBAAA;AAAA;;;;;;AAhCF;AAEZ;;;;;iBA4CgB,YAAA,yBACU,kBAAA,GAAqB,kBAAA,CAAA,CAE7C,OAAA,UACA,UAAA,GACE,OAAA,EAAS,yBAAA,CAA0B,eAAA,GACnC,GAAA,EAAK,qBAAA,KAEH,OAAA,CAAQ,kBAAA,uBACR,kBAAA,qBAGJ,OAAA,GAAS,mBAAA,GACR,eAAA,CAAgB,eAAA"}
|
|
@@ -3,7 +3,7 @@ import { ExecutorContext, PromiseExecutor } from "@nx/devkit";
|
|
|
3
3
|
import { StormWorkspaceConfig } from "@storm-software/config/types";
|
|
4
4
|
import { BaseExecutorResult } from "@storm-software/workspace-tools/types";
|
|
5
5
|
import { DeepPartial } from "@stryke/types/base";
|
|
6
|
-
import { ExecutionOptions, InlineConfig } from "powerlines";
|
|
6
|
+
import { ExecutionOptions, FrameworkOptions, InlineConfig } from "powerlines";
|
|
7
7
|
|
|
8
8
|
//#region src/base/base-executor.d.ts
|
|
9
9
|
type PowerlinesExecutorContext<TExecutorSchema extends BaseExecutorSchema = BaseExecutorSchema> = ExecutorContext & {
|
|
@@ -14,6 +14,36 @@ type PowerlinesExecutorContext<TExecutorSchema extends BaseExecutorSchema = Base
|
|
|
14
14
|
workspaceConfig: StormWorkspaceConfig;
|
|
15
15
|
};
|
|
16
16
|
type PowerlinesExecutorApi = (inlineConfig: InlineConfig) => Promise<void>;
|
|
17
|
+
interface WithExecutorOptions {
|
|
18
|
+
/**
|
|
19
|
+
* The import path for the executor API module, which is used to dynamically import the API function that will be called during execution. This value should be a string representing the module path, and it defaults to "powerlines/api" if not provided. The specified module should export a default function that matches the expected signature for the executor API, which will be invoked with the execution parameters when the executor is run.
|
|
20
|
+
*
|
|
21
|
+
* @defaultValue "powerlines/api"
|
|
22
|
+
*/
|
|
23
|
+
importPath?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Default options to be merged with the execution options, which can be used to provide default values for certain execution parameters or to override specific options for all executions of the executor. This value should be an object that matches the shape of the `ExecutionOptions` type, and it will be merged with the options provided during execution to create the final set of options that will be passed to the executor API function.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* This can be useful for setting default values for options that are commonly used across multiple executions, or for providing a consistent set of options for all executions of the executor without requiring the caller to specify them each time.
|
|
29
|
+
*/
|
|
30
|
+
defaultOptions?: DeepPartial<ExecutionOptions>;
|
|
31
|
+
/**
|
|
32
|
+
* Details about the framework being used in the current execution, which can be used by plugins and other parts of the system to customize behavior based on the framework.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* This should only be used by framework plugins to ensure the correct framework name is applied
|
|
36
|
+
*
|
|
37
|
+
* @defaultValue
|
|
38
|
+
* ```ts
|
|
39
|
+
* {
|
|
40
|
+
* name: "powerlines",
|
|
41
|
+
* orgId: "storm-software"
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
framework?: FrameworkOptions;
|
|
46
|
+
}
|
|
17
47
|
/**
|
|
18
48
|
* A utility function to create a Powerlines executor that can be used with the `withRunExecutor` function.
|
|
19
49
|
*
|
|
@@ -22,10 +52,10 @@ type PowerlinesExecutorApi = (inlineConfig: InlineConfig) => Promise<void>;
|
|
|
22
52
|
*
|
|
23
53
|
* @param command - The command that the executor will handle (e.g., "new", "prepare", "build", etc.).
|
|
24
54
|
* @param executorFn - The function that will be executed when the command is run.
|
|
25
|
-
* @param
|
|
55
|
+
* @param options - Additional options for configuring the executor, such as the import path for the API module and default execution options.
|
|
26
56
|
* @returns A Promise that resolves to the result of the executor function.
|
|
27
57
|
*/
|
|
28
|
-
declare function withExecutor<TExecutorSchema extends BaseExecutorSchema = BaseExecutorSchema>(command: string, executorFn: (context: PowerlinesExecutorContext<TExecutorSchema>, api: PowerlinesExecutorApi) => Promise<BaseExecutorResult | null | undefined> | BaseExecutorResult | null | undefined,
|
|
58
|
+
declare function withExecutor<TExecutorSchema extends BaseExecutorSchema = BaseExecutorSchema>(command: string, executorFn: (context: PowerlinesExecutorContext<TExecutorSchema>, api: PowerlinesExecutorApi) => Promise<BaseExecutorResult | null | undefined> | BaseExecutorResult | null | undefined, options?: WithExecutorOptions): PromiseExecutor<TExecutorSchema>;
|
|
29
59
|
//#endregion
|
|
30
|
-
export { PowerlinesExecutorApi, PowerlinesExecutorContext, withExecutor };
|
|
60
|
+
export { PowerlinesExecutorApi, PowerlinesExecutorContext, WithExecutorOptions, withExecutor };
|
|
31
61
|
//# sourceMappingURL=base-executor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-executor.d.ts","names":[],"sources":["../../../src/base/base-executor.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"base-executor.d.ts","names":[],"sources":["../../../src/base/base-executor.ts"],"mappings":";;;;;;;;KA6CY,yBAAA,yBACc,kBAAA,GAAqB,kBAAA,IAC3C,eAAA;EACF,WAAA;EACA,OAAA;EACA,OAAA,EAAS,eAAA;EACT,YAAA,EAAc,YAAA;EACd,eAAA,EAAiB,oBAAA;AAAA;AAAA,KAGP,qBAAA,IACV,YAAA,EAAc,YAAA,KACX,OAAO;AAAA,UAEK,mBAAA;EARD;;;;;EAcd,UAAA;EAnB6C;;;;;;EA2B7C,cAAA,GAAiB,WAAA,CAAY,gBAAA;EAtBf;;;;AACuB;AAGvC;;;;;;;;AAEY;EAgCV,SAAA,GAAY,gBAAA;AAAA;;;;;;;;;;;;iBAcE,YAAA,yBACU,kBAAA,GAAqB,kBAAA,CAAA,CAE7C,OAAA,UACA,UAAA,GACE,OAAA,EAAS,yBAAA,CAA0B,eAAA,GACnC,GAAA,EAAK,qBAAA,KAEH,OAAA,CAAQ,kBAAA,uBACR,kBAAA,qBAGJ,OAAA,GAAS,mBAAA,GACR,eAAA,CAAgB,eAAA"}
|
|
@@ -12,6 +12,7 @@ let _storm_software_config_tools_logger = require("@storm-software/config-tools/
|
|
|
12
12
|
let _storm_software_workspace_tools_base_base_executor = require("@storm-software/workspace-tools/base/base-executor");
|
|
13
13
|
let _stryke_helpers_omit = require("@stryke/helpers/omit");
|
|
14
14
|
let _stryke_path_join = require("@stryke/path/join");
|
|
15
|
+
let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
15
16
|
let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
16
17
|
let _stryke_type_checks_is_error = require("@stryke/type-checks/is-error");
|
|
17
18
|
let _stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
|
|
@@ -20,6 +21,7 @@ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-obje
|
|
|
20
21
|
let defu = require("defu");
|
|
21
22
|
defu = require_runtime.__toESM(defu);
|
|
22
23
|
let jiti = require("jiti");
|
|
24
|
+
let powerlines = require("powerlines");
|
|
23
25
|
|
|
24
26
|
//#region src/base/base-executor.ts
|
|
25
27
|
/**
|
|
@@ -30,19 +32,22 @@ let jiti = require("jiti");
|
|
|
30
32
|
*
|
|
31
33
|
* @param command - The command that the executor will handle (e.g., "new", "prepare", "build", etc.).
|
|
32
34
|
* @param executorFn - The function that will be executed when the command is run.
|
|
33
|
-
* @param
|
|
35
|
+
* @param options - Additional options for configuring the executor, such as the import path for the API module and default execution options.
|
|
34
36
|
* @returns A Promise that resolves to the result of the executor function.
|
|
35
37
|
*/
|
|
36
|
-
function withExecutor(command, executorFn,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
function withExecutor(command, executorFn, options = {}) {
|
|
39
|
+
const { importPath = "powerlines/api", defaultOptions = {}, framework = {} } = options;
|
|
40
|
+
framework.name ??= "powerlines";
|
|
41
|
+
framework.orgId ??= "storm-software";
|
|
42
|
+
return (0, _storm_software_workspace_tools_base_base_executor.withRunExecutor)(`${(0, _stryke_string_format_title_case.titleCase)(framework.name)} - ${(0, _stryke_string_format_title_case.titleCase)(command)} executor`, async (options, context, workspaceConfig) => {
|
|
43
|
+
if (!context.projectName) throw new Error(`The ${(0, _stryke_string_format_title_case.titleCase)(framework.name)} - ${(0, _stryke_string_format_title_case.titleCase)(command)} executor requires \`projectName\` on the context object.`);
|
|
44
|
+
if (!context.projectName || !context.projectsConfigurations?.projects || !context.projectsConfigurations.projects[context.projectName] || !context.projectsConfigurations.projects[context.projectName]?.root) throw new Error(`The ${(0, _stryke_string_format_title_case.titleCase)(framework.name)} - ${(0, _stryke_string_format_title_case.titleCase)(command)} executor requires \`projectsConfigurations\` on the context object.`);
|
|
40
45
|
const projectConfig = context.projectsConfigurations.projects[context.projectName];
|
|
41
46
|
const jiti$1 = (0, jiti.createJiti)(context.root, {
|
|
42
47
|
cache: false,
|
|
43
48
|
tsconfigPaths: true
|
|
44
49
|
});
|
|
45
|
-
const api = await jiti$1.import(jiti$1.esmResolve(
|
|
50
|
+
const api = await jiti$1.import(jiti$1.esmResolve(importPath)).then((mod) => mod.default);
|
|
46
51
|
try {
|
|
47
52
|
return await Promise.resolve(executorFn((0, defu.default)({
|
|
48
53
|
projectName: context.projectName,
|
|
@@ -90,21 +95,18 @@ function withExecutor(command, executorFn, defaultOptions = {}) {
|
|
|
90
95
|
]))
|
|
91
96
|
}, context), async (inlineConfig) => api({
|
|
92
97
|
options: (0, defu.default)(defaultOptions, {
|
|
93
|
-
executionId:
|
|
98
|
+
executionId: (0, powerlines.formatExecutionId)(inlineConfig.name || context.projectName || projectConfig.root, command, options.configIndex ?? 0),
|
|
94
99
|
cwd: context.root,
|
|
95
100
|
root: projectConfig.root,
|
|
96
|
-
configFile: options.configFile || options.config || (0, _stryke_path_join.joinPaths)(projectConfig.root,
|
|
101
|
+
configFile: options.configFile || options.config || (0, _stryke_path_join.joinPaths)(projectConfig.root, `${(0, _stryke_string_format_kebab_case.kebabCase)(framework.name)}.config.ts`),
|
|
97
102
|
configIndex: options.configIndex,
|
|
98
|
-
framework
|
|
99
|
-
name: "powerlines",
|
|
100
|
-
orgId: "storm-software"
|
|
101
|
-
}
|
|
103
|
+
framework
|
|
102
104
|
}),
|
|
103
105
|
command,
|
|
104
106
|
inlineConfig
|
|
105
107
|
})));
|
|
106
108
|
} catch (error) {
|
|
107
|
-
(0, _storm_software_config_tools_logger.writeError)(`An error occurred while executing the
|
|
109
|
+
(0, _storm_software_config_tools_logger.writeError)(`An error occurred while executing the ${(0, _stryke_string_format_title_case.titleCase)(framework.name)} - ${(0, _stryke_string_format_title_case.titleCase)(command)} executor: ${(0, _stryke_type_checks_is_error.isError)(error) ? `${error.message}
|
|
108
110
|
|
|
109
111
|
${error.stack}` : "Unknown error"}`);
|
|
110
112
|
return { success: false };
|
|
@@ -10,6 +10,7 @@ import { writeError } from "@storm-software/config-tools/logger";
|
|
|
10
10
|
import { withRunExecutor } from "@storm-software/workspace-tools/base/base-executor";
|
|
11
11
|
import { omit } from "@stryke/helpers/omit";
|
|
12
12
|
import { joinPaths } from "@stryke/path/join";
|
|
13
|
+
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
13
14
|
import { titleCase } from "@stryke/string-format/title-case";
|
|
14
15
|
import { isError } from "@stryke/type-checks/is-error";
|
|
15
16
|
import { isSet } from "@stryke/type-checks/is-set";
|
|
@@ -17,6 +18,7 @@ import { isSetArray } from "@stryke/type-checks/is-set-array";
|
|
|
17
18
|
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
18
19
|
import defu from "defu";
|
|
19
20
|
import { createJiti } from "jiti";
|
|
21
|
+
import { formatExecutionId } from "powerlines";
|
|
20
22
|
|
|
21
23
|
//#region src/base/base-executor.ts
|
|
22
24
|
/**
|
|
@@ -27,19 +29,22 @@ import { createJiti } from "jiti";
|
|
|
27
29
|
*
|
|
28
30
|
* @param command - The command that the executor will handle (e.g., "new", "prepare", "build", etc.).
|
|
29
31
|
* @param executorFn - The function that will be executed when the command is run.
|
|
30
|
-
* @param
|
|
32
|
+
* @param options - Additional options for configuring the executor, such as the import path for the API module and default execution options.
|
|
31
33
|
* @returns A Promise that resolves to the result of the executor function.
|
|
32
34
|
*/
|
|
33
|
-
function withExecutor(command, executorFn,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
function withExecutor(command, executorFn, options = {}) {
|
|
36
|
+
const { importPath = "powerlines/api", defaultOptions = {}, framework = {} } = options;
|
|
37
|
+
framework.name ??= "powerlines";
|
|
38
|
+
framework.orgId ??= "storm-software";
|
|
39
|
+
return withRunExecutor(`${titleCase(framework.name)} - ${titleCase(command)} executor`, async (options, context, workspaceConfig) => {
|
|
40
|
+
if (!context.projectName) throw new Error(`The ${titleCase(framework.name)} - ${titleCase(command)} executor requires \`projectName\` on the context object.`);
|
|
41
|
+
if (!context.projectName || !context.projectsConfigurations?.projects || !context.projectsConfigurations.projects[context.projectName] || !context.projectsConfigurations.projects[context.projectName]?.root) throw new Error(`The ${titleCase(framework.name)} - ${titleCase(command)} executor requires \`projectsConfigurations\` on the context object.`);
|
|
37
42
|
const projectConfig = context.projectsConfigurations.projects[context.projectName];
|
|
38
43
|
const jiti = createJiti(context.root, {
|
|
39
44
|
cache: false,
|
|
40
45
|
tsconfigPaths: true
|
|
41
46
|
});
|
|
42
|
-
const api = await jiti.import(jiti.esmResolve(
|
|
47
|
+
const api = await jiti.import(jiti.esmResolve(importPath)).then((mod) => mod.default);
|
|
43
48
|
try {
|
|
44
49
|
return await Promise.resolve(executorFn(defu({
|
|
45
50
|
projectName: context.projectName,
|
|
@@ -87,21 +92,18 @@ function withExecutor(command, executorFn, defaultOptions = {}) {
|
|
|
87
92
|
]))
|
|
88
93
|
}, context), async (inlineConfig) => api({
|
|
89
94
|
options: defu(defaultOptions, {
|
|
90
|
-
executionId:
|
|
95
|
+
executionId: formatExecutionId(inlineConfig.name || context.projectName || projectConfig.root, command, options.configIndex ?? 0),
|
|
91
96
|
cwd: context.root,
|
|
92
97
|
root: projectConfig.root,
|
|
93
|
-
configFile: options.configFile || options.config || joinPaths(projectConfig.root,
|
|
98
|
+
configFile: options.configFile || options.config || joinPaths(projectConfig.root, `${kebabCase(framework.name)}.config.ts`),
|
|
94
99
|
configIndex: options.configIndex,
|
|
95
|
-
framework
|
|
96
|
-
name: "powerlines",
|
|
97
|
-
orgId: "storm-software"
|
|
98
|
-
}
|
|
100
|
+
framework
|
|
99
101
|
}),
|
|
100
102
|
command,
|
|
101
103
|
inlineConfig
|
|
102
104
|
})));
|
|
103
105
|
} catch (error) {
|
|
104
|
-
writeError(`An error occurred while executing the
|
|
106
|
+
writeError(`An error occurred while executing the ${titleCase(framework.name)} - ${titleCase(command)} executor: ${isError(error) ? `${error.message}
|
|
105
107
|
|
|
106
108
|
${error.stack}` : "Unknown error"}`);
|
|
107
109
|
return { success: false };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-executor.mjs","names":[],"sources":["../../../src/base/base-executor.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { ExecutorContext, PromiseExecutor } from \"@nx/devkit\";\nimport { writeError } from \"@storm-software/config-tools/logger\";\nimport { StormWorkspaceConfig } from \"@storm-software/config/types\";\nimport { withRunExecutor } from \"@storm-software/workspace-tools/base/base-executor\";\nimport { BaseExecutorResult } from \"@storm-software/workspace-tools/types\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isError } from \"@stryke/type-checks/is-error\";\nimport { isSet } from \"@stryke/type-checks/is-set\";\nimport { isSetArray } from \"@stryke/type-checks/is-set-array\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport type { DeepPartial } from \"@stryke/types/base\";\nimport defu from \"defu\";\nimport { createJiti } from \"jiti\";\nimport type {\n ExecutionApiParams,\n ExecutionOptions,\n InlineConfig,\n Mode,\n OutputConfig\n} from \"powerlines\";\nimport { BaseExecutorSchema } from \"./base-executor.schema\";\n\nexport type PowerlinesExecutorContext<\n TExecutorSchema extends BaseExecutorSchema = BaseExecutorSchema\n> = ExecutorContext & {\n projectName: string;\n command: string;\n options: TExecutorSchema;\n inlineConfig: InlineConfig;\n workspaceConfig: StormWorkspaceConfig;\n};\n\nexport type PowerlinesExecutorApi = (\n inlineConfig: InlineConfig\n) => Promise<void>;\n\n/**\n * A utility function to create a Powerlines executor that can be used with the `withRunExecutor` function.\n *\n * @remarks\n * This function is designed to simplify the creation of Powerlines executors by providing a consistent interface and error handling.\n *\n * @param command - The command that the executor will handle (e.g., \"new\", \"prepare\", \"build\", etc.).\n * @param executorFn - The function that will be executed when the command is run.\n * @param defaultOptions - Default options to be merged with the execution options.\n * @returns A Promise that resolves to the result of the executor function.\n */\nexport function withExecutor<\n TExecutorSchema extends BaseExecutorSchema = BaseExecutorSchema\n>(\n command: string,\n executorFn: (\n context: PowerlinesExecutorContext<TExecutorSchema>,\n api: PowerlinesExecutorApi\n ) =>\n | Promise<BaseExecutorResult | null | undefined>\n | BaseExecutorResult\n | null\n | undefined,\n defaultOptions: DeepPartial<ExecutionOptions> = {}\n): PromiseExecutor<TExecutorSchema> {\n return withRunExecutor(\n `Powerlines - ${titleCase(command)} executor`,\n async (\n options: TExecutorSchema,\n context: ExecutorContext,\n workspaceConfig: StormWorkspaceConfig\n ): Promise<BaseExecutorResult | null | undefined> => {\n if (!context.projectName) {\n throw new Error(\n `The Powerlines - ${titleCase(command)} executor requires \\`projectName\\` on the context object.`\n );\n }\n\n if (\n !context.projectName ||\n !context.projectsConfigurations?.projects ||\n !context.projectsConfigurations.projects[context.projectName] ||\n !context.projectsConfigurations.projects[context.projectName]?.root\n ) {\n throw new Error(\n `The Powerlines - ${titleCase(command)} executor requires \\`projectsConfigurations\\` on the context object.`\n );\n }\n\n const projectConfig =\n context.projectsConfigurations.projects[context.projectName]!;\n\n const jiti = createJiti(context.root, {\n cache: false,\n tsconfigPaths: true\n });\n const api = await jiti\n .import<{\n default: (params: ExecutionApiParams) => Promise<void>;\n }>(jiti.esmResolve(\"powerlines/api\"))\n .then(mod => mod.default);\n\n try {\n return await Promise.resolve(\n executorFn(\n defu(\n {\n projectName: context.projectName,\n options,\n workspaceConfig,\n command,\n inlineConfig: defu(\n {\n name: context.projectName,\n command,\n root: projectConfig.root,\n configFile: options.configFile || options.config,\n configIndex: options.configIndex,\n projectType: projectConfig.projectType,\n mode: options.mode as Mode,\n output: {\n path: options.outputPath,\n copy:\n options.copyPath === false\n ? false\n : {\n path: options.copyPath,\n assets: options.assets\n },\n minify: options.minify,\n sourceMap: options.sourceMap\n } as OutputConfig,\n resolve:\n isSetArray(options.external) ||\n isSetArray(options.noExternal) ||\n isSet(options.skipNodeModulesBundle)\n ? {\n external: isSetArray(options.external)\n ? options.external\n : undefined,\n noExternal: isSetArray(options.noExternal)\n ? options.noExternal\n : undefined,\n skipNodeModulesBundle: isSet(\n options.skipNodeModulesBundle\n )\n ? options.skipNodeModulesBundle\n : undefined\n }\n : undefined,\n define: isSetObject(options.define)\n ? options.define\n : undefined,\n assets: isSetObject(options.assets)\n ? options.assets\n : undefined\n },\n omit(options, [\n \"config\",\n \"configFile\",\n \"outputPath\",\n \"copyPath\",\n \"sourceMap\",\n \"minify\",\n \"format\",\n \"external\",\n \"noExternal\",\n \"skipNodeModulesBundle\",\n \"mode\",\n \"define\",\n \"assets\"\n ])\n ) as InlineConfig\n },\n context\n ),\n async (inlineConfig: InlineConfig) =>\n api({\n // eslint-disable-next-line ts/no-unnecessary-type-assertion\n options: defu(defaultOptions, {\n executionId: `${context.projectName}-${command}-${options.configIndex}`,\n cwd: context.root,\n root: projectConfig.root,\n configFile:\n options.configFile ||\n options.config ||\n joinPaths(projectConfig.root, \"powerlines.config.ts\"),\n configIndex: options.configIndex,\n framework: {\n name: \"powerlines\",\n orgId: \"storm-software\"\n }\n }) as ExecutionOptions,\n command,\n inlineConfig\n })\n )\n );\n } catch (error) {\n writeError(\n `An error occurred while executing the Powerlines - ${titleCase(\n command\n )} executor: ${\n isError(error)\n ? `${error.message}\n\n${error.stack}`\n : \"Unknown error\"\n }`\n );\n\n return { success: false };\n }\n },\n {\n skipReadingConfig: false,\n hooks: {\n applyDefaultOptions: (options: Partial<TExecutorSchema>) => {\n options.copyPath ??= \"dist/{projectRoot}\";\n\n return options as TExecutorSchema;\n }\n }\n }\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,SAAgB,aAGd,SACA,YAQA,iBAAgD,CAAC,GACf;CAClC,OAAO,gBACL,gBAAgB,UAAU,OAAO,EAAE,YACnC,OACE,SACA,SACA,oBACmD;EACnD,IAAI,CAAC,QAAQ,aACX,MAAM,IAAI,MACR,oBAAoB,UAAU,OAAO,EAAE,0DACzC;EAGF,IACE,CAAC,QAAQ,eACT,CAAC,QAAQ,wBAAwB,YACjC,CAAC,QAAQ,uBAAuB,SAAS,QAAQ,gBACjD,CAAC,QAAQ,uBAAuB,SAAS,QAAQ,cAAc,MAE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C1D,KAAK,QAAQ;KACb,MAAM,cAAc;KACpB,YACE,QAAQ,cACR,QAAQ,UACR,UAAU,cAAc,MAAM,sBAAsB;KACtD,aAAa,QAAQ;KACrB,WAAW;MACT,MAAM;MACN,OAAO;KACT;IACF,CAAC;IACD;IACA;GACF,CAAC,CACL,CACF;EACF,SAAS,OAAO;GACd,WACE,sDAAsD,UACpD,OACF,EAAE,aACA,QAAQ,KAAK,IACT,GAAG,MAAM,QAAQ;;EAE/B,MAAM,UACQ,iBAER;GAEA,OAAO,EAAE,SAAS,MAAM;EAC1B;CACF,GACA;EACE,mBAAmB;EACnB,OAAO,EACL,sBAAsB,YAAsC;GAC1D,QAAQ,aAAa;GAErB,OAAO;EACT,EACF;CACF,CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"base-executor.mjs","names":[],"sources":["../../../src/base/base-executor.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { ExecutorContext, PromiseExecutor } from \"@nx/devkit\";\nimport { writeError } from \"@storm-software/config-tools/logger\";\nimport { StormWorkspaceConfig } from \"@storm-software/config/types\";\nimport { withRunExecutor } from \"@storm-software/workspace-tools/base/base-executor\";\nimport { BaseExecutorResult } from \"@storm-software/workspace-tools/types\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isError } from \"@stryke/type-checks/is-error\";\nimport { isSet } from \"@stryke/type-checks/is-set\";\nimport { isSetArray } from \"@stryke/type-checks/is-set-array\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport type { DeepPartial } from \"@stryke/types/base\";\nimport defu from \"defu\";\nimport { createJiti } from \"jiti\";\nimport type {\n ExecutionApiParams,\n ExecutionOptions,\n FrameworkOptions,\n InlineConfig,\n Mode,\n OutputConfig\n} from \"powerlines\";\nimport { formatExecutionId } from \"powerlines\";\nimport { BaseExecutorSchema } from \"./base-executor.schema\";\n\nexport type PowerlinesExecutorContext<\n TExecutorSchema extends BaseExecutorSchema = BaseExecutorSchema\n> = ExecutorContext & {\n projectName: string;\n command: string;\n options: TExecutorSchema;\n inlineConfig: InlineConfig;\n workspaceConfig: StormWorkspaceConfig;\n};\n\nexport type PowerlinesExecutorApi = (\n inlineConfig: InlineConfig\n) => Promise<void>;\n\nexport interface WithExecutorOptions {\n /**\n * The import path for the executor API module, which is used to dynamically import the API function that will be called during execution. This value should be a string representing the module path, and it defaults to \"powerlines/api\" if not provided. The specified module should export a default function that matches the expected signature for the executor API, which will be invoked with the execution parameters when the executor is run.\n *\n * @defaultValue \"powerlines/api\"\n */\n importPath?: string;\n\n /**\n * Default options to be merged with the execution options, which can be used to provide default values for certain execution parameters or to override specific options for all executions of the executor. This value should be an object that matches the shape of the `ExecutionOptions` type, and it will be merged with the options provided during execution to create the final set of options that will be passed to the executor API function.\n *\n * @remarks\n * This can be useful for setting default values for options that are commonly used across multiple executions, or for providing a consistent set of options for all executions of the executor without requiring the caller to specify them each time.\n */\n defaultOptions?: DeepPartial<ExecutionOptions>;\n\n /**\n * Details about the framework being used in the current execution, which can be used by plugins and other parts of the system to customize behavior based on the framework.\n *\n * @remarks\n * This should only be used by framework plugins to ensure the correct framework name is applied\n *\n * @defaultValue\n * ```ts\n * {\n * name: \"powerlines\",\n * orgId: \"storm-software\"\n * }\n * ```\n */\n framework?: FrameworkOptions;\n}\n\n/**\n * A utility function to create a Powerlines executor that can be used with the `withRunExecutor` function.\n *\n * @remarks\n * This function is designed to simplify the creation of Powerlines executors by providing a consistent interface and error handling.\n *\n * @param command - The command that the executor will handle (e.g., \"new\", \"prepare\", \"build\", etc.).\n * @param executorFn - The function that will be executed when the command is run.\n * @param options - Additional options for configuring the executor, such as the import path for the API module and default execution options.\n * @returns A Promise that resolves to the result of the executor function.\n */\nexport function withExecutor<\n TExecutorSchema extends BaseExecutorSchema = BaseExecutorSchema\n>(\n command: string,\n executorFn: (\n context: PowerlinesExecutorContext<TExecutorSchema>,\n api: PowerlinesExecutorApi\n ) =>\n | Promise<BaseExecutorResult | null | undefined>\n | BaseExecutorResult\n | null\n | undefined,\n options: WithExecutorOptions = {}\n): PromiseExecutor<TExecutorSchema> {\n const {\n importPath = \"powerlines/api\",\n defaultOptions = {},\n framework = {} as FrameworkOptions\n } = options;\n\n framework.name ??= \"powerlines\";\n framework.orgId ??= \"storm-software\";\n\n return withRunExecutor(\n `${titleCase(framework.name)} - ${titleCase(command)} executor`,\n async (\n options: TExecutorSchema,\n context: ExecutorContext,\n workspaceConfig: StormWorkspaceConfig\n ): Promise<BaseExecutorResult | null | undefined> => {\n if (!context.projectName) {\n throw new Error(\n `The ${titleCase(framework.name)} - ${titleCase(\n command\n )} executor requires \\`projectName\\` on the context object.`\n );\n }\n\n if (\n !context.projectName ||\n !context.projectsConfigurations?.projects ||\n !context.projectsConfigurations.projects[context.projectName] ||\n !context.projectsConfigurations.projects[context.projectName]?.root\n ) {\n throw new Error(\n `The ${titleCase(framework.name)} - ${titleCase(\n command\n )} executor requires \\`projectsConfigurations\\` on the context object.`\n );\n }\n\n const projectConfig =\n context.projectsConfigurations.projects[context.projectName]!;\n\n const jiti = createJiti(context.root, {\n cache: false,\n tsconfigPaths: true\n });\n const api = await jiti\n .import<{\n default: (params: ExecutionApiParams) => Promise<void>;\n }>(jiti.esmResolve(importPath))\n .then(mod => mod.default);\n\n try {\n return await Promise.resolve(\n executorFn(\n defu(\n {\n projectName: context.projectName,\n options,\n workspaceConfig,\n command,\n inlineConfig: defu(\n {\n name: context.projectName,\n command,\n root: projectConfig.root,\n configFile: options.configFile || options.config,\n configIndex: options.configIndex,\n projectType: projectConfig.projectType,\n mode: options.mode as Mode,\n output: {\n path: options.outputPath,\n copy:\n options.copyPath === false\n ? false\n : {\n path: options.copyPath,\n assets: options.assets\n },\n minify: options.minify,\n sourceMap: options.sourceMap\n } as OutputConfig,\n resolve:\n isSetArray(options.external) ||\n isSetArray(options.noExternal) ||\n isSet(options.skipNodeModulesBundle)\n ? {\n external: isSetArray(options.external)\n ? options.external\n : undefined,\n noExternal: isSetArray(options.noExternal)\n ? options.noExternal\n : undefined,\n skipNodeModulesBundle: isSet(\n options.skipNodeModulesBundle\n )\n ? options.skipNodeModulesBundle\n : undefined\n }\n : undefined,\n define: isSetObject(options.define)\n ? options.define\n : undefined,\n assets: isSetObject(options.assets)\n ? options.assets\n : undefined\n },\n omit(options, [\n \"config\",\n \"configFile\",\n \"outputPath\",\n \"copyPath\",\n \"sourceMap\",\n \"minify\",\n \"format\",\n \"external\",\n \"noExternal\",\n \"skipNodeModulesBundle\",\n \"mode\",\n \"define\",\n \"assets\"\n ])\n ) as InlineConfig\n },\n context\n ),\n async (inlineConfig: InlineConfig) =>\n api({\n options: defu(defaultOptions, {\n executionId: formatExecutionId(\n inlineConfig.name ||\n context.projectName ||\n projectConfig.root,\n command,\n options.configIndex ?? 0\n ),\n cwd: context.root,\n root: projectConfig.root,\n configFile:\n options.configFile ||\n options.config ||\n joinPaths(\n projectConfig.root,\n `${kebabCase(framework.name)}.config.ts`\n ),\n configIndex: options.configIndex,\n framework\n }) as ExecutionOptions,\n command,\n inlineConfig\n })\n )\n );\n } catch (error) {\n writeError(\n `An error occurred while executing the ${titleCase(\n framework.name\n )} - ${titleCase(command)} executor: ${\n isError(error)\n ? `${error.message}\n\n${error.stack}`\n : \"Unknown error\"\n }`\n );\n\n return { success: false };\n }\n },\n {\n skipReadingConfig: false,\n hooks: {\n applyDefaultOptions: (options: Partial<T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|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
|
-
import { PowerlinesExecutorApi, PowerlinesExecutorContext, withExecutor } from "./base-executor.mjs";
|
|
4
|
-
export { PowerlinesExecutorApi, PowerlinesExecutorContext, withExecutor };
|
|
3
|
+
import { PowerlinesExecutorApi, PowerlinesExecutorContext, WithExecutorOptions, withExecutor } from "./base-executor.mjs";
|
|
4
|
+
export { PowerlinesExecutorApi, PowerlinesExecutorContext, WithExecutorOptions, withExecutor };
|
package/dist/src/base/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PowerlinesExecutorApi, PowerlinesExecutorContext, withExecutor } from "./base-executor.js";
|
|
2
|
-
export { PowerlinesExecutorApi, PowerlinesExecutorContext, withExecutor };
|
|
1
|
+
import { PowerlinesExecutorApi, PowerlinesExecutorContext, WithExecutorOptions, withExecutor } from "./base-executor.js";
|
|
2
|
+
export { PowerlinesExecutorApi, PowerlinesExecutorContext, WithExecutorOptions, withExecutor };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
1
2
|
import { titleCase } from "@stryke/string-format/title-case";
|
|
2
3
|
import { isError } from "@stryke/type-checks/is-error";
|
|
3
4
|
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
@@ -9,6 +10,7 @@ import { joinPaths } from "@stryke/path/join";
|
|
|
9
10
|
import { isSet } from "@stryke/type-checks/is-set";
|
|
10
11
|
import { isSetArray } from "@stryke/type-checks/is-set-array";
|
|
11
12
|
import { createJiti } from "jiti";
|
|
13
|
+
import { formatExecutionId } from "powerlines";
|
|
12
14
|
|
|
13
15
|
//#region src/base/base-executor.ts
|
|
14
16
|
/**
|
|
@@ -19,19 +21,22 @@ import { createJiti } from "jiti";
|
|
|
19
21
|
*
|
|
20
22
|
* @param command - The command that the executor will handle (e.g., "new", "prepare", "build", etc.).
|
|
21
23
|
* @param executorFn - The function that will be executed when the command is run.
|
|
22
|
-
* @param
|
|
24
|
+
* @param options - Additional options for configuring the executor, such as the import path for the API module and default execution options.
|
|
23
25
|
* @returns A Promise that resolves to the result of the executor function.
|
|
24
26
|
*/
|
|
25
|
-
function withExecutor(command, executorFn,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
function withExecutor(command, executorFn, options = {}) {
|
|
28
|
+
const { importPath = "powerlines/api", defaultOptions = {}, framework = {} } = options;
|
|
29
|
+
framework.name ??= "powerlines";
|
|
30
|
+
framework.orgId ??= "storm-software";
|
|
31
|
+
return withRunExecutor(`${titleCase(framework.name)} - ${titleCase(command)} executor`, async (options, context, workspaceConfig) => {
|
|
32
|
+
if (!context.projectName) throw new Error(`The ${titleCase(framework.name)} - ${titleCase(command)} executor requires \`projectName\` on the context object.`);
|
|
33
|
+
if (!context.projectName || !context.projectsConfigurations?.projects || !context.projectsConfigurations.projects[context.projectName] || !context.projectsConfigurations.projects[context.projectName]?.root) throw new Error(`The ${titleCase(framework.name)} - ${titleCase(command)} executor requires \`projectsConfigurations\` on the context object.`);
|
|
29
34
|
const projectConfig = context.projectsConfigurations.projects[context.projectName];
|
|
30
35
|
const jiti = createJiti(context.root, {
|
|
31
36
|
cache: false,
|
|
32
37
|
tsconfigPaths: true
|
|
33
38
|
});
|
|
34
|
-
const api = await jiti.import(jiti.esmResolve(
|
|
39
|
+
const api = await jiti.import(jiti.esmResolve(importPath)).then((mod) => mod.default);
|
|
35
40
|
try {
|
|
36
41
|
return await Promise.resolve(executorFn(defu({
|
|
37
42
|
projectName: context.projectName,
|
|
@@ -79,21 +84,18 @@ function withExecutor(command, executorFn, defaultOptions = {}) {
|
|
|
79
84
|
]))
|
|
80
85
|
}, context), async (inlineConfig) => api({
|
|
81
86
|
options: defu(defaultOptions, {
|
|
82
|
-
executionId:
|
|
87
|
+
executionId: formatExecutionId(inlineConfig.name || context.projectName || projectConfig.root, command, options.configIndex ?? 0),
|
|
83
88
|
cwd: context.root,
|
|
84
89
|
root: projectConfig.root,
|
|
85
|
-
configFile: options.configFile || options.config || joinPaths(projectConfig.root,
|
|
90
|
+
configFile: options.configFile || options.config || joinPaths(projectConfig.root, `${kebabCase(framework.name)}.config.ts`),
|
|
86
91
|
configIndex: options.configIndex,
|
|
87
|
-
framework
|
|
88
|
-
name: "powerlines",
|
|
89
|
-
orgId: "storm-software"
|
|
90
|
-
}
|
|
92
|
+
framework
|
|
91
93
|
}),
|
|
92
94
|
command,
|
|
93
95
|
inlineConfig
|
|
94
96
|
})));
|
|
95
97
|
} catch (error) {
|
|
96
|
-
writeError(`An error occurred while executing the
|
|
98
|
+
writeError(`An error occurred while executing the ${titleCase(framework.name)} - ${titleCase(command)} executor: ${isError(error) ? `${error.message}
|
|
97
99
|
|
|
98
100
|
${error.stack}` : "Unknown error"}`);
|
|
99
101
|
return { success: false };
|
|
@@ -109,4 +111,4 @@ ${error.stack}` : "Unknown error"}`);
|
|
|
109
111
|
|
|
110
112
|
//#endregion
|
|
111
113
|
export { withExecutor as t };
|
|
112
|
-
//# sourceMappingURL=base-executor-
|
|
114
|
+
//# sourceMappingURL=base-executor-B1RffQX6.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-executor-B1RffQX6.mjs","names":[],"sources":["../../src/base/base-executor.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { ExecutorContext, PromiseExecutor } from \"@nx/devkit\";\nimport { writeError } from \"@storm-software/config-tools/logger\";\nimport { StormWorkspaceConfig } from \"@storm-software/config/types\";\nimport { withRunExecutor } from \"@storm-software/workspace-tools/base/base-executor\";\nimport { BaseExecutorResult } from \"@storm-software/workspace-tools/types\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isError } from \"@stryke/type-checks/is-error\";\nimport { isSet } from \"@stryke/type-checks/is-set\";\nimport { isSetArray } from \"@stryke/type-checks/is-set-array\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport type { DeepPartial } from \"@stryke/types/base\";\nimport defu from \"defu\";\nimport { createJiti } from \"jiti\";\nimport type {\n ExecutionApiParams,\n ExecutionOptions,\n FrameworkOptions,\n InlineConfig,\n Mode,\n OutputConfig\n} from \"powerlines\";\nimport { formatExecutionId } from \"powerlines\";\nimport { BaseExecutorSchema } from \"./base-executor.schema\";\n\nexport type PowerlinesExecutorContext<\n TExecutorSchema extends BaseExecutorSchema = BaseExecutorSchema\n> = ExecutorContext & {\n projectName: string;\n command: string;\n options: TExecutorSchema;\n inlineConfig: InlineConfig;\n workspaceConfig: StormWorkspaceConfig;\n};\n\nexport type PowerlinesExecutorApi = (\n inlineConfig: InlineConfig\n) => Promise<void>;\n\nexport interface WithExecutorOptions {\n /**\n * The import path for the executor API module, which is used to dynamically import the API function that will be called during execution. This value should be a string representing the module path, and it defaults to \"powerlines/api\" if not provided. The specified module should export a default function that matches the expected signature for the executor API, which will be invoked with the execution parameters when the executor is run.\n *\n * @defaultValue \"powerlines/api\"\n */\n importPath?: string;\n\n /**\n * Default options to be merged with the execution options, which can be used to provide default values for certain execution parameters or to override specific options for all executions of the executor. This value should be an object that matches the shape of the `ExecutionOptions` type, and it will be merged with the options provided during execution to create the final set of options that will be passed to the executor API function.\n *\n * @remarks\n * This can be useful for setting default values for options that are commonly used across multiple executions, or for providing a consistent set of options for all executions of the executor without requiring the caller to specify them each time.\n */\n defaultOptions?: DeepPartial<ExecutionOptions>;\n\n /**\n * Details about the framework being used in the current execution, which can be used by plugins and other parts of the system to customize behavior based on the framework.\n *\n * @remarks\n * This should only be used by framework plugins to ensure the correct framework name is applied\n *\n * @defaultValue\n * ```ts\n * {\n * name: \"powerlines\",\n * orgId: \"storm-software\"\n * }\n * ```\n */\n framework?: FrameworkOptions;\n}\n\n/**\n * A utility function to create a Powerlines executor that can be used with the `withRunExecutor` function.\n *\n * @remarks\n * This function is designed to simplify the creation of Powerlines executors by providing a consistent interface and error handling.\n *\n * @param command - The command that the executor will handle (e.g., \"new\", \"prepare\", \"build\", etc.).\n * @param executorFn - The function that will be executed when the command is run.\n * @param options - Additional options for configuring the executor, such as the import path for the API module and default execution options.\n * @returns A Promise that resolves to the result of the executor function.\n */\nexport function withExecutor<\n TExecutorSchema extends BaseExecutorSchema = BaseExecutorSchema\n>(\n command: string,\n executorFn: (\n context: PowerlinesExecutorContext<TExecutorSchema>,\n api: PowerlinesExecutorApi\n ) =>\n | Promise<BaseExecutorResult | null | undefined>\n | BaseExecutorResult\n | null\n | undefined,\n options: WithExecutorOptions = {}\n): PromiseExecutor<TExecutorSchema> {\n const {\n importPath = \"powerlines/api\",\n defaultOptions = {},\n framework = {} as FrameworkOptions\n } = options;\n\n framework.name ??= \"powerlines\";\n framework.orgId ??= \"storm-software\";\n\n return withRunExecutor(\n `${titleCase(framework.name)} - ${titleCase(command)} executor`,\n async (\n options: TExecutorSchema,\n context: ExecutorContext,\n workspaceConfig: StormWorkspaceConfig\n ): Promise<BaseExecutorResult | null | undefined> => {\n if (!context.projectName) {\n throw new Error(\n `The ${titleCase(framework.name)} - ${titleCase(\n command\n )} executor requires \\`projectName\\` on the context object.`\n );\n }\n\n if (\n !context.projectName ||\n !context.projectsConfigurations?.projects ||\n !context.projectsConfigurations.projects[context.projectName] ||\n !context.projectsConfigurations.projects[context.projectName]?.root\n ) {\n throw new Error(\n `The ${titleCase(framework.name)} - ${titleCase(\n command\n )} executor requires \\`projectsConfigurations\\` on the context object.`\n );\n }\n\n const projectConfig =\n context.projectsConfigurations.projects[context.projectName]!;\n\n const jiti = createJiti(context.root, {\n cache: false,\n tsconfigPaths: true\n });\n const api = await jiti\n .import<{\n default: (params: ExecutionApiParams) => Promise<void>;\n }>(jiti.esmResolve(importPath))\n .then(mod => mod.default);\n\n try {\n return await Promise.resolve(\n executorFn(\n defu(\n {\n projectName: context.projectName,\n options,\n workspaceConfig,\n command,\n inlineConfig: defu(\n {\n name: context.projectName,\n command,\n root: projectConfig.root,\n configFile: options.configFile || options.config,\n configIndex: options.configIndex,\n projectType: projectConfig.projectType,\n mode: options.mode as Mode,\n output: {\n path: options.outputPath,\n copy:\n options.copyPath === false\n ? false\n : {\n path: options.copyPath,\n assets: options.assets\n },\n minify: options.minify,\n sourceMap: options.sourceMap\n } as OutputConfig,\n resolve:\n isSetArray(options.external) ||\n isSetArray(options.noExternal) ||\n isSet(options.skipNodeModulesBundle)\n ? {\n external: isSetArray(options.external)\n ? options.external\n : undefined,\n noExternal: isSetArray(options.noExternal)\n ? options.noExternal\n : undefined,\n skipNodeModulesBundle: isSet(\n options.skipNodeModulesBundle\n )\n ? options.skipNodeModulesBundle\n : undefined\n }\n : undefined,\n define: isSetObject(options.define)\n ? options.define\n : undefined,\n assets: isSetObject(options.assets)\n ? options.assets\n : undefined\n },\n omit(options, [\n \"config\",\n \"configFile\",\n \"outputPath\",\n \"copyPath\",\n \"sourceMap\",\n \"minify\",\n \"format\",\n \"external\",\n \"noExternal\",\n \"skipNodeModulesBundle\",\n \"mode\",\n \"define\",\n \"assets\"\n ])\n ) as InlineConfig\n },\n context\n ),\n async (inlineConfig: InlineConfig) =>\n api({\n options: defu(defaultOptions, {\n executionId: formatExecutionId(\n inlineConfig.name ||\n context.projectName ||\n projectConfig.root,\n command,\n options.configIndex ?? 0\n ),\n cwd: context.root,\n root: projectConfig.root,\n configFile:\n options.configFile ||\n options.config ||\n joinPaths(\n projectConfig.root,\n `${kebabCase(framework.name)}.config.ts`\n ),\n configIndex: options.configIndex,\n framework\n }) as ExecutionOptions,\n command,\n inlineConfig\n })\n )\n );\n } catch (error) {\n writeError(\n `An error occurred while executing the ${titleCase(\n framework.name\n )} - ${titleCase(command)} executor: ${\n isError(error)\n ? `${error.message}\n\n${error.stack}`\n : \"Unknown error\"\n }`\n );\n\n return { success: false };\n }\n },\n {\n skipReadingConfig: false,\n hooks: {\n applyDefaultOptions: (options: Partial<TExecutorSchema>) => {\n options.copyPath ??= \"dist/{projectRoot}\";\n\n return options as TExecutorSchema;\n }\n }\n }\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAuGA,SAAgB,aAGd,SACA,YAQA,UAA+B,CAAC,GACE;CAClC,MAAM,EACJ,aAAa,kBACb,iBAAiB,CAAC,GAClB,YAAY,CAAC,MACX;CAEJ,UAAU,SAAS;CACnB,UAAU,UAAU;CAEpB,OAAO,gBACL,GAAG,UAAU,UAAU,IAAI,EAAE,KAAK,UAAU,OAAO,EAAE,YACrD,OACE,SACA,SACA,oBACmD;EACnD,IAAI,CAAC,QAAQ,aACX,MAAM,IAAI,MACR,OAAO,UAAU,UAAU,IAAI,EAAE,KAAK,UACpC,OACF,EAAE,0DACJ;EAGF,IACE,CAAC,QAAQ,eACT,CAAC,QAAQ,wBAAwB,YACjC,CAAC,QAAQ,uBAAuB,SAAS,QAAQ,gBACjD,CAAC,QAAQ,uBAAuB,SAAS,QAAQ,cAAc,MAE/D,MAAM,IAAI,MACR,OAAO,UAAU,UAAU,IAAI,EAAE,KAAK,UACpC,OACF,EAAE,qEACJ;EAGF,MAAM,gBACJ,QAAQ,uBAAuB,SAAS,QAAQ;EAElD,MAAM,OAAO,WAAW,QAAQ,MAAM;GACpC,OAAO;GACP,eAAe;EACjB,CAAC;EACD,MAAM,MAAM,MAAM,KACf,OAEE,KAAK,WAAW,UAAU,CAAC,EAC7B,MAAK,QAAO,IAAI,OAAO;EAE1B,IAAI;GACF,OAAO,MAAM,QAAQ,QACnB,WACE,KACE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MAAM,QAAQ;;EAE/B,MAAM,UACQ,iBAER;GAEA,OAAO,EAAE,SAAS,MAAM;EAC1B;CACF,GACA;EACE,mBAAmB;EACnB,OAAO,EACL,sBAAsB,YAAsC;GAC1D,QAAQ,aAAa;GAErB,OAAO;EACT,EACF;CACF,CACF;AACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-C_NdSu1c.js');
|
|
2
|
+
let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
2
3
|
let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
3
4
|
let _stryke_type_checks_is_error = require("@stryke/type-checks/is-error");
|
|
4
5
|
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
@@ -11,6 +12,7 @@ let _stryke_path_join = require("@stryke/path/join");
|
|
|
11
12
|
let _stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
|
|
12
13
|
let _stryke_type_checks_is_set_array = require("@stryke/type-checks/is-set-array");
|
|
13
14
|
let jiti = require("jiti");
|
|
15
|
+
let powerlines = require("powerlines");
|
|
14
16
|
|
|
15
17
|
//#region src/base/base-executor.ts
|
|
16
18
|
/**
|
|
@@ -21,19 +23,22 @@ let jiti = require("jiti");
|
|
|
21
23
|
*
|
|
22
24
|
* @param command - The command that the executor will handle (e.g., "new", "prepare", "build", etc.).
|
|
23
25
|
* @param executorFn - The function that will be executed when the command is run.
|
|
24
|
-
* @param
|
|
26
|
+
* @param options - Additional options for configuring the executor, such as the import path for the API module and default execution options.
|
|
25
27
|
* @returns A Promise that resolves to the result of the executor function.
|
|
26
28
|
*/
|
|
27
|
-
function withExecutor(command, executorFn,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
function withExecutor(command, executorFn, options = {}) {
|
|
30
|
+
const { importPath = "powerlines/api", defaultOptions = {}, framework = {} } = options;
|
|
31
|
+
framework.name ??= "powerlines";
|
|
32
|
+
framework.orgId ??= "storm-software";
|
|
33
|
+
return (0, _storm_software_workspace_tools_base_base_executor.withRunExecutor)(`${(0, _stryke_string_format_title_case.titleCase)(framework.name)} - ${(0, _stryke_string_format_title_case.titleCase)(command)} executor`, async (options, context, workspaceConfig) => {
|
|
34
|
+
if (!context.projectName) throw new Error(`The ${(0, _stryke_string_format_title_case.titleCase)(framework.name)} - ${(0, _stryke_string_format_title_case.titleCase)(command)} executor requires \`projectName\` on the context object.`);
|
|
35
|
+
if (!context.projectName || !context.projectsConfigurations?.projects || !context.projectsConfigurations.projects[context.projectName] || !context.projectsConfigurations.projects[context.projectName]?.root) throw new Error(`The ${(0, _stryke_string_format_title_case.titleCase)(framework.name)} - ${(0, _stryke_string_format_title_case.titleCase)(command)} executor requires \`projectsConfigurations\` on the context object.`);
|
|
31
36
|
const projectConfig = context.projectsConfigurations.projects[context.projectName];
|
|
32
37
|
const jiti$1 = (0, jiti.createJiti)(context.root, {
|
|
33
38
|
cache: false,
|
|
34
39
|
tsconfigPaths: true
|
|
35
40
|
});
|
|
36
|
-
const api = await jiti$1.import(jiti$1.esmResolve(
|
|
41
|
+
const api = await jiti$1.import(jiti$1.esmResolve(importPath)).then((mod) => mod.default);
|
|
37
42
|
try {
|
|
38
43
|
return await Promise.resolve(executorFn((0, defu.default)({
|
|
39
44
|
projectName: context.projectName,
|
|
@@ -81,21 +86,18 @@ function withExecutor(command, executorFn, defaultOptions = {}) {
|
|
|
81
86
|
]))
|
|
82
87
|
}, context), async (inlineConfig) => api({
|
|
83
88
|
options: (0, defu.default)(defaultOptions, {
|
|
84
|
-
executionId:
|
|
89
|
+
executionId: (0, powerlines.formatExecutionId)(inlineConfig.name || context.projectName || projectConfig.root, command, options.configIndex ?? 0),
|
|
85
90
|
cwd: context.root,
|
|
86
91
|
root: projectConfig.root,
|
|
87
|
-
configFile: options.configFile || options.config || (0, _stryke_path_join.joinPaths)(projectConfig.root,
|
|
92
|
+
configFile: options.configFile || options.config || (0, _stryke_path_join.joinPaths)(projectConfig.root, `${(0, _stryke_string_format_kebab_case.kebabCase)(framework.name)}.config.ts`),
|
|
88
93
|
configIndex: options.configIndex,
|
|
89
|
-
framework
|
|
90
|
-
name: "powerlines",
|
|
91
|
-
orgId: "storm-software"
|
|
92
|
-
}
|
|
94
|
+
framework
|
|
93
95
|
}),
|
|
94
96
|
command,
|
|
95
97
|
inlineConfig
|
|
96
98
|
})));
|
|
97
99
|
} catch (error) {
|
|
98
|
-
(0, _storm_software_config_tools_logger.writeError)(`An error occurred while executing the
|
|
100
|
+
(0, _storm_software_config_tools_logger.writeError)(`An error occurred while executing the ${(0, _stryke_string_format_title_case.titleCase)(framework.name)} - ${(0, _stryke_string_format_title_case.titleCase)(command)} executor: ${(0, _stryke_type_checks_is_error.isError)(error) ? `${error.message}
|
|
99
101
|
|
|
100
102
|
${error.stack}` : "Unknown error"}`);
|
|
101
103
|
return { success: false };
|
|
@@ -9,6 +9,7 @@ const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TS
|
|
|
9
9
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
10
10
|
const require_runtime = require('../_virtual/_rolldown/runtime.js');
|
|
11
11
|
const require_helpers_constants = require('./constants.js');
|
|
12
|
+
let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
12
13
|
let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
13
14
|
let _stryke_type_checks_is_error = require("@stryke/type-checks/is-error");
|
|
14
15
|
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
@@ -22,7 +23,6 @@ let _stryke_env_environment_checks = require("@stryke/env/environment-checks");
|
|
|
22
23
|
let _stryke_env_get_env_paths = require("@stryke/env/get-env-paths");
|
|
23
24
|
let _stryke_fs_exists = require("@stryke/fs/exists");
|
|
24
25
|
let _stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
25
|
-
let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
26
26
|
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
27
27
|
let node_fs_promises = require("node:fs/promises");
|
|
28
28
|
let nx_src_config_nx_json_js = require("nx/src/config/nx-json.js");
|
|
@@ -7,6 +7,7 @@ const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPat
|
|
|
7
7
|
const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
|
|
8
8
|
|
|
9
9
|
import { CONFIG_INPUTS } from "./constants.mjs";
|
|
10
|
+
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
10
11
|
import { titleCase } from "@stryke/string-format/title-case";
|
|
11
12
|
import { isError } from "@stryke/type-checks/is-error";
|
|
12
13
|
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
@@ -19,7 +20,6 @@ import { isDevelopment } from "@stryke/env/environment-checks";
|
|
|
19
20
|
import { getEnvPaths } from "@stryke/env/get-env-paths";
|
|
20
21
|
import { existsSync } from "@stryke/fs/exists";
|
|
21
22
|
import { joinPaths } from "@stryke/path/join-paths";
|
|
22
|
-
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
23
23
|
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
24
24
|
import { readFile } from "node:fs/promises";
|
|
25
25
|
import { readNxJson } from "nx/src/config/nx-json.js";
|
package/dist/src/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import __tsdown_shims_path from 'node:path';
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
|
-
import { PowerlinesExecutorApi, PowerlinesExecutorContext, withExecutor } from "./base/base-executor.mjs";
|
|
3
|
+
import { PowerlinesExecutorApi, PowerlinesExecutorContext, WithExecutorOptions, withExecutor } from "./base/base-executor.mjs";
|
|
4
4
|
import { CONFIG_INPUTS } from "./helpers/constants.mjs";
|
|
5
5
|
import { NxPluginOptions } from "./types/plugin.mjs";
|
|
6
6
|
import { CreateNxPluginOptions, createNxPlugin, getNxPluginInputs, getNxTargetInputs } from "./helpers/plugin-utilities.mjs";
|
|
7
|
-
export { CONFIG_INPUTS, CreateNxPluginOptions, NxPluginOptions, PowerlinesExecutorApi, PowerlinesExecutorContext, createNxPlugin, getNxPluginInputs, getNxTargetInputs, withExecutor };
|
|
7
|
+
export { CONFIG_INPUTS, CreateNxPluginOptions, NxPluginOptions, PowerlinesExecutorApi, PowerlinesExecutorContext, WithExecutorOptions, createNxPlugin, getNxPluginInputs, getNxTargetInputs, withExecutor };
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PowerlinesExecutorApi, PowerlinesExecutorContext, withExecutor } from "./base/base-executor.js";
|
|
1
|
+
import { PowerlinesExecutorApi, PowerlinesExecutorContext, WithExecutorOptions, withExecutor } from "./base/base-executor.js";
|
|
2
2
|
import { CONFIG_INPUTS } from "./helpers/constants.js";
|
|
3
3
|
import { NxPluginOptions } from "./types/plugin.js";
|
|
4
4
|
import { CreateNxPluginOptions, createNxPlugin, getNxPluginInputs, getNxTargetInputs } from "./helpers/plugin-utilities.js";
|
|
5
|
-
export { CONFIG_INPUTS, CreateNxPluginOptions, NxPluginOptions, PowerlinesExecutorApi, PowerlinesExecutorContext, createNxPlugin, getNxPluginInputs, getNxTargetInputs, withExecutor };
|
|
5
|
+
export { CONFIG_INPUTS, CreateNxPluginOptions, NxPluginOptions, PowerlinesExecutorApi, PowerlinesExecutorContext, WithExecutorOptions, createNxPlugin, getNxPluginInputs, getNxTargetInputs, withExecutor };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/nx",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.126",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A Nx plugin to support Powerlines development in Nx monorepos.",
|
|
6
6
|
"repository": {
|
|
@@ -174,10 +174,10 @@
|
|
|
174
174
|
],
|
|
175
175
|
"dependencies": {
|
|
176
176
|
"@nx/devkit": "^22.7.5",
|
|
177
|
-
"@storm-software/build-tools": "^0.158.
|
|
178
|
-
"@storm-software/config": "^1.137.
|
|
179
|
-
"@storm-software/config-tools": "^1.190.
|
|
180
|
-
"@storm-software/workspace-tools": "^1.296.
|
|
177
|
+
"@storm-software/build-tools": "^0.158.196",
|
|
178
|
+
"@storm-software/config": "^1.137.68",
|
|
179
|
+
"@storm-software/config-tools": "^1.190.36",
|
|
180
|
+
"@storm-software/workspace-tools": "^1.296.14",
|
|
181
181
|
"@stryke/env": "^0.20.96",
|
|
182
182
|
"@stryke/fs": "^0.33.79",
|
|
183
183
|
"@stryke/hash": "^0.13.32",
|
|
@@ -187,13 +187,13 @@
|
|
|
187
187
|
"@stryke/type-checks": "^0.6.12",
|
|
188
188
|
"defu": "^6.1.7",
|
|
189
189
|
"jiti": "^2.7.0",
|
|
190
|
-
"powerlines": "^0.47.
|
|
190
|
+
"powerlines": "^0.47.88"
|
|
191
191
|
},
|
|
192
192
|
"devDependencies": {
|
|
193
193
|
"@nx/workspace": "22.7.5",
|
|
194
|
-
"@storm-software/testing-tools": "^1.119.
|
|
195
|
-
"@storm-software/tsup": "^0.2.
|
|
196
|
-
"@storm-software/untyped": "^0.24.
|
|
194
|
+
"@storm-software/testing-tools": "^1.119.189",
|
|
195
|
+
"@storm-software/tsup": "^0.2.194",
|
|
196
|
+
"@storm-software/untyped": "^0.24.178",
|
|
197
197
|
"@stryke/types": "^0.12.7",
|
|
198
198
|
"@types/node": "^25.9.1",
|
|
199
199
|
"eslint-flat-config-utils": "^2.1.4",
|
|
@@ -206,5 +206,5 @@
|
|
|
206
206
|
"publishConfig": { "access": "public" },
|
|
207
207
|
"executors": "./executors.json",
|
|
208
208
|
"generators": "./generators.json",
|
|
209
|
-
"gitHead": "
|
|
209
|
+
"gitHead": "8712f695515d4d33d5bcfe8c460580d83f321c0e"
|
|
210
210
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base-executor-0AtMZrSx.mjs","names":[],"sources":["../../src/base/base-executor.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { ExecutorContext, PromiseExecutor } from \"@nx/devkit\";\nimport { writeError } from \"@storm-software/config-tools/logger\";\nimport { StormWorkspaceConfig } from \"@storm-software/config/types\";\nimport { withRunExecutor } from \"@storm-software/workspace-tools/base/base-executor\";\nimport { BaseExecutorResult } from \"@storm-software/workspace-tools/types\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isError } from \"@stryke/type-checks/is-error\";\nimport { isSet } from \"@stryke/type-checks/is-set\";\nimport { isSetArray } from \"@stryke/type-checks/is-set-array\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport type { DeepPartial } from \"@stryke/types/base\";\nimport defu from \"defu\";\nimport { createJiti } from \"jiti\";\nimport type {\n ExecutionApiParams,\n ExecutionOptions,\n InlineConfig,\n Mode,\n OutputConfig\n} from \"powerlines\";\nimport { BaseExecutorSchema } from \"./base-executor.schema\";\n\nexport type PowerlinesExecutorContext<\n TExecutorSchema extends BaseExecutorSchema = BaseExecutorSchema\n> = ExecutorContext & {\n projectName: string;\n command: string;\n options: TExecutorSchema;\n inlineConfig: InlineConfig;\n workspaceConfig: StormWorkspaceConfig;\n};\n\nexport type PowerlinesExecutorApi = (\n inlineConfig: InlineConfig\n) => Promise<void>;\n\n/**\n * A utility function to create a Powerlines executor that can be used with the `withRunExecutor` function.\n *\n * @remarks\n * This function is designed to simplify the creation of Powerlines executors by providing a consistent interface and error handling.\n *\n * @param command - The command that the executor will handle (e.g., \"new\", \"prepare\", \"build\", etc.).\n * @param executorFn - The function that will be executed when the command is run.\n * @param defaultOptions - Default options to be merged with the execution options.\n * @returns A Promise that resolves to the result of the executor function.\n */\nexport function withExecutor<\n TExecutorSchema extends BaseExecutorSchema = BaseExecutorSchema\n>(\n command: string,\n executorFn: (\n context: PowerlinesExecutorContext<TExecutorSchema>,\n api: PowerlinesExecutorApi\n ) =>\n | Promise<BaseExecutorResult | null | undefined>\n | BaseExecutorResult\n | null\n | undefined,\n defaultOptions: DeepPartial<ExecutionOptions> = {}\n): PromiseExecutor<TExecutorSchema> {\n return withRunExecutor(\n `Powerlines - ${titleCase(command)} executor`,\n async (\n options: TExecutorSchema,\n context: ExecutorContext,\n workspaceConfig: StormWorkspaceConfig\n ): Promise<BaseExecutorResult | null | undefined> => {\n if (!context.projectName) {\n throw new Error(\n `The Powerlines - ${titleCase(command)} executor requires \\`projectName\\` on the context object.`\n );\n }\n\n if (\n !context.projectName ||\n !context.projectsConfigurations?.projects ||\n !context.projectsConfigurations.projects[context.projectName] ||\n !context.projectsConfigurations.projects[context.projectName]?.root\n ) {\n throw new Error(\n `The Powerlines - ${titleCase(command)} executor requires \\`projectsConfigurations\\` on the context object.`\n );\n }\n\n const projectConfig =\n context.projectsConfigurations.projects[context.projectName]!;\n\n const jiti = createJiti(context.root, {\n cache: false,\n tsconfigPaths: true\n });\n const api = await jiti\n .import<{\n default: (params: ExecutionApiParams) => Promise<void>;\n }>(jiti.esmResolve(\"powerlines/api\"))\n .then(mod => mod.default);\n\n try {\n return await Promise.resolve(\n executorFn(\n defu(\n {\n projectName: context.projectName,\n options,\n workspaceConfig,\n command,\n inlineConfig: defu(\n {\n name: context.projectName,\n command,\n root: projectConfig.root,\n configFile: options.configFile || options.config,\n configIndex: options.configIndex,\n projectType: projectConfig.projectType,\n mode: options.mode as Mode,\n output: {\n path: options.outputPath,\n copy:\n options.copyPath === false\n ? false\n : {\n path: options.copyPath,\n assets: options.assets\n },\n minify: options.minify,\n sourceMap: options.sourceMap\n } as OutputConfig,\n resolve:\n isSetArray(options.external) ||\n isSetArray(options.noExternal) ||\n isSet(options.skipNodeModulesBundle)\n ? {\n external: isSetArray(options.external)\n ? options.external\n : undefined,\n noExternal: isSetArray(options.noExternal)\n ? options.noExternal\n : undefined,\n skipNodeModulesBundle: isSet(\n options.skipNodeModulesBundle\n )\n ? options.skipNodeModulesBundle\n : undefined\n }\n : undefined,\n define: isSetObject(options.define)\n ? options.define\n : undefined,\n assets: isSetObject(options.assets)\n ? options.assets\n : undefined\n },\n omit(options, [\n \"config\",\n \"configFile\",\n \"outputPath\",\n \"copyPath\",\n \"sourceMap\",\n \"minify\",\n \"format\",\n \"external\",\n \"noExternal\",\n \"skipNodeModulesBundle\",\n \"mode\",\n \"define\",\n \"assets\"\n ])\n ) as InlineConfig\n },\n context\n ),\n async (inlineConfig: InlineConfig) =>\n api({\n // eslint-disable-next-line ts/no-unnecessary-type-assertion\n options: defu(defaultOptions, {\n executionId: `${context.projectName}-${command}-${options.configIndex}`,\n cwd: context.root,\n root: projectConfig.root,\n configFile:\n options.configFile ||\n options.config ||\n joinPaths(projectConfig.root, \"powerlines.config.ts\"),\n configIndex: options.configIndex,\n framework: {\n name: \"powerlines\",\n orgId: \"storm-software\"\n }\n }) as ExecutionOptions,\n command,\n inlineConfig\n })\n )\n );\n } catch (error) {\n writeError(\n `An error occurred while executing the Powerlines - ${titleCase(\n command\n )} executor: ${\n isError(error)\n ? `${error.message}\n\n${error.stack}`\n : \"Unknown error\"\n }`\n );\n\n return { success: false };\n }\n },\n {\n skipReadingConfig: false,\n hooks: {\n applyDefaultOptions: (options: Partial<TExecutorSchema>) => {\n options.copyPath ??= \"dist/{projectRoot}\";\n\n return options as TExecutorSchema;\n }\n }\n }\n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