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

172 lines
21 KiB
JavaScript

"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9zY2hlbWF0aWNzL2FuZ3VsYXIvbGlicmFyeS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7OztHQU1HOztBQUVILCtDQUF1RDtBQUN2RCwyREFhb0M7QUFDcEMsNERBQTBFO0FBQzFFLDBEQUF1RjtBQUN2RixvREFBZ0Q7QUFDaEQsZ0VBQTREO0FBQzVELDRDQUErRDtBQUMvRCxvREFBcUU7QUFDckUsa0VBQW9FO0FBR3BFLFNBQVMsY0FBYyxDQUFDLFdBQW1CLEVBQUUsR0FBRyxLQUFlO0lBQzdELE9BQU8sQ0FBQyxJQUFVLEVBQUUsRUFBRTtRQUNwQixJQUFJLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxlQUFlLENBQUMsRUFBRTtZQUNqQyxPQUFPLElBQUksQ0FBQztTQUNiO1FBRUQsTUFBTSxJQUFJLEdBQUcsSUFBSSxvQkFBUSxDQUFDLElBQUksRUFBRSxlQUFlLENBQUMsQ0FBQztRQUNqRCxNQUFNLFFBQVEsR0FBRyxDQUFDLGlCQUFpQixFQUFFLE9BQU8sRUFBRSxXQUFXLENBQU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cm9kdWN0aW9uOiB7XG4gICAgICAgICAgICAgIHRzQ29uZmlnOiBgJHtwcm9qZWN0Um9vdH0vdHNjb25maWcubGliLnByb2QuanNvbmAsXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgZGV2ZWxvcG1lbnQ6IHtcbiAgICAgICAgICAgICAgdHNDb25maWc6IGAke3Byb2plY3RSb290fS90c2NvbmZpZy5saWIuanNvbmAsXG4gICAgICAgICAgICB9LFxuICAgICAgICAgIH0sXG4gICAgICAgIH0sXG4gICAgICAgIHRlc3Q6IHtcbiAgICAgICAgICBidWlsZGVyOiBCdWlsZGVycy5LYXJtYSxcbiAgICAgICAgICBvcHRpb25zOiB7XG4gICAgICAgICAgICB0c0NvbmZpZzogYCR7cHJvamVjdFJvb3R9L3RzY29uZmlnLnNwZWMuanNvbmAsXG4gICAgICAgICAgICBwb2x5ZmlsbHM6IFsnem9uZS5qcycsICd6b25lLmpzL3Rlc3RpbmcnXSxcbiAgICAgICAgICB9LFxuICAgICAgICB9LFxuICAgICAgfSxcbiAgICB9KTtcbiAgfSk7XG59XG5cbmV4cG9ydCBkZWZhdWx0IGZ1bmN0aW9uIChvcHRpb25zOiBMaWJyYXJ5T3B0aW9ucyk6IFJ1bGUge1xuICByZXR1cm4gYXN5bmMgKGhvc3Q6IFRyZWUpID0+IHtcbiAgICBjb25zdCBwcmVmaXggPSBvcHRpb25zLnByZWZpeDtcblxuICAgIC8vIElmIHNjb3BlZCBwcm9qZWN0IChpLmUuIFwiQGZvby9iYXJcIiksIGNvbnZlcnQgcHJvamVjdERpciB0byBcImZvby9iYXJcIi5cbiAgICBjb25zdCBwYWNrYWdlTmFtZSA9IG9wdGlvbnMubmFtZTtcbiAgICBpZiAoL15ALipcXC8uKi8udGVzdChvcHRpb25zLm5hbWUpKSB7XG4gICAgICBjb25zdCBbLCBuYW1lXSA9IG9wdGlvbnMubmFtZS5zcGxpdCgnLycpO1xuICAgICAgb3B0aW9ucy5uYW1lID0gbmFtZTtcbiAg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I6IGAke3ByZWZpeH0tJHtvcHRpb25zLm5hbWV9YCxcbiAgICAgICAgaW5saW5lU3R5bGU6IHRydWUsXG4gICAgICAgIGlubGluZVRlbXBsYXRlOiB0cnVlLFxuICAgICAgICBmbGF0OiB0cnVlLFxuICAgICAgICBwYXRoOiBzb3VyY2VEaXIsXG4gICAgICAgIGV4cG9ydDogdHJ1ZSxcbiAgICAgICAgc3RhbmRhbG9uZTogb3B0aW9ucy5zdGFuZGFsb25lLFxuICAgICAgICBwcm9qZWN0OiBwYWNrYWdlTmFtZSxcbiAgICAgIH0pLFxuICAgICAgc2NoZW1hdGljKCdzZXJ2aWNlJywge1xuICAgICAgICBuYW1lOiBvcHRpb25zLm5hbWUsXG4gICAgICAgIGZsYXQ6IHRydWUsXG4gICAgICAgIHBhdGg6IHNvdXJjZURpcixcbiAgICAgICAgcHJvamVjdDogcGFja2FnZU5hbWUsXG4gICAgICB9KSxcbiAgICAgIChfdHJlZTogVHJlZSwgY29udGV4dDogU2NoZW1hdGljQ29udGV4dCkgPT4ge1xuICAgICAgICBpZiAoIW9wdGlvbnMuc2tpcFBhY2thZ2VKc29uICYmICFvcHRpb25zLnNraXBJbnN0YWxsKSB7XG4gICAgICAgICAgY29udGV4dC5hZGRUYXNrKG5ldyBOb2RlUGFja2FnZUluc3RhbGxUYXNrKCkpO1xuICAgICAgICB9XG4gICAgICB9LFxuICAgIF0pO1xuICB9O1xufVxuIl19