generate-taro-route.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const fse = require('fs-extra');
  2. const config = require('../src/config.json');
  3. const targetBaseUrl = `${process.cwd()}/src`;
  4. const taroConfig = `${targetBaseUrl}/sites/mobile-taro/vue/src/app.config.ts`;
  5. // 创建 config
  6. const createConfig = async () => {
  7. let configRef = [];
  8. return new Promise((res, rej) => {
  9. config.nav.map((item) => {
  10. let co = {
  11. root: item.enName,
  12. pages: []
  13. };
  14. item.packages.map((it) => {
  15. if (!(it.exportEmpty == false) && it.show) {
  16. co.pages.push(`pages/${it.name.toLowerCase()}/index`);
  17. }
  18. });
  19. configRef.push(co);
  20. });
  21. res(configRef);
  22. });
  23. };
  24. const create = async () => {
  25. const configTemplate = {
  26. pages: ['pages/index/index'],
  27. subpackages: '',
  28. window: {
  29. backgroundTextStyle: 'light',
  30. navigationBarBackgroundColor: '#fff',
  31. navigationBarTitleText: 'NutUI',
  32. navigationBarTextStyle: 'black'
  33. }
  34. };
  35. configTemplate.subpackages = await createConfig();
  36. fse.writeFileSync(taroConfig, `export default ${JSON.stringify(configTemplate)}`, 'utf8');
  37. };
  38. create();