1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.copyAssets = void 0;
|
11 | const fs = require("fs");
|
12 | const glob = require("glob");
|
13 | const path = require("path");
|
14 | const copy_file_1 = require("./copy-file");
|
15 | function globAsync(pattern, options) {
|
16 | return new Promise((resolve, reject) => glob(pattern, options, (e, m) => (e ? reject(e) : resolve(m))));
|
17 | }
|
18 | async 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 | }
|
50 | exports.copyAssets = copyAssets;
|