UNPKG

2.52 kBJavaScriptView Raw
1"use strict";
2var __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};
11Object.defineProperty(exports, "__esModule", { value: true });
12exports.ngAdd = void 0;
13const core_1 = require("@angular-devkit/core");
14const schematics_1 = require("@angular-devkit/schematics");
15const utils_1 = require("./utils");
16const ngAdd = (options) => (tree, _context) => __awaiter(void 0, void 0, void 0, function* () {
17 var _a, _b;
18 const host = (0, utils_1.createHost)(tree);
19 const { workspace } = yield core_1.workspaces.readWorkspace('/', host);
20 if (!options.project) {
21 if (workspace.projects.size === 1) {
22 options.project = Array.from(workspace.projects.keys())[0];
23 }
24 else {
25 throw new schematics_1.SchematicsException('There is more than one project in your workspace. Please select it manually by using the --project argument.');
26 }
27 }
28 const project = workspace.projects.get(options.project);
29 if (!project) {
30 throw new schematics_1.SchematicsException('The specified Angular project is not defined in this workspace');
31 }
32 if (project.extensions.projectType !== 'application') {
33 throw new schematics_1.SchematicsException(`Deploy requires an Angular project type of "application" in angular.json`);
34 }
35 if (!((_b = (_a = project.targets.get('build')) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.outputPath)) {
36 throw new schematics_1.SchematicsException(`Cannot read the output path (architect.build.options.outputPath) of the Angular project "${options.project}" in angular.json`);
37 }
38 project.targets.add({
39 name: 'deploy',
40 builder: 'angular-cli-ghpages:deploy',
41 options: {}
42 });
43 core_1.workspaces.writeWorkspace(workspace, host);
44 return tree;
45});
46exports.ngAdd = ngAdd;
47//# sourceMappingURL=ng-add.js.map
\No newline at end of file