1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.allTargetOptions = exports.allWorkspaceTargets = exports.createDefaultPath = exports.buildDefaultPath = exports.getWorkspace = exports.updateWorkspace = void 0;
|
11 | const core_1 = require("@angular-devkit/core");
|
12 | const schematics_1 = require("@angular-devkit/schematics");
|
13 | const workspace_models_1 = require("./workspace-models");
|
14 | function createHost(tree) {
|
15 | return {
|
16 | async readFile(path) {
|
17 | const data = tree.read(path);
|
18 | if (!data) {
|
19 | throw new Error('File not found.');
|
20 | }
|
21 | return core_1.virtualFs.fileBufferToString(data);
|
22 | },
|
23 | async writeFile(path, data) {
|
24 | return tree.overwrite(path, data);
|
25 | },
|
26 | async isDirectory(path) {
|
27 |
|
28 | return !tree.exists(path) && tree.getDir(path).subfiles.length > 0;
|
29 | },
|
30 | async isFile(path) {
|
31 | return tree.exists(path);
|
32 | },
|
33 | };
|
34 | }
|
35 | function updateWorkspace(updaterOrWorkspace) {
|
36 | return async (tree) => {
|
37 | const host = createHost(tree);
|
38 | if (typeof updaterOrWorkspace === 'function') {
|
39 | const { workspace } = await core_1.workspaces.readWorkspace('/', host);
|
40 | const result = await updaterOrWorkspace(workspace);
|
41 | await core_1.workspaces.writeWorkspace(workspace, host);
|
42 | return result || schematics_1.noop;
|
43 | }
|
44 | else {
|
45 | await core_1.workspaces.writeWorkspace(updaterOrWorkspace, host);
|
46 | return schematics_1.noop;
|
47 | }
|
48 | };
|
49 | }
|
50 | exports.updateWorkspace = updateWorkspace;
|
51 | async function getWorkspace(tree, path = '/') {
|
52 | const host = createHost(tree);
|
53 | const { workspace } = await core_1.workspaces.readWorkspace(path, host);
|
54 | return workspace;
|
55 | }
|
56 | exports.getWorkspace = getWorkspace;
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | function buildDefaultPath(project) {
|
62 | const root = project.sourceRoot ? `/${project.sourceRoot}/` : `/${project.root}/src/`;
|
63 | const projectDirName = project.extensions['projectType'] === workspace_models_1.ProjectType.Application ? 'app' : 'lib';
|
64 | return `${root}${projectDirName}`;
|
65 | }
|
66 | exports.buildDefaultPath = buildDefaultPath;
|
67 | async function createDefaultPath(tree, projectName) {
|
68 | const workspace = await getWorkspace(tree);
|
69 | const project = workspace.projects.get(projectName);
|
70 | if (!project) {
|
71 | throw new Error(`Project "${projectName}" does not exist.`);
|
72 | }
|
73 | return buildDefaultPath(project);
|
74 | }
|
75 | exports.createDefaultPath = createDefaultPath;
|
76 | function* allWorkspaceTargets(workspace) {
|
77 | for (const [projectName, project] of workspace.projects) {
|
78 | for (const [targetName, target] of project.targets) {
|
79 | yield [targetName, target, projectName, project];
|
80 | }
|
81 | }
|
82 | }
|
83 | exports.allWorkspaceTargets = allWorkspaceTargets;
|
84 | function* allTargetOptions(target, skipBaseOptions = false) {
|
85 | if (!skipBaseOptions && target.options) {
|
86 | yield [undefined, target.options];
|
87 | }
|
88 | if (!target.configurations) {
|
89 | return;
|
90 | }
|
91 | for (const [name, options] of Object.entries(target.configurations)) {
|
92 | if (options !== undefined) {
|
93 | yield [name, options];
|
94 | }
|
95 | }
|
96 | }
|
97 | exports.allTargetOptions = allTargetOptions;
|