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

141 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 latest_versions_1 = require("../utility/latest-versions");
const ng_ast_utils_1 = require("../utility/ng-ast-utils");
const paths_1 = require("../utility/paths");
const project_targets_1 = require("../utility/project-targets");
const workspace_1 = require("../utility/workspace");
const workspace_models_1 = require("../utility/workspace-models");
function updateConfigFile(options, tsConfigDirectory) {
return (0, workspace_1.updateWorkspace)((workspace) => {
const clientProject = workspace.projects.get(options.project);
if (clientProject) {
// In case the browser builder hashes the assets
// we need to add this setting to the server builder
// as otherwise when assets it will be requested twice.
// One for the server which will be unhashed, and other on the client which will be hashed.
const getServerOptions = (options = {}) => {
return {
buildOptimizer: options?.buildOptimizer,
outputHashing: options?.outputHashing === 'all' ? 'media' : options?.outputHashing,
fileReplacements: options?.fileReplacements,
optimization: options?.optimization === undefined ? undefined : !!options?.optimization,
sourceMap: options?.sourceMap,
localization: options?.localization,
stylePreprocessorOptions: options?.stylePreprocessorOptions,
resourcesOutputPath: options?.resourcesOutputPath,
deployUrl: options?.deployUrl,
i18nMissingTranslation: options?.i18nMissingTranslation,
preserveSymlinks: options?.preserveSymlinks,
extractLicenses: options?.extractLicenses,
inlineStyleLanguage: options?.inlineStyleLanguage,
vendorChunk: options?.vendorChunk,
};
};
const buildTarget = clientProject.targets.get('build');
if (buildTarget?.options) {
buildTarget.options.outputPath = `dist/${options.project}/browser`;
}
const buildConfigurations = buildTarget?.configurations;
const configurations = {};
if (buildConfigurations) {
for (const [key, options] of Object.entries(buildConfigurations)) {
configurations[key] = getServerOptions(options);
}
}
const mainPath = options.main;
const sourceRoot = clientProject.sourceRoot ?? (0, core_1.join)((0, core_1.normalize)(clientProject.root), 'src');
const serverTsConfig = (0, core_1.join)(tsConfigDirectory, 'tsconfig.server.json');
clientProject.targets.add({
name: 'server',
builder: workspace_models_1.Builders.Server,
defaultConfiguration: 'production',
options: {
outputPath: `dist/${options.project}/server`,
main: (0, core_1.join)((0, core_1.normalize)(sourceRoot), mainPath.endsWith('.ts') ? mainPath : mainPath + '.ts'),
tsConfig: serverTsConfig,
...(buildTarget?.options ? getServerOptions(buildTarget?.options) : {}),
},
configurations,
});
}
});
}
function addDependencies() {
return (host) => {
const coreDep = (0, dependencies_1.getPackageJsonDependency)(host, '@angular/core');
if (coreDep === null) {
throw new schematics_1.SchematicsException('Could not find version.');
}
const platformServerDep = {
...coreDep,
name: '@angular/platform-server',
};
(0, dependencies_1.addPackageJsonDependency)(host, platformServerDep);
(0, dependencies_1.addPackageJsonDependency)(host, {
type: dependencies_1.NodeDependencyType.Dev,
name: '@types/node',
version: latest_versions_1.latestVersions['@types/node'],
});
};
}
function default_1(options) {
return async (host, context) => {
const workspace = await (0, workspace_1.getWorkspace)(host);
const clientProject = workspace.projects.get(options.project);
if (!clientProject || clientProject.extensions.projectType !== 'application') {
throw new schematics_1.SchematicsException(`Universal requires a project type of "application".`);
}
const clientBuildTarget = clientProject.targets.get('build');
if (!clientBuildTarget) {
throw (0, project_targets_1.targetBuildNotFoundError)();
}
const clientBuildOptions = (clientBuildTarget.options ||
{});
if (!options.skipInstall) {
context.addTask(new tasks_1.NodePackageInstallTask());
}
const isStandalone = (0, ng_ast_utils_1.isStandaloneApp)(host, clientBuildOptions.main);
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)(isStandalone ? './files/standalone-src' : './files/src'), [
(0, schematics_1.applyTemplates)({
...schematics_1.strings,
...options,
stripTsExtension: (s) => s.replace(/\.ts$/, ''),
}),
(0, schematics_1.move)((0, core_1.join)((0, core_1.normalize)(clientProject.root), 'src')),
]);
const clientTsConfig = (0, core_1.normalize)(clientBuildOptions.tsConfig);
const tsConfigExtends = (0, core_1.basename)(clientTsConfig);
const tsConfigDirectory = (0, core_1.dirname)(clientTsConfig);
const rootSource = (0, schematics_1.apply)((0, schematics_1.url)('./files/root'), [
(0, schematics_1.applyTemplates)({
...schematics_1.strings,
...options,
stripTsExtension: (s) => s.replace(/\.ts$/, ''),
tsConfigExtends,
hasLocalizePackage: !!(0, dependencies_1.getPackageJsonDependency)(host, '@angular/localize'),
relativePathToWorkspaceRoot: (0, paths_1.relativePathToWorkspaceRoot)(tsConfigDirectory),
}),
(0, schematics_1.move)(tsConfigDirectory),
]);
return (0, schematics_1.chain)([
(0, schematics_1.mergeWith)(templateSource),
(0, schematics_1.mergeWith)(rootSource),
addDependencies(),
updateConfigFile(options, tsConfigDirectory),
]);
};
}
exports.default = default_1;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9zY2hlbWF0aWNzL2FuZ3VsYXIvdW5pdmVyc2FsL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7O0dBTUc7O0FBRUgsK0NBQTJGO0FBQzNGLDJEQVlvQztBQUNwQyw0REFBMEU7QUFDMUUsMERBSWlDO0FBQ2pDLGdFQUE0RDtBQUM1RCwwREFBMEQ7QUFDMUQsNENBQStEO0FBQy9ELGdFQUFzRTtBQUN0RSxvREFBcUU7QUFDckUsa0VBQThFO0FBRzlFLFNBQVMsZ0JBQWdCLENBQUMsT0FBeUIsRUFBRSxpQkFBdUI7SUFDMUUsT0FBTyxJQUFBLDJCQUFlLEVBQUMsQ0FBQyxTQUFTLEVBQUUsRUFBRTtRQUNuQyxNQUFNLGFBQWEsR0FBRyxTQUFTLENBQUMsUUFBUSxDQUFDLEdBQUcsQ0FBQyxPQUFPLEN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