feat(angular): use consistent artifact generation for generators (#19601)
This commit is contained in:
parent
4697b06fd1
commit
5a6adb717c
@ -7,7 +7,7 @@
|
|||||||
"cli": "nx",
|
"cli": "nx",
|
||||||
"title": "Nx Angular Directive Options Schema",
|
"title": "Nx Angular Directive Options Schema",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Creates a new, generic directive definition in the given project.",
|
"description": "Creates a new Angular directive.",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"properties": {
|
"properties": {
|
||||||
"name": {
|
"name": {
|
||||||
@ -16,18 +16,23 @@
|
|||||||
"$default": { "$source": "argv", "index": 0 },
|
"$default": { "$source": "argv", "index": 0 },
|
||||||
"x-prompt": "What name would you like to use for the directive?"
|
"x-prompt": "What name would you like to use for the directive?"
|
||||||
},
|
},
|
||||||
"path": {
|
"directory": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "path",
|
"description": "The directory at which to create the directive file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
|
||||||
"$default": { "$source": "workingDirectory" },
|
"aliases": ["dir", "path"],
|
||||||
"description": "The path at which to create the interface that defines the directive, relative to the workspace root.",
|
"x-priority": "important"
|
||||||
"visible": false
|
},
|
||||||
|
"nameAndDirectoryFormat": {
|
||||||
|
"description": "Whether to generate the directive 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`).",
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["as-provided", "derived"]
|
||||||
},
|
},
|
||||||
"project": {
|
"project": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The name of the project.",
|
"description": "The name of the project.",
|
||||||
"$default": { "$source": "projectName" },
|
"$default": { "$source": "projectName" },
|
||||||
"x-dropdown": "projects"
|
"x-dropdown": "projects",
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
|
||||||
},
|
},
|
||||||
"prefix": {
|
"prefix": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -61,7 +66,8 @@
|
|||||||
"flat": {
|
"flat": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "When true (the default), creates the new files at the top level of the current project.",
|
"description": "When true (the default), creates the new files at the top level of the current project.",
|
||||||
"default": true
|
"default": true,
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
|
||||||
},
|
},
|
||||||
"module": {
|
"module": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -79,7 +85,7 @@
|
|||||||
"description": "Skip formatting of files."
|
"description": "Skip formatting of files."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["name", "project"],
|
"required": ["name"],
|
||||||
"presets": []
|
"presets": []
|
||||||
},
|
},
|
||||||
"aliases": ["d"],
|
"aliases": ["d"],
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"cli": "nx",
|
"cli": "nx",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"description": "Creates a new, generic pipe definition in the given project.",
|
"description": "Creates an Angular pipe.",
|
||||||
"properties": {
|
"properties": {
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -16,23 +16,29 @@
|
|||||||
"$default": { "$source": "argv", "index": 0 },
|
"$default": { "$source": "argv", "index": 0 },
|
||||||
"x-prompt": "What name would you like to use for the pipe?"
|
"x-prompt": "What name would you like to use for the pipe?"
|
||||||
},
|
},
|
||||||
"path": {
|
"directory": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "path",
|
"description": "The directory at which to create the pipe file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
|
||||||
"$default": { "$source": "workingDirectory" },
|
"aliases": ["dir", "path"],
|
||||||
"description": "The path at which to create the pipe, relative to the workspace root.",
|
"x-priority": "important"
|
||||||
"visible": false
|
},
|
||||||
|
"nameAndDirectoryFormat": {
|
||||||
|
"description": "Whether to generate the pipe 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`).",
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["as-provided", "derived"]
|
||||||
},
|
},
|
||||||
"project": {
|
"project": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The name of the project.",
|
"description": "The name of the project.",
|
||||||
"$default": { "$source": "projectName" },
|
"$default": { "$source": "projectName" },
|
||||||
"x-dropdown": "projects"
|
"x-dropdown": "projects",
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
|
||||||
},
|
},
|
||||||
"flat": {
|
"flat": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
"description": "When true (the default) creates files at the top level of the project."
|
"description": "When true (the default) creates files at the top level of the project.",
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
|
||||||
},
|
},
|
||||||
"skipTests": {
|
"skipTests": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@ -65,7 +71,7 @@
|
|||||||
"description": "Skip formatting of files."
|
"description": "Skip formatting of files."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["name", "project"],
|
"required": ["name"],
|
||||||
"presets": []
|
"presets": []
|
||||||
},
|
},
|
||||||
"description": "Generate an Angular Pipe",
|
"description": "Generate an Angular Pipe",
|
||||||
|
|||||||
@ -9,25 +9,13 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"examples": [
|
"examples": [
|
||||||
{
|
{
|
||||||
"command": "nx g @nx/angular:scam-directive --project=my-lib --flat=false my-sample",
|
"command": "nx g @nx/angular:scam-directive my-sample --directory=my-lib/src/lib/my-sample",
|
||||||
"description": "Generate a `MySampleDirective` directive in a `my-sample` folder in the `my-lib` library"
|
"description": "Generate a `MySampleDirective` directive in a `my-sample` folder in the `my-lib` library"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Creates a new, generic Angular directive definition in the given or default project.",
|
"description": "Creates a new, generic Angular directive definition in the given or default project.",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"properties": {
|
"properties": {
|
||||||
"path": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "path",
|
|
||||||
"description": "The path at which to create the directive file, relative to the current workspace. Default is a folder with the same name as the directive in the project root.",
|
|
||||||
"visible": false
|
|
||||||
},
|
|
||||||
"project": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The name of the project.",
|
|
||||||
"$default": { "$source": "projectName" },
|
|
||||||
"x-dropdown": "projects"
|
|
||||||
},
|
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The name of the directive.",
|
"description": "The name of the directive.",
|
||||||
@ -35,6 +23,24 @@
|
|||||||
"x-prompt": "What name would you like to use for the directive?",
|
"x-prompt": "What name would you like to use for the directive?",
|
||||||
"x-priority": "important"
|
"x-priority": "important"
|
||||||
},
|
},
|
||||||
|
"directory": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The directory at which to create the SCAM Directive files. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
|
||||||
|
"aliases": ["dir", "path"],
|
||||||
|
"x-priority": "important"
|
||||||
|
},
|
||||||
|
"nameAndDirectoryFormat": {
|
||||||
|
"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`).",
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["as-provided", "derived"]
|
||||||
|
},
|
||||||
|
"project": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the project.",
|
||||||
|
"$default": { "$source": "projectName" },
|
||||||
|
"x-dropdown": "projects",
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
|
||||||
|
},
|
||||||
"skipTests": {
|
"skipTests": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Do not create `spec.ts` test files for the new directive.",
|
"description": "Do not create `spec.ts` test files for the new directive.",
|
||||||
@ -49,7 +55,8 @@
|
|||||||
"flat": {
|
"flat": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Create the new files at the top level of the current project.",
|
"description": "Create the new files at the top level of the current project.",
|
||||||
"default": true
|
"default": true,
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
|
||||||
},
|
},
|
||||||
"selector": {
|
"selector": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -72,7 +79,7 @@
|
|||||||
"x-priority": "important"
|
"x-priority": "important"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["name", "project"],
|
"required": ["name"],
|
||||||
"presets": []
|
"presets": []
|
||||||
},
|
},
|
||||||
"description": "Generate a directive with an accompanying Single Component Angular Module (SCAM).",
|
"description": "Generate a directive with an accompanying Single Component Angular Module (SCAM).",
|
||||||
|
|||||||
@ -16,18 +16,6 @@
|
|||||||
"description": "Creates a new, generic Angular pipe definition in the given or default project.",
|
"description": "Creates a new, generic Angular pipe definition in the given or default project.",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"properties": {
|
"properties": {
|
||||||
"path": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "path",
|
|
||||||
"description": "The path at which to create the pipe file, relative to the current workspace. Default is a folder with the same name as the pipe in the project root.",
|
|
||||||
"visible": false
|
|
||||||
},
|
|
||||||
"project": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The name of the project.",
|
|
||||||
"$default": { "$source": "projectName" },
|
|
||||||
"x-dropdown": "projects"
|
|
||||||
},
|
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The name of the pipe.",
|
"description": "The name of the pipe.",
|
||||||
@ -35,6 +23,24 @@
|
|||||||
"x-prompt": "What name would you like to use for the pipe?",
|
"x-prompt": "What name would you like to use for the pipe?",
|
||||||
"x-priority": "important"
|
"x-priority": "important"
|
||||||
},
|
},
|
||||||
|
"directory": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The directory at which to create the component file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
|
||||||
|
"aliases": ["dir", "path"],
|
||||||
|
"x-priority": "important"
|
||||||
|
},
|
||||||
|
"nameAndDirectoryFormat": {
|
||||||
|
"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`).",
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["as-provided", "derived"]
|
||||||
|
},
|
||||||
|
"project": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the project.",
|
||||||
|
"$default": { "$source": "projectName" },
|
||||||
|
"x-dropdown": "projects",
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
|
||||||
|
},
|
||||||
"skipTests": {
|
"skipTests": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Do not create `spec.ts` test files for the new pipe.",
|
"description": "Do not create `spec.ts` test files for the new pipe.",
|
||||||
@ -49,7 +55,8 @@
|
|||||||
"flat": {
|
"flat": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Create the new files at the top level of the current project.",
|
"description": "Create the new files at the top level of the current project.",
|
||||||
"default": true
|
"default": true,
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
|
||||||
},
|
},
|
||||||
"export": {
|
"export": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@ -58,7 +65,7 @@
|
|||||||
"x-priority": "important"
|
"x-priority": "important"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["name", "project"],
|
"required": ["name"],
|
||||||
"presets": []
|
"presets": []
|
||||||
},
|
},
|
||||||
"description": "Generate a pipe with an accompanying Single Component Angular Module (SCAM).",
|
"description": "Generate a pipe with an accompanying Single Component Angular Module (SCAM).",
|
||||||
|
|||||||
@ -9,31 +9,37 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"examples": [
|
"examples": [
|
||||||
{
|
{
|
||||||
"command": "nx g @nx/angular:scam --project=my-lib my-sample",
|
"command": "nx g @nx/angular:scam my-sample --directory=my-lib/src/lib/my-sample",
|
||||||
"description": "Generate a `MySampleComponent` component in the `my-lib` library."
|
"description": "Generate a `MySampleComponent` component in the `my-lib` library."
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Creates a new, generic Angular component definition in the given or default project.",
|
"description": "Creates a new Angular SCAM.",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"properties": {
|
"properties": {
|
||||||
"path": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "path",
|
|
||||||
"description": "The path at which to create the component file, relative to the current workspace. Default is a folder with the same name as the component in the project root.",
|
|
||||||
"visible": false
|
|
||||||
},
|
|
||||||
"project": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The name of the project.",
|
|
||||||
"$default": { "$source": "projectName" },
|
|
||||||
"x-dropdown": "projects"
|
|
||||||
},
|
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The name of the component.",
|
"description": "The name of the component.",
|
||||||
"$default": { "$source": "argv", "index": 0 },
|
"$default": { "$source": "argv", "index": 0 },
|
||||||
"x-prompt": "What name would you like to use for the component?"
|
"x-prompt": "What name would you like to use for the component?"
|
||||||
},
|
},
|
||||||
|
"directory": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The directory at which to create the SCAM files. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
|
||||||
|
"aliases": ["dir", "path"],
|
||||||
|
"x-priority": "important"
|
||||||
|
},
|
||||||
|
"nameAndDirectoryFormat": {
|
||||||
|
"description": "Whether to generate the SCAM 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`).",
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["as-provided", "derived"]
|
||||||
|
},
|
||||||
|
"project": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the project.",
|
||||||
|
"$default": { "$source": "projectName" },
|
||||||
|
"x-dropdown": "projects",
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
|
||||||
|
},
|
||||||
"displayBlock": {
|
"displayBlock": {
|
||||||
"description": "Specifies if the style will contain `:host { display: block; }`.",
|
"description": "Specifies if the style will contain `:host { display: block; }`.",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@ -85,7 +91,8 @@
|
|||||||
"flat": {
|
"flat": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Create the new files at the top level of the current project.",
|
"description": "Create the new files at the top level of the current project.",
|
||||||
"default": false
|
"default": false,
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
|
||||||
},
|
},
|
||||||
"selector": {
|
"selector": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -124,7 +131,7 @@
|
|||||||
"x-priority": "internal"
|
"x-priority": "internal"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["name", "project"],
|
"required": ["name"],
|
||||||
"presets": []
|
"presets": []
|
||||||
},
|
},
|
||||||
"description": "Generate a component with an accompanying Single Component Angular Module (SCAM).",
|
"description": "Generate a component with an accompanying Single Component Angular Module (SCAM).",
|
||||||
|
|||||||
@ -11,9 +11,7 @@ import type { Schema } from './schema';
|
|||||||
|
|
||||||
export async function directiveGenerator(tree: Tree, schema: Schema) {
|
export async function directiveGenerator(tree: Tree, schema: Schema) {
|
||||||
validateOptions(tree, schema);
|
validateOptions(tree, schema);
|
||||||
const options = normalizeOptions(tree, schema);
|
const options = await normalizeOptions(tree, schema);
|
||||||
|
|
||||||
const directiveNames = names(options.name);
|
|
||||||
|
|
||||||
generateFiles(
|
generateFiles(
|
||||||
tree,
|
tree,
|
||||||
@ -21,8 +19,8 @@ export async function directiveGenerator(tree: Tree, schema: Schema) {
|
|||||||
options.directory,
|
options.directory,
|
||||||
{
|
{
|
||||||
selector: options.selector,
|
selector: options.selector,
|
||||||
directiveClassName: directiveNames.className,
|
symbolName: options.symbolName,
|
||||||
directiveFileName: directiveNames.fileName,
|
fileName: options.fileName,
|
||||||
standalone: options.standalone,
|
standalone: options.standalone,
|
||||||
tpl: '',
|
tpl: '',
|
||||||
}
|
}
|
||||||
@ -31,21 +29,21 @@ export async function directiveGenerator(tree: Tree, schema: Schema) {
|
|||||||
if (options.skipTests) {
|
if (options.skipTests) {
|
||||||
const pathToSpecFile = joinPathFragments(
|
const pathToSpecFile = joinPathFragments(
|
||||||
options.directory,
|
options.directory,
|
||||||
`${directiveNames.fileName}.directive.spec.ts`
|
`${options.fileName}.spec.ts`
|
||||||
);
|
);
|
||||||
|
|
||||||
tree.delete(pathToSpecFile);
|
tree.delete(pathToSpecFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.skipImport && !options.standalone) {
|
if (!options.skipImport && !options.standalone) {
|
||||||
const modulePath = findModule(tree, options.path, options.module);
|
const modulePath = findModule(tree, options.directory, options.module);
|
||||||
addToNgModule(
|
addToNgModule(
|
||||||
tree,
|
tree,
|
||||||
options.path,
|
options.directory,
|
||||||
modulePath,
|
modulePath,
|
||||||
directiveNames.fileName,
|
'',
|
||||||
`${directiveNames.className}Directive`,
|
options.symbolName,
|
||||||
`${directiveNames.fileName}.directive`,
|
options.fileName,
|
||||||
'declarations',
|
'declarations',
|
||||||
options.flat,
|
options.flat,
|
||||||
options.export
|
options.export
|
||||||
|
|||||||
@ -1,8 +0,0 @@
|
|||||||
import { <%= directiveClassName %>Directive } from './<%= directiveFileName %>.directive';
|
|
||||||
|
|
||||||
describe('<%= directiveClassName %>Directive', () => {
|
|
||||||
it('should create an instance', () => {
|
|
||||||
const directive = new <%= directiveClassName %>Directive();
|
|
||||||
expect(directive).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
import { <%= symbolName %> } from './<%= fileName %>';
|
||||||
|
|
||||||
|
describe('<%= symbolName %>', () => {
|
||||||
|
it('should create an instance', () => {
|
||||||
|
const directive = new <%= symbolName %>();
|
||||||
|
expect(directive).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -4,7 +4,7 @@ import { Directive } from '@angular/core';
|
|||||||
selector: '[<%= selector %>]'<% if(standalone) {%>,
|
selector: '[<%= selector %>]'<% if(standalone) {%>,
|
||||||
standalone: true<%}%>
|
standalone: true<%}%>
|
||||||
})
|
})
|
||||||
export class <%= directiveClassName %>Directive {
|
export class <%= symbolName %> {
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
@ -1,22 +1,38 @@
|
|||||||
import type { Tree } from '@nx/devkit';
|
import type { Tree } from '@nx/devkit';
|
||||||
import { readProjectConfiguration } from '@nx/devkit';
|
import { names, readProjectConfiguration } from '@nx/devkit';
|
||||||
import type { AngularProjectConfiguration } from '../../../utils/types';
|
import type { AngularProjectConfiguration } from '../../../utils/types';
|
||||||
import { normalizeNameAndPaths } from '../../utils/path';
|
|
||||||
import { buildSelector } from '../../utils/selector';
|
import { buildSelector } from '../../utils/selector';
|
||||||
import type { NormalizedSchema, Schema } from '../schema';
|
import type { NormalizedSchema, Schema } from '../schema';
|
||||||
|
import { determineArtifactNameAndDirectoryOptions } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
||||||
|
|
||||||
export function normalizeOptions(
|
export async function normalizeOptions(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
options: Schema
|
options: Schema
|
||||||
): NormalizedSchema {
|
): Promise<NormalizedSchema> {
|
||||||
const { directory, name, path } = normalizeNameAndPaths(tree, {
|
const {
|
||||||
...options,
|
artifactName: name,
|
||||||
type: 'directive',
|
directory,
|
||||||
|
fileName,
|
||||||
|
filePath,
|
||||||
|
project,
|
||||||
|
} = await determineArtifactNameAndDirectoryOptions(tree, {
|
||||||
|
artifactType: 'directive',
|
||||||
|
callingGenerator: '@nx/angular:directive',
|
||||||
|
name: options.name,
|
||||||
|
directory: options.directory ?? options.path,
|
||||||
|
flat: options.flat,
|
||||||
|
nameAndDirectoryFormat: options.nameAndDirectoryFormat,
|
||||||
|
project: options.project,
|
||||||
|
suffix: 'directive',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { className } = names(name);
|
||||||
|
const { className: suffixClassName } = names('directive');
|
||||||
|
const symbolName = `${className}${suffixClassName}`;
|
||||||
|
|
||||||
const { prefix } = readProjectConfiguration(
|
const { prefix } = readProjectConfiguration(
|
||||||
tree,
|
tree,
|
||||||
options.project
|
project
|
||||||
) as AngularProjectConfiguration;
|
) as AngularProjectConfiguration;
|
||||||
|
|
||||||
const selector =
|
const selector =
|
||||||
@ -25,9 +41,12 @@ export function normalizeOptions(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
directory,
|
project,
|
||||||
name,
|
name,
|
||||||
path,
|
directory,
|
||||||
|
fileName,
|
||||||
|
filePath,
|
||||||
|
symbolName,
|
||||||
selector,
|
selector,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,7 @@
|
|||||||
import type { Tree } from '@nx/devkit';
|
import type { Tree } from '@nx/devkit';
|
||||||
import {
|
import { validateStandaloneOption } from '../../utils/validations';
|
||||||
validatePathIsUnderProjectRoot,
|
|
||||||
validateProject,
|
|
||||||
validateStandaloneOption,
|
|
||||||
} from '../../utils/validations';
|
|
||||||
import type { Schema } from '../schema';
|
import type { Schema } from '../schema';
|
||||||
|
|
||||||
export function validateOptions(tree: Tree, options: Schema): void {
|
export function validateOptions(tree: Tree, options: Schema): void {
|
||||||
validateProject(tree, options.project);
|
|
||||||
validatePathIsUnderProjectRoot(tree, options.project, options.path);
|
|
||||||
validateStandaloneOption(tree, options.standalone);
|
validateStandaloneOption(tree, options.standalone);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +1,35 @@
|
|||||||
|
import { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
||||||
|
|
||||||
export interface Schema {
|
export interface Schema {
|
||||||
name: string;
|
name: string;
|
||||||
project: string;
|
directory?: string;
|
||||||
path?: string;
|
nameAndDirectoryFormat?: NameAndDirectoryFormat;
|
||||||
prefix?: string;
|
prefix?: string;
|
||||||
skipTests?: boolean;
|
skipTests?: boolean;
|
||||||
skipImport?: boolean;
|
skipImport?: boolean;
|
||||||
selector?: string;
|
selector?: string;
|
||||||
standalone?: boolean;
|
standalone?: boolean;
|
||||||
flat?: boolean;
|
|
||||||
module?: string;
|
module?: string;
|
||||||
export?: boolean;
|
export?: boolean;
|
||||||
skipFormat?: boolean;
|
skipFormat?: boolean;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
flat?: boolean;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
path?: string;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead. The project will be determined from the directory provided. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
project?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NormalizedSchema extends Schema {
|
export interface NormalizedSchema extends Schema {
|
||||||
directory: string;
|
directory: string;
|
||||||
path: string;
|
filePath: string;
|
||||||
|
fileName: string;
|
||||||
|
symbolName: string;
|
||||||
|
project: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
"cli": "nx",
|
"cli": "nx",
|
||||||
"title": "Nx Angular Directive Options Schema",
|
"title": "Nx Angular Directive Options Schema",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Creates a new, generic directive definition in the given project.",
|
"description": "Creates a new Angular directive.",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"properties": {
|
"properties": {
|
||||||
"name": {
|
"name": {
|
||||||
@ -16,14 +16,16 @@
|
|||||||
},
|
},
|
||||||
"x-prompt": "What name would you like to use for the directive?"
|
"x-prompt": "What name would you like to use for the directive?"
|
||||||
},
|
},
|
||||||
"path": {
|
"directory": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "path",
|
"description": "The directory at which to create the directive file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
|
||||||
"$default": {
|
"aliases": ["dir", "path"],
|
||||||
"$source": "workingDirectory"
|
"x-priority": "important"
|
||||||
},
|
},
|
||||||
"description": "The path at which to create the interface that defines the directive, relative to the workspace root.",
|
"nameAndDirectoryFormat": {
|
||||||
"visible": false
|
"description": "Whether to generate the directive 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`).",
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["as-provided", "derived"]
|
||||||
},
|
},
|
||||||
"project": {
|
"project": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -31,7 +33,8 @@
|
|||||||
"$default": {
|
"$default": {
|
||||||
"$source": "projectName"
|
"$source": "projectName"
|
||||||
},
|
},
|
||||||
"x-dropdown": "projects"
|
"x-dropdown": "projects",
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
|
||||||
},
|
},
|
||||||
"prefix": {
|
"prefix": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -70,7 +73,8 @@
|
|||||||
"flat": {
|
"flat": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "When true (the default), creates the new files at the top level of the current project.",
|
"description": "When true (the default), creates the new files at the top level of the current project.",
|
||||||
"default": true
|
"default": true,
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
|
||||||
},
|
},
|
||||||
"module": {
|
"module": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -88,5 +92,5 @@
|
|||||||
"description": "Skip formatting of files."
|
"description": "Skip formatting of files."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["name", "project"]
|
"required": ["name"]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,8 @@
|
|||||||
|
import { <%= symbolName %> } from './<%= fileName %>';
|
||||||
|
|
||||||
|
describe('<%= symbolName %>', () => {
|
||||||
|
it('create an instance', () => {
|
||||||
|
const pipe = new <%= symbolName %>();
|
||||||
|
expect(pipe).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,10 +1,10 @@
|
|||||||
import { Pipe, PipeTransform } from '@angular/core';
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
|
|
||||||
@Pipe({
|
@Pipe({
|
||||||
name: '<%= pipePropertyName %>'<% if(standalone) {%>,
|
name: '<%= selector %>'<% if(standalone) {%>,
|
||||||
standalone: true<%}%>
|
standalone: true<%}%>
|
||||||
})
|
})
|
||||||
export class <%= pipeClassName %>Pipe implements PipeTransform {
|
export class <%= symbolName %> implements PipeTransform {
|
||||||
|
|
||||||
transform(value: unknown, ...args: unknown[]): unknown {
|
transform(value: unknown, ...args: unknown[]): unknown {
|
||||||
return null;
|
return null;
|
||||||
@ -1,8 +0,0 @@
|
|||||||
import { <%= pipeClassName %>Pipe } from './<%= pipeFileName %>.pipe';
|
|
||||||
|
|
||||||
describe('<%= pipeClassName %>Pipe', () => {
|
|
||||||
it('create an instance', () => {
|
|
||||||
const pipe = new <%= pipeClassName %>Pipe();
|
|
||||||
expect(pipe).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,20 +1,40 @@
|
|||||||
import type { Tree } from '@nx/devkit';
|
import type { Tree } from '@nx/devkit';
|
||||||
import { normalizeNameAndPaths } from '../../utils/path';
|
|
||||||
import type { NormalizedSchema, Schema } from '../schema';
|
import type { NormalizedSchema, Schema } from '../schema';
|
||||||
|
import { determineArtifactNameAndDirectoryOptions } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
||||||
|
import { names } from '@nx/devkit';
|
||||||
|
|
||||||
export function normalizeOptions(
|
export async function normalizeOptions(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
options: Schema
|
options: Schema
|
||||||
): NormalizedSchema {
|
): Promise<NormalizedSchema> {
|
||||||
const { directory, name, path } = normalizeNameAndPaths(tree, {
|
const {
|
||||||
...options,
|
artifactName: name,
|
||||||
type: 'pipe',
|
directory,
|
||||||
|
fileName,
|
||||||
|
filePath,
|
||||||
|
project,
|
||||||
|
} = await determineArtifactNameAndDirectoryOptions(tree, {
|
||||||
|
artifactType: 'pipe',
|
||||||
|
callingGenerator: '@nx/angular:pipe',
|
||||||
|
name: options.name,
|
||||||
|
directory: options.directory ?? options.path,
|
||||||
|
flat: options.flat,
|
||||||
|
nameAndDirectoryFormat: options.nameAndDirectoryFormat,
|
||||||
|
project: options.project,
|
||||||
|
suffix: 'pipe',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { className } = names(name);
|
||||||
|
const { className: suffixClassName } = names('pipe');
|
||||||
|
const symbolName = `${className}${suffixClassName}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
directory,
|
project,
|
||||||
name,
|
name,
|
||||||
path,
|
directory,
|
||||||
|
fileName,
|
||||||
|
filePath,
|
||||||
|
symbolName,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,7 @@
|
|||||||
import type { Tree } from '@nx/devkit';
|
import type { Tree } from '@nx/devkit';
|
||||||
import {
|
import { validateStandaloneOption } from '../../utils/validations';
|
||||||
validatePathIsUnderProjectRoot,
|
|
||||||
validateProject,
|
|
||||||
validateStandaloneOption,
|
|
||||||
} from '../../utils/validations';
|
|
||||||
import type { Schema } from '../schema';
|
import type { Schema } from '../schema';
|
||||||
|
|
||||||
export function validateOptions(tree: Tree, options: Schema): void {
|
export function validateOptions(tree: Tree, options: Schema): void {
|
||||||
validateProject(tree, options.project);
|
|
||||||
validatePathIsUnderProjectRoot(tree, options.project, options.path);
|
|
||||||
validateStandaloneOption(tree, options.standalone);
|
validateStandaloneOption(tree, options.standalone);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import type { Schema } from './schema';
|
|||||||
|
|
||||||
export async function pipeGenerator(tree: Tree, rawOptions: Schema) {
|
export async function pipeGenerator(tree: Tree, rawOptions: Schema) {
|
||||||
validateOptions(tree, rawOptions);
|
validateOptions(tree, rawOptions);
|
||||||
const options = normalizeOptions(tree, rawOptions);
|
const options = await normalizeOptions(tree, rawOptions);
|
||||||
|
|
||||||
const pipeNames = names(options.name);
|
const pipeNames = names(options.name);
|
||||||
|
|
||||||
@ -20,9 +20,9 @@ export async function pipeGenerator(tree: Tree, rawOptions: Schema) {
|
|||||||
joinPathFragments(__dirname, 'files'),
|
joinPathFragments(__dirname, 'files'),
|
||||||
options.directory,
|
options.directory,
|
||||||
{
|
{
|
||||||
pipeClassName: pipeNames.className,
|
symbolName: options.symbolName,
|
||||||
pipeFileName: pipeNames.fileName,
|
fileName: options.fileName,
|
||||||
pipePropertyName: pipeNames.propertyName,
|
selector: pipeNames.propertyName,
|
||||||
standalone: options.standalone,
|
standalone: options.standalone,
|
||||||
tpl: '',
|
tpl: '',
|
||||||
}
|
}
|
||||||
@ -31,21 +31,21 @@ export async function pipeGenerator(tree: Tree, rawOptions: Schema) {
|
|||||||
if (options.skipTests) {
|
if (options.skipTests) {
|
||||||
const pathToSpecFile = joinPathFragments(
|
const pathToSpecFile = joinPathFragments(
|
||||||
options.directory,
|
options.directory,
|
||||||
`${pipeNames.fileName}.pipe.spec.ts`
|
`${options.fileName}.spec.ts`
|
||||||
);
|
);
|
||||||
|
|
||||||
tree.delete(pathToSpecFile);
|
tree.delete(pathToSpecFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.skipImport && !options.standalone) {
|
if (!options.skipImport && !options.standalone) {
|
||||||
const modulePath = findModule(tree, options.path, options.module);
|
const modulePath = findModule(tree, options.directory, options.module);
|
||||||
addToNgModule(
|
addToNgModule(
|
||||||
tree,
|
tree,
|
||||||
options.path,
|
options.directory,
|
||||||
modulePath,
|
modulePath,
|
||||||
pipeNames.fileName,
|
'',
|
||||||
`${pipeNames.className}Pipe`,
|
options.symbolName,
|
||||||
`${pipeNames.fileName}.pipe`,
|
options.fileName,
|
||||||
'declarations',
|
'declarations',
|
||||||
options.flat,
|
options.flat,
|
||||||
options.export
|
options.export
|
||||||
|
|||||||
24
packages/angular/src/generators/pipe/schema.d.ts
vendored
24
packages/angular/src/generators/pipe/schema.d.ts
vendored
@ -1,17 +1,33 @@
|
|||||||
|
import { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
||||||
|
|
||||||
export interface Schema {
|
export interface Schema {
|
||||||
name: string;
|
name: string;
|
||||||
project: string;
|
directory?: string;
|
||||||
path?: string;
|
nameAndDirectoryFormat?: NameAndDirectoryFormat;
|
||||||
flat?: boolean;
|
|
||||||
skipTests?: boolean;
|
skipTests?: boolean;
|
||||||
skipImport?: boolean;
|
skipImport?: boolean;
|
||||||
standalone?: boolean;
|
standalone?: boolean;
|
||||||
module?: string;
|
module?: string;
|
||||||
export?: boolean;
|
export?: boolean;
|
||||||
skipFormat?: boolean;
|
skipFormat?: boolean;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
flat?: boolean;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
path?: string;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead. The project will be determined from the directory provided. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
project?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NormalizedSchema extends Schema {
|
export interface NormalizedSchema extends Schema {
|
||||||
directory: string;
|
directory: string;
|
||||||
path: string;
|
filePath: string;
|
||||||
|
project: string;
|
||||||
|
fileName: string;
|
||||||
|
symbolName: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"cli": "nx",
|
"cli": "nx",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"description": "Creates a new, generic pipe definition in the given project.",
|
"description": "Creates an Angular pipe.",
|
||||||
"properties": {
|
"properties": {
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -16,14 +16,16 @@
|
|||||||
},
|
},
|
||||||
"x-prompt": "What name would you like to use for the pipe?"
|
"x-prompt": "What name would you like to use for the pipe?"
|
||||||
},
|
},
|
||||||
"path": {
|
"directory": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "path",
|
"description": "The directory at which to create the pipe file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
|
||||||
"$default": {
|
"aliases": ["dir", "path"],
|
||||||
"$source": "workingDirectory"
|
"x-priority": "important"
|
||||||
},
|
},
|
||||||
"description": "The path at which to create the pipe, relative to the workspace root.",
|
"nameAndDirectoryFormat": {
|
||||||
"visible": false
|
"description": "Whether to generate the pipe 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`).",
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["as-provided", "derived"]
|
||||||
},
|
},
|
||||||
"project": {
|
"project": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -31,12 +33,14 @@
|
|||||||
"$default": {
|
"$default": {
|
||||||
"$source": "projectName"
|
"$source": "projectName"
|
||||||
},
|
},
|
||||||
"x-dropdown": "projects"
|
"x-dropdown": "projects",
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
|
||||||
},
|
},
|
||||||
"flat": {
|
"flat": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
"description": "When true (the default) creates files at the top level of the project."
|
"description": "When true (the default) creates files at the top level of the project.",
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
|
||||||
},
|
},
|
||||||
"skipTests": {
|
"skipTests": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@ -69,5 +73,5 @@
|
|||||||
"description": "Skip formatting of files."
|
"description": "Skip formatting of files."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["name", "project"]
|
"required": ["name"]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,7 @@ describe('convertDirectiveToScam', () => {
|
|||||||
flat: false,
|
flat: false,
|
||||||
inlineScam: true,
|
inlineScam: true,
|
||||||
path: 'apps/app1/src/app',
|
path: 'apps/app1/src/app',
|
||||||
|
symbolName: 'ExampleDirective',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -87,6 +88,7 @@ describe('convertDirectiveToScam', () => {
|
|||||||
flat: false,
|
flat: false,
|
||||||
inlineScam: false,
|
inlineScam: false,
|
||||||
path: 'apps/app1/src/app',
|
path: 'apps/app1/src/app',
|
||||||
|
symbolName: 'ExampleDirective',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -136,6 +138,7 @@ describe('convertDirectiveToScam', () => {
|
|||||||
inlineScam: true,
|
inlineScam: true,
|
||||||
flat: true,
|
flat: true,
|
||||||
path: 'apps/app1/src/app',
|
path: 'apps/app1/src/app',
|
||||||
|
symbolName: 'ExampleDirective',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -191,6 +194,7 @@ describe('convertDirectiveToScam', () => {
|
|||||||
inlineScam: false,
|
inlineScam: false,
|
||||||
flat: true,
|
flat: true,
|
||||||
path: 'apps/app1/src/app',
|
path: 'apps/app1/src/app',
|
||||||
|
symbolName: 'ExampleDirective',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -241,6 +245,7 @@ describe('convertDirectiveToScam', () => {
|
|||||||
flat: false,
|
flat: false,
|
||||||
inlineScam: true,
|
inlineScam: true,
|
||||||
path: 'apps/app1/src/app/random',
|
path: 'apps/app1/src/app/random',
|
||||||
|
symbolName: 'ExampleDirective',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -297,6 +302,7 @@ describe('convertDirectiveToScam', () => {
|
|||||||
flat: true,
|
flat: true,
|
||||||
inlineScam: true,
|
inlineScam: true,
|
||||||
path: 'apps/app1/src/app/random',
|
path: 'apps/app1/src/app/random',
|
||||||
|
symbolName: 'ExampleDirective',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
|
|||||||
@ -19,10 +19,6 @@ export function convertDirectiveToScam(
|
|||||||
tsModule = ensureTypescript();
|
tsModule = ensureTypescript();
|
||||||
}
|
}
|
||||||
|
|
||||||
const directiveNames = names(options.name);
|
|
||||||
const typeNames = names('directive');
|
|
||||||
const directiveClassName = `${directiveNames.className}${typeNames.className}`;
|
|
||||||
|
|
||||||
if (options.inlineScam) {
|
if (options.inlineScam) {
|
||||||
const currentDirectiveContents = tree.read(options.filePath, 'utf-8');
|
const currentDirectiveContents = tree.read(options.filePath, 'utf-8');
|
||||||
let source = tsModule.createSourceFile(
|
let source = tsModule.createSourceFile(
|
||||||
@ -49,7 +45,7 @@ export function convertDirectiveToScam(
|
|||||||
|
|
||||||
let updatedDirectiveSource = source.getText();
|
let updatedDirectiveSource = source.getText();
|
||||||
updatedDirectiveSource = `${updatedDirectiveSource}${getNgModuleDeclaration(
|
updatedDirectiveSource = `${updatedDirectiveSource}${getNgModuleDeclaration(
|
||||||
directiveClassName
|
options.symbolName
|
||||||
)}`;
|
)}`;
|
||||||
|
|
||||||
tree.write(options.filePath, updatedDirectiveSource);
|
tree.write(options.filePath, updatedDirectiveSource);
|
||||||
@ -58,12 +54,12 @@ export function convertDirectiveToScam(
|
|||||||
|
|
||||||
const scamFilePath = joinPathFragments(
|
const scamFilePath = joinPathFragments(
|
||||||
options.directory,
|
options.directory,
|
||||||
`${directiveNames.fileName}.module.ts`
|
`${options.name}.module.ts`
|
||||||
);
|
);
|
||||||
|
|
||||||
tree.write(
|
tree.write(
|
||||||
scamFilePath,
|
scamFilePath,
|
||||||
getModuleFileContent(directiveClassName, options.fileName)
|
getModuleFileContent(options.symbolName, options.fileName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,28 +1,43 @@
|
|||||||
import type { Tree } from '@nx/devkit';
|
import type { Tree } from '@nx/devkit';
|
||||||
import { normalizeNameAndPaths } from '../../utils/path';
|
import { normalizeNameAndPaths } from '../../utils/path';
|
||||||
import type { NormalizedSchema, Schema } from '../schema';
|
import type { NormalizedSchema, Schema } from '../schema';
|
||||||
|
import { determineArtifactNameAndDirectoryOptions } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
||||||
|
import { names } from '@nx/devkit';
|
||||||
|
|
||||||
export function normalizeOptions(
|
export async function normalizeOptions(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
options: Schema
|
options: Schema
|
||||||
): NormalizedSchema {
|
): Promise<NormalizedSchema> {
|
||||||
const { directory, fileName, filePath, name, path } = normalizeNameAndPaths(
|
const {
|
||||||
tree,
|
artifactName: name,
|
||||||
{
|
directory,
|
||||||
...options,
|
fileName,
|
||||||
type: 'directive',
|
filePath,
|
||||||
}
|
project,
|
||||||
);
|
} = await determineArtifactNameAndDirectoryOptions(tree, {
|
||||||
|
artifactType: 'directive',
|
||||||
|
callingGenerator: '@nx/angular:scam-directive',
|
||||||
|
name: options.name,
|
||||||
|
directory: options.directory ?? options.path,
|
||||||
|
flat: options.flat,
|
||||||
|
nameAndDirectoryFormat: options.nameAndDirectoryFormat,
|
||||||
|
project: options.project,
|
||||||
|
suffix: 'directive',
|
||||||
|
});
|
||||||
|
|
||||||
|
const { className } = names(name);
|
||||||
|
const { className: suffixClassName } = names('directive');
|
||||||
|
const symbolName = `${className}${suffixClassName}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
export: options.export ?? true,
|
export: options.export ?? true,
|
||||||
flat: options.flat ?? true,
|
|
||||||
inlineScam: options.inlineScam ?? true,
|
inlineScam: options.inlineScam ?? true,
|
||||||
directory,
|
directory,
|
||||||
fileName,
|
fileName,
|
||||||
filePath,
|
filePath,
|
||||||
path,
|
|
||||||
name,
|
name,
|
||||||
|
symbolName,
|
||||||
|
project,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ export async function scamDirectiveGenerator(tree: Tree, rawOptions: Schema) {
|
|||||||
skipFormat: true,
|
skipFormat: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const options = normalizeOptions(tree, rawOptions);
|
const options = await normalizeOptions(tree, rawOptions);
|
||||||
convertDirectiveToScam(tree, options);
|
convertDirectiveToScam(tree, options);
|
||||||
exportScam(tree, options);
|
exportScam(tree, options);
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,26 @@
|
|||||||
|
import { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
||||||
|
|
||||||
export interface Schema {
|
export interface Schema {
|
||||||
name: string;
|
name: string;
|
||||||
project: string;
|
directory?: string;
|
||||||
path?: string;
|
nameAndDirectoryFormat?: NameAndDirectoryFormat;
|
||||||
skipTests?: boolean;
|
skipTests?: boolean;
|
||||||
inlineScam?: boolean;
|
inlineScam?: boolean;
|
||||||
flat?: boolean;
|
|
||||||
prefix?: string;
|
prefix?: string;
|
||||||
selector?: string;
|
selector?: string;
|
||||||
export?: boolean;
|
export?: boolean;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
flat?: boolean;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
path?: string;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead. The project will be determined from the directory provided. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
project?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NormalizedSchema extends Schema {
|
export interface NormalizedSchema extends Schema {
|
||||||
@ -15,7 +28,7 @@ export interface NormalizedSchema extends Schema {
|
|||||||
export: boolean;
|
export: boolean;
|
||||||
fileName: string;
|
fileName: string;
|
||||||
filePath: string;
|
filePath: string;
|
||||||
flat: boolean;
|
|
||||||
inlineScam: boolean;
|
inlineScam: boolean;
|
||||||
path: string;
|
symbolName: string;
|
||||||
|
project: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,27 +6,13 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"examples": [
|
"examples": [
|
||||||
{
|
{
|
||||||
"command": "nx g @nx/angular:scam-directive --project=my-lib --flat=false my-sample",
|
"command": "nx g @nx/angular:scam-directive my-sample --directory=my-lib/src/lib/my-sample",
|
||||||
"description": "Generate a `MySampleDirective` directive in a `my-sample` folder in the `my-lib` library"
|
"description": "Generate a `MySampleDirective` directive in a `my-sample` folder in the `my-lib` library"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Creates a new, generic Angular directive definition in the given or default project.",
|
"description": "Creates a new, generic Angular directive definition in the given or default project.",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"properties": {
|
"properties": {
|
||||||
"path": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "path",
|
|
||||||
"description": "The path at which to create the directive file, relative to the current workspace. Default is a folder with the same name as the directive in the project root.",
|
|
||||||
"visible": false
|
|
||||||
},
|
|
||||||
"project": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The name of the project.",
|
|
||||||
"$default": {
|
|
||||||
"$source": "projectName"
|
|
||||||
},
|
|
||||||
"x-dropdown": "projects"
|
|
||||||
},
|
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The name of the directive.",
|
"description": "The name of the directive.",
|
||||||
@ -37,6 +23,26 @@
|
|||||||
"x-prompt": "What name would you like to use for the directive?",
|
"x-prompt": "What name would you like to use for the directive?",
|
||||||
"x-priority": "important"
|
"x-priority": "important"
|
||||||
},
|
},
|
||||||
|
"directory": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The directory at which to create the SCAM Directive files. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
|
||||||
|
"aliases": ["dir", "path"],
|
||||||
|
"x-priority": "important"
|
||||||
|
},
|
||||||
|
"nameAndDirectoryFormat": {
|
||||||
|
"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`).",
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["as-provided", "derived"]
|
||||||
|
},
|
||||||
|
"project": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the project.",
|
||||||
|
"$default": {
|
||||||
|
"$source": "projectName"
|
||||||
|
},
|
||||||
|
"x-dropdown": "projects",
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
|
||||||
|
},
|
||||||
"skipTests": {
|
"skipTests": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Do not create `spec.ts` test files for the new directive.",
|
"description": "Do not create `spec.ts` test files for the new directive.",
|
||||||
@ -51,7 +57,8 @@
|
|||||||
"flat": {
|
"flat": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Create the new files at the top level of the current project.",
|
"description": "Create the new files at the top level of the current project.",
|
||||||
"default": true
|
"default": true,
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
|
||||||
},
|
},
|
||||||
"selector": {
|
"selector": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -79,5 +86,5 @@
|
|||||||
"x-priority": "important"
|
"x-priority": "important"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["name", "project"]
|
"required": ["name"]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,7 @@ describe('convertPipeToScam', () => {
|
|||||||
flat: false,
|
flat: false,
|
||||||
inlineScam: true,
|
inlineScam: true,
|
||||||
path: 'apps/app1/src/app',
|
path: 'apps/app1/src/app',
|
||||||
|
symbolName: 'ExamplePipe',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -89,6 +90,7 @@ describe('convertPipeToScam', () => {
|
|||||||
flat: false,
|
flat: false,
|
||||||
inlineScam: false,
|
inlineScam: false,
|
||||||
path: 'apps/app1/src/app',
|
path: 'apps/app1/src/app',
|
||||||
|
symbolName: 'ExamplePipe',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -138,6 +140,7 @@ describe('convertPipeToScam', () => {
|
|||||||
inlineScam: true,
|
inlineScam: true,
|
||||||
flat: true,
|
flat: true,
|
||||||
path: 'apps/app1/src/app',
|
path: 'apps/app1/src/app',
|
||||||
|
symbolName: 'ExamplePipe',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -192,6 +195,7 @@ describe('convertPipeToScam', () => {
|
|||||||
inlineScam: false,
|
inlineScam: false,
|
||||||
flat: true,
|
flat: true,
|
||||||
path: 'apps/app1/src/app',
|
path: 'apps/app1/src/app',
|
||||||
|
symbolName: 'ExamplePipe',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -242,6 +246,7 @@ describe('convertPipeToScam', () => {
|
|||||||
flat: false,
|
flat: false,
|
||||||
inlineScam: true,
|
inlineScam: true,
|
||||||
path: 'apps/app1/src/app/random',
|
path: 'apps/app1/src/app/random',
|
||||||
|
symbolName: 'ExamplePipe',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -300,6 +305,7 @@ describe('convertPipeToScam', () => {
|
|||||||
flat: true,
|
flat: true,
|
||||||
inlineScam: true,
|
inlineScam: true,
|
||||||
path: 'apps/app1/src/app/random',
|
path: 'apps/app1/src/app/random',
|
||||||
|
symbolName: 'ExamplePipe',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
|
|||||||
@ -16,10 +16,6 @@ export function convertPipeToScam(tree: Tree, options: NormalizedSchema) {
|
|||||||
tsModule = ensureTypescript();
|
tsModule = ensureTypescript();
|
||||||
}
|
}
|
||||||
|
|
||||||
const pipeNames = names(options.name);
|
|
||||||
const typeNames = names('pipe');
|
|
||||||
const pipeClassName = `${pipeNames.className}${typeNames.className}`;
|
|
||||||
|
|
||||||
if (options.inlineScam) {
|
if (options.inlineScam) {
|
||||||
const currentPipeContents = tree.read(options.filePath, 'utf-8');
|
const currentPipeContents = tree.read(options.filePath, 'utf-8');
|
||||||
let source = tsModule.createSourceFile(
|
let source = tsModule.createSourceFile(
|
||||||
@ -46,7 +42,7 @@ export function convertPipeToScam(tree: Tree, options: NormalizedSchema) {
|
|||||||
|
|
||||||
let updatedPipeSource = source.getText();
|
let updatedPipeSource = source.getText();
|
||||||
updatedPipeSource = `${updatedPipeSource}${getNgModuleDeclaration(
|
updatedPipeSource = `${updatedPipeSource}${getNgModuleDeclaration(
|
||||||
pipeClassName
|
options.symbolName
|
||||||
)}`;
|
)}`;
|
||||||
|
|
||||||
tree.write(options.filePath, updatedPipeSource);
|
tree.write(options.filePath, updatedPipeSource);
|
||||||
@ -55,12 +51,12 @@ export function convertPipeToScam(tree: Tree, options: NormalizedSchema) {
|
|||||||
|
|
||||||
const scamFilePath = joinPathFragments(
|
const scamFilePath = joinPathFragments(
|
||||||
options.directory,
|
options.directory,
|
||||||
`${pipeNames.fileName}.module.ts`
|
`${options.name}.module.ts`
|
||||||
);
|
);
|
||||||
|
|
||||||
tree.write(
|
tree.write(
|
||||||
scamFilePath,
|
scamFilePath,
|
||||||
getModuleFileContent(pipeClassName, options.fileName)
|
getModuleFileContent(options.symbolName, options.fileName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,28 +1,42 @@
|
|||||||
import type { Tree } from '@nx/devkit';
|
import type { Tree } from '@nx/devkit';
|
||||||
import { normalizeNameAndPaths } from '../../utils/path';
|
|
||||||
import type { NormalizedSchema, Schema } from '../schema';
|
import type { NormalizedSchema, Schema } from '../schema';
|
||||||
|
import { determineArtifactNameAndDirectoryOptions } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
||||||
|
import { names } from '@nx/devkit';
|
||||||
|
|
||||||
export function normalizeOptions(
|
export async function normalizeOptions(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
options: Schema
|
options: Schema
|
||||||
): NormalizedSchema {
|
): Promise<NormalizedSchema> {
|
||||||
const { directory, fileName, filePath, name, path } = normalizeNameAndPaths(
|
const {
|
||||||
tree,
|
artifactName: name,
|
||||||
{
|
directory,
|
||||||
...options,
|
fileName,
|
||||||
type: 'pipe',
|
filePath,
|
||||||
}
|
project,
|
||||||
);
|
} = await determineArtifactNameAndDirectoryOptions(tree, {
|
||||||
|
artifactType: 'pipe',
|
||||||
|
callingGenerator: '@nx/angular:scam-pipe',
|
||||||
|
name: options.name,
|
||||||
|
directory: options.directory ?? options.path,
|
||||||
|
flat: options.flat,
|
||||||
|
nameAndDirectoryFormat: options.nameAndDirectoryFormat,
|
||||||
|
project: options.project,
|
||||||
|
suffix: 'pipe',
|
||||||
|
});
|
||||||
|
|
||||||
|
const { className } = names(name);
|
||||||
|
const { className: suffixClassName } = names('pipe');
|
||||||
|
const symbolName = `${className}${suffixClassName}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
export: options.export ?? true,
|
export: options.export ?? true,
|
||||||
flat: options.flat ?? true,
|
|
||||||
inlineScam: options.inlineScam ?? true,
|
inlineScam: options.inlineScam ?? true,
|
||||||
directory,
|
directory,
|
||||||
fileName,
|
fileName,
|
||||||
filePath,
|
filePath,
|
||||||
name,
|
name,
|
||||||
path,
|
symbolName,
|
||||||
|
project,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ export async function scamPipeGenerator(tree: Tree, rawOptions: Schema) {
|
|||||||
skipFormat: true,
|
skipFormat: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const options = normalizeOptions(tree, rawOptions);
|
const options = await normalizeOptions(tree, rawOptions);
|
||||||
convertPipeToScam(tree, options);
|
convertPipeToScam(tree, options);
|
||||||
exportScam(tree, options);
|
exportScam(tree, options);
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,24 @@
|
|||||||
|
import { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
||||||
|
|
||||||
export interface Schema {
|
export interface Schema {
|
||||||
name: string;
|
name: string;
|
||||||
project: string;
|
directory?: string;
|
||||||
path?: string;
|
nameAndDirectoryFormat?: NameAndDirectoryFormat;
|
||||||
skipTests?: boolean;
|
skipTests?: boolean;
|
||||||
inlineScam?: boolean;
|
inlineScam?: boolean;
|
||||||
flat?: boolean;
|
|
||||||
export?: boolean;
|
export?: boolean;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
flat?: boolean;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
path?: string;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead. The project will be determined from the directory provided. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
project?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NormalizedSchema extends Schema {
|
export interface NormalizedSchema extends Schema {
|
||||||
@ -13,7 +26,7 @@ export interface NormalizedSchema extends Schema {
|
|||||||
export: boolean;
|
export: boolean;
|
||||||
fileName: string;
|
fileName: string;
|
||||||
filePath: string;
|
filePath: string;
|
||||||
flat: boolean;
|
|
||||||
inlineScam: boolean;
|
inlineScam: boolean;
|
||||||
path: string;
|
project: string;
|
||||||
|
symbolName: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,20 +13,6 @@
|
|||||||
"description": "Creates a new, generic Angular pipe definition in the given or default project.",
|
"description": "Creates a new, generic Angular pipe definition in the given or default project.",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"properties": {
|
"properties": {
|
||||||
"path": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "path",
|
|
||||||
"description": "The path at which to create the pipe file, relative to the current workspace. Default is a folder with the same name as the pipe in the project root.",
|
|
||||||
"visible": false
|
|
||||||
},
|
|
||||||
"project": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The name of the project.",
|
|
||||||
"$default": {
|
|
||||||
"$source": "projectName"
|
|
||||||
},
|
|
||||||
"x-dropdown": "projects"
|
|
||||||
},
|
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The name of the pipe.",
|
"description": "The name of the pipe.",
|
||||||
@ -37,6 +23,26 @@
|
|||||||
"x-prompt": "What name would you like to use for the pipe?",
|
"x-prompt": "What name would you like to use for the pipe?",
|
||||||
"x-priority": "important"
|
"x-priority": "important"
|
||||||
},
|
},
|
||||||
|
"directory": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The directory at which to create the component file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
|
||||||
|
"aliases": ["dir", "path"],
|
||||||
|
"x-priority": "important"
|
||||||
|
},
|
||||||
|
"nameAndDirectoryFormat": {
|
||||||
|
"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`).",
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["as-provided", "derived"]
|
||||||
|
},
|
||||||
|
"project": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the project.",
|
||||||
|
"$default": {
|
||||||
|
"$source": "projectName"
|
||||||
|
},
|
||||||
|
"x-dropdown": "projects",
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
|
||||||
|
},
|
||||||
"skipTests": {
|
"skipTests": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Do not create `spec.ts` test files for the new pipe.",
|
"description": "Do not create `spec.ts` test files for the new pipe.",
|
||||||
@ -51,7 +57,8 @@
|
|||||||
"flat": {
|
"flat": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Create the new files at the top level of the current project.",
|
"description": "Create the new files at the top level of the current project.",
|
||||||
"default": true
|
"default": true,
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
|
||||||
},
|
},
|
||||||
"export": {
|
"export": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@ -60,5 +67,5 @@
|
|||||||
"x-priority": "important"
|
"x-priority": "important"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["name", "project"]
|
"required": ["name"]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,7 @@ describe('convertComponentToScam', () => {
|
|||||||
export: false,
|
export: false,
|
||||||
inlineScam: true,
|
inlineScam: true,
|
||||||
path: 'apps/app1/src/app',
|
path: 'apps/app1/src/app',
|
||||||
|
symbolName: 'ExampleComponent',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -83,6 +84,7 @@ describe('convertComponentToScam', () => {
|
|||||||
export: false,
|
export: false,
|
||||||
inlineScam: false,
|
inlineScam: false,
|
||||||
path: 'apps/app1/src/app',
|
path: 'apps/app1/src/app',
|
||||||
|
symbolName: 'ExampleComponent',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -132,6 +134,7 @@ describe('convertComponentToScam', () => {
|
|||||||
inlineScam: true,
|
inlineScam: true,
|
||||||
flat: true,
|
flat: true,
|
||||||
path: 'apps/app1/src/app',
|
path: 'apps/app1/src/app',
|
||||||
|
symbolName: 'ExampleComponent',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -187,6 +190,7 @@ describe('convertComponentToScam', () => {
|
|||||||
inlineScam: false,
|
inlineScam: false,
|
||||||
flat: true,
|
flat: true,
|
||||||
path: 'apps/app1/src/app',
|
path: 'apps/app1/src/app',
|
||||||
|
symbolName: 'ExampleComponent',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -238,6 +242,7 @@ describe('convertComponentToScam', () => {
|
|||||||
flat: true,
|
flat: true,
|
||||||
type: 'random',
|
type: 'random',
|
||||||
path: 'apps/app1/src/app',
|
path: 'apps/app1/src/app',
|
||||||
|
symbolName: 'ExampleRandom',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -295,6 +300,7 @@ describe('convertComponentToScam', () => {
|
|||||||
flat: true,
|
flat: true,
|
||||||
type: 'random',
|
type: 'random',
|
||||||
path: 'apps/app1/src/app',
|
path: 'apps/app1/src/app',
|
||||||
|
symbolName: 'ExampleRandom',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -345,6 +351,7 @@ describe('convertComponentToScam', () => {
|
|||||||
flat: false,
|
flat: false,
|
||||||
inlineScam: true,
|
inlineScam: true,
|
||||||
path: 'apps/app1/src/app/random',
|
path: 'apps/app1/src/app/random',
|
||||||
|
symbolName: 'ExampleComponent',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
@ -401,6 +408,7 @@ describe('convertComponentToScam', () => {
|
|||||||
flat: true,
|
flat: true,
|
||||||
inlineScam: true,
|
inlineScam: true,
|
||||||
path: 'apps/app1/src/app/random',
|
path: 'apps/app1/src/app/random',
|
||||||
|
symbolName: 'ExampleComponent',
|
||||||
});
|
});
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
|
|||||||
@ -13,10 +13,6 @@ export function convertComponentToScam(tree: Tree, options: NormalizedSchema) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const componentNames = names(options.name);
|
|
||||||
const typeNames = names(options.type ?? 'component');
|
|
||||||
const componentClassName = `${componentNames.className}${typeNames.className}`;
|
|
||||||
|
|
||||||
if (!tsModule) {
|
if (!tsModule) {
|
||||||
tsModule = ensureTypescript();
|
tsModule = ensureTypescript();
|
||||||
}
|
}
|
||||||
@ -47,7 +43,7 @@ export function convertComponentToScam(tree: Tree, options: NormalizedSchema) {
|
|||||||
|
|
||||||
let updatedComponentSource = source.getText();
|
let updatedComponentSource = source.getText();
|
||||||
updatedComponentSource = `${updatedComponentSource}${getNgModuleDeclaration(
|
updatedComponentSource = `${updatedComponentSource}${getNgModuleDeclaration(
|
||||||
componentClassName
|
options.symbolName
|
||||||
)}`;
|
)}`;
|
||||||
|
|
||||||
tree.write(options.filePath, updatedComponentSource);
|
tree.write(options.filePath, updatedComponentSource);
|
||||||
@ -56,12 +52,12 @@ export function convertComponentToScam(tree: Tree, options: NormalizedSchema) {
|
|||||||
|
|
||||||
const moduleFilePath = joinPathFragments(
|
const moduleFilePath = joinPathFragments(
|
||||||
options.directory,
|
options.directory,
|
||||||
`${componentNames.fileName}.module.ts`
|
`${options.name}.module.ts`
|
||||||
);
|
);
|
||||||
|
|
||||||
tree.write(
|
tree.write(
|
||||||
moduleFilePath,
|
moduleFilePath,
|
||||||
getModuleFileContent(componentClassName, options.fileName)
|
getModuleFileContent(options.symbolName, options.fileName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,16 +1,34 @@
|
|||||||
import type { Tree } from '@nx/devkit';
|
import type { Tree } from '@nx/devkit';
|
||||||
import { normalizeNameAndPaths } from '../../utils/path';
|
|
||||||
import type { NormalizedSchema, Schema } from '../schema';
|
import type { NormalizedSchema, Schema } from '../schema';
|
||||||
|
import { determineArtifactNameAndDirectoryOptions } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
||||||
|
import { names } from '@nx/devkit';
|
||||||
|
|
||||||
export function normalizeOptions(
|
export async function normalizeOptions(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
options: Schema
|
options: Schema
|
||||||
): NormalizedSchema {
|
): Promise<NormalizedSchema> {
|
||||||
const { directory, fileName, filePath, name } = normalizeNameAndPaths(tree, {
|
options.type ??= 'component';
|
||||||
...options,
|
const {
|
||||||
type: options.type ?? 'component',
|
artifactName: name,
|
||||||
|
directory,
|
||||||
|
fileName,
|
||||||
|
filePath,
|
||||||
|
project,
|
||||||
|
} = await determineArtifactNameAndDirectoryOptions(tree, {
|
||||||
|
artifactType: options.type,
|
||||||
|
callingGenerator: '@nx/angular:scam',
|
||||||
|
name: options.name,
|
||||||
|
directory: options.directory ?? options.path,
|
||||||
|
flat: options.flat,
|
||||||
|
nameAndDirectoryFormat: options.nameAndDirectoryFormat,
|
||||||
|
project: options.project,
|
||||||
|
suffix: options.type ?? 'component',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { className } = names(name);
|
||||||
|
const { className: suffixClassName } = names(options.type);
|
||||||
|
const symbolName = `${className}${suffixClassName}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
export: options.export ?? true,
|
export: options.export ?? true,
|
||||||
@ -19,5 +37,7 @@ export function normalizeOptions(
|
|||||||
fileName,
|
fileName,
|
||||||
filePath,
|
filePath,
|
||||||
name,
|
name,
|
||||||
|
symbolName,
|
||||||
|
project,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ export async function scamGenerator(tree: Tree, rawOptions: Schema) {
|
|||||||
skipFormat: true,
|
skipFormat: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const options = normalizeOptions(tree, rawOptions);
|
const options = await normalizeOptions(tree, rawOptions);
|
||||||
convertComponentToScam(tree, options);
|
convertComponentToScam(tree, options);
|
||||||
exportScam(tree, options);
|
exportScam(tree, options);
|
||||||
|
|
||||||
|
|||||||
21
packages/angular/src/generators/scam/schema.d.ts
vendored
21
packages/angular/src/generators/scam/schema.d.ts
vendored
@ -1,7 +1,9 @@
|
|||||||
|
import { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
||||||
|
|
||||||
export interface Schema {
|
export interface Schema {
|
||||||
name: string;
|
name: string;
|
||||||
project: string;
|
directory?: string;
|
||||||
path?: string;
|
nameAndDirectoryFormat?: NameAndDirectoryFormat;
|
||||||
displayBlock?: boolean;
|
displayBlock?: boolean;
|
||||||
inlineStyle?: boolean;
|
inlineStyle?: boolean;
|
||||||
inlineTemplate?: boolean;
|
inlineTemplate?: boolean;
|
||||||
@ -11,18 +13,31 @@ export interface Schema {
|
|||||||
skipTests?: boolean;
|
skipTests?: boolean;
|
||||||
inlineScam?: boolean;
|
inlineScam?: boolean;
|
||||||
type?: string;
|
type?: string;
|
||||||
flat?: boolean;
|
|
||||||
prefix?: string;
|
prefix?: string;
|
||||||
selector?: string;
|
selector?: string;
|
||||||
skipSelector?: boolean;
|
skipSelector?: boolean;
|
||||||
export?: boolean;
|
export?: boolean;
|
||||||
skipFormat?: boolean;
|
skipFormat?: boolean;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
flat?: boolean;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
path?: string;
|
||||||
|
/**
|
||||||
|
* @deprecated Provide the `directory` option instead. The project will be determined from the directory provided. It will be removed in Nx v18.
|
||||||
|
*/
|
||||||
|
project?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NormalizedSchema extends Schema {
|
export interface NormalizedSchema extends Schema {
|
||||||
directory: string;
|
directory: string;
|
||||||
|
project: string;
|
||||||
fileName: string;
|
fileName: string;
|
||||||
filePath: string;
|
filePath: string;
|
||||||
|
symbolName: string;
|
||||||
export: boolean;
|
export: boolean;
|
||||||
inlineScam: boolean;
|
inlineScam: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,27 +6,13 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"examples": [
|
"examples": [
|
||||||
{
|
{
|
||||||
"command": "nx g @nx/angular:scam --project=my-lib my-sample",
|
"command": "nx g @nx/angular:scam my-sample --directory=my-lib/src/lib/my-sample",
|
||||||
"description": "Generate a `MySampleComponent` component in the `my-lib` library."
|
"description": "Generate a `MySampleComponent` component in the `my-lib` library."
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Creates a new, generic Angular component definition in the given or default project.",
|
"description": "Creates a new Angular SCAM.",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"properties": {
|
"properties": {
|
||||||
"path": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "path",
|
|
||||||
"description": "The path at which to create the component file, relative to the current workspace. Default is a folder with the same name as the component in the project root.",
|
|
||||||
"visible": false
|
|
||||||
},
|
|
||||||
"project": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The name of the project.",
|
|
||||||
"$default": {
|
|
||||||
"$source": "projectName"
|
|
||||||
},
|
|
||||||
"x-dropdown": "projects"
|
|
||||||
},
|
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The name of the component.",
|
"description": "The name of the component.",
|
||||||
@ -36,6 +22,26 @@
|
|||||||
},
|
},
|
||||||
"x-prompt": "What name would you like to use for the component?"
|
"x-prompt": "What name would you like to use for the component?"
|
||||||
},
|
},
|
||||||
|
"directory": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The directory at which to create the SCAM files. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the workspace root.",
|
||||||
|
"aliases": ["dir", "path"],
|
||||||
|
"x-priority": "important"
|
||||||
|
},
|
||||||
|
"nameAndDirectoryFormat": {
|
||||||
|
"description": "Whether to generate the SCAM 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`).",
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["as-provided", "derived"]
|
||||||
|
},
|
||||||
|
"project": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the project.",
|
||||||
|
"$default": {
|
||||||
|
"$source": "projectName"
|
||||||
|
},
|
||||||
|
"x-dropdown": "projects",
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
|
||||||
|
},
|
||||||
"displayBlock": {
|
"displayBlock": {
|
||||||
"description": "Specifies if the style will contain `:host { display: block; }`.",
|
"description": "Specifies if the style will contain `:host { display: block; }`.",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@ -87,7 +93,8 @@
|
|||||||
"flat": {
|
"flat": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Create the new files at the top level of the current project.",
|
"description": "Create the new files at the top level of the current project.",
|
||||||
"default": false
|
"default": false,
|
||||||
|
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v18."
|
||||||
},
|
},
|
||||||
"selector": {
|
"selector": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -131,5 +138,5 @@
|
|||||||
"x-priority": "internal"
|
"x-priority": "internal"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["name", "project"]
|
"required": ["name"]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user