UNPKG

1.88 kBJavaScriptView Raw
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.copyAssets = void 0;
11const fs = require("fs");
12const glob = require("glob");
13const path = require("path");
14const copy_file_1 = require("./copy-file");
15function globAsync(pattern, options) {
16 return new Promise((resolve, reject) => glob(pattern, options, (e, m) => (e ? reject(e) : resolve(m))));
17}
18async function copyAssets(entries, basePaths, root, changed) {
19 const defaultIgnore = ['.gitkeep', '**/.DS_Store', '**/Thumbs.db'];
20 for (const entry of entries) {
21 const cwd = path.resolve(root, entry.input);
22 const files = await globAsync(entry.glob, {
23 cwd,
24 dot: true,
25 nodir: true,
26 ignore: entry.ignore ? defaultIgnore.concat(entry.ignore) : defaultIgnore,
27 follow: entry.followSymlinks,
28 });
29 const directoryExists = new Set();
30 for (const file of files) {
31 const src = path.join(cwd, file);
32 if (changed && !changed.has(src)) {
33 continue;
34 }
35 const filePath = entry.flatten ? path.basename(file) : file;
36 for (const base of basePaths) {
37 const dest = path.join(base, entry.output, filePath);
38 const dir = path.dirname(dest);
39 if (!directoryExists.has(dir)) {
40 if (!fs.existsSync(dir)) {
41 fs.mkdirSync(dir, { recursive: true });
42 }
43 directoryExists.add(dir);
44 }
45 copy_file_1.copyFile(src, dest);
46 }
47 }
48 }
49}
50exports.copyAssets = copyAssets;