source: trip-planner-front/node_modules/@fortawesome/angular-fontawesome/schematics/ng-add/index.js

Last change on this file was 59329aa, checked in by Ema <ema_spirova@…>, 3 years ago

adding photos

  • Property mode set to 100644
File size: 4.8 KB
Line 
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.getProjectTargetOptions = void 0;
13const schematics_1 = require("@angular-devkit/schematics");
14const tasks_1 = require("@angular-devkit/schematics/tasks");
15const typescript_1 = require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript");
16const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
17const change_1 = require("@schematics/angular/utility/change");
18const dependencies_1 = require("@schematics/angular/utility/dependencies");
19const ng_ast_utils_1 = require("@schematics/angular/utility/ng-ast-utils");
20const workspace_1 = require("@schematics/angular/utility/workspace");
21const versions_1 = require("./versions");
22function default_1(options) {
23 return schematics_1.chain([
24 (tree, context) => {
25 dependencies_1.addPackageJsonDependency(tree, {
26 type: dependencies_1.NodeDependencyType.Default,
27 name: '@fortawesome/fontawesome-svg-core',
28 version: versions_1.svgCoreVersion,
29 });
30 dependencies_1.addPackageJsonDependency(tree, {
31 type: dependencies_1.NodeDependencyType.Default,
32 name: '@fortawesome/angular-fontawesome',
33 version: versions_1.angularFontawesomeVersion,
34 });
35 const iconPackages = options.iconPackages != null ? options.iconPackages : ['free-solid'];
36 for (const pack of iconPackages) {
37 dependencies_1.addPackageJsonDependency(tree, {
38 type: dependencies_1.NodeDependencyType.Default,
39 name: `@fortawesome/${pack}-svg-icons`,
40 version: versions_1.iconPackVersion,
41 });
42 }
43 context.addTask(new tasks_1.NodePackageInstallTask());
44 return tree;
45 },
46 addModule(options),
47 ]);
48}
49exports.default = default_1;
50function addModule(options) {
51 return (host, context) => __awaiter(this, void 0, void 0, function* () {
52 var _a;
53 const workspace = yield workspace_1.getWorkspace(host);
54 const projectName = (_a = options.project) !== null && _a !== void 0 ? _a : workspace.extensions.defaultProject;
55 const project = workspace.projects.get(projectName);
56 if (project == null) {
57 throw new schematics_1.SchematicsException(`Project with name ${projectName} does not exist.`);
58 }
59 const buildOptions = getProjectTargetOptions(project, 'build');
60 const modulePath = ng_ast_utils_1.getAppModulePath(host, buildOptions.main);
61 const moduleSource = getSourceFile(host, modulePath);
62 const changes = ast_utils_1.addImportToModule(moduleSource, modulePath, 'FontAwesomeModule', '@fortawesome/angular-fontawesome');
63 const recorder = host.beginUpdate(modulePath);
64 changes.forEach((change) => {
65 if (change instanceof change_1.InsertChange) {
66 recorder.insertLeft(change.pos, change.toAdd);
67 }
68 });
69 host.commitUpdate(recorder);
70 /* tslint is required to add a tslint fix task */
71 try {
72 require('tslint');
73 context.addTask(new tasks_1.TslintFixTask(modulePath, {}));
74 }
75 catch (err) {
76 context.logger.warn('Formatting was skipped because tslint is not installed.');
77 }
78 });
79}
80function getSourceFile(host, path) {
81 const buffer = host.read(path);
82 if (!buffer) {
83 throw new schematics_1.SchematicsException(`Could not find ${path}.`);
84 }
85 const content = buffer.toString('utf-8');
86 return typescript_1.createSourceFile(path, content, typescript_1.ScriptTarget.Latest, true);
87}
88function getProjectTargetOptions(project, buildTarget) {
89 const buildTargetObject = project.targets.get(buildTarget);
90 if (buildTargetObject && buildTargetObject.options) {
91 return buildTargetObject.options;
92 }
93 throw new schematics_1.SchematicsException(`Cannot determine project target configuration for: ${buildTarget}.`);
94}
95exports.getProjectTargetOptions = getProjectTargetOptions;
96//# sourceMappingURL=index.js.map
Note: See TracBrowser for help on using the repository browser.