-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
angular-cli_utils.js
55 lines (47 loc) · 1.48 KB
/
angular-cli_utils.js
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
import fs from 'fs';
import { basename, dirname, normalize, relative, resolve } from '@angular-devkit/core';
function isDirectory(assetPath) {
try {
return fs.statSync(assetPath).isDirectory();
} catch (e) {
return false;
}
}
function getAssetsParts(resolvedAssetPath, assetPath) {
if (isDirectory(resolvedAssetPath)) {
return {
glob: '**/*', // Folders get a recursive star glob.
input: assetPath, // Input directory is their original path.
};
}
return {
glob: basename(assetPath), // Files are their own glob.
input: dirname(assetPath), // Input directory is their original dirname.
};
}
export function isBuildAngularInstalled() {
try {
require.resolve('@angular-devkit/build-angular');
return true;
} catch (e) {
return false;
}
}
export function normalizeAssetPatterns(assetPatterns, dirToSearch, sourceRoot) {
if (!assetPatterns || !assetPatterns.length) {
return [];
}
return assetPatterns.map(assetPattern => {
const assetPath = normalize(assetPattern);
const resolvedSourceRoot = resolve(dirToSearch, sourceRoot);
const resolvedAssetPath = resolve(dirToSearch, assetPath);
const parts = getAssetsParts(resolvedAssetPath, assetPath);
// Output directory for both is the relative path from source root to input.
const output = relative(resolvedSourceRoot, resolve(dirToSearch, parts.input));
// Return the asset pattern in object format.
return {
...parts,
output,
};
});
}