-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
application.ts
115 lines (100 loc) · 2.75 KB
/
application.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import {
formatFiles,
GeneratorCallback,
installPackagesTask,
offsetFromRoot,
readNxJson,
Tree,
updateNxJson,
} from '@nx/devkit';
import { initGenerator as jsInitGenerator } from '@nx/js';
import { angularInitGenerator } from '../init/init';
import { setupSsr } from '../setup-ssr/setup-ssr';
import { setupTailwindGenerator } from '../setup-tailwind/setup-tailwind';
import { ensureAngularDependencies } from '../utils/ensure-angular-dependencies';
import {
addE2e,
addLinting,
addProxyConfig,
addUnitTestRunner,
createFiles,
createProject,
enableStrictTypeChecking,
normalizeOptions,
setApplicationStrictDefault,
setGeneratorDefaults,
updateEditorTsConfig,
} from './lib';
import type { Schema } from './schema';
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
export async function applicationGenerator(
tree: Tree,
schema: Partial<Schema>
): Promise<GeneratorCallback> {
return await applicationGeneratorInternal(tree, {
projectNameAndRootFormat: 'derived',
...schema,
});
}
export async function applicationGeneratorInternal(
tree: Tree,
schema: Partial<Schema>
): Promise<GeneratorCallback> {
const options = await normalizeOptions(tree, schema);
const rootOffset = offsetFromRoot(options.appProjectRoot);
await jsInitGenerator(tree, {
...options,
tsConfigName: options.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
js: false,
skipFormat: true,
});
await angularInitGenerator(tree, {
...options,
skipFormat: true,
});
if (!options.skipPackageJson) {
ensureAngularDependencies(tree);
}
createProject(tree, options);
await createFiles(tree, options, rootOffset);
if (options.addTailwind) {
await setupTailwindGenerator(tree, {
project: options.name,
skipFormat: true,
skipPackageJson: options.skipPackageJson,
});
}
await addLinting(tree, options);
await addUnitTestRunner(tree, options);
await addE2e(tree, options);
updateEditorTsConfig(tree, options);
setGeneratorDefaults(tree, options);
if (options.rootProject) {
const nxJson = readNxJson(tree);
nxJson.defaultProject = options.name;
updateNxJson(tree, nxJson);
}
if (options.backendProject) {
addProxyConfig(tree, options);
}
if (options.strict) {
enableStrictTypeChecking(tree, options);
} else {
setApplicationStrictDefault(tree, false);
}
if (options.ssr) {
await setupSsr(tree, {
project: options.name,
standalone: options.standalone,
skipPackageJson: options.skipPackageJson,
});
}
if (!options.skipFormat) {
await formatFiles(tree);
}
return () => {
installPackagesTask(tree);
logShowProjectCommand(options.name);
};
}
export default applicationGenerator;