forked from jd-opensource/nutui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-types.js
30 lines (29 loc) · 987 Bytes
/
generate-types.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
const config = require('../src/config.json');
const package = require('../package.json');
const path = require('path');
const fs = require('fs-extra');
let importStr = `import Locale from '../packages/locale';\n`;
const packages = [];
config.nav.map((item) => {
item.packages.forEach((element) => {
let { name, type } = element;
importStr += `import ${name} from './__VUE/${name.toLowerCase()}${type === 'methods' ? '' : '/index.vue'}';\n`;
packages.push(name);
});
});
let installFunction = `
export { Locale,${packages.join(',')} };`;
let fileStr = importStr + installFunction;
fs.outputFileSync(path.resolve(__dirname, '../dist/types/nutui.d.ts'), fileStr, 'utf8');
fs.outputFileSync(
path.resolve(__dirname, '../dist/types/index.d.ts'),
`declare namespace _default {
export { install };
export { version };
}
export function install(app: any): void;
export const version: '${package.version}';
export default _default;
export * from './nutui';`,
'utf8'
);