Skip to content

Commit

Permalink
fix(core): Remove nameAndDirectoryFormat option from generators
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham committed Sep 25, 2024
1 parent 04cf92a commit a9a6d4d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 45 deletions.
24 changes: 9 additions & 15 deletions docs/generated/packages/vue/generators/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
"type": "object",
"examples": [
{
"command": "nx g @nx/vue:component --directory=my-app/src/app/one --name=one --nameAndDirectoryFormat=as-provided --unitTestRunner=vitest",
"description": "Generate a component in the `my-app` application"
"command": "nx g @nx/vue:component my-app/src/app/one --name=one --unitTestRunner=vitest",
"description": "Generate a component in the `my-app` at my-app/src/app/one application"
}
],
"properties": {
"name": {
"path": {
"type": "string",
"description": "The name of the component.",
"description": "Path where the component will be generated.",
"$default": { "$source": "argv", "index": 0 },
"x-prompt": "What name would you like to use for the component?",
"x-prompt": "Where should the component be generated?",
"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`).",
"name": {
"type": "string",
"enum": ["as-provided", "derived"]
"description": "The name of the component.",
"x-prompt": "What name would you like to use for the component?"
},
"js": {
"type": "boolean",
Expand All @@ -38,12 +38,6 @@
"default": false,
"x-priority": "internal"
},
"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.",
"alias": "dir",
"x-priority": "important"
},
"export": {
"type": "boolean",
"description": "When true, the component is exported from the project `index.ts` (if it exists).",
Expand Down Expand Up @@ -71,7 +65,7 @@
"x-priority": "internal"
}
},
"required": ["name"],
"required": ["path"],
"presets": []
},
"aliases": ["c"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export type NameAndDirectoryFormat = 'as-provided';

export type ArtifactGenerationOptions = {
name: string;
directory?: string;
directory?: string; // Deprecated in favor of path
path?: string;
fileExtension?: 'js' | 'jsx' | 'ts' | 'tsx' | 'vue';
fileName?: string;
nameAndDirectoryFormat?: NameAndDirectoryFormat;
Expand All @@ -30,9 +31,15 @@ export type NameAndDirectoryOptions = {
*/
artifactName: string;
/**
* @deprecated Use `path` instead.
* Normalized directory path where the artifact will be generated.
*/
directory: string;

/**
* Normalized path where the artifact will be generated.
*/
path: string;
/**
* Normalized file name of the artifact without the extension.
*/
Expand All @@ -53,7 +60,7 @@ export async function determineArtifactNameAndDirectoryOptions(
): Promise<
NameAndDirectoryOptions & {
// TODO(leo): remove in a follow up
nameAndDirectoryFormat: NameAndDirectoryFormat;
nameAndDirectoryFormat: 'as-provided';
}
> {
const nameAndDirectoryOptions = getNameAndDirectoryOptions(tree, options);
Expand Down Expand Up @@ -132,6 +139,7 @@ function getAsProvidedOptions(
return {
artifactName: options.name,
directory: asProvidedDirectory,
path: asProvidedDirectory,
fileName: asProvidedFileName,
filePath: asProvidedFilePath,
project: asProvidedProject,
Expand Down
10 changes: 5 additions & 5 deletions packages/vue/src/generators/component/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('component', () => {
it('should generate files with vitest', async () => {
await componentGenerator(appTree, {
name: 'hello',
directory: `${libName}/src/lib/hello`,
path: `${libName}/src/lib/hello`,
});

expect(appTree.read(`${libName}/src/lib/hello/hello.vue`, 'utf-8'))
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('component', () => {
it('should have correct component name based on directory', async () => {
await componentGenerator(appTree, {
name: 'hello-world',
directory: `${libName}/src/foo/bar/hello-world`,
path: `${libName}/src/foo/bar/hello-world`,
});

expect(
Expand All @@ -73,7 +73,7 @@ describe('component', () => {
it('should generate files for an app', async () => {
await componentGenerator(appTree, {
name: 'hello',
directory: `${appName}/src/app/hello`,
path: `${appName}/src/app/hello`,
});

expect(
Expand All @@ -88,7 +88,7 @@ describe('component', () => {
it('should add to index.ts barrel', async () => {
await componentGenerator(appTree, {
name: 'hello',
directory: `${libName}/src/lib/hello`,
path: `${libName}/src/lib/hello`,
export: true,
});
expect(appTree.read(`${libName}/src/index.ts`, 'utf-8'))
Expand All @@ -101,7 +101,7 @@ describe('component', () => {
it('should not export from an app', async () => {
await componentGenerator(appTree, {
name: 'hello',
directory: `${appName}/src/app/hello`,
path: `${appName}/src/app/hello`,
export: true,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/generators/component/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function componentGenerator(
}

function createComponentFiles(host: Tree, options: NormalizedSchema) {
generateFiles(host, join(__dirname, './files'), options.directory, {
generateFiles(host, join(__dirname, './files'), options.path, {
...options,
tmpl: '',
});
Expand Down
7 changes: 3 additions & 4 deletions packages/vue/src/generators/component/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ export async function normalizeOptions(
): Promise<NormalizedSchema> {
const {
artifactName: name,
directory,
path,
fileName,
filePath,
project: projectName,
} = await determineArtifactNameAndDirectoryOptions(host, {
name: options.name,
directory: options.directory,
nameAndDirectoryFormat: options.nameAndDirectoryFormat,
directory: options.path,
fileExtension: 'vue',
});

Expand All @@ -49,7 +48,7 @@ export async function normalizeOptions(
return {
...options,
filePath,
directory,
path,
className,
fileName: componentFileName,
projectSourceRoot,
Expand Down
5 changes: 2 additions & 3 deletions packages/vue/src/generators/component/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';

export interface ComponentGeneratorSchema {
name: string;
path: string;
name?: string;
skipTests?: boolean;
directory?: string;
export?: boolean;
routing?: boolean;
js?: boolean;
fileName?: string;
inSourceTests?: boolean;
skipFormat?: boolean;
nameAndDirectoryFormat?: NameAndDirectoryFormat;
}

export interface NormalizedSchema extends ComponentGeneratorSchema {
Expand Down
24 changes: 9 additions & 15 deletions packages/vue/src/generators/component/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@
"type": "object",
"examples": [
{
"command": "nx g @nx/vue:component --directory=my-app/src/app/one --name=one --nameAndDirectoryFormat=as-provided --unitTestRunner=vitest",
"description": "Generate a component in the `my-app` application"
"command": "nx g @nx/vue:component my-app/src/app/one --name=one --unitTestRunner=vitest",
"description": "Generate a component in the `my-app` at my-app/src/app/one application"
}
],
"properties": {
"name": {
"path": {
"type": "string",
"description": "The name of the component.",
"description": "Path where the component will be generated.",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What name would you like to use for the component?",
"x-prompt": "Where should the component be generated?",
"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`).",
"name": {
"type": "string",
"enum": ["as-provided", "derived"]
"description": "The name of the component.",
"x-prompt": "What name would you like to use for the component?"
},
"js": {
"type": "boolean",
Expand All @@ -38,12 +38,6 @@
"default": false,
"x-priority": "internal"
},
"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.",
"alias": "dir",
"x-priority": "important"
},
"export": {
"type": "boolean",
"description": "When true, the component is exported from the project `index.ts` (if it exists).",
Expand Down Expand Up @@ -71,5 +65,5 @@
"x-priority": "internal"
}
},
"required": ["name"]
"required": ["path"]
}

0 comments on commit a9a6d4d

Please sign in to comment.