generate-taro-route.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 subpackages = await createConfig();
  26. fse.writeFileSync(
  27. taroConfig,
  28. `
  29. const subpackages = ${JSON.stringify(subpackages, null, 2)};\n
  30. export default {
  31. pages: ['pages/index/index'],
  32. subpackages,
  33. window: {
  34. backgroundTextStyle: 'light',
  35. navigationBarBackgroundColor: '#fff',
  36. navigationBarTitleText: 'NutUI',
  37. navigationBarTextStyle: 'black'
  38. }
  39. }`,
  40. 'utf8'
  41. );
  42. };
  43. create();