@nx/plugin 17.0.0-beta.4 → 17.0.0-beta.6

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/generators.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "description": "Create a generator for an Nx Plugin."
30
30
  },
31
31
  "executor": {
32
- "factory": "./src/generators/executor/executor",
32
+ "factory": "./src/generators/executor/executor#executorGeneratorInternal",
33
33
  "schema": "./src/generators/executor/schema.json",
34
34
  "description": "Create an executor for an Nx Plugin."
35
35
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/plugin",
3
- "version": "17.0.0-beta.4",
3
+ "version": "17.0.0-beta.6",
4
4
  "private": false,
5
5
  "description": "This plugin is used to create Nx plugins! It contains generators for generating common plugin features like generators, executors, migrations and more.",
6
6
  "repository": {
@@ -31,11 +31,11 @@
31
31
  "@phenomnomnominal/tsquery": "~5.0.1",
32
32
  "fs-extra": "^11.1.0",
33
33
  "tslib": "^2.3.0",
34
- "@nx/devkit": "17.0.0-beta.4",
35
- "@nx/jest": "17.0.0-beta.4",
36
- "@nx/js": "17.0.0-beta.4",
37
- "@nx/linter": "17.0.0-beta.4",
38
- "@nrwl/nx-plugin": "17.0.0-beta.4"
34
+ "@nx/devkit": "17.0.0-beta.6",
35
+ "@nx/jest": "17.0.0-beta.6",
36
+ "@nx/js": "17.0.0-beta.6",
37
+ "@nx/linter": "17.0.0-beta.6",
38
+ "@nrwl/nx-plugin": "17.0.0-beta.6"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"
@@ -1,5 +1,6 @@
1
1
  import type { Tree } from '@nx/devkit';
2
2
  import type { Schema } from './schema';
3
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>;
4
+ export declare function executorGenerator(tree: Tree, rawOptions: Schema): Promise<void>;
5
+ export declare function executorGeneratorInternal(host: Tree, schema: Schema): Promise<void>;
5
6
  export default executorGenerator;
@@ -1,26 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executorGenerator = exports.createExecutorsJson = void 0;
3
+ exports.executorGeneratorInternal = exports.executorGenerator = exports.createExecutorsJson = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const path = require("path");
6
6
  const generator_1 = require("../lint-checks/generator");
7
7
  const versions_1 = require("../../utils/versions");
8
+ const get_npm_scope_1 = require("@nx/js/src/utils/package-json/get-npm-scope");
9
+ const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
10
+ const path_1 = require("path");
8
11
  function addFiles(host, options) {
9
- (0, devkit_1.generateFiles)(host, path.join(__dirname, './files/executor'), `${options.projectSourceRoot}/executors`, {
12
+ (0, devkit_1.generateFiles)(host, path.join(__dirname, './files/executor'), options.directory, {
10
13
  ...options,
11
- tmpl: '',
12
14
  });
13
15
  if (options.unitTestRunner === 'none') {
14
- host.delete((0, devkit_1.joinPathFragments)(options.projectSourceRoot, 'executors', options.fileName, `executor.spec.ts`));
16
+ host.delete((0, devkit_1.joinPathFragments)(options.directory, `executor.spec.ts`));
15
17
  }
16
18
  }
17
19
  function addHasherFiles(host, options) {
18
- (0, devkit_1.generateFiles)(host, path.join(__dirname, './files/hasher'), `${options.projectSourceRoot}/executors`, {
20
+ (0, devkit_1.generateFiles)(host, path.join(__dirname, './files/hasher'), options.directory, {
19
21
  ...options,
20
- tmpl: '',
21
22
  });
22
23
  if (options.unitTestRunner === 'none') {
23
- host.delete((0, devkit_1.joinPathFragments)(options.projectSourceRoot, 'executors', options.fileName, 'hasher.spec.ts'));
24
+ host.delete((0, devkit_1.joinPathFragments)(options.directory, 'hasher.spec.ts'));
24
25
  }
25
26
  }
26
27
  async function createExecutorsJson(host, projectRoot, projectName, skipLintChecks) {
@@ -62,21 +63,32 @@ async function updateExecutorJson(host, options) {
62
63
  let executors = json.executors ?? json.builders;
63
64
  executors ||= {};
64
65
  executors[options.name] = {
65
- implementation: `./src/executors/${options.fileName}/executor`,
66
- schema: `./src/executors/${options.fileName}/schema.json`,
66
+ implementation: `./${(0, devkit_1.normalizePath)((0, path_1.relative)(options.projectRoot, (0, path_1.join)(options.directory, 'executor')))}`,
67
+ schema: `./${(0, devkit_1.normalizePath)((0, path_1.relative)(options.projectRoot, (0, path_1.join)(options.directory, 'schema.json')))}`,
67
68
  description: options.description,
68
69
  };
69
70
  if (options.includeHasher) {
70
- executors[options.name].hasher = `./src/executors/${options.fileName}/hasher`;
71
+ executors[options.name].hasher = `./${(0, devkit_1.normalizePath)((0, path_1.relative)(options.projectRoot, (0, path_1.join)(options.directory, 'hasher')))}`;
71
72
  }
72
73
  json.executors = executors;
73
74
  return json;
74
75
  });
75
76
  }
76
- function normalizeOptions(host, options) {
77
- const { npmScope } = (0, devkit_1.getWorkspaceLayout)(host);
78
- const { fileName, className, propertyName } = (0, devkit_1.names)(options.name);
79
- const { root: projectRoot, sourceRoot: projectSourceRoot } = (0, devkit_1.readProjectConfiguration)(host, options.project);
77
+ async function normalizeOptions(tree, options) {
78
+ const npmScope = (0, get_npm_scope_1.getNpmScope)(tree);
79
+ const res = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
80
+ artifactType: 'executor',
81
+ callingGenerator: '@nx/plugin:executor',
82
+ name: options.name,
83
+ nameAndDirectoryFormat: options.nameAndDirectoryFormat,
84
+ project: options.project,
85
+ directory: options.directory,
86
+ fileName: 'executor',
87
+ derivedDirectory: 'executors',
88
+ });
89
+ const { project, fileName, artifactName, filePath, directory } = res;
90
+ const { className, propertyName } = (0, devkit_1.names)(artifactName);
91
+ const { root: projectRoot } = (0, devkit_1.readProjectConfiguration)(tree, project);
80
92
  let description;
81
93
  if (options.description) {
82
94
  description = options.description;
@@ -86,17 +98,26 @@ function normalizeOptions(host, options) {
86
98
  }
87
99
  return {
88
100
  ...options,
101
+ filePath,
102
+ project,
103
+ directory,
89
104
  fileName,
90
105
  className,
91
106
  propertyName,
92
107
  description,
93
108
  projectRoot,
94
- projectSourceRoot,
95
109
  npmScope,
96
110
  };
97
111
  }
98
- async function executorGenerator(host, schema) {
99
- const options = normalizeOptions(host, schema);
112
+ async function executorGenerator(tree, rawOptions) {
113
+ await executorGeneratorInternal(tree, {
114
+ nameAndDirectoryFormat: 'derived',
115
+ ...rawOptions,
116
+ });
117
+ }
118
+ exports.executorGenerator = executorGenerator;
119
+ async function executorGeneratorInternal(host, schema) {
120
+ const options = await normalizeOptions(host, schema);
100
121
  addFiles(host, options);
101
122
  if (options.includeHasher) {
102
123
  addHasherFiles(host, options);
@@ -106,5 +127,5 @@ async function executorGenerator(host, schema) {
106
127
  await (0, devkit_1.formatFiles)(host);
107
128
  }
108
129
  }
109
- exports.executorGenerator = executorGenerator;
130
+ exports.executorGeneratorInternal = executorGeneratorInternal;
110
131
  exports.default = executorGenerator;
@@ -1,9 +1,13 @@
1
+ import type { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
2
+
1
3
  export interface Schema {
2
- project: string;
4
+ project?: string;
3
5
  name: string;
6
+ directory?: string;
4
7
  description?: string;
5
8
  unitTestRunner: 'jest' | 'none';
6
9
  includeHasher: boolean;
10
+ nameAndDirectoryFormat?: NameAndDirectoryFormat;
7
11
  skipLintChecks?: boolean;
8
12
  skipFormat?: boolean;
9
13
  }
@@ -19,9 +19,7 @@
19
19
  "alias": "p",
20
20
  "$default": {
21
21
  "$source": "projectName"
22
- },
23
- "x-prompt": "What is the name of the project for the executor?",
24
- "x-priority": "important"
22
+ }
25
23
  },
26
24
  "name": {
27
25
  "type": "string",
@@ -33,6 +31,11 @@
33
31
  "x-prompt": "What name would you like to use for the executor?",
34
32
  "x-priority": "important"
35
33
  },
34
+ "directory": {
35
+ "type": "string",
36
+ "description": "The directory at which to create the executor file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
37
+ "aliases": ["dir"]
38
+ },
36
39
  "description": {
37
40
  "type": "string",
38
41
  "description": "Executor description."
@@ -53,6 +56,11 @@
53
56
  "default": false,
54
57
  "description": "Do not add an eslint configuration for plugin json files."
55
58
  },
59
+ "nameAndDirectoryFormat": {
60
+ "description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
61
+ "type": "string",
62
+ "enum": ["as-provided", "derived"]
63
+ },
56
64
  "skipFormat": {
57
65
  "type": "boolean",
58
66
  "description": "Skip formatting files.",
@@ -60,6 +68,6 @@
60
68
  "x-priority": "internal"
61
69
  }
62
70
  },
63
- "required": ["project", "name"],
71
+ "required": ["name"],
64
72
  "additionalProperties": false
65
73
  }