Icard/angular-clarity-master(work.../node_modules/@schematics/angular/library/index.js

172 lines
21 KiB
JavaScript
Raw Normal View History

2024-07-16 14:55:36 +00:00
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@angular-devkit/core");
const schematics_1 = require("@angular-devkit/schematics");
const tasks_1 = require("@angular-devkit/schematics/tasks");
const dependencies_1 = require("../utility/dependencies");
const json_file_1 = require("../utility/json-file");
const latest_versions_1 = require("../utility/latest-versions");
const paths_1 = require("../utility/paths");
const workspace_1 = require("../utility/workspace");
const workspace_models_1 = require("../utility/workspace-models");
function updateTsConfig(packageName, ...paths) {
return (host) => {
if (!host.exists('tsconfig.json')) {
return host;
}
const file = new json_file_1.JSONFile(host, 'tsconfig.json');
const jsonPath = ['compilerOptions', 'paths', packageName];
const value = file.get(jsonPath);
file.modify(jsonPath, Array.isArray(value) ? [...value, ...paths] : paths);
};
}
function addDependenciesToPackageJson() {
return (host) => {
[
{
type: dependencies_1.NodeDependencyType.Dev,
name: '@angular/compiler-cli',
version: latest_versions_1.latestVersions.Angular,
},
{
type: dependencies_1.NodeDependencyType.Dev,
name: '@angular-devkit/build-angular',
version: latest_versions_1.latestVersions.DevkitBuildAngular,
},
{
type: dependencies_1.NodeDependencyType.Dev,
name: 'ng-packagr',
version: latest_versions_1.latestVersions['ng-packagr'],
},
{
type: dependencies_1.NodeDependencyType.Default,
name: 'tslib',
version: latest_versions_1.latestVersions['tslib'],
},
{
type: dependencies_1.NodeDependencyType.Dev,
name: 'typescript',
version: latest_versions_1.latestVersions['typescript'],
},
].forEach((dependency) => (0, dependencies_1.addPackageJsonDependency)(host, dependency));
return host;
};
}
function addLibToWorkspaceFile(options, projectRoot, projectName) {
return (0, workspace_1.updateWorkspace)((workspace) => {
workspace.projects.add({
name: projectName,
root: projectRoot,
sourceRoot: `${projectRoot}/src`,
projectType: workspace_models_1.ProjectType.Library,
prefix: options.prefix,
targets: {
build: {
builder: workspace_models_1.Builders.NgPackagr,
defaultConfiguration: 'production',
options: {
project: `${projectRoot}/ng-package.json`,
},
configurations: {
production: {
tsConfig: `${projectRoot}/tsconfig.lib.prod.json`,
},
development: {
tsConfig: `${projectRoot}/tsconfig.lib.json`,
},
},
},
test: {
builder: workspace_models_1.Builders.Karma,
options: {
tsConfig: `${projectRoot}/tsconfig.spec.json`,
polyfills: ['zone.js', 'zone.js/testing'],
},
},
},
});
});
}
function default_1(options) {
return async (host) => {
const prefix = options.prefix;
// If scoped project (i.e. "@foo/bar"), convert projectDir to "foo/bar".
const packageName = options.name;
if (/^@.*\/.*/.test(options.name)) {
const [, name] = options.name.split('/');
options.name = name;
}
const workspace = await (0, workspace_1.getWorkspace)(host);
const newProjectRoot = workspace.extensions.newProjectRoot || '';
let folderName = packageName.startsWith('@') ? packageName.slice(1) : packageName;
if (/[A-Z]/.test(folderName)) {
folderName = schematics_1.strings.dasherize(folderName);
}
const libDir = options.projectRoot !== undefined
? (0, core_1.normalize)(options.projectRoot)
: (0, core_1.join)((0, core_1.normalize)(newProjectRoot), folderName);
const distRoot = `dist/${folderName}`;
const sourceDir = `${libDir}/src/lib`;
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
(0, schematics_1.applyTemplates)({
...schematics_1.strings,
...options,
packageName,
libDir,
distRoot,
relativePathToWorkspaceRoot: (0, paths_1.relativePathToWorkspaceRoot)(libDir),
prefix,
angularLatestVersion: latest_versions_1.latestVersions.Angular.replace(/~|\^/, ''),
tsLibLatestVersion: latest_versions_1.latestVersions['tslib'].replace(/~|\^/, ''),
folderName,
}),
(0, schematics_1.move)(libDir),
]);
return (0, schematics_1.chain)([
(0, schematics_1.mergeWith)(templateSource),
addLibToWorkspaceFile(options, libDir, packageName),
options.skipPackageJson ? (0, schematics_1.noop)() : addDependenciesToPackageJson(),
options.skipTsConfig ? (0, schematics_1.noop)() : updateTsConfig(packageName, distRoot),
options.standalone
? (0, schematics_1.noop)()
: (0, schematics_1.schematic)('module', {
name: options.name,
commonModule: false,
flat: true,
path: sourceDir,
project: packageName,
}),
(0, schematics_1.schematic)('component', {
name: options.name,
selector: `${prefix}-${options.name}`,
inlineStyle: true,
inlineTemplate: true,
flat: true,
path: sourceDir,
export: true,
standalone: options.standalone,
project: packageName,
}),
(0, schematics_1.schematic)('service', {
name: options.name,
flat: true,
path: sourceDir,
project: packageName,
}),
(_tree, context) => {
if (!options.skipPackageJson && !options.skipInstall) {
context.addTask(new tasks_1.NodePackageInstallTask());
}
},
]);
};
}
exports.default = default_1;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9zY2hlbWF0aWNzL2FuZ3VsYXIvbGlicmFyeS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7OztHQU1HOztBQUVILCtDQUF1RDtBQUN2RCwyREFhb0M7QUFDcEMsNERBQTBFO0FBQzFFLDBEQUF1RjtBQUN2RixvREFBZ0Q7QUFDaEQsZ0VBQTREO0FBQzVELDRDQUErRDtBQUMvRCxvREFBcUU7QUFDckUsa0VBQW9FO0FBR3BFLFNBQVMsY0FBYyxDQUFDLFdBQW1CLEVBQUUsR0FBRyxLQUFlO0lBQzdELE9BQU8sQ0FBQyxJQUFVLEVBQUUsRUFBRTtRQUNwQixJQUFJLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxlQUFlLENBQUMsRUFBRTtZQUNqQyxPQUFPLElBQUksQ0FBQztTQUNiO1FBRUQsTUFBTSxJQUFJLEdBQUcsSUFBSSxvQkFBUSxDQUFDLElBQUksRUFBRSxlQUFlLENBQUMsQ0FBQztRQUNqRCxNQUFNLFFBQVEsR0FBRyxDQUFDLGlCQUFpQixFQU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