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

71 lines
10 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 schematics_1 = require("@angular-devkit/schematics");
const utility_1 = require("@schematics/angular/utility");
const path_1 = require("path");
const paths_1 = require("../utility/paths");
const schema_1 = require("./schema");
function default_1(options) {
switch (options.type) {
case schema_1.Type.Karma:
return addKarmaConfig(options);
case schema_1.Type.Browserslist:
return addBrowserslistConfig(options);
default:
throw new schematics_1.SchematicsException(`"${options.type}" is an unknown configuration file type.`);
}
}
exports.default = default_1;
function addBrowserslistConfig(options) {
return async (host) => {
const workspace = await (0, utility_1.readWorkspace)(host);
const project = workspace.projects.get(options.project);
if (!project) {
throw new schematics_1.SchematicsException(`Project name "${options.project}" doesn't not exist.`);
}
return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
(0, schematics_1.filter)((p) => p.endsWith('.browserslistrc.template')),
(0, schematics_1.applyTemplates)({}),
(0, schematics_1.move)(project.root),
]));
};
}
function addKarmaConfig(options) {
return (0, utility_1.updateWorkspace)((workspace) => {
const project = workspace.projects.get(options.project);
if (!project) {
throw new schematics_1.SchematicsException(`Project name "${options.project}" doesn't not exist.`);
}
const testTarget = project.targets.get('test');
if (!testTarget) {
throw new schematics_1.SchematicsException(`No "test" target found for project "${options.project}".` +
' A "test" target is required to generate a karma configuration.');
}
if (testTarget.builder !== utility_1.AngularBuilder.Karma) {
throw new schematics_1.SchematicsException(`Cannot add a karma configuration as builder for "test" target in project does not use "${utility_1.AngularBuilder.Karma}".`);
}
testTarget.options ?? (testTarget.options = {});
testTarget.options.karmaConfig = path_1.posix.join(project.root, 'karma.conf.js');
// If scoped project (i.e. "@foo/bar"), convert dir to "foo/bar".
let folderName = options.project.startsWith('@') ? options.project.slice(1) : options.project;
if (/[A-Z]/.test(folderName)) {
folderName = schematics_1.strings.dasherize(folderName);
}
return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [
(0, schematics_1.filter)((p) => p.endsWith('karma.conf.js.template')),
(0, schematics_1.applyTemplates)({
relativePathToWorkspaceRoot: (0, paths_1.relativePathToWorkspaceRoot)(project.root),
folderName,
}),
(0, schematics_1.move)(project.root),
]));
});
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9zY2hlbWF0aWNzL2FuZ3VsYXIvY29uZmlnL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7O0dBTUc7O0FBRUgsMkRBVW9DO0FBQ3BDLHlEQUE2RjtBQUM3RiwrQkFBcUM7QUFDckMsNENBQStEO0FBQy9ELHFDQUF1RTtBQUV2RSxtQkFBeUIsT0FBc0I7SUFDN0MsUUFBUSxPQUFPLENBQUMsSUFBSSxFQUFFO1FBQ3BCLEtBQUssYUFBVSxDQUFDLEtBQUs7WUFDbkIsT0FBTyxjQUFjLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDakMsS0FBSyxhQUFVLENBQUMsWUFBWTtZQUMxQixPQUFPLHFCQUFxQixDQUFDLE9BQU8sQ0FBQyxDQUFDO1FBQ3hDO1lBQ0UsTUFBTSxJQUFJLGdDQUFtQixDQUFDLElBQUksT0FBTyxDQUFDLElBQUksMENBQTBDLENBQUMsQ0FBQztLQUM3RjtBQUNILENBQUM7QUFURCw0QkFTQztBQUVELFNBQVMscUJBQXFCLENBQUMsT0FBc0I7SUFDbkQsT0FBTyxLQUFLLEVBQUUsSUFBSSxFQUFFLEVBQUU7UUFDcEIsTUFBTSxTQUFTLEdBQUcsTUFBTSx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