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.getProjectTargetOptions = void 0;
|
---|
13 | const schematics_1 = require("@angular-devkit/schematics");
|
---|
14 | const tasks_1 = require("@angular-devkit/schematics/tasks");
|
---|
15 | const typescript_1 = require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript");
|
---|
16 | const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
|
---|
17 | const change_1 = require("@schematics/angular/utility/change");
|
---|
18 | const dependencies_1 = require("@schematics/angular/utility/dependencies");
|
---|
19 | const ng_ast_utils_1 = require("@schematics/angular/utility/ng-ast-utils");
|
---|
20 | const workspace_1 = require("@schematics/angular/utility/workspace");
|
---|
21 | const versions_1 = require("./versions");
|
---|
22 | function 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 | }
|
---|
49 | exports.default = default_1;
|
---|
50 | function 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 | }
|
---|
80 | function 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 | }
|
---|
88 | function 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 | }
|
---|
95 | exports.getProjectTargetOptions = getProjectTargetOptions;
|
---|
96 | //# sourceMappingURL=index.js.map |
---|