forked from jd-opensource/nutui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-taro-route.js
51 lines (43 loc) · 1.08 KB
/
generate-taro-route.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
const fse = require('fs-extra');
const config = require('../src/config.json');
const targetBaseUrl = `${process.cwd()}/src`;
const taroConfig = `${targetBaseUrl}/sites/mobile-taro/vue/src/app.config.ts`;
// 创建 config
const createConfig = async () => {
let configRef = [];
return new Promise((res, rej) => {
config.nav.map((item) => {
let co = {
root: item.enName,
pages: []
};
item.packages.map((it) => {
if (!(it.exportEmpty == false) && it.show) {
co.pages.push(`pages/${it.name.toLowerCase()}/index`);
}
});
configRef.push(co);
});
res(configRef);
});
};
const create = async () => {
const subpackages = await createConfig();
fse.writeFileSync(
taroConfig,
`
const subPackages = ${JSON.stringify(subpackages, null, 2)};\n
export default {
pages: ['pages/index/index'],
subPackages,
window: {
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: 'NutUI',
navigationBarTextStyle: 'black'
}
}`,
'utf8'
);
};
create();