1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getWorkspaceDetails = exports.insideWorkspace = void 0;
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
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 insideWorkspace() {
|
17 | return getWorkspaceDetails() !== null;
|
18 | }
|
19 | exports.insideWorkspace = insideWorkspace;
|
20 | function getWorkspaceDetails() {
|
21 | const currentDir = process.cwd();
|
22 | const possibleConfigFiles = [
|
23 | 'angular.json',
|
24 | '.angular.json',
|
25 | 'angular-cli.json',
|
26 | '.angular-cli.json',
|
27 | ];
|
28 | const configFilePath = find_up_1.findUp(possibleConfigFiles, currentDir);
|
29 | if (configFilePath === null) {
|
30 | return null;
|
31 | }
|
32 | const configFileName = path.basename(configFilePath);
|
33 | const possibleDir = path.dirname(configFilePath);
|
34 | const homedir = os.homedir();
|
35 | if (core_1.normalize(possibleDir) === core_1.normalize(homedir)) {
|
36 | const packageJsonPath = path.join(possibleDir, 'package.json');
|
37 | if (!fs.existsSync(packageJsonPath)) {
|
38 |
|
39 | return null;
|
40 | }
|
41 | const packageJsonBuffer = fs.readFileSync(packageJsonPath);
|
42 | const packageJsonText = packageJsonBuffer === null ? '{}' : packageJsonBuffer.toString();
|
43 | const packageJson = JSON.parse(packageJsonText);
|
44 | if (!containsCliDep(packageJson)) {
|
45 |
|
46 | return null;
|
47 | }
|
48 | }
|
49 | return {
|
50 | root: possibleDir,
|
51 | configFile: configFileName,
|
52 | };
|
53 | }
|
54 | exports.getWorkspaceDetails = getWorkspaceDetails;
|
55 | function containsCliDep(obj) {
|
56 | var _a, _b;
|
57 | const pkgName = '@angular/cli';
|
58 | if (!obj) {
|
59 | return false;
|
60 | }
|
61 | return !!(((_a = obj.dependencies) === null || _a === void 0 ? void 0 : _a[pkgName]) || ((_b = obj.devDependencies) === null || _b === void 0 ? void 0 : _b[pkgName]));
|
62 | }
|