-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
46 lines (39 loc) · 1.01 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
'use strict';
const fs = require('fs');
const path = require('path');
function walk(dir) {
const result = [];
const files = fs.readdirSync(dir);
for (const f of files) {
const file = path.resolve(dir, f);
if (fs.statSync(file).isDirectory()) {
result.push(...walk(file));
} else {
result.push(file);
}
}
return result;
}
const pairs = walk(path.resolve(__dirname, './src'))
.map(file => path.relative(path.resolve(__dirname, 'src'), file))
.map(file => {
const basename = path.basename(file, path.extname(file));
file = './' + file.substr(0, file.length - 3);
return [
file,
basename,
];
});
const names = [];
let index = '';
for (const [file, basename] of pairs) {
index += `import ${basename} from '${file}';\n`;
names.push(basename);
}
index += '\n';
index += 'export {\n';
for (const name of names) {
index += ` ${name},\n`;
}
index += '};\n';
console.log(index);