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