@nx/plugin 16.0.0-beta.5
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/CHANGELOG.md +8 -0
- package/LICENSE +22 -0
- package/README.md +67 -0
- package/executors.json +16 -0
- package/generators.d.ts +6 -0
- package/generators.js +10 -0
- package/generators.js.map +1 -0
- package/generators.json +81 -0
- package/index.d.ts +0 -0
- package/index.js +1 -0
- package/index.js.map +1 -0
- package/migrations.json +46 -0
- package/package.json +45 -0
- package/src/executors/e2e/compat.d.ts +1 -0
- package/src/executors/e2e/compat.js +7 -0
- package/src/executors/e2e/compat.js.map +1 -0
- package/src/executors/e2e/e2e.impl.d.ts +7 -0
- package/src/executors/e2e/e2e.impl.js +81 -0
- package/src/executors/e2e/e2e.impl.js.map +1 -0
- package/src/executors/e2e/schema.d.ts +6 -0
- package/src/executors/e2e/schema.json +220 -0
- package/src/generators/create-package/create-package.d.ts +5 -0
- package/src/generators/create-package/create-package.js +115 -0
- package/src/generators/create-package/create-package.js.map +1 -0
- package/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ +26 -0
- package/src/generators/create-package/files/e2e/__name__.spec.ts__tmpl__ +30 -0
- package/src/generators/create-package/schema.d.ts +17 -0
- package/src/generators/create-package/schema.json +69 -0
- package/src/generators/create-package/utils/normalize-schema.d.ts +10 -0
- package/src/generators/create-package/utils/normalize-schema.js +22 -0
- package/src/generators/create-package/utils/normalize-schema.js.map +1 -0
- package/src/generators/e2e-project/e2e.d.ts +6 -0
- package/src/generators/e2e-project/e2e.js +107 -0
- package/src/generators/e2e-project/e2e.js.map +1 -0
- package/src/generators/e2e-project/files/tests/__pluginName__.spec.ts__tmpl__ +37 -0
- package/src/generators/e2e-project/files/tsconfig.json__tmpl__ +6 -0
- package/src/generators/e2e-project/schema.d.ts +12 -0
- package/src/generators/e2e-project/schema.json +57 -0
- package/src/generators/executor/executor.d.ts +6 -0
- package/src/generators/executor/executor.js +104 -0
- package/src/generators/executor/executor.js.map +1 -0
- package/src/generators/executor/files/executor/__fileName__/executor.spec.ts__tmpl__ +11 -0
- package/src/generators/executor/files/executor/__fileName__/executor.ts__tmpl__ +11 -0
- package/src/generators/executor/files/executor/__fileName__/schema.d.ts__tmpl__ +1 -0
- package/src/generators/executor/files/executor/__fileName__/schema.json__tmpl__ +9 -0
- package/src/generators/executor/files/hasher/__fileName__/hasher.spec.ts__tmpl__ +22 -0
- package/src/generators/executor/files/hasher/__fileName__/hasher.ts__tmpl__ +12 -0
- package/src/generators/executor/schema.d.ts +9 -0
- package/src/generators/executor/schema.json +64 -0
- package/src/generators/generator/files/generator/__fileName__/generator.spec.ts__tmpl__ +20 -0
- package/src/generators/generator/files/generator/__fileName__/generator.ts__tmpl__ +72 -0
- package/src/generators/generator/files/generator/__fileName__/schema.d.ts__tmpl__ +5 -0
- package/src/generators/generator/files/generator/__fileName__/schema.json__tmpl__ +27 -0
- package/src/generators/generator/generator.d.ts +6 -0
- package/src/generators/generator/generator.js +106 -0
- package/src/generators/generator/generator.js.map +1 -0
- package/src/generators/generator/schema.d.ts +8 -0
- package/src/generators/generator/schema.json +60 -0
- package/src/generators/lint-checks/generator.d.ts +7 -0
- package/src/generators/lint-checks/generator.js +187 -0
- package/src/generators/lint-checks/generator.js.map +1 -0
- package/src/generators/lint-checks/schema.d.ts +4 -0
- package/src/generators/lint-checks/schema.json +25 -0
- package/src/generators/migration/files/migration/__name__/__name__.spec.ts__tmpl__ +17 -0
- package/src/generators/migration/files/migration/__name__/__name__.ts__tmpl__ +6 -0
- package/src/generators/migration/migration.d.ts +5 -0
- package/src/generators/migration/migration.js +111 -0
- package/src/generators/migration/migration.js.map +1 -0
- package/src/generators/migration/schema.d.ts +8 -0
- package/src/generators/migration/schema.json +59 -0
- package/src/generators/plugin/files/plugin/src/index.ts__tmpl__ +0 -0
- package/src/generators/plugin/plugin.d.ts +5 -0
- package/src/generators/plugin/plugin.js +95 -0
- package/src/generators/plugin/plugin.js.map +1 -0
- package/src/generators/plugin/schema.d.ts +17 -0
- package/src/generators/plugin/schema.json +93 -0
- package/src/generators/plugin/utils/normalize-schema.d.ts +14 -0
- package/src/generators/plugin/utils/normalize-schema.js +31 -0
- package/src/generators/plugin/utils/normalize-schema.js.map +1 -0
- package/src/generators/preset/generator.d.ts +3 -0
- package/src/generators/preset/generator.js +53 -0
- package/src/generators/preset/generator.js.map +1 -0
- package/src/generators/preset/schema.d.ts +4 -0
- package/src/generators/preset/schema.json +20 -0
- package/src/migrations/update-14-1-9/add-swc-deps-if-needed.d.ts +2 -0
- package/src/migrations/update-14-1-9/add-swc-deps-if-needed.js +14 -0
- package/src/migrations/update-14-1-9/add-swc-deps-if-needed.js.map +1 -0
- package/src/migrations/update-15-0-0/specify-output-capture.d.ts +2 -0
- package/src/migrations/update-15-0-0/specify-output-capture.js +57 -0
- package/src/migrations/update-15-0-0/specify-output-capture.js.map +1 -0
- package/src/migrations/update-15-9-0/jest-29-configs.d.ts +3 -0
- package/src/migrations/update-15-9-0/jest-29-configs.js +154 -0
- package/src/migrations/update-15-9-0/jest-29-configs.js.map +1 -0
- package/src/migrations/update-15-9-0/jest-29-tests.d.ts +5 -0
- package/src/migrations/update-15-9-0/jest-29-tests.js +65 -0
- package/src/migrations/update-15-9-0/jest-29-tests.js.map +1 -0
- package/src/migrations/update-16-0-0/cli-in-schema-json.d.ts +3 -0
- package/src/migrations/update-16-0-0/cli-in-schema-json.js +84 -0
- package/src/migrations/update-16-0-0/cli-in-schema-json.js.map +1 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +13 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js.map +1 -0
- package/src/utils/has-generator.d.ts +2 -0
- package/src/utils/has-generator.js +17 -0
- package/src/utils/has-generator.js.map +1 -0
- package/src/utils/testing-utils/async-commands.d.ts +28 -0
- package/src/utils/testing-utils/async-commands.js +51 -0
- package/src/utils/testing-utils/async-commands.js.map +1 -0
- package/src/utils/testing-utils/commands.d.ts +17 -0
- package/src/utils/testing-utils/commands.js +64 -0
- package/src/utils/testing-utils/commands.js.map +1 -0
- package/src/utils/testing-utils/create-package-cli.d.ts +18 -0
- package/src/utils/testing-utils/create-package-cli.js +53 -0
- package/src/utils/testing-utils/create-package-cli.js.map +1 -0
- package/src/utils/testing-utils/index.d.ts +6 -0
- package/src/utils/testing-utils/index.js +10 -0
- package/src/utils/testing-utils/index.js.map +1 -0
- package/src/utils/testing-utils/nx-project.d.ts +25 -0
- package/src/utils/testing-utils/nx-project.js +64 -0
- package/src/utils/testing-utils/nx-project.js.map +1 -0
- package/src/utils/testing-utils/paths.d.ts +15 -0
- package/src/utils/testing-utils/paths.js +33 -0
- package/src/utils/testing-utils/paths.js.map +1 -0
- package/src/utils/testing-utils/utils.d.ts +80 -0
- package/src/utils/testing-utils/utils.js +145 -0
- package/src/utils/testing-utils/utils.js.map +1 -0
- package/src/utils/versions.d.ts +1 -0
- package/src/utils/versions.js +5 -0
- package/src/utils/versions.js.map +1 -0
- package/testing.d.ts +1 -0
- package/testing.js +5 -0
- package/testing.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"e2e.js","sourceRoot":"","sources":["../../../../../../packages/plugin/src/generators/e2e-project/e2e.ts"],"names":[],"mappings":";;;;AACA,uCAaoB;AACpB,mCAAgD;AAChD,+BAAuD;AACvD,6BAA6B;AAG7B,uCAA0D;AAU1D,SAAS,gBAAgB,CAAC,IAAU,EAAE,OAAe;;IACnD,MAAM,EAAE,eAAe,EAAE,gBAAgB,EAAE,GAAG,IAAA,+BAAsB,EAClE,OAAO,CAAC,gBAAgB,CACzB,CAAC;IACF,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,IAAA,2BAAkB,EAAC,IAAI,CAAC,CAAC;IACvE,MAAM,OAAO,GAAG,eA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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
checkFilesExist,
|
|
3
|
+
ensureNxProject,
|
|
4
|
+
readJson,
|
|
5
|
+
runNxCommandAsync,
|
|
6
|
+
runNxCommand,
|
|
7
|
+
uniq,
|
|
8
|
+
} from '@nx/plugin/testing';
|
|
9
|
+
|
|
10
|
+
describe('<%= pluginName %> e2e', () => {
|
|
11
|
+
// Setting up individual workspaces per
|
|
12
|
+
// test can cause e2e runs to take a long time.
|
|
13
|
+
// For this reason, we recommend each suite only
|
|
14
|
+
// consumes 1 workspace. The tests should each operate
|
|
15
|
+
// on a unique project in the workspace, such that they
|
|
16
|
+
// are not dependant on one another.
|
|
17
|
+
beforeAll(() => {
|
|
18
|
+
ensureNxProject('<%= npmPackageName %>', '<%= pluginOutputPath %>');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterAll(() => {
|
|
22
|
+
// `nx reset` kills the daemon, and performs
|
|
23
|
+
// some work which can help clean up e2e leftovers
|
|
24
|
+
runNxCommandAsync('reset');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// Add some tests here to check that your plugin functionality works as expected.
|
|
29
|
+
// A sample test is included below to give you some ideas.
|
|
30
|
+
xit('should be able to build generated projects', async () => {
|
|
31
|
+
const name = uniq('proj');
|
|
32
|
+
const generator = 'PLACEHOLDER';
|
|
33
|
+
await runNxCommandAsync(`generate <%= npmPackageName %>:${generator} --name ${name}`);
|
|
34
|
+
expect(() => runNxCommand('build ${proj}')).not.toThrow();
|
|
35
|
+
expect(() => checkFilesExist(`dist/${name}/index.js`)).not.toThrow();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Linter } from '@nx/linter';
|
|
2
|
+
|
|
3
|
+
export interface Schema {
|
|
4
|
+
pluginName: string;
|
|
5
|
+
npmPackageName: string;
|
|
6
|
+
projectDirectory?: string;
|
|
7
|
+
pluginOutputPath?: string;
|
|
8
|
+
jestConfig?: string;
|
|
9
|
+
linter?: Linter;
|
|
10
|
+
skipFormat?: boolean;
|
|
11
|
+
rootProject?: boolean;
|
|
12
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "NxPluginE2E",
|
|
5
|
+
"title": "Create an E2E app for a Nx Plugin",
|
|
6
|
+
"description": "Create an E2E app for a Nx Plugin.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"pluginName": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "the project name of the plugin to be tested.",
|
|
12
|
+
"x-priority": "important"
|
|
13
|
+
},
|
|
14
|
+
"npmPackageName": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "the package name of the plugin as it would be published to NPM.",
|
|
17
|
+
"x-priority": "important"
|
|
18
|
+
},
|
|
19
|
+
"projectDirectory": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"description": "the directory where the plugin is placed."
|
|
22
|
+
},
|
|
23
|
+
"pluginOutputPath": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"description": "the output path of the plugin after it builds.",
|
|
26
|
+
"x-priority": "important"
|
|
27
|
+
},
|
|
28
|
+
"jestConfig": {
|
|
29
|
+
"type": "string",
|
|
30
|
+
"description": "Jest config file."
|
|
31
|
+
},
|
|
32
|
+
"standaloneConfig": {
|
|
33
|
+
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
|
|
34
|
+
"type": "boolean",
|
|
35
|
+
"default": true,
|
|
36
|
+
"x-deprecated": "Nx only supports standaloneConfig"
|
|
37
|
+
},
|
|
38
|
+
"linter": {
|
|
39
|
+
"description": "The tool to use for running lint checks.",
|
|
40
|
+
"type": "string",
|
|
41
|
+
"enum": ["eslint", "none"],
|
|
42
|
+
"default": "eslint"
|
|
43
|
+
},
|
|
44
|
+
"minimal": {
|
|
45
|
+
"type": "boolean",
|
|
46
|
+
"description": "Generate the e2e project with a minimal setup. This would involve not generating tests for a default executor and generator.",
|
|
47
|
+
"default": false
|
|
48
|
+
},
|
|
49
|
+
"skipFormat": {
|
|
50
|
+
"description": "Skip formatting files.",
|
|
51
|
+
"type": "boolean",
|
|
52
|
+
"default": false,
|
|
53
|
+
"x-priority": "internal"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"required": ["pluginName", "npmPackageName"]
|
|
57
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Tree } from '@nx/devkit';
|
|
2
|
+
import type { Schema } from './schema';
|
|
3
|
+
export declare function createExecutorsJson(host: Tree, projectRoot: string, projectName: string, skipLintChecks?: boolean): Promise<void>;
|
|
4
|
+
export declare function executorGenerator(host: Tree, schema: Schema): Promise<void>;
|
|
5
|
+
export default executorGenerator;
|
|
6
|
+
export declare const executorSchematic: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executorSchematic = exports.executorGenerator = exports.createExecutorsJson = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const generator_1 = require("../lint-checks/generator");
|
|
8
|
+
function addFiles(host, options) {
|
|
9
|
+
(0, devkit_1.generateFiles)(host, path.join(__dirname, './files/executor'), `${options.projectSourceRoot}/executors`, Object.assign(Object.assign({}, options), { tmpl: '' }));
|
|
10
|
+
if (options.unitTestRunner === 'none') {
|
|
11
|
+
host.delete((0, devkit_1.joinPathFragments)(options.projectSourceRoot, 'executors', options.fileName, `executor.spec.ts`));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function addHasherFiles(host, options) {
|
|
15
|
+
(0, devkit_1.generateFiles)(host, path.join(__dirname, './files/hasher'), `${options.projectSourceRoot}/executors`, Object.assign(Object.assign({}, options), { tmpl: '' }));
|
|
16
|
+
if (options.unitTestRunner === 'none') {
|
|
17
|
+
host.delete((0, devkit_1.joinPathFragments)(options.projectSourceRoot, 'executors', options.fileName, 'hasher.spec.ts'));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function createExecutorsJson(host, projectRoot, projectName, skipLintChecks) {
|
|
21
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'), (json) => {
|
|
23
|
+
var _a;
|
|
24
|
+
(_a = json.executors) !== null && _a !== void 0 ? _a : (json.executors = './executors.json');
|
|
25
|
+
return json;
|
|
26
|
+
});
|
|
27
|
+
(0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'executors.json'), {
|
|
28
|
+
executors: {},
|
|
29
|
+
});
|
|
30
|
+
if (!skipLintChecks) {
|
|
31
|
+
yield (0, generator_1.default)(host, {
|
|
32
|
+
projectName,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
exports.createExecutorsJson = createExecutorsJson;
|
|
38
|
+
function updateExecutorJson(host, options) {
|
|
39
|
+
var _a;
|
|
40
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const packageJson = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'));
|
|
42
|
+
const packageJsonExecutors = (_a = packageJson.executors) !== null && _a !== void 0 ? _a : packageJson.builders;
|
|
43
|
+
let executorsPath = packageJsonExecutors
|
|
44
|
+
? (0, devkit_1.joinPathFragments)(options.projectRoot, packageJsonExecutors)
|
|
45
|
+
: null;
|
|
46
|
+
if (!executorsPath) {
|
|
47
|
+
executorsPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'executors.json');
|
|
48
|
+
}
|
|
49
|
+
if (!host.exists(executorsPath)) {
|
|
50
|
+
yield createExecutorsJson(host, options.projectRoot, options.project, options.skipLintChecks);
|
|
51
|
+
}
|
|
52
|
+
return (0, devkit_1.updateJson)(host, executorsPath, (json) => {
|
|
53
|
+
var _a;
|
|
54
|
+
let executors = (_a = json.executors) !== null && _a !== void 0 ? _a : json.builders;
|
|
55
|
+
executors || (executors = {});
|
|
56
|
+
executors[options.name] = {
|
|
57
|
+
implementation: `./src/executors/${options.fileName}/executor`,
|
|
58
|
+
schema: `./src/executors/${options.fileName}/schema.json`,
|
|
59
|
+
description: options.description,
|
|
60
|
+
};
|
|
61
|
+
if (options.includeHasher) {
|
|
62
|
+
executors[options.name].hasher = `./src/executors/${options.fileName}/hasher`;
|
|
63
|
+
}
|
|
64
|
+
json.executors = executors;
|
|
65
|
+
return json;
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function normalizeOptions(host, options) {
|
|
70
|
+
const { npmScope } = (0, devkit_1.getWorkspaceLayout)(host);
|
|
71
|
+
const { fileName, className, propertyName } = (0, devkit_1.names)(options.name);
|
|
72
|
+
const { root: projectRoot, sourceRoot: projectSourceRoot } = (0, devkit_1.readProjectConfiguration)(host, options.project);
|
|
73
|
+
let description;
|
|
74
|
+
if (options.description) {
|
|
75
|
+
description = options.description;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
description = `${options.name} executor`;
|
|
79
|
+
}
|
|
80
|
+
return Object.assign(Object.assign({}, options), { fileName,
|
|
81
|
+
className,
|
|
82
|
+
propertyName,
|
|
83
|
+
description,
|
|
84
|
+
projectRoot,
|
|
85
|
+
projectSourceRoot,
|
|
86
|
+
npmScope });
|
|
87
|
+
}
|
|
88
|
+
function executorGenerator(host, schema) {
|
|
89
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const options = normalizeOptions(host, schema);
|
|
91
|
+
addFiles(host, options);
|
|
92
|
+
if (options.includeHasher) {
|
|
93
|
+
addHasherFiles(host, options);
|
|
94
|
+
}
|
|
95
|
+
yield updateExecutorJson(host, options);
|
|
96
|
+
if (!schema.skipFormat) {
|
|
97
|
+
yield (0, devkit_1.formatFiles)(host);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
exports.executorGenerator = executorGenerator;
|
|
102
|
+
exports.default = executorGenerator;
|
|
103
|
+
exports.executorSchematic = (0, devkit_1.convertNxGenerator)(executorGenerator);
|
|
104
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../packages/plugin/src/generators/executor/executor.ts"],"names":[],"mappings":";;;;AAAA,uCAYoB;AAGpB,6BAA6B;AAE7B,wDAAgE;AAWhE,SAAS,QAAQ,CAAC,IAAU,EAAE,OAAyB;IACrD,IAAA,sBAAa,EACX,IAAI,EACJ,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,kBAAkB,CAAC,EACxC,GAAG,OAAO,CAAC,iBAAiB,YAAY,kCAEnC,OAAO,KACV,IAAI,EAAE,EAAE,IAEX,CAAC;IAEF,IAAI,OAAO,CAAC,cAAc,KAAK,MAAM,EAAE;QACrC,IAAI,CAAC,MAAM,CACT,IAAA,0BAAiB,EACf,OAAO,CAAC,iBAAiB,EACzB,WAAW,EACX,OAAO,CAAC,QAAQ,EAChB,kBAAkB,CACnB,CACF,CAAC;KACH;AACH,CAAC;AAED,SAAS,cAAc,CAAC,IAAU,EAAE,OAAyB;IAC3D,IAAA,sBAAa,EACX,IAAI,EACJ,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,EACtC,GAAG,OAAO,CAAC,iBAAiB,YAAY,kCAEnC,OAAO,KACV,IAAI,EAAE,EAAE,IAEX,CAAC;IAEF,IAAI,OAAO,CAAC,cAAc,KAAK,MAAM,EAAE;QACrC,IAAI,CAAC,MAAM,CACT,IAAA,0BAAi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AW,GAAG,OAAO,CAAC,WAAW,CAAC;KACnC;SAAM;QACL,WAAW,GAAG,GAAG,OAAO,CAAC,IAAI,WAAW,CAAC;KAC1C;IAED,uCACK,OAAO,KACV,QAAQ;QACR,SAAS;QACT,YAAY;QACZ,WAAW;QACX,WAAW;QACX,iBAAiB;QACjB,QAAQ,IACR;AACJ,CAAC;AAED,SAAsB,iBAAiB,CAAC,IAAU,EAAE,MAAc;;QAChE,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAE/C,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,OAAO,CAAC,aAAa,EAAE;YACzB,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;SAC/B;QAED,MAAM,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAExC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;YACtB,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;SACzB;IACH,CAAC;CAAA;AAbD,8CAaC;AAED,kBAAe,iBAAiB,CAAC;AACpB,QAAA,iBAAiB,GAAG,IAAA,2BAAkB,EAAC,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { <%= className %>ExecutorSchema } from './schema';
|
|
2
|
+
import executor from './executor';
|
|
3
|
+
|
|
4
|
+
const options: <%= className %>ExecutorSchema = {};
|
|
5
|
+
|
|
6
|
+
describe('<%= className %> Executor', () => {
|
|
7
|
+
it('can run', async () => {
|
|
8
|
+
const output = await executor(options);
|
|
9
|
+
expect(output.success).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export interface <%= className %>ExecutorSchema {} // eslint-disable-line
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Hasher, HasherContext } from '@nx/devkit';
|
|
2
|
+
|
|
3
|
+
import { <%=propertyName%>Hasher } from './hasher';
|
|
4
|
+
|
|
5
|
+
describe('<%=propertyName%>Hasher', () => {
|
|
6
|
+
it('should generate hash', async () => {
|
|
7
|
+
const mockHasher: Hasher = {
|
|
8
|
+
hashTask: jest.fn().mockReturnValue({value: 'hashed-task'})
|
|
9
|
+
} as unknown as Hasher
|
|
10
|
+
const hash = await <%=propertyName%>Hasher({
|
|
11
|
+
id: 'my-task-id',
|
|
12
|
+
target: {
|
|
13
|
+
project: 'proj',
|
|
14
|
+
target: 'target'
|
|
15
|
+
},
|
|
16
|
+
overrides: {}
|
|
17
|
+
}, {
|
|
18
|
+
hasher: mockHasher
|
|
19
|
+
} as unknown as HasherContext)
|
|
20
|
+
expect(hash).toEqual({value: 'hashed-task'})
|
|
21
|
+
})
|
|
22
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CustomHasher } from '@nx/devkit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This is a boilerplate custom hasher that matches
|
|
5
|
+
* the default Nx hasher. If you need to extend the behavior,
|
|
6
|
+
* you can consume workspace details from the context.
|
|
7
|
+
*/
|
|
8
|
+
export const <%=propertyName%>Hasher: CustomHasher = async (task, context) => {
|
|
9
|
+
return context.hasher.hashTask(task);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default <%=propertyName%>Hasher;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "NxPluginExecutor",
|
|
5
|
+
"title": "Create an Executor for an Nx Plugin",
|
|
6
|
+
"description": "Create an Executor for an Nx Plugin.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"examples": [
|
|
9
|
+
{
|
|
10
|
+
"command": "nx g executor my-executor --project=my-plugin",
|
|
11
|
+
"description": "Generate `libs/my-plugin/src/executors/my-executor`"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"properties": {
|
|
15
|
+
"project": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"description": "The name of the project.",
|
|
18
|
+
"alias": "p",
|
|
19
|
+
"$default": {
|
|
20
|
+
"$source": "projectName"
|
|
21
|
+
},
|
|
22
|
+
"x-prompt": "What is the name of the project for the executor?",
|
|
23
|
+
"x-priority": "important"
|
|
24
|
+
},
|
|
25
|
+
"name": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "Executor name.",
|
|
28
|
+
"$default": {
|
|
29
|
+
"$source": "argv",
|
|
30
|
+
"index": 0
|
|
31
|
+
},
|
|
32
|
+
"x-prompt": "What name would you like to use for the executor?",
|
|
33
|
+
"x-priority": "important"
|
|
34
|
+
},
|
|
35
|
+
"description": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"description": "Executor description."
|
|
38
|
+
},
|
|
39
|
+
"unitTestRunner": {
|
|
40
|
+
"type": "string",
|
|
41
|
+
"enum": ["jest", "none"],
|
|
42
|
+
"description": "Test runner to use for unit tests.",
|
|
43
|
+
"default": "jest"
|
|
44
|
+
},
|
|
45
|
+
"includeHasher": {
|
|
46
|
+
"type": "boolean",
|
|
47
|
+
"default": false,
|
|
48
|
+
"description": "Should the boilerplate for a custom hasher be generated?"
|
|
49
|
+
},
|
|
50
|
+
"skipLintChecks": {
|
|
51
|
+
"type": "boolean",
|
|
52
|
+
"default": false,
|
|
53
|
+
"description": "Do not add an eslint configuration for plugin json files."
|
|
54
|
+
},
|
|
55
|
+
"skipFormat": {
|
|
56
|
+
"type": "boolean",
|
|
57
|
+
"description": "Skip formatting files.",
|
|
58
|
+
"default": false,
|
|
59
|
+
"x-priority": "internal"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"required": ["project", "name"],
|
|
63
|
+
"additionalProperties": false
|
|
64
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
2
|
+
import { Tree, readProjectConfiguration } from '@nx/devkit';
|
|
3
|
+
|
|
4
|
+
import generator from './generator';
|
|
5
|
+
import { <%= className %>GeneratorSchema } from './schema';
|
|
6
|
+
|
|
7
|
+
describe('<%= name %> generator', () => {
|
|
8
|
+
let appTree: Tree;
|
|
9
|
+
const options: <%= className %>GeneratorSchema = { name: 'test' };
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
appTree = createTreeWithEmptyWorkspace({layout: 'apps-libs'});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should run successfully', async () => {
|
|
16
|
+
await generator(appTree, options);
|
|
17
|
+
const config = readProjectConfiguration(appTree, 'test');
|
|
18
|
+
expect(config).toBeDefined();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addProjectConfiguration,
|
|
3
|
+
formatFiles,
|
|
4
|
+
generateFiles,
|
|
5
|
+
getWorkspaceLayout,
|
|
6
|
+
names,
|
|
7
|
+
offsetFromRoot,
|
|
8
|
+
Tree,
|
|
9
|
+
} from '@nx/devkit';
|
|
10
|
+
import * as path from 'path';
|
|
11
|
+
import { <%= className %>GeneratorSchema } from './schema';
|
|
12
|
+
|
|
13
|
+
interface NormalizedSchema extends <%= className %>GeneratorSchema {
|
|
14
|
+
projectName: string;
|
|
15
|
+
projectRoot: string;
|
|
16
|
+
projectDirectory: string;
|
|
17
|
+
parsedTags: string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function normalizeOptions(tree: Tree, options: <%= className %>GeneratorSchema): NormalizedSchema {
|
|
21
|
+
const name = names(options.name).fileName;
|
|
22
|
+
const projectDirectory = options.directory
|
|
23
|
+
? `${names(options.directory).fileName}/${name}`
|
|
24
|
+
: name;
|
|
25
|
+
const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-');
|
|
26
|
+
const projectRoot =
|
|
27
|
+
getWorkspaceLayout(tree).libsDir === '.'
|
|
28
|
+
? '.'
|
|
29
|
+
: `${getWorkspaceLayout(tree).libsDir}/${projectDirectory}`;
|
|
30
|
+
const parsedTags = options.tags
|
|
31
|
+
? options.tags.split(',').map((s) => s.trim())
|
|
32
|
+
: [];
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
...options,
|
|
36
|
+
projectName,
|
|
37
|
+
projectRoot,
|
|
38
|
+
projectDirectory,
|
|
39
|
+
parsedTags,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function addFiles(tree: Tree, options: NormalizedSchema) {
|
|
44
|
+
const templateOptions = {
|
|
45
|
+
...options,
|
|
46
|
+
...names(options.name),
|
|
47
|
+
offsetFromRoot: offsetFromRoot(options.projectRoot),
|
|
48
|
+
template: ''
|
|
49
|
+
};
|
|
50
|
+
generateFiles(tree, path.join(__dirname, 'files'), options.projectRoot, templateOptions);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export default async function (tree: Tree, options: <%= className %>GeneratorSchema) {
|
|
54
|
+
const normalizedOptions = normalizeOptions(tree, options);
|
|
55
|
+
addProjectConfiguration(
|
|
56
|
+
tree,
|
|
57
|
+
normalizedOptions.projectName,
|
|
58
|
+
{
|
|
59
|
+
root: normalizedOptions.projectRoot,
|
|
60
|
+
projectType: 'library',
|
|
61
|
+
sourceRoot: `${normalizedOptions.projectRoot}/src`,
|
|
62
|
+
targets: {
|
|
63
|
+
build: {
|
|
64
|
+
executor: "<%= npmPackageName %>:build",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
tags: normalizedOptions.parsedTags,
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
addFiles(tree, normalizedOptions);
|
|
71
|
+
await formatFiles(tree);
|
|
72
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "<%= className %>",
|
|
4
|
+
"title": "",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"name": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "",
|
|
10
|
+
"$default": {
|
|
11
|
+
"$source": "argv",
|
|
12
|
+
"index": 0
|
|
13
|
+
},
|
|
14
|
+
"x-prompt": "What name would you like to use?"
|
|
15
|
+
},
|
|
16
|
+
"tags": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "Add tags to the project (used for linting)",
|
|
19
|
+
"alias": "t"
|
|
20
|
+
},
|
|
21
|
+
"directory": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "A directory where the project is placed"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"required": ["name"]
|
|
27
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import type { Schema } from './schema';
|
|
3
|
+
export declare function createGeneratorsJson(host: Tree, projectRoot: string, projectName: string, skipLintChecks?: boolean, skipFormat?: boolean): Promise<void>;
|
|
4
|
+
export declare function generatorGenerator(host: Tree, schema: Schema): Promise<void>;
|
|
5
|
+
export default generatorGenerator;
|
|
6
|
+
export declare const generatorSchematic: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generatorSchematic = exports.generatorGenerator = exports.createGeneratorsJson = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const has_generator_1 = require("../../utils/has-generator");
|
|
8
|
+
const generator_1 = require("../lint-checks/generator");
|
|
9
|
+
function normalizeOptions(host, options) {
|
|
10
|
+
const { npmScope } = (0, devkit_1.getWorkspaceLayout)(host);
|
|
11
|
+
const { fileName, className } = (0, devkit_1.names)(options.name);
|
|
12
|
+
const { root: projectRoot, sourceRoot: projectSourceRoot } = (0, devkit_1.readProjectConfiguration)(host, options.project);
|
|
13
|
+
const npmPackageName = (0, devkit_1.readJson)(host, path.join(projectRoot, 'package.json')).name;
|
|
14
|
+
let description;
|
|
15
|
+
if (options.description) {
|
|
16
|
+
description = options.description;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
description = `${options.name} generator`;
|
|
20
|
+
}
|
|
21
|
+
return Object.assign(Object.assign({}, options), { fileName,
|
|
22
|
+
className,
|
|
23
|
+
description,
|
|
24
|
+
projectRoot,
|
|
25
|
+
projectSourceRoot,
|
|
26
|
+
npmScope,
|
|
27
|
+
npmPackageName });
|
|
28
|
+
}
|
|
29
|
+
function addFiles(host, options) {
|
|
30
|
+
const indexPath = `${options.projectSourceRoot}/generators/${options.fileName}/files/src/index.ts__template__`;
|
|
31
|
+
if (!host.exists(indexPath)) {
|
|
32
|
+
host.write(indexPath, 'const variable = "<%= projectName %>";');
|
|
33
|
+
}
|
|
34
|
+
(0, devkit_1.generateFiles)(host, path.join(__dirname, './files/generator'), `${options.projectSourceRoot}/generators`, Object.assign(Object.assign({}, options), { tmpl: '' }));
|
|
35
|
+
if (options.unitTestRunner === 'none') {
|
|
36
|
+
host.delete(path.join(options.projectSourceRoot, 'generators', options.fileName, `generator.spec.ts`));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function createGeneratorsJson(host, projectRoot, projectName, skipLintChecks, skipFormat) {
|
|
40
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'package.json'), (json) => {
|
|
42
|
+
var _a;
|
|
43
|
+
(_a = json.generators) !== null && _a !== void 0 ? _a : (json.generators = './generators.json');
|
|
44
|
+
return json;
|
|
45
|
+
});
|
|
46
|
+
(0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(projectRoot, 'generators.json'), {
|
|
47
|
+
generators: {},
|
|
48
|
+
});
|
|
49
|
+
if (!skipLintChecks) {
|
|
50
|
+
yield (0, generator_1.default)(host, {
|
|
51
|
+
projectName,
|
|
52
|
+
skipFormat,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
exports.createGeneratorsJson = createGeneratorsJson;
|
|
58
|
+
function updateGeneratorJson(host, options) {
|
|
59
|
+
var _a;
|
|
60
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const packageJson = (0, devkit_1.readJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'));
|
|
62
|
+
const packageJsonGenerators = (_a = packageJson.generators) !== null && _a !== void 0 ? _a : packageJson.schematics;
|
|
63
|
+
let generatorsPath = packageJsonGenerators
|
|
64
|
+
? (0, devkit_1.joinPathFragments)(options.projectRoot, packageJsonGenerators)
|
|
65
|
+
: null;
|
|
66
|
+
if (!generatorsPath) {
|
|
67
|
+
generatorsPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'generators.json');
|
|
68
|
+
}
|
|
69
|
+
if (!host.exists(generatorsPath)) {
|
|
70
|
+
yield createGeneratorsJson(host, options.projectRoot, options.project, options.skipLintChecks, options.skipFormat);
|
|
71
|
+
}
|
|
72
|
+
(0, devkit_1.updateJson)(host, generatorsPath, (json) => {
|
|
73
|
+
var _a;
|
|
74
|
+
let generators = (_a = json.generators) !== null && _a !== void 0 ? _a : json.schematics;
|
|
75
|
+
generators = generators || {};
|
|
76
|
+
generators[options.name] = {
|
|
77
|
+
factory: `./src/generators/${options.fileName}/generator`,
|
|
78
|
+
schema: `./src/generators/${options.fileName}/schema.json`,
|
|
79
|
+
description: options.description,
|
|
80
|
+
};
|
|
81
|
+
// @todo(v17): Remove this, prop is defunct.
|
|
82
|
+
if (options.name === 'preset') {
|
|
83
|
+
generators[options.name]['x-use-standalone-layout'] = true;
|
|
84
|
+
}
|
|
85
|
+
json.generators = generators;
|
|
86
|
+
return json;
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function generatorGenerator(host, schema) {
|
|
91
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
const options = normalizeOptions(host, schema);
|
|
93
|
+
if ((0, has_generator_1.hasGenerator)(host, options.project, options.name)) {
|
|
94
|
+
throw new Error(`Generator ${options.name} already exists.`);
|
|
95
|
+
}
|
|
96
|
+
addFiles(host, options);
|
|
97
|
+
yield updateGeneratorJson(host, options);
|
|
98
|
+
if (!options.skipFormat) {
|
|
99
|
+
yield (0, devkit_1.formatFiles)(host);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
exports.generatorGenerator = generatorGenerator;
|
|
104
|
+
exports.default = generatorGenerator;
|
|
105
|
+
exports.generatorSchematic = (0, devkit_1.convertNxGenerator)(generatorGenerator);
|
|
106
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/plugin/src/generators/generator/generator.ts"],"names":[],"mappings":";;;;AAAA,uCAaoB;AAEpB,6BAA6B;AAC7B,6DAAyD;AACzD,wDAAgE;AAYhE,SAAS,gBAAgB,CAAC,IAAU,EAAE,OAAe;IACnD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,2BAAkB,EAAC,IAAI,CAAC,CAAC;IAC9C,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAA,cAAK,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpD,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,iBAAiB,EAAE,GACxD,IAAA,iCAAwB,EAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAElD,MAAM,cAAc,GAAG,IAAA,iBAAQ,EAC7B,IAAI,EACJ,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CACvC,CAAC,IAAI,CAAC;IAEP,IAAI,WAAmB,CAAC;IACxB,IAAI,OAAO,CAAC,W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