source: trip-planner-front/node_modules/@angular-devkit/build-angular/src/utils/normalize-asset-patterns.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.7 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.normalizeAssetPatterns = exports.MissingAssetSourceRootException = void 0;
11const core_1 = require("@angular-devkit/core");
12const fs_1 = require("fs");
13class MissingAssetSourceRootException extends core_1.BaseException {
14 constructor(path) {
15 super(`The ${path} asset path must start with the project source root.`);
16 }
17}
18exports.MissingAssetSourceRootException = MissingAssetSourceRootException;
19function normalizeAssetPatterns(assetPatterns, root, projectRoot, maybeSourceRoot) {
20 // When sourceRoot is not available, we default to ${projectRoot}/src.
21 const sourceRoot = maybeSourceRoot || core_1.join(projectRoot, 'src');
22 const resolvedSourceRoot = core_1.resolve(root, sourceRoot);
23 if (assetPatterns.length === 0) {
24 return [];
25 }
26 return assetPatterns.map((assetPattern) => {
27 // Normalize string asset patterns to objects.
28 if (typeof assetPattern === 'string') {
29 const assetPath = core_1.normalize(assetPattern);
30 const resolvedAssetPath = core_1.resolve(root, assetPath);
31 // Check if the string asset is within sourceRoot.
32 if (!resolvedAssetPath.startsWith(resolvedSourceRoot)) {
33 throw new MissingAssetSourceRootException(assetPattern);
34 }
35 let glob, input;
36 let isDirectory = false;
37 try {
38 isDirectory = fs_1.statSync(core_1.getSystemPath(resolvedAssetPath)).isDirectory();
39 }
40 catch {
41 isDirectory = true;
42 }
43 if (isDirectory) {
44 // Folders get a recursive star glob.
45 glob = '**/*';
46 // Input directory is their original path.
47 input = assetPath;
48 }
49 else {
50 // Files are their own glob.
51 glob = core_1.basename(assetPath);
52 // Input directory is their original dirname.
53 input = core_1.dirname(assetPath);
54 }
55 // Output directory for both is the relative path from source root to input.
56 const output = core_1.relative(resolvedSourceRoot, core_1.resolve(root, input));
57 // Return the asset pattern in object format.
58 return { glob, input, output };
59 }
60 else {
61 // It's already an AssetPatternObject, no need to convert.
62 return assetPattern;
63 }
64 });
65}
66exports.normalizeAssetPatterns = normalizeAssetPatterns;
Note: See TracBrowser for help on using the repository browser.