copyComponentMd.js 950 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import fse from 'fs-extra';
  2. import fs from 'fs';
  3. const copyFile = (from, to) => {
  4. fse
  5. .copy(from, to)
  6. .then(() => {
  7. console.log('success!>', to);
  8. })
  9. .catch((err) => {
  10. console.error(err);
  11. });
  12. };
  13. const copy = async () => {
  14. let configPath = `src/config.json`;
  15. // 复制所有组件
  16. const fromConfig = await fse.readJson(configPath);
  17. fromConfig.nav.forEach(({ packages }) => {
  18. packages.forEach((item) => {
  19. if (item.show) {
  20. let cmpName = item.name.toLowerCase();
  21. let docpath = `src/packages/__VUE/${cmpName}/doc.md`;
  22. let doctaropath = `src/packages/__VUE/${cmpName}/doc.taro.md`;
  23. fs.access(doctaropath, fs.constants.F_OK, (err) => {
  24. if (err) {
  25. fse.readFile(docpath, (err, data) => {
  26. if (!err) {
  27. copyFile(docpath, doctaropath);
  28. }
  29. });
  30. }
  31. });
  32. }
  33. });
  34. });
  35. };
  36. copy();