1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | exports.findAngularProjectTarget = exports.getDefaultProjectName = exports.readAngularWorkspaceConfig = void 0;
|
13 | const node_1 = require("@angular-devkit/core/node");
|
14 | const core_1 = require("@angular-devkit/core");
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | exports.readAngularWorkspaceConfig = (dirToSearch) => __awaiter(void 0, void 0, void 0, function* () {
|
22 | const host = core_1.workspaces.createWorkspaceHost(new node_1.NodeJsSyncHost());
|
23 | try {
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | require('@nrwl/workspace').readNxJson();
|
31 | const nxWorkspace = require('@nrwl/workspace').readWorkspaceConfig({
|
32 | format: 'angularCli',
|
33 | path: dirToSearch,
|
34 | });
|
35 |
|
36 | host.readFile = (path) => {
|
37 | if (typeof path === 'string' && path.endsWith('angular.json')) {
|
38 | return Promise.resolve(JSON.stringify(nxWorkspace));
|
39 | }
|
40 | return host.readFile(path);
|
41 | };
|
42 | host.isFile = (path) => {
|
43 | if (typeof path === 'string' && path.endsWith('angular.json')) {
|
44 | return Promise.resolve(true);
|
45 | }
|
46 | return host.isFile(path);
|
47 | };
|
48 | }
|
49 | catch (e) {
|
50 |
|
51 | }
|
52 | return (yield core_1.workspaces.readWorkspace(dirToSearch, host)).workspace;
|
53 | });
|
54 | exports.getDefaultProjectName = (workspace) => {
|
55 | const environmentProjectName = process.env.STORYBOOK_ANGULAR_PROJECT;
|
56 | if (environmentProjectName) {
|
57 | return environmentProjectName;
|
58 | }
|
59 | if (workspace.projects.has('storybook')) {
|
60 | return 'storybook';
|
61 | }
|
62 | if (workspace.extensions.defaultProject) {
|
63 | return workspace.extensions.defaultProject;
|
64 | }
|
65 | const firstProjectName = workspace.projects.keys().next().value;
|
66 | if (firstProjectName) {
|
67 | return firstProjectName;
|
68 | }
|
69 | throw new Error('No angular projects found');
|
70 | };
|
71 | exports.findAngularProjectTarget = (workspace, projectName, targetName) => {
|
72 | if (!workspace.projects || !Object.keys(workspace.projects).length) {
|
73 | throw new Error('No angular projects found');
|
74 | }
|
75 | const project = workspace.projects.get(projectName);
|
76 | if (!project) {
|
77 | throw new Error(`"${projectName}" project is not found in angular.json`);
|
78 | }
|
79 | if (!project.targets.has(targetName)) {
|
80 | throw new Error(`"${targetName}" target is not found in "${projectName}" project`);
|
81 | }
|
82 | const target = project.targets.get(targetName);
|
83 | return { project, target };
|
84 | };
|