1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getAppFromConfig = exports.getConfig = exports.configPath = exports.updateWorkspace = exports.addProjectToWorkspace = exports.getWorkspace = exports.getWorkspacePath = void 0;
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const core_1 = require("@angular-devkit/core");
|
12 | const schematics_1 = require("@angular-devkit/schematics");
|
13 | function getWorkspacePath(host) {
|
14 | const possibleFiles = ['/angular.json', '/.angular.json'];
|
15 | const path = possibleFiles.filter(path => host.exists(path))[0];
|
16 | return path;
|
17 | }
|
18 | exports.getWorkspacePath = getWorkspacePath;
|
19 | function getWorkspace(host) {
|
20 | const path = getWorkspacePath(host);
|
21 | const configBuffer = host.read(path);
|
22 | if (configBuffer === null) {
|
23 | throw new schematics_1.SchematicsException(`Could not find (${path})`);
|
24 | }
|
25 | const content = configBuffer.toString();
|
26 | return core_1.parseJson(content, core_1.JsonParseMode.Loose);
|
27 | }
|
28 | exports.getWorkspace = getWorkspace;
|
29 | function addProjectToWorkspace(workspace, name, project) {
|
30 | return (host, context) => {
|
31 | if (workspace.projects[name]) {
|
32 | throw new Error(`Project '${name}' already exists in workspace.`);
|
33 | }
|
34 |
|
35 | workspace.projects[name] = project;
|
36 | if (!workspace.defaultProject && Object.keys(workspace.projects).length === 1) {
|
37 |
|
38 | workspace.defaultProject = name;
|
39 | }
|
40 | return updateWorkspace(workspace);
|
41 | };
|
42 | }
|
43 | exports.addProjectToWorkspace = addProjectToWorkspace;
|
44 | function updateWorkspace(workspace) {
|
45 | return (host, context) => {
|
46 | host.overwrite(getWorkspacePath(host), JSON.stringify(workspace, null, 2));
|
47 | };
|
48 | }
|
49 | exports.updateWorkspace = updateWorkspace;
|
50 | exports.configPath = '/.angular-cli.json';
|
51 | function getConfig(host) {
|
52 | const configBuffer = host.read(exports.configPath);
|
53 | if (configBuffer === null) {
|
54 | throw new schematics_1.SchematicsException('Could not find .angular-cli.json');
|
55 | }
|
56 | const config = core_1.parseJson(configBuffer.toString(), core_1.JsonParseMode.Loose);
|
57 | return config;
|
58 | }
|
59 | exports.getConfig = getConfig;
|
60 | function getAppFromConfig(config, appIndexOrName) {
|
61 | if (!config.apps) {
|
62 | return null;
|
63 | }
|
64 | if (parseInt(appIndexOrName) >= 0) {
|
65 | return config.apps[parseInt(appIndexOrName)];
|
66 | }
|
67 | return config.apps.filter((app) => app.name === appIndexOrName)[0];
|
68 | }
|
69 | exports.getAppFromConfig = getAppFromConfig;
|