forked from 3d-dice/dice-box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copyAssets.js
48 lines (37 loc) · 1.38 KB
/
copyAssets.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
'use strict'
const copydir = require('copy-dir');
const path = require('path');
const fs = require('fs');
const readline = require('readline');
const { stdin: input, stdout: output } = require('process');
const { AbortController } = require('node-abort-controller'); //polyfill for Node <v14
const ac = new AbortController();
const signal = ac.signal;
const filesToCopy = './dist/assets'
let staticPath = '/public/assets'
// creat prompt asking for static folder
const rl = readline.createInterface({ input, output });
const writeFiles = (path) => {
// Creates directory if it doesn't exist
fs.mkdir(path, { recursive: true }, (err) => {
if (err) throw err;
// Moving files to user's local directory
copydir(filesToCopy, path, {
utimes: true, // keep add time and modify time
mode: true, // keep file mode
cover: true // cover file when exists, default is true
})
});
}
rl.question('Path to your static assets folder (press "Enter" for /public/assets): ', (answer) => {
answer = answer || staticPath
console.log(`Copying assets to: ${answer}`);
writeFiles(path.join(process.env.INIT_CWD,answer))
rl.close();
});
signal.addEventListener('abort', () => {
console.log(`Question timeout. Using default: ${staticPath}`);
writeFiles(path.join(process.env.INIT_CWD,staticPath))
rl.close();
}, { once: true });
setTimeout(() => ac.abort(), 10000);