Skip to content

Commit 767838e

Browse files
feat(qwik-nx): make directory a required option for generators
1 parent 6c48442 commit 767838e

File tree

15 files changed

+77
-93
lines changed

15 files changed

+77
-93
lines changed

packages/qwik-nx/src/generators/application/generator.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('qwik-nx generator', () => {
1414

1515
let appTree: Tree;
1616
const defaultOptions: QwikAppGeneratorSchema = {
17-
name: 'myapp',
17+
directory: 'myapp',
1818
style: 'css',
1919
linter: Linter.None,
2020
skipFormat: false,

packages/qwik-nx/src/generators/application/schema.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type { Linter } from '@nx/eslint';
22
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
33

44
export interface QwikAppGeneratorSchema {
5-
name: string;
5+
directory: string;
6+
name?: string;
67
tags?: string;
7-
directory?: string;
88
style?: 'css' | 'scss' | 'styl' | 'less' | 'none';
99
linter?: Linter;
1010
skipFormat?: boolean;
@@ -14,10 +14,10 @@ export interface QwikAppGeneratorSchema {
1414
e2eTestRunner?: 'playwright' | 'cypress' | 'none';
1515
devServerPort?: number;
1616
previewServerPort?: number;
17-
projectNameAndRootFormat?: ProjectNameAndRootFormat;
1817
}
1918

2019
export interface NormalizedSchema extends QwikAppGeneratorSchema {
20+
name: string;
2121
devServerPort: number;
2222
previewServerPort: number;
2323
projectName: string;
@@ -27,7 +27,6 @@ export interface NormalizedSchema extends QwikAppGeneratorSchema {
2727
setupVitest: boolean;
2828
parsedTags: string[];
2929
styleExtension: Exclude<QwikAppGeneratorSchema['style'], 'none'> | null;
30-
projectNameAndRootFormat: ProjectNameAndRootFormat;
3130
e2eProjectName: string;
3231
e2eProjectRoot: string;
3332
}

packages/qwik-nx/src/generators/application/schema.json

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
"properties": {
77
"name": {
88
"type": "string",
9-
"description": "",
10-
"$default": {
11-
"$source": "argv",
12-
"index": 0
13-
},
14-
"x-prompt": "What name would you like to use?"
9+
"description": "The name of the application.",
10+
"pattern": "^[a-zA-Z][^:]*$",
11+
"x-priority": "important"
1512
},
1613
"tags": {
1714
"type": "string",
@@ -20,7 +17,9 @@
2017
},
2118
"directory": {
2219
"type": "string",
23-
"description": "A directory where the project is placed"
20+
"description": "A directory where the project is placed",
21+
"$default": { "$source": "argv", "index": 0 },
22+
"x-prompt": "Which directory do you want to create the application in?"
2423
},
2524
"style": {
2625
"description": "The file extension to be used for style files.",
@@ -51,11 +50,6 @@
5150
"default": "css"
5251
}
5352
},
54-
"projectNameAndRootFormat": {
55-
"description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
56-
"type": "string",
57-
"enum": ["as-provided", "derived"]
58-
},
5953
"linter": {
6054
"description": "The tool to use for running lint checks.",
6155
"type": "string",
@@ -100,5 +94,5 @@
10094
"default": 4173
10195
}
10296
},
103-
"required": ["name"]
97+
"required": ["directory"]
10498
}

packages/qwik-nx/src/generators/application/utils/normalize-options.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { offsetFromRoot, Tree } from '@nx/devkit';
22
import { getRelativePathToRootTsConfig } from '@nx/js';
33
import { NormalizedSchema, QwikAppGeneratorSchema } from '../schema';
4-
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
4+
import {
5+
determineProjectNameAndRootOptions,
6+
ensureProjectName,
7+
} from '@nx/devkit/src/generators/project-name-and-root-utils';
58

69
export async function normalizeOptions(
710
host: Tree,
811
options: QwikAppGeneratorSchema
912
): Promise<NormalizedSchema> {
10-
const {
11-
projectName: appProjectName,
12-
projectRoot: appProjectRoot,
13-
projectNameAndRootFormat,
14-
} = await determineProjectNameAndRootOptions(host, {
15-
name: options.name,
16-
projectType: 'application',
17-
callingGenerator: 'qwik-nx:application',
18-
directory: options.directory,
19-
projectNameAndRootFormat: options.projectNameAndRootFormat,
20-
});
13+
await ensureProjectName(host, options, 'application');
14+
15+
const { projectName: appProjectName, projectRoot: appProjectRoot } =
16+
await determineProjectNameAndRootOptions(host, {
17+
name: options.name,
18+
projectType: 'application',
19+
directory: options.directory,
20+
});
2121

2222
const parsedTags = options.tags
2323
? options.tags.split(',').map((s) => s.trim())
@@ -34,6 +34,7 @@ export async function normalizeOptions(
3434

3535
return {
3636
...options,
37+
name: options.name!, // defined by "ensureProjectName"
3738
projectName: appProjectName,
3839
projectRoot: appProjectRoot,
3940
offsetFromRoot: offsetFromRoot(appProjectRoot),
@@ -43,7 +44,6 @@ export async function normalizeOptions(
4344
parsedTags,
4445
devServerPort: options.devServerPort ?? 5173,
4546
previewServerPort: options.previewServerPort ?? 4173,
46-
projectNameAndRootFormat,
4747
e2eProjectName,
4848
e2eProjectRoot,
4949
};

packages/qwik-nx/src/generators/host/schema.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name
22
import { Linter } from '@nx/eslint';
33

44
export interface HostGeneratorSchema {
5-
name: string;
5+
name?: string;
66
tags?: string;
7-
directory?: string;
7+
directory: string;
88
style?: 'css' | 'scss' | 'styl' | 'less' | 'none';
99
linter?: Linter;
1010
skipFormat?: boolean;

packages/qwik-nx/src/generators/host/schema.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@
77
"properties": {
88
"name": {
99
"type": "string",
10-
"description": "",
11-
"$default": {
12-
"$source": "argv",
13-
"index": 0
14-
},
15-
"x-prompt": "What name would you like to use?"
10+
"description": "The name of the application.",
11+
"pattern": "^[a-zA-Z][^:]*$",
12+
"x-priority": "important"
13+
},
14+
"directory": {
15+
"type": "string",
16+
"description": "A directory where the project is placed",
17+
"$default": { "$source": "argv", "index": 0 },
18+
"x-prompt": "Which directory do you want to create the application in?"
1619
},
1720
"tags": {
1821
"type": "string",
1922
"description": "Add tags to the project (used for linting)",
2023
"alias": "t"
2124
},
22-
"directory": {
23-
"type": "string",
24-
"description": "A directory where the project is placed",
25-
"x-priority": "important"
26-
},
2725
"projectNameAndRootFormat": {
2826
"description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
2927
"type": "string",
@@ -102,5 +100,5 @@
102100
"x-priority": "important"
103101
}
104102
},
105-
"required": ["name"]
103+
"required": ["directory"]
106104
}

packages/qwik-nx/src/generators/integrations/react-library/generator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from '../../../utils/react/init';
1919

2020
interface NormalizedSchema extends ReactLibraryGeneratorSchema {
21+
name: string;
2122
installMUIExample: boolean;
2223
targetApps: string[];
2324
projectName: string;

packages/qwik-nx/src/generators/integrations/react-library/schema.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
"name": {
99
"type": "string",
1010
"description": "Library name.",
11+
"x-priority": "important"
12+
},
13+
"directory": {
14+
"type": "string",
15+
"description": "A directory where the lib is placed.",
1116
"$default": {
1217
"$source": "argv",
1318
"index": 0
1419
},
15-
"x-prompt": "What name would you like to use for the library?",
16-
"pattern": "^[a-zA-Z].*$"
17-
},
18-
"directory": {
19-
"type": "string",
20-
"description": "A directory where the lib is placed."
20+
"x-prompt": "Which directory do you want to create the library in?"
2121
},
2222
"projectNameAndRootFormat": {
2323
"description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
@@ -90,5 +90,5 @@
9090
"default": false
9191
}
9292
},
93-
"required": ["name"]
93+
"required": ["directory"]
9494
}

packages/qwik-nx/src/generators/library/generator-internal.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ async function addLibrary(
7070
includeBabelRc: false,
7171
buildable: false,
7272
bundler: 'none',
73-
projectNameAndRootFormat: options.projectNameAndRootFormat,
7473
});
7574
tasks.push(libGeneratorTask);
7675

packages/qwik-nx/src/generators/library/schema.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Linter } from '@nx/eslint';
22

33
export interface LibraryGeneratorSchema {
4-
name: string;
5-
directory?: string;
4+
name?: string;
5+
directory: string;
66
skipFormat?: boolean;
77
style?: 'css' | 'scss' | 'styl' | 'less' | 'none';
88
tags?: string;
@@ -13,16 +13,15 @@ export interface LibraryGeneratorSchema {
1313
buildable?: boolean;
1414
storybookConfiguration?: boolean;
1515
generateComponent?: boolean;
16-
projectNameAndRootFormat?: ProjectNameAndRootFormat;
1716
}
1817

1918
type NormalizedRequiredPropsNames =
19+
| 'name'
2020
| 'style'
2121
| 'unitTestRunner'
2222
| 'linter'
2323
| 'storybookConfiguration'
2424
| 'generateComponent'
25-
| 'projectNameAndRootFormat'
2625
| 'buildable';
2726
type NormalizedRequiredProps = Required<
2827
Pick<LibraryGeneratorSchema, NormalizedRequiredPropsNames>

0 commit comments

Comments
 (0)