-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathoptions.ts
74 lines (69 loc) · 2.68 KB
/
options.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @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
*/
import { BuilderContext } from '@angular-devkit/architect';
import * as path from 'path';
import { normalizeAssetPatterns, normalizeOptimization, normalizeSourceMaps } from '../../utils';
import { Schema as BrowserBuilderOptions, OutputHashing } from '../browser/schema';
/**
* Normalize the user provided options by creating full paths for all path based options
* and converting multi-form options into a single form that can be directly used
* by the build process.
*
* @param context The context for current builder execution.
* @param projectName The name of the project for the current execution.
* @param options An object containing the options to use for the build.
* @returns An object containing normalized options required to perform the build.
*/
export async function normalizeOptions(
context: BuilderContext,
projectName: string,
options: BrowserBuilderOptions,
) {
const workspaceRoot = context.workspaceRoot;
const projectMetadata = await context.getProjectMetadata(projectName);
const projectRoot = path.join(workspaceRoot, (projectMetadata.root as string | undefined) ?? '');
const projectSourceRoot = path.join(
workspaceRoot,
(projectMetadata.sourceRoot as string | undefined) ?? 'src',
);
// Normalize options
const mainEntryPoint = path.join(workspaceRoot, options.main);
const polyfillsEntryPoint = options.polyfills && path.join(workspaceRoot, options.polyfills);
const tsconfig = path.join(workspaceRoot, options.tsConfig);
const outputPath = path.join(workspaceRoot, options.outputPath);
const optimizationOptions = normalizeOptimization(options.optimization);
const sourcemapOptions = normalizeSourceMaps(options.sourceMap ?? false);
const assets = options.assets?.length
? normalizeAssetPatterns(options.assets, workspaceRoot, projectRoot, projectSourceRoot)
: undefined;
const outputNames = {
bundles:
options.outputHashing === OutputHashing.All || options.outputHashing === OutputHashing.Bundles
? '[name].[hash]'
: '[name]',
media:
options.outputHashing === OutputHashing.All || options.outputHashing === OutputHashing.Media
? '[name].[hash]'
: '[name]',
};
if (options.resourcesOutputPath) {
outputNames.media = path.join(options.resourcesOutputPath, outputNames.media);
}
return {
workspaceRoot,
mainEntryPoint,
polyfillsEntryPoint,
optimizationOptions,
outputPath,
sourcemapOptions,
tsconfig,
projectRoot,
assets,
outputNames,
};
}