1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.verifyBaseTsConfigExists = exports.addTsConfigProjectReferences = void 0;
|
11 | const core_1 = require("@angular-devkit/core");
|
12 | const schematics_1 = require("@angular-devkit/schematics");
|
13 | const json_utils_1 = require("./json-utils");
|
14 | const SOLUTION_TSCONFIG_PATH = 'tsconfig.json';
|
15 |
|
16 |
|
17 |
|
18 | function addTsConfigProjectReferences(paths) {
|
19 | return (host, context) => {
|
20 | const logger = context.logger;
|
21 |
|
22 | for (const path of paths) {
|
23 | const source = host.read(SOLUTION_TSCONFIG_PATH);
|
24 | if (!source) {
|
25 |
|
26 | logger.warn(`Cannot add reference '${path}' in '${SOLUTION_TSCONFIG_PATH}'. File doesn't exists.`);
|
27 | return;
|
28 | }
|
29 | const jsonAst = core_1.parseJsonAst(source.toString(), core_1.JsonParseMode.Loose);
|
30 | if ((jsonAst === null || jsonAst === void 0 ? void 0 : jsonAst.kind) !== 'object') {
|
31 |
|
32 | throw new schematics_1.SchematicsException(`Invalid JSON AST Object '${SOLUTION_TSCONFIG_PATH}'.`);
|
33 | }
|
34 |
|
35 |
|
36 |
|
37 | const filesAst = json_utils_1.findPropertyInAstObject(jsonAst, 'files');
|
38 | const referencesAst = json_utils_1.findPropertyInAstObject(jsonAst, 'references');
|
39 | if ((filesAst === null || filesAst === void 0 ? void 0 : filesAst.kind) !== 'array' ||
|
40 | filesAst.elements.length !== 0 ||
|
41 | (referencesAst === null || referencesAst === void 0 ? void 0 : referencesAst.kind) !== 'array') {
|
42 | logger.warn(`Cannot add reference '${path}' in '${SOLUTION_TSCONFIG_PATH}'. It appears to be an invalid solution style tsconfig.`);
|
43 | return;
|
44 | }
|
45 |
|
46 | const recorder = host.beginUpdate(SOLUTION_TSCONFIG_PATH);
|
47 | json_utils_1.appendValueInAstArray(recorder, referencesAst, { 'path': `./${path}` }, 4);
|
48 | host.commitUpdate(recorder);
|
49 | }
|
50 | };
|
51 | }
|
52 | exports.addTsConfigProjectReferences = addTsConfigProjectReferences;
|
53 |
|
54 |
|
55 |
|
56 | function verifyBaseTsConfigExists(host) {
|
57 | if (host.exists('tsconfig.base.json')) {
|
58 | return;
|
59 | }
|
60 | throw new schematics_1.SchematicsException(`Cannot find base TypeScript configuration file 'tsconfig.base.json'.`);
|
61 | }
|
62 | exports.verifyBaseTsConfigExists = verifyBaseTsConfigExists;
|