forked from jd-opensource/nutui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-nutui.js
39 lines (39 loc) · 1.06 KB
/
generate-nutui.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
const package = require('../package.json');
const config = require('../src/config.json');
const path = require('path');
const fs = require('fs-extra');
let importStr = `import { App } from 'vue';\n`;
const packages = [];
config.nav.map(item => {
item.packages.forEach(element => {
let { name, show, type } = element;
if (show) {
importStr += `import ${name} from './packages/${name.toLowerCase()}/index${
type === 'methods' ? '' : '.vue'
}';\n`;
packages.push(name);
}
});
});
let installFunction = `function install(app: App) {
const packages = [${packages.join(',')}];
packages.forEach((item:any) => {
if (item.install) {
app.use(item);
} else if (item.name) {
app.component(item.name, item);
}
});
}`;
let fileStr = `${importStr}
${installFunction}
export { ${packages.join(',')} };
export default { install, version:'${package.version}'};`;
fs.outputFile(
path.resolve(__dirname, '../src/nutui.ts'),
fileStr,
'utf8',
error => {
// logger.success(`${package_config_path} 文件写入成功`);
}
);