-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.js
49 lines (38 loc) · 1.16 KB
/
build.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 fs = require('fs');
const babel = require('@babel/core');
function fileExists(filename) {
let stats;
try {
stats = fs.statSync(filename);
} catch (e) {
return false;
}
return true;
}
const rootDir = __dirname;
let presets = JSON.parse(fs.readFileSync(rootDir + '/.babelrc', 'utf8'));
try {
fs.mkdirSync(rootDir + '/dist', 0o755);
} catch (err) {
}
['icon'].forEach(filename => {
// Transpile .js file
let source = rootDir + '/src/' + filename + '.js',
target = rootDir + '/dist/' + filename + '.js';
if (fileExists(source)) {
let code = fs.readFileSync(source),
result = babel.transform(code, presets);
fs.writeFileSync(target, result.code, 'utf8');
console.log('Transpiled', filename + '.js');
}
// Copy optional files
['.d.ts'].forEach(ext => {
let source = rootDir + '/src/' + filename + ext,
target = rootDir + '/dist/' + filename + ext;
if (fileExists(source)) {
fs.writeFileSync(target, fs.readFileSync(source, 'utf8'), 'utf8');
console.log('Copied', filename + ext);
}
});
});