UNPKG

2.17 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getWorkspaceDetails = exports.insideWorkspace = void 0;
4/**
5 * @license
6 * Copyright Google Inc. All Rights Reserved.
7 *
8 * Use of this source code is governed by an MIT-style license that can be
9 * found in the LICENSE file at https://angular.io/license
10 */
11const core_1 = require("@angular-devkit/core");
12const fs = require("fs");
13const os = require("os");
14const path = require("path");
15const find_up_1 = require("./find-up");
16function insideWorkspace() {
17 return getWorkspaceDetails() !== null;
18}
19exports.insideWorkspace = insideWorkspace;
20function 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 // No package.json
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 // No CLI dependency
46 return null;
47 }
48 }
49 return {
50 root: possibleDir,
51 configFile: configFileName,
52 };
53}
54exports.getWorkspaceDetails = getWorkspaceDetails;
55function 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}