1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.normalizeFileReplacements = exports.MissingFileReplacementException = void 0;
|
11 | const core_1 = require("@angular-devkit/core");
|
12 | const fs_1 = require("fs");
|
13 | class MissingFileReplacementException extends core_1.BaseException {
|
14 | constructor(path) {
|
15 | super(`The ${path} path in file replacements does not exist.`);
|
16 | }
|
17 | }
|
18 | exports.MissingFileReplacementException = MissingFileReplacementException;
|
19 | function normalizeFileReplacements(fileReplacements, root) {
|
20 | if (fileReplacements.length === 0) {
|
21 | return [];
|
22 | }
|
23 | const normalizedReplacement = fileReplacements.map((replacement) => normalizeFileReplacement(replacement, root));
|
24 | for (const { replace, with: replacementWith } of normalizedReplacement) {
|
25 | if (!fs_1.existsSync(core_1.getSystemPath(replacementWith))) {
|
26 | throw new MissingFileReplacementException(core_1.getSystemPath(replacementWith));
|
27 | }
|
28 | if (!fs_1.existsSync(core_1.getSystemPath(replace))) {
|
29 | throw new MissingFileReplacementException(core_1.getSystemPath(replace));
|
30 | }
|
31 | }
|
32 | return normalizedReplacement;
|
33 | }
|
34 | exports.normalizeFileReplacements = normalizeFileReplacements;
|
35 | function normalizeFileReplacement(fileReplacement, root) {
|
36 | let replacePath;
|
37 | let withPath;
|
38 | if (fileReplacement.src && fileReplacement.replaceWith) {
|
39 | replacePath = core_1.normalize(fileReplacement.src);
|
40 | withPath = core_1.normalize(fileReplacement.replaceWith);
|
41 | }
|
42 | else if (fileReplacement.replace && fileReplacement.with) {
|
43 | replacePath = core_1.normalize(fileReplacement.replace);
|
44 | withPath = core_1.normalize(fileReplacement.with);
|
45 | }
|
46 | else {
|
47 | throw new Error(`Invalid file replacement: ${JSON.stringify(fileReplacement)}`);
|
48 | }
|
49 |
|
50 | if (root) {
|
51 | replacePath = core_1.join(root, replacePath);
|
52 | }
|
53 | if (root) {
|
54 | withPath = core_1.join(root, withPath);
|
55 | }
|
56 | return { replace: replacePath, with: withPath };
|
57 | }
|