1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.updateBuilderConfig = exports.updateWorkspace = exports.getWorkspace = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const core_1 = require("@angular-devkit/core");
|
6 | function createHost(tree) {
|
7 | return {
|
8 | readFile(path) {
|
9 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
10 | const data = tree.read(path);
|
11 | if (!data) {
|
12 | throw new Error('File not found.');
|
13 | }
|
14 | return data.toString();
|
15 | });
|
16 | },
|
17 | writeFile(path, data) {
|
18 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
19 | return tree.overwrite(path, data);
|
20 | });
|
21 | },
|
22 | isDirectory(path) {
|
23 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
24 |
|
25 |
|
26 | if (path === '/')
|
27 | return true;
|
28 | return !tree.exists(path) && tree.getDir(path).subfiles.length > 0;
|
29 | });
|
30 | },
|
31 | isFile(path) {
|
32 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
33 | return tree.exists(path);
|
34 | });
|
35 | },
|
36 | };
|
37 | }
|
38 | function getWorkspace(tree, path = '/') {
|
39 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
40 | const host = createHost(tree);
|
41 | const { workspace } = yield core_1.workspaces.readWorkspace(path, host);
|
42 | return workspace;
|
43 | });
|
44 | }
|
45 | exports.getWorkspace = getWorkspace;
|
46 | function updateWorkspace(updaterOrWorkspace) {
|
47 | return (tree) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
48 | const host = createHost(tree);
|
49 | if (typeof updaterOrWorkspace === 'function') {
|
50 | const { workspace } = yield core_1.workspaces.readWorkspace('/', host);
|
51 | const result = updaterOrWorkspace(workspace);
|
52 | if (result !== undefined) {
|
53 | yield result;
|
54 | }
|
55 | yield core_1.workspaces.writeWorkspace(workspace, host);
|
56 | }
|
57 | else {
|
58 | yield core_1.workspaces.writeWorkspace(updaterOrWorkspace, host);
|
59 | }
|
60 | });
|
61 | }
|
62 | exports.updateWorkspace = updateWorkspace;
|
63 |
|
64 |
|
65 |
|
66 | function updateBuilderConfig(updater, ...builderNames) {
|
67 | return updateWorkspace((workspace) => {
|
68 | if (!workspace.projects) {
|
69 | return;
|
70 | }
|
71 | workspace.projects.forEach((project) => {
|
72 | project.targets.forEach((target) => {
|
73 | if (!builderNames.includes(target.builder)) {
|
74 | return;
|
75 | }
|
76 | if (target.options) {
|
77 | target.options = updater(target.options, target, project);
|
78 | }
|
79 | if (!target.configurations) {
|
80 | return;
|
81 | }
|
82 | Object.entries(target.configurations).forEach(([configName, options]) => {
|
83 | target.configurations[configName] = updater(options, target, project);
|
84 | });
|
85 | });
|
86 | });
|
87 | });
|
88 | }
|
89 | exports.updateBuilderConfig = updateBuilderConfig;
|
90 |
|
\ | No newline at end of file |