1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.newGenerator = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const devkit_1 = require("@nrwl/devkit");
|
6 | const path_1 = require("path");
|
7 | const presets_1 = require("../utils/presets");
|
8 | const generate_workspace_files_1 = require("./generate-workspace-files");
|
9 | const generate_preset_1 = require("./generate-preset");
|
10 | function newGenerator(host, options) {
|
11 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
12 | options = normalizeOptions(options);
|
13 | validateOptions(options, host);
|
14 | yield (0, generate_workspace_files_1.generateWorkspaceFiles)(host, Object.assign(Object.assign({}, options), { nxCloud: undefined }));
|
15 | (0, generate_preset_1.addPresetDependencies)(host, options);
|
16 | const isCustomPreset = !Object.values(presets_1.Preset).includes(options.preset);
|
17 | addCloudDependencies(host, options);
|
18 | yield (0, devkit_1.formatFiles)(host);
|
19 | return () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
20 | (0, devkit_1.installPackagesTask)(host, false, options.directory, options.packageManager);
|
21 |
|
22 | if (options.preset !== presets_1.Preset.NPM &&
|
23 | options.preset !== presets_1.Preset.Core &&
|
24 | !isCustomPreset) {
|
25 | yield (0, generate_preset_1.generatePreset)(host, options);
|
26 | }
|
27 | });
|
28 | });
|
29 | }
|
30 | exports.newGenerator = newGenerator;
|
31 | exports.default = newGenerator;
|
32 | function validateOptions(options, host) {
|
33 | if (options.skipInstall &&
|
34 | options.preset !== presets_1.Preset.Apps &&
|
35 | options.preset !== presets_1.Preset.Core &&
|
36 | options.preset !== presets_1.Preset.TS &&
|
37 | options.preset !== presets_1.Preset.Empty &&
|
38 | options.preset !== presets_1.Preset.NPM) {
|
39 | throw new Error(`Cannot select a preset when skipInstall is set to true.`);
|
40 | }
|
41 | if (options.skipInstall && options.nxCloud) {
|
42 | throw new Error(`Cannot select nxCloud when skipInstall is set to true.`);
|
43 | }
|
44 | if (options.preset === presets_1.Preset.NodeServer && !options.framework) {
|
45 | throw new Error(`Cannot generate ${options.preset} without selecting a framework`);
|
46 | }
|
47 | if (host.exists(options.name) &&
|
48 | !host.isFile(options.name) &&
|
49 | host.children(options.name).length > 0) {
|
50 | throw new Error(`${(0, path_1.join)(host.root, options.name)} is not an empty directory.`);
|
51 | }
|
52 | }
|
53 | function normalizeOptions(options) {
|
54 | options.name = (0, devkit_1.names)(options.name).fileName;
|
55 | if (!options.directory) {
|
56 | options.directory = options.name;
|
57 | }
|
58 |
|
59 |
|
60 |
|
61 | const match = options.preset.match(/^(?<package>(@.+\/)?[^@]+)(@(?<version>\d+\.\d+\.\d+))?$/);
|
62 | if (match) {
|
63 | options.preset = match.groups.package;
|
64 | options.presetVersion = match.groups.version;
|
65 | }
|
66 | return options;
|
67 | }
|
68 | function addCloudDependencies(host, options) {
|
69 | if (options.nxCloud) {
|
70 | return (0, devkit_1.addDependenciesToPackageJson)(host, {}, { '@nrwl/nx-cloud': 'latest' }, (0, path_1.join)(options.directory, 'package.json'));
|
71 | }
|
72 | }
|
73 |
|
\ | No newline at end of file |