UNPKG

2.96 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.convertToNxProjectSchematic = exports.convertToNxProjectGenerator = exports.validateSchema = exports.SCHEMA_OPTIONS_ARE_MUTUALLY_EXCLUSIVE = void 0;
4const tslib_1 = require("tslib");
5const path_1 = require("path");
6const enquirer_1 = require("enquirer");
7const devkit_1 = require("@nrwl/devkit");
8const get_project_configuration_path_1 = require("./utils/get-project-configuration-path");
9exports.SCHEMA_OPTIONS_ARE_MUTUALLY_EXCLUSIVE = '--project and --all are mutually exclusive';
10function 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}
26exports.validateSchema = validateSchema;
27function 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(`
32NX Only workspaces with version 2+ support project.json files.
33To 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}
59exports.convertToNxProjectGenerator = convertToNxProjectGenerator;
60exports.default = convertToNxProjectGenerator;
61exports.convertToNxProjectSchematic = (0, devkit_1.convertNxGenerator)(convertToNxProjectGenerator);
62//# sourceMappingURL=convert-to-nx-project.js.map
\No newline at end of file