-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcopy-to-deploy-folder.js
53 lines (43 loc) · 1.31 KB
/
copy-to-deploy-folder.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
const fs = require('fs');
const path = require('path');
const os = require('os');
const fse = require('fs-extra');
let filesToCopy = ['package.json', 'yarn.lock'];
let foldersToCopy = ['dist'];
function copyFile(src, dest) {
let readStream = fs.createReadStream(src);
readStream.once('error', err => {
console.log(err);
});
readStream.once('end', () => {
console.log('done copying');
});
readStream.pipe(fs.createWriteStream(dest));
}
let pathFolder;
if (os.platform() == 'win32') {
// Windows
pathFolder = __dirname.split('\\');
} else {
// Linux / MacOS
pathFolder = __dirname.split('/');
}
let folderLength = pathFolder.length;
let currentFolder = pathFolder[folderLength - parseInt(1)];
filesToCopy.forEach(file => {
let src = path.join(__dirname, file);
let destDir = path.join('..', currentFolder + '-deploy');
fs.access(destDir, err => {
if (err) console.log('error', err);
copyFile(src, path.join(destDir, file));
});
});
foldersToCopy.forEach(folder => {
let src = path.join(__dirname, folder);
let destDir = path.join('..', currentFolder + '-deploy', folder);
fse.removeSync(destDir);
fse.copy(src, destDir, err => {
if (err) console.log(err);
console.log(`successfully moved ${folder}`);
});
});