-
Notifications
You must be signed in to change notification settings - Fork 40
/
dts-bundle.js
67 lines (59 loc) · 1.77 KB
/
dts-bundle.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
#!/usr/bin/env node
/**
* @File : dts-bundle.js
* @Author : dtysky (dtysky@outlook.com)
* @Date : 12/3/2018, 3:53:54 PM
* @Description:
*/
const fs = require('fs');
const path = require('path');
const dts = require('dts-bundle');
const rimraf = require('rimraf');
const package = require('./package.json');
const header = `/*!
* @license Sein.js v${package.version}
* Copyright (c) 2018-present SeinJS Group.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
`;
function walk(dir, callback) {
const files = fs.readdirSync(dir);
files.forEach(file => {
const filepath = path.join(dir, file);
const stats = fs.statSync(filepath);
callback(filepath, stats.isDirectory());
});
}
dts.bundle({
name: 'seinjs',
main: 'lib/index.d.ts'
});
walk('./lib', (fp, isDir) => {
if (isDir) {
rimraf.sync(fp);
return;
}
if (fp === 'lib/index.d.ts') {
rimraf.sync(fp);
return;
}
if (/\.js$/.test(fp)) {
let content = fs.readFileSync(fp, {encoding: 'utf8'});
content = content.replace(/\\n\s+/g, '\\n');
fs.writeFileSync(fp, header + content);
}
});
let res = header + fs.readFileSync('./lib/seinjs.d.ts', {encoding: 'utf8'}) + '\n\n';
res = res.replace(`declare module 'seinjs/index//hilo3d'`, `module 'hilo3d'`);
const hiloDTS = fs.readFileSync('./Hilo3d/types/index.d.ts', {encoding: 'utf8'})
.replace('export = hilo3d;', '')
.replace('export as namespace hilo3d;', '')
.replace('declare namespace hilo3d', "declare module 'hilo3d'");
let axiosDTS = fs.readFileSync('./node_modules/axios/index.d.ts', {encoding: 'utf8'})
.replace('export default Axios;', '');
axiosDTS = "declare module 'axios' {\n" + axiosDTS + '};\n';
res += hiloDTS;
res += axiosDTS;
fs.writeFileSync('./lib/seinjs.d.ts', res);