1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.generatePreset = exports.addPresetDependencies = void 0;
|
4 | const devkit_1 = require("@nrwl/devkit");
|
5 | const presets_1 = require("../utils/presets");
|
6 | const versions_1 = require("../../utils/versions");
|
7 | const get_npm_package_version_1 = require("../utils/get-npm-package-version");
|
8 | const path_1 = require("path");
|
9 | const yargsParser = require("yargs-parser");
|
10 | const child_process_1 = require("child_process");
|
11 | function addPresetDependencies(host, options) {
|
12 | if (options.preset === presets_1.Preset.Apps ||
|
13 | options.preset === presets_1.Preset.Core ||
|
14 | options.preset === presets_1.Preset.Empty ||
|
15 | options.preset === presets_1.Preset.NPM) {
|
16 | return;
|
17 | }
|
18 | const { dependencies, dev } = getPresetDependencies(options.preset, options.presetVersion);
|
19 | return (0, devkit_1.addDependenciesToPackageJson)(host, dependencies, dev, (0, path_1.join)(options.directory, 'package.json'));
|
20 | }
|
21 | exports.addPresetDependencies = addPresetDependencies;
|
22 | function generatePreset(host, opts) {
|
23 | const parsedArgs = yargsParser(process.argv, {
|
24 | boolean: ['interactive'],
|
25 | default: {
|
26 | interactive: true,
|
27 | },
|
28 | });
|
29 | const spawnOptions = {
|
30 | stdio: 'inherit',
|
31 | shell: true,
|
32 | cwd: (0, path_1.join)(host.root, opts.directory),
|
33 | };
|
34 | const pmc = (0, devkit_1.getPackageManagerCommand)();
|
35 | const executable = `${pmc.exec} nx`;
|
36 | const args = getPresetArgs(opts);
|
37 | return new Promise((resolve, reject) => {
|
38 | (0, child_process_1.spawn)(executable, args, spawnOptions).on('close', (code) => {
|
39 | if (code === 0) {
|
40 | resolve();
|
41 | }
|
42 | else {
|
43 | const message = 'Workspace creation failed, see above.';
|
44 | reject(new Error(message));
|
45 | }
|
46 | });
|
47 | });
|
48 | function getPresetArgs(options) {
|
49 |
|
50 | return getDefaultArgs(options);
|
51 | }
|
52 | function getDefaultArgs(opts) {
|
53 | return [
|
54 | `g`,
|
55 | `@nrwl/workspace:preset`,
|
56 | `--name=${opts.appName}`,
|
57 | opts.style ? `--style=${opts.style}` : null,
|
58 | opts.linter ? `--linter=${opts.linter}` : null,
|
59 | opts.npmScope ? `--npmScope=${opts.npmScope}` : `--npmScope=${opts.name}`,
|
60 | opts.preset ? `--preset=${opts.preset}` : null,
|
61 | opts.bundler ? `--bundler=${opts.bundler}` : null,
|
62 | opts.framework ? `--framework=${opts.framework}` : null,
|
63 | opts.docker ? `--docker=${opts.docker}` : null,
|
64 | opts.packageManager ? `--packageManager=${opts.packageManager}` : null,
|
65 | opts.standaloneApi !== undefined
|
66 | ? `--standaloneApi=${opts.standaloneApi}`
|
67 | : null,
|
68 | parsedArgs.interactive ? '--interactive=true' : '--interactive=false',
|
69 | opts.routing !== undefined ? `--routing=${opts.routing}` : null,
|
70 | ].filter((e) => !!e);
|
71 | }
|
72 | }
|
73 | exports.generatePreset = generatePreset;
|
74 | function getPresetDependencies(preset, version) {
|
75 | switch (preset) {
|
76 | case presets_1.Preset.TS:
|
77 | return { dependencies: {}, dev: { '@nrwl/js': versions_1.nxVersion } };
|
78 | case presets_1.Preset.AngularMonorepo:
|
79 | case presets_1.Preset.AngularStandalone:
|
80 | return { dependencies: { '@nrwl/angular': versions_1.nxVersion }, dev: {} };
|
81 | case presets_1.Preset.Express:
|
82 | return { dependencies: {}, dev: { '@nrwl/express': versions_1.nxVersion } };
|
83 | case presets_1.Preset.Nest:
|
84 | return { dependencies: {}, dev: { '@nrwl/nest': versions_1.nxVersion } };
|
85 | case presets_1.Preset.NextJs:
|
86 | return { dependencies: { '@nrwl/next': versions_1.nxVersion }, dev: {} };
|
87 | case presets_1.Preset.ReactMonorepo:
|
88 | return { dependencies: {}, dev: { '@nrwl/react': versions_1.nxVersion } };
|
89 | case presets_1.Preset.ReactStandalone:
|
90 | return { dependencies: {}, dev: { '@nrwl/react': versions_1.nxVersion } };
|
91 | case presets_1.Preset.ReactNative:
|
92 | return { dependencies: {}, dev: { '@nrwl/react-native': versions_1.nxVersion } };
|
93 | case presets_1.Preset.Expo:
|
94 | return { dependencies: {}, dev: { '@nrwl/expo': versions_1.nxVersion } };
|
95 | case presets_1.Preset.WebComponents:
|
96 | return { dependencies: {}, dev: { '@nrwl/web': versions_1.nxVersion } };
|
97 | case presets_1.Preset.NodeServer:
|
98 | return { dependencies: {}, dev: { '@nrwl/node': versions_1.nxVersion } };
|
99 | default: {
|
100 | return {
|
101 | dev: {},
|
102 | dependencies: { [preset]: version !== null && version !== void 0 ? version : (0, get_npm_package_version_1.getNpmPackageVersion)(preset) },
|
103 | };
|
104 | }
|
105 | }
|
106 | }
|
107 |
|
\ | No newline at end of file |