104 lines
17 KiB
JavaScript
104 lines
17 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 schematics_1 = require("@angular-devkit/schematics");
|
|
const utility_1 = require("@schematics/angular/utility");
|
|
const path_1 = require("path");
|
|
const ENVIRONMENTS_DIRECTORY = 'environments';
|
|
const ENVIRONMENT_FILE_CONTENT = 'export const environment = {};\n';
|
|
function default_1(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 type = project.extensions['projectType'];
|
|
if (type !== 'application') {
|
|
return log('error', 'Only application project types are support by this schematic.' + type
|
|
? ` Project "${options.project}" has a "projectType" of "${type}".`
|
|
: ` Project "${options.project}" has no "projectType" defined.`);
|
|
}
|
|
const buildTarget = project.targets.get('build');
|
|
if (!buildTarget) {
|
|
return log('error', `No "build" target found for project "${options.project}".` +
|
|
' A "build" target is required to generate environment files.');
|
|
}
|
|
const serverTarget = project.targets.get('server');
|
|
const sourceRoot = project.sourceRoot ?? path_1.posix.join(project.root, 'src');
|
|
// The generator needs to be iterated prior to returning to ensure all workspace changes that occur
|
|
// within the generator are present for `updateWorkspace` when it writes the workspace file.
|
|
return (0, schematics_1.chain)([
|
|
...generateConfigurationEnvironments(buildTarget, serverTarget, sourceRoot, options.project),
|
|
]);
|
|
});
|
|
}
|
|
exports.default = default_1;
|
|
function createIfMissing(path) {
|
|
return (tree, context) => {
|
|
if (tree.exists(path)) {
|
|
context.logger.info(`Skipping creation of already existing environment file "${path}".`);
|
|
}
|
|
else {
|
|
tree.create(path, ENVIRONMENT_FILE_CONTENT);
|
|
}
|
|
};
|
|
}
|
|
function log(type, text) {
|
|
return (_, context) => context.logger[type](text);
|
|
}
|
|
function* generateConfigurationEnvironments(buildTarget, serverTarget, sourceRoot, projectName) {
|
|
if (!buildTarget.builder.startsWith(utility_1.AngularBuilder.Browser)) {
|
|
yield log('warn', `"build" target found for project "${projectName}" has a third-party builder "${buildTarget.builder}".` +
|
|
' The generated project options may not be compatible with this builder.');
|
|
}
|
|
if (serverTarget && !serverTarget.builder.startsWith(utility_1.AngularBuilder.Server)) {
|
|
yield log('warn', `"server" target found for project "${projectName}" has a third-party builder "${buildTarget.builder}".` +
|
|
' The generated project options may not be compatible with this builder.');
|
|
}
|
|
// Create default environment file
|
|
const defaultFilePath = path_1.posix.join(sourceRoot, ENVIRONMENTS_DIRECTORY, 'environment.ts');
|
|
yield createIfMissing(defaultFilePath);
|
|
const configurationEntries = [
|
|
...Object.entries(buildTarget.configurations ?? {}),
|
|
...Object.entries(serverTarget?.configurations ?? {}),
|
|
];
|
|
const addedFiles = new Set();
|
|
for (const [name, configurationOptions] of configurationEntries) {
|
|
if (!configurationOptions) {
|
|
// Invalid configuration
|
|
continue;
|
|
}
|
|
// Default configuration will use the default environment file
|
|
if (name === buildTarget.defaultConfiguration) {
|
|
continue;
|
|
}
|
|
const configurationFilePath = path_1.posix.join(sourceRoot, ENVIRONMENTS_DIRECTORY, `environment.${name}.ts`);
|
|
// Add file replacement option entry for the configuration environment file
|
|
const replacements = (configurationOptions['fileReplacements'] ?? (configurationOptions['fileReplacements'] = []));
|
|
const existing = replacements.find((value) => value.replace === defaultFilePath);
|
|
if (existing) {
|
|
if (existing.with === configurationFilePath) {
|
|
yield log('info', `Skipping addition of already existing file replacements option for "${defaultFilePath}" to "${configurationFilePath}".`);
|
|
}
|
|
else {
|
|
yield log('warn', `Configuration "${name}" has a file replacements option for "${defaultFilePath}" but with a different replacement.` +
|
|
` Expected "${configurationFilePath}" but found "${existing.with}". This may result in unexpected build behavior.`);
|
|
}
|
|
}
|
|
else {
|
|
replacements.push({ replace: defaultFilePath, with: configurationFilePath });
|
|
}
|
|
// Create configuration specific environment file if not already added
|
|
if (!addedFiles.has(configurationFilePath)) {
|
|
addedFiles.add(configurationFilePath);
|
|
yield createIfMissing(configurationFilePath);
|
|
}
|
|
}
|
|
}
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9zY2hlbWF0aWNzL2FuZ3VsYXIvZW52aXJvbm1lbnRzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7O0dBTUc7O0FBRUgsMkRBQThFO0FBQzlFLHlEQUFnRztBQUNoRywrQkFBcUM7QUFHckMsTUFBTSxzQkFBc0IsR0FBRyxjQUFjLENBQUM7QUFDOUMsTUFBTSx3QkFBd0IsR0FBRyxrQ0FBa0MsQ0FBQztBQUVwRSxtQkFBeUIsT0FBMkI7SUFDbEQsT0FBTyxJQUFBLHlCQUFlLEVBQUMsQ0FBQyxTQUFTLEVBQUUsRUFBRTtRQUNuQyxNQUFNLE9BQU8sR0FBRyxTQUFTLENBQUMsUUFBUSxDQUFDLEdBQUcsQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDeEQsSUFBSSxDQUFDLE9BQU8sRUFBRTtZQUNaLE1BQU0sSUFBSSxnQ0FBbUIsQ0FBQyxpQkFBaUIsT0FBTyxDQUFDLE9BQU8sc0JBQXNCLENBQUMsQ0FBQztTQUN2RjtRQUVELE1BQU0sSUFBSSxHQUFHLE9BQU8sQ0FBQyxVQUFVLENBQUMsYUFBYSxDQUFDLENBQUM7UUFDL0MsSUFBSSxJQUFJLEtBQUssYUFBYSxFQUFFO1lBQzFCLE9BQU8sR0FBRyxDQUNSLE9BQU8sRUFDUCwrREFBK0QsR0FBRyxJQUFJO2dCQUNwRSxDQUFDLENBQUMsYUFBY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