source: trip-planner-front/node_modules/@schematics/angular/library/index.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 7.4 KB
RevLine 
[6a3a178]1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10const core_1 = require("@angular-devkit/core");
11const schematics_1 = require("@angular-devkit/schematics");
12const tasks_1 = require("@angular-devkit/schematics/tasks");
13const dependencies_1 = require("../utility/dependencies");
14const json_file_1 = require("../utility/json-file");
15const latest_versions_1 = require("../utility/latest-versions");
16const lint_fix_1 = require("../utility/lint-fix");
17const paths_1 = require("../utility/paths");
18const validation_1 = require("../utility/validation");
19const workspace_1 = require("../utility/workspace");
20const workspace_models_1 = require("../utility/workspace-models");
21function updateTsConfig(packageName, ...paths) {
22 return (host) => {
23 if (!host.exists('tsconfig.json')) {
24 return host;
25 }
26 const file = new json_file_1.JSONFile(host, 'tsconfig.json');
27 const jsonPath = ['compilerOptions', 'paths', packageName];
28 const value = file.get(jsonPath);
29 file.modify(jsonPath, Array.isArray(value) ? [...value, ...paths] : paths);
30 };
31}
32function addDependenciesToPackageJson() {
33 return (host) => {
34 [
35 {
36 type: dependencies_1.NodeDependencyType.Dev,
37 name: '@angular/compiler-cli',
38 version: latest_versions_1.latestVersions.Angular,
39 },
40 {
41 type: dependencies_1.NodeDependencyType.Dev,
42 name: '@angular-devkit/build-angular',
43 version: latest_versions_1.latestVersions.DevkitBuildAngular,
44 },
45 {
46 type: dependencies_1.NodeDependencyType.Dev,
47 name: 'ng-packagr',
48 version: latest_versions_1.latestVersions['ng-packagr'],
49 },
50 {
51 type: dependencies_1.NodeDependencyType.Default,
52 name: 'tslib',
53 version: latest_versions_1.latestVersions['tslib'],
54 },
55 {
56 type: dependencies_1.NodeDependencyType.Dev,
57 name: 'typescript',
58 version: latest_versions_1.latestVersions['typescript'],
59 },
60 ].forEach((dependency) => dependencies_1.addPackageJsonDependency(host, dependency));
61 return host;
62 };
63}
64function addLibToWorkspaceFile(options, projectRoot, projectName) {
65 return workspace_1.updateWorkspace((workspace) => {
66 if (workspace.projects.size === 0) {
67 workspace.extensions.defaultProject = projectName;
68 }
69 workspace.projects.add({
70 name: projectName,
71 root: projectRoot,
72 sourceRoot: `${projectRoot}/src`,
73 projectType: workspace_models_1.ProjectType.Library,
74 prefix: options.prefix,
75 targets: {
76 build: {
77 builder: workspace_models_1.Builders.NgPackagr,
78 defaultConfiguration: 'production',
79 options: {
80 project: `${projectRoot}/ng-package.json`,
81 },
82 configurations: {
83 production: {
84 tsConfig: `${projectRoot}/tsconfig.lib.prod.json`,
85 },
86 development: {
87 tsConfig: `${projectRoot}/tsconfig.lib.json`,
88 },
89 },
90 },
91 test: {
92 builder: workspace_models_1.Builders.Karma,
93 options: {
94 main: `${projectRoot}/src/test.ts`,
95 tsConfig: `${projectRoot}/tsconfig.spec.json`,
96 karmaConfig: `${projectRoot}/karma.conf.js`,
97 },
98 },
99 },
100 });
101 });
102}
103function default_1(options) {
104 return async (host) => {
105 if (!options.name) {
106 throw new schematics_1.SchematicsException(`Invalid options, "name" is required.`);
107 }
108 const prefix = options.prefix;
109 validation_1.validateProjectName(options.name);
110 // If scoped project (i.e. "@foo/bar"), convert projectDir to "foo/bar".
111 const projectName = options.name;
112 const packageName = core_1.strings.dasherize(projectName);
113 let scopeName = null;
114 if (/^@.*\/.*/.test(options.name)) {
115 const [scope, name] = options.name.split('/');
116 scopeName = scope.replace(/^@/, '');
117 options.name = name;
118 }
119 const workspace = await workspace_1.getWorkspace(host);
120 const newProjectRoot = workspace.extensions.newProjectRoot || '';
121 const scopeFolder = scopeName ? core_1.strings.dasherize(scopeName) + '/' : '';
122 const folderName = `${scopeFolder}${core_1.strings.dasherize(options.name)}`;
123 const projectRoot = core_1.join(core_1.normalize(newProjectRoot), folderName);
124 const distRoot = `dist/${folderName}`;
125 const pathImportLib = `${distRoot}/${folderName.replace('/', '-')}`;
126 const sourceDir = `${projectRoot}/src/lib`;
127 const templateSource = schematics_1.apply(schematics_1.url('./files'), [
128 schematics_1.applyTemplates({
129 ...core_1.strings,
130 ...options,
131 packageName,
132 projectRoot,
133 distRoot,
134 relativePathToWorkspaceRoot: paths_1.relativePathToWorkspaceRoot(projectRoot),
135 prefix,
136 angularLatestVersion: latest_versions_1.latestVersions.Angular.replace(/\~|\^/, ''),
137 tsLibLatestVersion: latest_versions_1.latestVersions['tslib'].replace(/\~|\^/, ''),
138 folderName,
139 }),
140 schematics_1.move(projectRoot),
141 ]);
142 return schematics_1.chain([
143 schematics_1.mergeWith(templateSource),
144 addLibToWorkspaceFile(options, projectRoot, projectName),
145 options.skipPackageJson ? schematics_1.noop() : addDependenciesToPackageJson(),
146 options.skipTsConfig ? schematics_1.noop() : updateTsConfig(packageName, pathImportLib, distRoot),
147 schematics_1.schematic('module', {
148 name: options.name,
149 commonModule: false,
150 flat: true,
151 path: sourceDir,
152 project: projectName,
153 }),
154 schematics_1.schematic('component', {
155 name: options.name,
156 selector: `${prefix}-${options.name}`,
157 inlineStyle: true,
158 inlineTemplate: true,
159 flat: true,
160 path: sourceDir,
161 export: true,
162 project: projectName,
163 }),
164 schematics_1.schematic('service', {
165 name: options.name,
166 flat: true,
167 path: sourceDir,
168 project: projectName,
169 }),
170 options.lintFix ? lint_fix_1.applyLintFix(sourceDir) : schematics_1.noop(),
171 (_tree, context) => {
172 if (!options.skipPackageJson && !options.skipInstall) {
173 context.addTask(new tasks_1.NodePackageInstallTask());
174 }
175 },
176 ]);
177 };
178}
179exports.default = default_1;
Note: See TracBrowser for help on using the repository browser.