1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.convertToNxProjectSchematic = exports.convertToNxProjectGenerator = exports.validateSchema = exports.SCHEMA_OPTIONS_ARE_MUTUALLY_EXCLUSIVE = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const path_1 = require("path");
|
6 | const enquirer_1 = require("enquirer");
|
7 | const devkit_1 = require("@nrwl/devkit");
|
8 | const get_project_configuration_path_1 = require("./utils/get-project-configuration-path");
|
9 | exports.SCHEMA_OPTIONS_ARE_MUTUALLY_EXCLUSIVE = '--project and --all are mutually exclusive';
|
10 | function validateSchema(schema) {
|
11 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
12 | if (schema.project && schema.all) {
|
13 | throw exports.SCHEMA_OPTIONS_ARE_MUTUALLY_EXCLUSIVE;
|
14 | }
|
15 | if (!schema.project && !schema.all) {
|
16 | schema.project = (yield (0, enquirer_1.prompt)([
|
17 | {
|
18 | message: 'What project should be converted?',
|
19 | type: 'input',
|
20 | name: 'project',
|
21 | },
|
22 | ])).project;
|
23 | }
|
24 | });
|
25 | }
|
26 | exports.validateSchema = validateSchema;
|
27 | function convertToNxProjectGenerator(host, schema) {
|
28 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
29 | const workspace = (0, devkit_1.readWorkspaceConfiguration)(host);
|
30 | if (workspace.version < 2) {
|
31 | devkit_1.logger.error(`
|
32 | NX Only workspaces with version 2+ support project.json files.
|
33 | To upgrade change the version number at the top of ${(0, devkit_1.getWorkspacePath)(host)} and run 'nx format'.
|
34 | `);
|
35 | throw new Error('v2+ Required');
|
36 | }
|
37 | yield validateSchema(schema);
|
38 | const projects = schema.all
|
39 | ? (0, devkit_1.getProjects)(host).entries()
|
40 | : [[schema.project, (0, devkit_1.readProjectConfiguration)(host, schema.project)]];
|
41 | for (const [project, configuration] of projects) {
|
42 | const configPath = (0, get_project_configuration_path_1.getProjectConfigurationPath)(configuration);
|
43 | if (host.exists(configPath)) {
|
44 | devkit_1.logger.warn(`Skipping ${project} since ${configPath} already exists.`);
|
45 | continue;
|
46 | }
|
47 | delete configuration.root;
|
48 | (0, devkit_1.writeJson)(host, configPath, configuration);
|
49 | (0, devkit_1.updateJson)(host, (0, devkit_1.getWorkspacePath)(host), (value) => {
|
50 | value.projects[project] = (0, devkit_1.normalizePath)((0, path_1.dirname)(configPath));
|
51 | return value;
|
52 | });
|
53 | }
|
54 | if (!schema.skipFormat) {
|
55 | yield (0, devkit_1.formatFiles)(host);
|
56 | }
|
57 | });
|
58 | }
|
59 | exports.convertToNxProjectGenerator = convertToNxProjectGenerator;
|
60 | exports.default = convertToNxProjectGenerator;
|
61 | exports.convertToNxProjectSchematic = (0, devkit_1.convertNxGenerator)(convertToNxProjectGenerator);
|
62 |
|
\ | No newline at end of file |