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 | addCloudDependencies(host, options);
|
17 | yield (0, devkit_1.formatFiles)(host);
|
18 | return () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
19 | (0, devkit_1.installPackagesTask)(host, false, options.directory, options.packageManager);
|
20 | if (options.preset !== presets_1.Preset.NPM && options.preset !== presets_1.Preset.Core) {
|
21 | yield (0, generate_preset_1.generatePreset)(host, options);
|
22 | }
|
23 | });
|
24 | });
|
25 | }
|
26 | exports.newGenerator = newGenerator;
|
27 | exports.default = newGenerator;
|
28 | function validateOptions(options, host) {
|
29 | if (options.skipInstall &&
|
30 | options.preset !== presets_1.Preset.Apps &&
|
31 | options.preset !== presets_1.Preset.Core &&
|
32 | options.preset !== presets_1.Preset.TS &&
|
33 | options.preset !== presets_1.Preset.Empty &&
|
34 | options.preset !== presets_1.Preset.NPM) {
|
35 | throw new Error(`Cannot select a preset when skipInstall is set to true.`);
|
36 | }
|
37 | if (options.skipInstall && options.nxCloud) {
|
38 | throw new Error(`Cannot select nxCloud when skipInstall is set to true.`);
|
39 | }
|
40 | if ((0, devkit_1.getWorkspacePath)(host)) {
|
41 | throw new Error('Cannot generate a new workspace within an existing workspace');
|
42 | }
|
43 | if (host.exists(options.name) &&
|
44 | !host.isFile(options.name) &&
|
45 | host.children(options.name).length > 0) {
|
46 | throw new Error(`${(0, path_1.join)(host.root, options.name)} is not an empty directory.`);
|
47 | }
|
48 | }
|
49 | function normalizeOptions(options) {
|
50 | options.name = (0, devkit_1.names)(options.name).fileName;
|
51 | if (!options.directory) {
|
52 | options.directory = options.name;
|
53 | }
|
54 |
|
55 |
|
56 |
|
57 | const match = options.preset.match(/^(?<package>(@.+\/)?[^@]+)(@(?<version>\d+\.\d+\.\d+))?$/);
|
58 | if (match) {
|
59 | options.preset = match.groups.package;
|
60 | options.presetVersion = match.groups.version;
|
61 | }
|
62 | return options;
|
63 | }
|
64 | function addCloudDependencies(host, options) {
|
65 | if (options.nxCloud) {
|
66 | return (0, devkit_1.addDependenciesToPackageJson)(host, {}, { '@nrwl/nx-cloud': 'latest' }, (0, path_1.join)(options.directory, 'package.json'));
|
67 | }
|
68 | }
|
69 |
|
\ | No newline at end of file |