1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.findWorkspaceFile = void 0;
|
11 | const core_1 = require("@angular-devkit/core");
|
12 | const fs = require("fs");
|
13 | const os = require("os");
|
14 | const path = require("path");
|
15 | const find_up_1 = require("./find-up");
|
16 | function findWorkspaceFile(currentDirectory = process.cwd()) {
|
17 | const possibleConfigFiles = [
|
18 | 'angular.json',
|
19 | '.angular.json',
|
20 | 'angular-cli.json',
|
21 | '.angular-cli.json',
|
22 | ];
|
23 | const configFilePath = find_up_1.findUp(possibleConfigFiles, currentDirectory);
|
24 | if (configFilePath === null) {
|
25 | return null;
|
26 | }
|
27 | const possibleDir = path.dirname(configFilePath);
|
28 | const homedir = os.homedir();
|
29 | if (core_1.normalize(possibleDir) === core_1.normalize(homedir)) {
|
30 | const packageJsonPath = path.join(possibleDir, 'package.json');
|
31 | try {
|
32 | const packageJsonText = fs.readFileSync(packageJsonPath, 'utf-8');
|
33 | const packageJson = JSON.parse(packageJsonText);
|
34 | if (!containsCliDep(packageJson)) {
|
35 |
|
36 | return null;
|
37 | }
|
38 | }
|
39 | catch {
|
40 |
|
41 | return null;
|
42 | }
|
43 | }
|
44 | return configFilePath;
|
45 | }
|
46 | exports.findWorkspaceFile = findWorkspaceFile;
|
47 | function containsCliDep(obj) {
|
48 | var _a, _b;
|
49 | const pkgName = '@angular/cli';
|
50 | if (!obj) {
|
51 | return false;
|
52 | }
|
53 | return !!(((_a = obj.dependencies) === null || _a === void 0 ? void 0 : _a[pkgName]) || ((_b = obj.devDependencies) === null || _b === void 0 ? void 0 : _b[pkgName]));
|
54 | }
|