forked from JulianG/react-list-drag-and-drop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-lib.js
73 lines (62 loc) · 1.45 KB
/
build-lib.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
const exec = require('child_process').exec;
const glob = require('glob');
const fs = require('fs');
console.log('running build-lib.js...');
exec('tsc -p tsconfig-lib.json', (err, stdout, stderr) => {
if (err == null) {
console.log('success!');
console.log(stdout);
copyCSSFiles();
} else {
console.error(err);
console.error(stdout);
console.error(stderr);
}
});
function copyCSSFiles() {
const config = require('./tsconfig-lib.json');
const outDir = config['compilerOptions']['outDir'];
console.assert(outDir);
const tsxGlob = config['include'][0];
const cssGlob = tsxGlob.replace('.tsx', '.css');
console.log('copying css files to lib...');
glob(cssGlob, {}, (er, files) => {
if (!er) {
console.assert(files.length > 0);
files.forEach(file => {
const dest = file.replace('./src', outDir);
copyFile(file, dest, (err) => {
if (err) {
console.warn(`problem copying ${file} to ${dest}`);
console.error(err);
} else {
console.log(`copied ${file} to ${dest}`);
}
});
});
} else {
console.error(er);
}
});
}
function copyFile(source, target, cb) {
var cbCalled = false;
var rd = fs.createReadStream(source);
rd.on("error", function (err) {
done(err);
});
var wr = fs.createWriteStream(target);
wr.on("error", function (err) {
done(err);
});
wr.on("close", function (ex) {
done();
});
rd.pipe(wr);
function done(err) {
if (!cbCalled) {
cb(err);
cbCalled = true;
}
}
}