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

141 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 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9zY2hlbWF0aWNzL2FuZ3VsYXIvdW5pdmVyc2FsL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7O0dBTUc7O0FBRUgsK0NBQTJGO0FBQzNGLDJEQVlvQztBQUNwQyw0REFBMEU7QUFDMUUsMERBSWlDO0FBQ2pDLGdFQUE0RDtBQUM1RCwwREFBMEQ7QUFDMUQsNENBQStEO0FBQy9ELGdFQUFzRTtBQUN0RSxvREFBcUU7QUFDckUsa0VBQThFO0FBRzlFLFNBQVMsZ0JBQWdCLENBQUMsT0FBeUIsRUFBRSxpQkFBdUI7SUFDMUUsT0FBTyxJQUFBLDJCQUFlLEVBQUMsQ0FBQyxTQUFTLEVBQUUsRUFBRTtRQUNuQyxNQUFNLGFBQWEsR0FBRyxTQUFTLENBQUMsUUFBUSxD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