forked from RussCoder/djvujs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.js
79 lines (68 loc) · 2.61 KB
/
.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const util = require('util');
const child_process = require('child_process');
const fs = require('fs');
const path = require('path');
function execute(command) {
return new Promise(resolve => {
const subProcess = child_process.exec(command, resolve);
subProcess.stdio.forEach((stream, i) => stream.pipe(process.stdout));
})
}
function copyFile(source, target) {
var rd = fs.createReadStream(source);
var wr = fs.createWriteStream(target);
return new Promise(function (resolve, reject) {
rd.on('error', reject);
wr.on('error', reject);
wr.on('finish', resolve);
rd.pipe(wr);
}).catch(function (error) {
rd.destroy();
wr.end();
throw error;
});
}
const buildFolder = 'build/';
const extensionFolder = 'extension/dist/'
if (!fs.existsSync(buildFolder)) {
fs.mkdirSync(buildFolder);
}
async function processFile(dir, destFile) {
const files = fs.readdirSync(dir);
for (const file of files) {
if (path.extname(file) === path.extname(destFile)) {
await copyFile(dir + file, buildFolder + destFile);
await copyFile(dir + file, extensionFolder + destFile);
}
}
}
function decorate(string) {
const line = '***************************************';
return `\n${line}\n\n${string}\n\n${line}\n`;
}
async function main() {
const viewerBuildDir = 'viewer/build/static/';
// const time = Date.now();
// console.log("The build process is running... Wait for a while, please.");
// const install = process.argv.includes('install') ? '& npm install' : '';
// const isOnlyLib = !!process.argv.includes('lib');
// // try {
// // await Promise.all([
// // isOnlyLib ? null : execute(`cd viewer ${install} & npm run build`, process.cwd() + '\\viewer')
// // .then(() => console.log(decorate('The Viewer is built!'))),
// // execute(`cd library ${install} & npm run build`, process.cwd() + '\\library')
// // .then(() => console.log(decorate('The Library is built!')))
// // ]);
// // } catch (e) {
// // console.error(decorate("The build process threw an error! Try to execute 'node build.js install'"));
// // console.error(e);
// // }
await Promise.all([
//processFile(viewerBuildDir + 'css/', 'djvu_viewer.css'),
processFile(viewerBuildDir + 'js/', 'djvu_viewer.js'),
processFile('library/dist/', 'djvu.js'),
]);
console.log('All files are copied to the ./build/ directory!');
//console.log('It has taken ', (Date.now() - time) / 1000, ' seconds.');
}
main();