@code-pushup/nx-plugin 0.51.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.
- package/README.md +23 -0
- package/executors.json +9 -0
- package/generators.json +14 -0
- package/package.json +31 -0
- package/src/executors/autorun/README.md +61 -0
- package/src/executors/autorun/constants.d.ts +1 -0
- package/src/executors/autorun/constants.js +5 -0
- package/src/executors/autorun/constants.js.map +1 -0
- package/src/executors/autorun/executor.d.ts +15 -0
- package/src/executors/autorun/executor.js +44 -0
- package/src/executors/autorun/executor.js.map +1 -0
- package/src/executors/autorun/schema.d.ts +7 -0
- package/src/executors/autorun/schema.js +3 -0
- package/src/executors/autorun/schema.js.map +1 -0
- package/src/executors/autorun/schema.json +100 -0
- package/src/executors/autorun/utils.d.ts +4 -0
- package/src/executors/autorun/utils.js +24 -0
- package/src/executors/autorun/utils.js.map +1 -0
- package/src/executors/internal/cli.d.ts +10 -0
- package/src/executors/internal/cli.js +48 -0
- package/src/executors/internal/cli.js.map +1 -0
- package/src/executors/internal/config.d.ts +5 -0
- package/src/executors/internal/config.js +47 -0
- package/src/executors/internal/config.js.map +1 -0
- package/src/executors/internal/context.d.ts +6 -0
- package/src/executors/internal/context.js +13 -0
- package/src/executors/internal/context.js.map +1 -0
- package/src/executors/internal/env.d.ts +2 -0
- package/src/executors/internal/env.js +36 -0
- package/src/executors/internal/env.js.map +1 -0
- package/src/executors/internal/types.d.ts +39 -0
- package/src/executors/internal/types.js +3 -0
- package/src/executors/internal/types.js.map +1 -0
- package/src/generators/configuration/README.md +27 -0
- package/src/generators/configuration/code-pushup-config.d.ts +13 -0
- package/src/generators/configuration/code-pushup-config.js +38 -0
- package/src/generators/configuration/code-pushup-config.js.map +1 -0
- package/src/generators/configuration/files/code-pushup.config.ts.template +9 -0
- package/src/generators/configuration/generator.d.ts +6 -0
- package/src/generators/configuration/generator.js +46 -0
- package/src/generators/configuration/generator.js.map +1 -0
- package/src/generators/configuration/schema.d.ts +9 -0
- package/src/generators/configuration/schema.json +45 -0
- package/src/generators/configuration/types.d.ts +5 -0
- package/src/generators/configuration/types.js +3 -0
- package/src/generators/configuration/types.js.map +1 -0
- package/src/generators/configuration/utils.d.ts +9 -0
- package/src/generators/configuration/utils.js +47 -0
- package/src/generators/configuration/utils.js.map +1 -0
- package/src/generators/init/README.md +24 -0
- package/src/generators/init/generator.d.ts +5 -0
- package/src/generators/init/generator.js +78 -0
- package/src/generators/init/generator.js.map +1 -0
- package/src/generators/init/schema.d.ts +5 -0
- package/src/generators/init/schema.json +23 -0
- package/src/index.d.ts +11 -0
- package/src/index.js +22 -0
- package/src/index.js.map +1 -0
- package/src/internal/constants.d.ts +3 -0
- package/src/internal/constants.js +8 -0
- package/src/internal/constants.js.map +1 -0
- package/src/internal/execute-process.d.ts +123 -0
- package/src/internal/execute-process.js +104 -0
- package/src/internal/execute-process.js.map +1 -0
- package/src/internal/types.d.ts +4 -0
- package/src/internal/types.js +3 -0
- package/src/internal/types.js.map +1 -0
- package/src/internal/versions.d.ts +4 -0
- package/src/internal/versions.js +15 -0
- package/src/internal/versions.js.map +1 -0
- package/src/plugin/constants.d.ts +1 -0
- package/src/plugin/constants.js +5 -0
- package/src/plugin/constants.js.map +1 -0
- package/src/plugin/index.d.ts +2 -0
- package/src/plugin/index.js +6 -0
- package/src/plugin/index.js.map +1 -0
- package/src/plugin/plugin.d.ts +2 -0
- package/src/plugin/plugin.js +22 -0
- package/src/plugin/plugin.js.map +1 -0
- package/src/plugin/target/configuration-target.d.ts +7 -0
- package/src/plugin/target/configuration-target.js +18 -0
- package/src/plugin/target/configuration-target.js.map +1 -0
- package/src/plugin/target/constants.d.ts +1 -0
- package/src/plugin/target/constants.js +5 -0
- package/src/plugin/target/constants.js.map +1 -0
- package/src/plugin/target/executor-target.d.ts +6 -0
- package/src/plugin/target/executor-target.js +19 -0
- package/src/plugin/target/executor-target.js.map +1 -0
- package/src/plugin/target/targets.d.ts +6 -0
- package/src/plugin/target/targets.js +26 -0
- package/src/plugin/target/targets.js.map +1 -0
- package/src/plugin/types.d.ts +13 -0
- package/src/plugin/types.js +3 -0
- package/src/plugin/types.js.map +1 -0
- package/src/plugin/utils.d.ts +3 -0
- package/src/plugin/utils.js +27 -0
- package/src/plugin/utils.js.map +1 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Configuration Generator
|
|
2
|
+
|
|
3
|
+
#### @code-pushup/nx-plugin:configuration
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
`nx generate configuration ...`
|
|
8
|
+
|
|
9
|
+
By default, the Nx plugin will search for existing configuration files. If they are not present it creates a `code-pushup.config.ts` and adds a target to your `project.json` file.
|
|
10
|
+
|
|
11
|
+
You can specify the collection explicitly as follows:
|
|
12
|
+
|
|
13
|
+
`nx g @code-pushup/nx-plugin:configuration ...`
|
|
14
|
+
|
|
15
|
+
Show what will be generated without writing to disk:
|
|
16
|
+
|
|
17
|
+
`nx g configuration ... --dry-run`
|
|
18
|
+
|
|
19
|
+
## Options
|
|
20
|
+
|
|
21
|
+
| Name | type | description |
|
|
22
|
+
| ----------------- | -------------------------------- | -------------------------------------------------------- |
|
|
23
|
+
| **--project** | `string` (REQUIRED) | The name of the project. |
|
|
24
|
+
| **--targetName** | `string` (DEFAULT 'code-pushup') | The id used to identify a target in your project.json. |
|
|
25
|
+
| **--bin** | `string` | Path to Code PushUp CLI |
|
|
26
|
+
| **--skipProject** | `boolean` (DEFAULT false) | Skip adding the target to `project.json`. |
|
|
27
|
+
| **--skipConfig** | `boolean` (DEFAULT false) | Skip adding the `code-pushup.config.ts` to project root. |
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
import type { PersistConfig, UploadConfig } from '@code-pushup/models';
|
|
3
|
+
import type { ItemOrArray } from '@code-pushup/utils';
|
|
4
|
+
import type { ExecutableCode } from './types';
|
|
5
|
+
export declare const DEFAULT_IMPORTS: string[];
|
|
6
|
+
export type GenerateCodePushupConfigOptions = {
|
|
7
|
+
fileImports?: ItemOrArray<string>;
|
|
8
|
+
persist?: Partial<PersistConfig>;
|
|
9
|
+
upload?: Partial<UploadConfig>;
|
|
10
|
+
plugins?: ExecutableCode[];
|
|
11
|
+
categories?: ExecutableCode[];
|
|
12
|
+
};
|
|
13
|
+
export declare function generateCodePushupConfig(tree: Tree, root: string, options?: GenerateCodePushupConfigOptions): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateCodePushupConfig = exports.DEFAULT_IMPORTS = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
exports.DEFAULT_IMPORTS = [
|
|
8
|
+
"import type { CoreConfig } from '@code-pushup/models';",
|
|
9
|
+
];
|
|
10
|
+
function generateCodePushupConfig(tree, root, options) {
|
|
11
|
+
const supportedFormats = ['ts', 'mjs', 'js'];
|
|
12
|
+
const firstExistingFormat = supportedFormats.find(ext => tree.exists((0, node_path_1.join)(root, `code-pushup.config.${ext}`)));
|
|
13
|
+
if (firstExistingFormat) {
|
|
14
|
+
devkit_1.logger.warn(`NOTE: No config file created as code-pushup.config.${firstExistingFormat} file already exists.`);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const { fileImports: rawImports, persist, upload, plugins: rawPlugins = [], // plugins are required
|
|
18
|
+
categories: rawCategories, } = options ?? {};
|
|
19
|
+
const plugins = rawPlugins.map(utils_1.normalizeExecutableCode);
|
|
20
|
+
const categories = rawCategories?.map(utils_1.normalizeExecutableCode);
|
|
21
|
+
const configFileImports = [
|
|
22
|
+
...(rawImports ? (0, utils_1.normalizeItemOrArray)(rawImports) : exports.DEFAULT_IMPORTS),
|
|
23
|
+
...plugins.flatMap(({ fileImports }) => fileImports),
|
|
24
|
+
...(categories ?? []).flatMap(({ fileImports }) => fileImports),
|
|
25
|
+
];
|
|
26
|
+
(0, devkit_1.generateFiles)(tree, (0, node_path_1.join)(__dirname, 'files'), root, {
|
|
27
|
+
...options,
|
|
28
|
+
fileImports: (0, utils_1.formatArrayToLinesOfJsString)(configFileImports),
|
|
29
|
+
persist: (0, utils_1.formatObjectToFormattedJsString)(persist),
|
|
30
|
+
upload: (0, utils_1.formatObjectToFormattedJsString)(upload),
|
|
31
|
+
plugins: (0, utils_1.formatArrayToJSArray)(plugins.flatMap(({ codeStrings }) => codeStrings)),
|
|
32
|
+
categories: categories &&
|
|
33
|
+
(0, utils_1.formatArrayToJSArray)(categories.flatMap(({ codeStrings }) => codeStrings)),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.generateCodePushupConfig = generateCodePushupConfig;
|
|
38
|
+
//# sourceMappingURL=code-pushup-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-pushup-config.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/generators/configuration/code-pushup-config.ts"],"names":[],"mappings":";;;AAAA,uCAA8D;AAC9D,yCAAiC;AAIjC,mCAMiB;AAEJ,QAAA,eAAe,GAAG;IAC7B,wDAAwD;CACzD,CAAC;AAUF,SAAgB,wBAAwB,CACtC,IAAU,EACV,IAAY,EACZ,OAAyC;IAEzC,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC7C,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CACtD,IAAI,CAAC,MAAM,CAAC,IAAA,gBAAI,EAAC,IAAI,EAAE,sBAAsB,GAAG,EAAE,CAAC,CAAC,CACrD,CAAC;IACF,IAAI,mBAAmB,EAAE,CAAC;QACxB,eAAM,CAAC,IAAI,CACT,sDAAsD,mBAAmB,uBAAuB,CACjG,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,EACJ,WAAW,EAAE,UAAU,EACvB,OAAO,EACP,MAAM,EACN,OAAO,EAAE,UAAU,GAAG,EAAE,EAAE,uBAAuB;QACjD,UAAU,EAAE,aAAa,GAC1B,GAAG,OAAO,IAAI,EAAE,CAAC;QAElB,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,+BAAuB,CAAC,CAAC;QACxD,MAAM,UAAU,GAAG,aAAa,EAAE,GAAG,CAAC,+BAAuB,CAAC,CAAC;QAC/D,MAAM,iBAAiB,GAAG;YACxB,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,4BAAoB,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC,uBAAe,CAAC;YACpE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC;YACpD,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC;SAChE,CAAC;QAEF,IAAA,sBAAa,EAAC,IAAI,EAAE,IAAA,gBAAI,EAAC,SAAS,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE;YAClD,GAAG,OAAO;YACV,WAAW,EAAE,IAAA,oCAA4B,EAAC,iBAAiB,CAAC;YAC5D,OAAO,EAAE,IAAA,uCAA+B,EAAC,OAAO,CAAC;YACjD,MAAM,EAAE,IAAA,uCAA+B,EAAC,MAAM,CAAC;YAC/C,OAAO,EAAE,IAAA,4BAAoB,EAC3B,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,CAClD;YACD,UAAU,EACR,UAAU;gBACV,IAAA,4BAAoB,EAClB,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,CACrD;SACJ,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AA7CD,4DA6CC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<%- fileImports %>
|
|
2
|
+
|
|
3
|
+
// see: https://github.com/code-pushup/cli/blob/main/packages/models/docs/models-reference.md#coreconfig
|
|
4
|
+
export default {
|
|
5
|
+
<% if (persist) { %>persist: <%- persist %>,<% } %>
|
|
6
|
+
<% if (upload) { %>update: <%- upload %>,<% } %>
|
|
7
|
+
<% if (plugins) { %>plugins: <%- plugins %>,<% } %>
|
|
8
|
+
<% if (categories) { %>categories: <%- categories %><% } %>
|
|
9
|
+
} satisfies CoreConfig;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
import type { ProjectConfiguration } from 'nx/src/config/workspace-json-project-json';
|
|
3
|
+
import type { ConfigurationGeneratorOptions } from './schema';
|
|
4
|
+
export declare function configurationGenerator(tree: Tree, options: ConfigurationGeneratorOptions): Promise<void>;
|
|
5
|
+
export declare function addTargetToProject(tree: Tree, projectConfiguration: ProjectConfiguration, options: ConfigurationGeneratorOptions): void;
|
|
6
|
+
export default configurationGenerator;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addTargetToProject = exports.configurationGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const constants_1 = require("../../internal/constants");
|
|
6
|
+
const code_pushup_config_1 = require("./code-pushup-config");
|
|
7
|
+
async function configurationGenerator(tree, options) {
|
|
8
|
+
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
9
|
+
const { skipConfig, skipTarget, skipFormat } = options;
|
|
10
|
+
if (skipConfig === true) {
|
|
11
|
+
devkit_1.logger.info('Skip config file creation');
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
(0, code_pushup_config_1.generateCodePushupConfig)(tree, projectConfiguration.root);
|
|
15
|
+
}
|
|
16
|
+
if (skipTarget === true) {
|
|
17
|
+
devkit_1.logger.info('Skip adding target to project');
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
addTargetToProject(tree, projectConfiguration, options);
|
|
21
|
+
}
|
|
22
|
+
if (skipFormat === true) {
|
|
23
|
+
devkit_1.logger.info('Skip formatting files');
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.configurationGenerator = configurationGenerator;
|
|
30
|
+
function addTargetToProject(tree, projectConfiguration, options) {
|
|
31
|
+
const { targets } = projectConfiguration;
|
|
32
|
+
const { targetName, project } = options;
|
|
33
|
+
const codePushupTargetConfig = {
|
|
34
|
+
executor: `${constants_1.PACKAGE_NAME}:autorun`,
|
|
35
|
+
};
|
|
36
|
+
(0, devkit_1.updateProjectConfiguration)(tree, project, {
|
|
37
|
+
...projectConfiguration,
|
|
38
|
+
targets: {
|
|
39
|
+
...targets,
|
|
40
|
+
[targetName ?? constants_1.DEFAULT_TARGET_NAME]: codePushupTargetConfig,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.addTargetToProject = addTargetToProject;
|
|
45
|
+
exports.default = configurationGenerator;
|
|
46
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/generators/configuration/generator.ts"],"names":[],"mappings":";;;AAAA,uCAMoB;AAEpB,wDAA6E;AAC7E,6DAAgE;AAGzD,KAAK,UAAU,sBAAsB,CAC1C,IAAU,EACV,OAAsC;IAEtC,MAAM,oBAAoB,GAAG,IAAA,iCAAwB,EAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7E,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAEvD,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACxB,eAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IAC3C,CAAC;SAAM,CAAC;QACN,IAAA,6CAAwB,EAAC,IAAI,EAAE,oBAAoB,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACxB,eAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;IAC/C,CAAC;SAAM,CAAC;QACN,kBAAkB,CAAC,IAAI,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACxB,eAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IACvC,CAAC;SAAM,CAAC;QACN,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC;AAzBD,wDAyBC;AAED,SAAgB,kBAAkB,CAChC,IAAU,EACV,oBAA0C,EAC1C,OAAsC;IAEtC,MAAM,EAAE,OAAO,EAAE,GAAG,oBAAoB,CAAC;IACzC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAExC,MAAM,sBAAsB,GAAG;QAC7B,QAAQ,EAAE,GAAG,wBAAY,UAAU;KACpC,CAAC;IAEF,IAAA,mCAA0B,EAAC,IAAI,EAAE,OAAO,EAAE;QACxC,GAAG,oBAAoB;QACvB,OAAO,EAAE;YACP,GAAG,OAAO;YACV,CAAC,UAAU,IAAI,+BAAmB,CAAC,EAAE,sBAAsB;SAC5D;KACF,CAAC,CAAC;AACL,CAAC;AAnBD,gDAmBC;AAED,kBAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "AddConfigurationToProject",
|
|
4
|
+
"title": "Add CodePushup configuration to a project",
|
|
5
|
+
"description": "Add CodePushup configuration to a project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"project": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The name of the project.",
|
|
11
|
+
"x-prompt": "Which project should configure Code Pushup?",
|
|
12
|
+
"x-dropdown": "projects",
|
|
13
|
+
"$default": {
|
|
14
|
+
"$source": "argv",
|
|
15
|
+
"index": 0
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"targetName": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "The name of the target.",
|
|
21
|
+
"x-prompt": "Which name should the target get? default is code-pushup.",
|
|
22
|
+
"default": "code-pushup"
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "Path to Code PushUp CLI"
|
|
27
|
+
},
|
|
28
|
+
"skipTarget": {
|
|
29
|
+
"type": "boolean",
|
|
30
|
+
"description": "Skip adding the target to project.json.",
|
|
31
|
+
"$default": "false"
|
|
32
|
+
},
|
|
33
|
+
"skipConfig": {
|
|
34
|
+
"type": "boolean",
|
|
35
|
+
"description": "Skip adding the code-pushup.config.ts to the project root.",
|
|
36
|
+
"$default": "false"
|
|
37
|
+
},
|
|
38
|
+
"skipFormat": {
|
|
39
|
+
"type": "boolean",
|
|
40
|
+
"description": "Skip formatting of changed files",
|
|
41
|
+
"$default": "false"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"required": ["project"]
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/generators/configuration/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ExtractArrays } from '@code-pushup/utils';
|
|
2
|
+
import type { ExecutableCode } from './types';
|
|
3
|
+
export declare function normalizeExecutableCode(executableCode: ExecutableCode): ExtractArrays<ExecutableCode>;
|
|
4
|
+
export declare function normalizeItemOrArray<T>(itemOrArray: T | T[]): T[];
|
|
5
|
+
export declare function formatObjectToFormattedJsString(jsonObj?: {
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
} | Array<unknown>): string | undefined;
|
|
8
|
+
export declare function formatArrayToLinesOfJsString(lines?: string[], separator?: string): string | undefined;
|
|
9
|
+
export declare function formatArrayToJSArray(lines?: string[]): string | undefined;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatArrayToJSArray = exports.formatArrayToLinesOfJsString = exports.formatObjectToFormattedJsString = exports.normalizeItemOrArray = exports.normalizeExecutableCode = void 0;
|
|
4
|
+
function normalizeExecutableCode(executableCode) {
|
|
5
|
+
const { fileImports: rawFileImports, codeStrings: rawCodeStrings } = executableCode;
|
|
6
|
+
return {
|
|
7
|
+
fileImports: normalizeItemOrArray(rawFileImports),
|
|
8
|
+
codeStrings: normalizeItemOrArray(rawCodeStrings),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
exports.normalizeExecutableCode = normalizeExecutableCode;
|
|
12
|
+
function normalizeItemOrArray(itemOrArray) {
|
|
13
|
+
if (itemOrArray == null) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(itemOrArray)) {
|
|
17
|
+
return itemOrArray;
|
|
18
|
+
}
|
|
19
|
+
return [itemOrArray];
|
|
20
|
+
}
|
|
21
|
+
exports.normalizeItemOrArray = normalizeItemOrArray;
|
|
22
|
+
// Return a formatted JSON in TS object with the same keys as the input object but remove the " for the properties
|
|
23
|
+
function formatObjectToFormattedJsString(jsonObj) {
|
|
24
|
+
if (!jsonObj) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// Convert JSON object to a string with indentation
|
|
28
|
+
const jsonString = JSON.stringify(jsonObj, null, 2);
|
|
29
|
+
// Remove double quotes around property names
|
|
30
|
+
return jsonString.replace(/"(\w+)":/g, '$1:');
|
|
31
|
+
}
|
|
32
|
+
exports.formatObjectToFormattedJsString = formatObjectToFormattedJsString;
|
|
33
|
+
function formatArrayToLinesOfJsString(lines, separator = '\n') {
|
|
34
|
+
if (lines == null || lines.length === 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
return lines.join(separator).replace(/'/g, '"');
|
|
38
|
+
}
|
|
39
|
+
exports.formatArrayToLinesOfJsString = formatArrayToLinesOfJsString;
|
|
40
|
+
function formatArrayToJSArray(lines) {
|
|
41
|
+
if (!Array.isArray(lines)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
return `[${formatArrayToLinesOfJsString(lines, ',\n') ?? ''}]`.replace(/"/g, '');
|
|
45
|
+
}
|
|
46
|
+
exports.formatArrayToJSArray = formatArrayToJSArray;
|
|
47
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/generators/configuration/utils.ts"],"names":[],"mappings":";;;AAGA,SAAgB,uBAAuB,CACrC,cAA8B;IAE9B,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,GAChE,cAAc,CAAC;IAEjB,OAAO;QACL,WAAW,EAAE,oBAAoB,CAAC,cAAc,CAAC;QACjD,WAAW,EAAE,oBAAoB,CAAC,cAAc,CAAC;KAClD,CAAC;AACJ,CAAC;AAVD,0DAUC;AAGD,SAAgB,oBAAoB,CAClC,WAAgC;IAEhC,IAAI,WAAW,IAAI,IAAI,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/B,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,OAAO,CAAC,WAAW,CAAC,CAAC;AACvB,CAAC;AAVD,oDAUC;AAED,kHAAkH;AAClH,SAAgB,+BAA+B,CAC7C,OAIkB;IAElB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO;IACT,CAAC;IACD,mDAAmD;IACnD,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAEpD,6CAA6C;IAC7C,OAAO,UAAU,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;AAChD,CAAC;AAfD,0EAeC;AAED,SAAgB,4BAA4B,CAC1C,KAAgB,EAChB,SAAS,GAAG,IAAI;IAEhB,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxC,OAAO;IACT,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAClD,CAAC;AARD,oEAQC;AAED,SAAgB,oBAAoB,CAAC,KAAgB;IACnD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO;IACT,CAAC;IAED,OAAO,IAAI,4BAA4B,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CACpE,IAAI,EACJ,EAAE,CACH,CAAC;AACJ,CAAC;AATD,oDASC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Init Generator
|
|
2
|
+
|
|
3
|
+
#### @code-pushup/nx-plugin:init
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
`nx generate configuration ...`
|
|
8
|
+
|
|
9
|
+
By default, the Nx plugin will update your `package.json` with needed dependencies and register the plugin in your `nx.json` configuration.
|
|
10
|
+
|
|
11
|
+
You can specify the collection explicitly as follows:
|
|
12
|
+
|
|
13
|
+
`nx g @code-pushup/nx-plugin:init`
|
|
14
|
+
|
|
15
|
+
Show what will be generated without writing to disk:
|
|
16
|
+
|
|
17
|
+
`nx g @code-pushup/nx-plugin:init --dry-run`
|
|
18
|
+
|
|
19
|
+
## Options
|
|
20
|
+
|
|
21
|
+
| Name | type | description |
|
|
22
|
+
| --------------------- | --------------------------- | ------------------------------------------- |
|
|
23
|
+
| **--skipPackageJson** | `boolean` (DEFAULT `false`) | Skip adding `package.json` dependencies. |
|
|
24
|
+
| **--skipNxJson** | `boolean` (DEFAULT `false`) | Skip updating `nx.json` with configuration. |
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
import type { InitGeneratorSchema } from './schema';
|
|
3
|
+
export declare function initGenerator(tree: Tree, schema: InitGeneratorSchema): import("@nx/devkit").GeneratorCallback;
|
|
4
|
+
export default initGenerator;
|
|
5
|
+
export declare const initSchematic: (generatorOptions: InitGeneratorSchema) => (tree: any, context: any) => Promise<any>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initSchematic = exports.initGenerator = void 0;
|
|
4
|
+
/* eslint-disable functional/immutable-data */
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const constants_1 = require("../../internal/constants");
|
|
7
|
+
const versions_1 = require("../../internal/versions");
|
|
8
|
+
function checkDependenciesInstalled(host) {
|
|
9
|
+
const packageJson = (0, devkit_1.readJson)(host, 'package.json');
|
|
10
|
+
const devDependencies = {};
|
|
11
|
+
const dependencies = {};
|
|
12
|
+
packageJson.dependencies = packageJson.dependencies ?? {};
|
|
13
|
+
packageJson.devDependencies = packageJson.devDependencies ?? {};
|
|
14
|
+
// base deps
|
|
15
|
+
devDependencies[constants_1.PACKAGE_NAME] = versions_1.cpNxPluginVersion;
|
|
16
|
+
devDependencies['@code-pushup/models'] = versions_1.cpModelVersion;
|
|
17
|
+
devDependencies['@code-pushup/utils'] = versions_1.cpUtilsVersion;
|
|
18
|
+
devDependencies['@code-pushup/cli'] = versions_1.cpCliVersion;
|
|
19
|
+
return (0, devkit_1.addDependenciesToPackageJson)(host, dependencies, devDependencies);
|
|
20
|
+
}
|
|
21
|
+
function moveToDevDependencies(tree) {
|
|
22
|
+
(0, devkit_1.updateJson)(tree, 'package.json', (packageJson) => {
|
|
23
|
+
const newPackageJson = {
|
|
24
|
+
dependencies: {},
|
|
25
|
+
devDependencies: {},
|
|
26
|
+
...packageJson,
|
|
27
|
+
};
|
|
28
|
+
if (newPackageJson.dependencies?.[constants_1.PACKAGE_NAME] !== undefined) {
|
|
29
|
+
const { [constants_1.PACKAGE_NAME]: version, ...dependencies } = newPackageJson.dependencies;
|
|
30
|
+
return {
|
|
31
|
+
...newPackageJson,
|
|
32
|
+
dependencies,
|
|
33
|
+
devDependencies: {
|
|
34
|
+
...newPackageJson.devDependencies,
|
|
35
|
+
[constants_1.PACKAGE_NAME]: version,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return newPackageJson;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function updateNxJsonConfig(tree) {
|
|
43
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
44
|
+
const targetName = 'code-pushup';
|
|
45
|
+
nxJson.targetDefaults ??= {};
|
|
46
|
+
nxJson.targetDefaults[targetName] = {
|
|
47
|
+
inputs: ['default', '^production'],
|
|
48
|
+
cache: true,
|
|
49
|
+
};
|
|
50
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
51
|
+
}
|
|
52
|
+
function initGenerator(tree, schema) {
|
|
53
|
+
if (schema.skipNxJson) {
|
|
54
|
+
devkit_1.logger.info(`Skip updating nx.json`);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
updateNxJsonConfig(tree);
|
|
58
|
+
}
|
|
59
|
+
const tasks = [];
|
|
60
|
+
if (schema.skipPackageJson) {
|
|
61
|
+
devkit_1.logger.info(`Skip updating package.json`);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
moveToDevDependencies(tree);
|
|
65
|
+
const installDependencies = checkDependenciesInstalled(tree);
|
|
66
|
+
if (schema.skipInstall) {
|
|
67
|
+
devkit_1.logger.info(`Skip installing packages`);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
tasks.push(installDependencies);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
74
|
+
}
|
|
75
|
+
exports.initGenerator = initGenerator;
|
|
76
|
+
exports.default = initGenerator;
|
|
77
|
+
exports.initSchematic = (0, devkit_1.convertNxGenerator)(initGenerator);
|
|
78
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/generators/init/generator.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cli": "nx",
|
|
3
|
+
"title": "Initialize Code Pushup in the workspace.",
|
|
4
|
+
"description": "Initialize Code Pushup in the workspace.",
|
|
5
|
+
"$id": "init-code-pushup-plugin",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"skipPackageJson": {
|
|
9
|
+
"type": "boolean",
|
|
10
|
+
"description": "Skip adding package.json dependencies",
|
|
11
|
+
"x-priority": "internal"
|
|
12
|
+
},
|
|
13
|
+
"skipInstall": {
|
|
14
|
+
"type": "boolean",
|
|
15
|
+
"description": "Skip package installation",
|
|
16
|
+
"x-priority": "internal"
|
|
17
|
+
},
|
|
18
|
+
"skipNxJson": {
|
|
19
|
+
"type": "boolean",
|
|
20
|
+
"description": "Skip updating nx.json with configuration"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createNodes } from './plugin';
|
|
2
|
+
export default createNodes;
|
|
3
|
+
export * from './internal/versions';
|
|
4
|
+
export { type InitGeneratorSchema } from './generators/init/schema';
|
|
5
|
+
export { initGenerator, initSchematic } from './generators/init/generator';
|
|
6
|
+
export type { ConfigurationGeneratorOptions } from './generators/configuration/schema';
|
|
7
|
+
export { configurationGenerator } from './generators/configuration/generator';
|
|
8
|
+
export { generateCodePushupConfig } from './generators/configuration/code-pushup-config';
|
|
9
|
+
export { createNodes } from './plugin';
|
|
10
|
+
export { executeProcess, type ProcessConfig } from './internal/execute-process';
|
|
11
|
+
export { objectToCliArgs } from './executors/internal/cli';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.objectToCliArgs = exports.executeProcess = exports.createNodes = exports.generateCodePushupConfig = exports.configurationGenerator = exports.initSchematic = exports.initGenerator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const plugin_1 = require("./plugin");
|
|
6
|
+
// default export for nx.json#plugins
|
|
7
|
+
exports.default = plugin_1.createNodes;
|
|
8
|
+
tslib_1.__exportStar(require("./internal/versions"), exports);
|
|
9
|
+
var generator_1 = require("./generators/init/generator");
|
|
10
|
+
Object.defineProperty(exports, "initGenerator", { enumerable: true, get: function () { return generator_1.initGenerator; } });
|
|
11
|
+
Object.defineProperty(exports, "initSchematic", { enumerable: true, get: function () { return generator_1.initSchematic; } });
|
|
12
|
+
var generator_2 = require("./generators/configuration/generator");
|
|
13
|
+
Object.defineProperty(exports, "configurationGenerator", { enumerable: true, get: function () { return generator_2.configurationGenerator; } });
|
|
14
|
+
var code_pushup_config_1 = require("./generators/configuration/code-pushup-config");
|
|
15
|
+
Object.defineProperty(exports, "generateCodePushupConfig", { enumerable: true, get: function () { return code_pushup_config_1.generateCodePushupConfig; } });
|
|
16
|
+
var plugin_2 = require("./plugin");
|
|
17
|
+
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_2.createNodes; } });
|
|
18
|
+
var execute_process_1 = require("./internal/execute-process");
|
|
19
|
+
Object.defineProperty(exports, "executeProcess", { enumerable: true, get: function () { return execute_process_1.executeProcess; } });
|
|
20
|
+
var cli_1 = require("./executors/internal/cli");
|
|
21
|
+
Object.defineProperty(exports, "objectToCliArgs", { enumerable: true, get: function () { return cli_1.objectToCliArgs; } });
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/nx-plugin/src/index.ts"],"names":[],"mappings":";;;;AAAA,qCAAuC;AAEvC,qCAAqC;AACrC,kBAAe,oBAAW,CAAC;AAE3B,8DAAoC;AAEpC,yDAA2E;AAAlE,0GAAA,aAAa,OAAA;AAAE,0GAAA,aAAa,OAAA;AAErC,kEAA8E;AAArE,mHAAA,sBAAsB,OAAA;AAC/B,oFAAyF;AAAhF,8HAAA,wBAAwB,OAAA;AACjC,mCAAuC;AAA9B,qGAAA,WAAW,OAAA;AACpB,8DAAgF;AAAvE,iHAAA,cAAc,OAAA;AACvB,gDAA2D;AAAlD,sGAAA,eAAe,OAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_TARGET_NAME = exports.PACKAGE_NAME = exports.PROJECT_JSON_FILE_NAME = void 0;
|
|
4
|
+
const package_json_1 = require("../../package.json");
|
|
5
|
+
exports.PROJECT_JSON_FILE_NAME = 'project.json';
|
|
6
|
+
exports.PACKAGE_NAME = package_json_1.name;
|
|
7
|
+
exports.DEFAULT_TARGET_NAME = 'code-pushup';
|
|
8
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../packages/nx-plugin/src/internal/constants.ts"],"names":[],"mappings":";;;AAAA,qDAA0C;AAE7B,QAAA,sBAAsB,GAAG,cAAc,CAAC;AACxC,QAAA,YAAY,GAAG,mBAAI,CAAC;AACpB,QAAA,mBAAmB,GAAG,aAAa,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export declare function calcDuration(start: number, stop?: number): number;
|
|
2
|
+
/**
|
|
3
|
+
* Represents the process result.
|
|
4
|
+
* @category Types
|
|
5
|
+
* @public
|
|
6
|
+
* @property {string} stdout - The stdout of the process.
|
|
7
|
+
* @property {string} stderr - The stderr of the process.
|
|
8
|
+
* @property {number | null} code - The exit code of the process.
|
|
9
|
+
*/
|
|
10
|
+
export type ProcessResult = {
|
|
11
|
+
stdout: string;
|
|
12
|
+
stderr: string;
|
|
13
|
+
code: number | null;
|
|
14
|
+
date: string;
|
|
15
|
+
duration: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Error class for process errors.
|
|
19
|
+
* Contains additional information about the process result.
|
|
20
|
+
* @category Error
|
|
21
|
+
* @public
|
|
22
|
+
* @class
|
|
23
|
+
* @extends Error
|
|
24
|
+
* @example
|
|
25
|
+
* const result = await executeProcess({})
|
|
26
|
+
* .catch((error) => {
|
|
27
|
+
* if (error instanceof ProcessError) {
|
|
28
|
+
* console.error(error.code);
|
|
29
|
+
* console.error(error.stderr);
|
|
30
|
+
* console.error(error.stdout);
|
|
31
|
+
* }
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
export declare class ProcessError extends Error {
|
|
36
|
+
code: number | null;
|
|
37
|
+
stderr: string;
|
|
38
|
+
stdout: string;
|
|
39
|
+
constructor(result: ProcessResult);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Process config object. Contains the command, args and observer.
|
|
43
|
+
* @param cfg - process config object with command, args and observer (optional)
|
|
44
|
+
* @category Types
|
|
45
|
+
* @public
|
|
46
|
+
* @property {string} command - The command to execute.
|
|
47
|
+
* @property {string[]} args - The arguments for the command.
|
|
48
|
+
* @property {ProcessObserver} observer - The observer for the process.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
*
|
|
52
|
+
* // bash command
|
|
53
|
+
* const cfg = {
|
|
54
|
+
* command: 'bash',
|
|
55
|
+
* args: ['-c', 'echo "hello world"']
|
|
56
|
+
* };
|
|
57
|
+
*
|
|
58
|
+
* // node command
|
|
59
|
+
* const cfg = {
|
|
60
|
+
* command: 'node',
|
|
61
|
+
* args: ['--version']
|
|
62
|
+
* };
|
|
63
|
+
*
|
|
64
|
+
* // npx command
|
|
65
|
+
* const cfg = {
|
|
66
|
+
* command: 'npx',
|
|
67
|
+
* args: ['--version']
|
|
68
|
+
*
|
|
69
|
+
*/
|
|
70
|
+
export type ProcessConfig = {
|
|
71
|
+
command: string;
|
|
72
|
+
args?: string[];
|
|
73
|
+
cwd?: string;
|
|
74
|
+
observer?: ProcessObserver;
|
|
75
|
+
ignoreExitCode?: boolean;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Process observer object. Contains the onStdout, error and complete function.
|
|
79
|
+
* @category Types
|
|
80
|
+
* @public
|
|
81
|
+
* @property {function} onStdout - The onStdout function of the observer (optional).
|
|
82
|
+
* @property {function} onError - The error function of the observer (optional).
|
|
83
|
+
* @property {function} onComplete - The complete function of the observer (optional).
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* const observer = {
|
|
87
|
+
* onStdout: (stdout) => console.info(stdout)
|
|
88
|
+
* }
|
|
89
|
+
*/
|
|
90
|
+
export type ProcessObserver = {
|
|
91
|
+
onStdout?: (stdout: string) => void;
|
|
92
|
+
onError?: (error: ProcessError) => void;
|
|
93
|
+
onComplete?: () => void;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Executes a process and returns a promise with the result as `ProcessResult`.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
*
|
|
100
|
+
* // sync process execution
|
|
101
|
+
* const result = await executeProcess({
|
|
102
|
+
* command: 'node',
|
|
103
|
+
* args: ['--version']
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* console.info(result);
|
|
107
|
+
*
|
|
108
|
+
* // async process execution
|
|
109
|
+
* const result = await executeProcess({
|
|
110
|
+
* command: 'node',
|
|
111
|
+
* args: ['download-data.js'],
|
|
112
|
+
* observer: {
|
|
113
|
+
* onStdout: updateProgress,
|
|
114
|
+
* error: handleError,
|
|
115
|
+
* complete: cleanLogs,
|
|
116
|
+
* }
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* console.info(result);
|
|
120
|
+
*
|
|
121
|
+
* @param cfg - see {@link ProcessConfig}
|
|
122
|
+
*/
|
|
123
|
+
export declare function executeProcess(cfg: ProcessConfig): Promise<ProcessResult>;
|