copymd.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const targetBaseUrl = 'site_docs';
  2. const fse = require('fs-extra');
  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. let configPkgPath = `package.json`;
  16. let nutuiDocsConfigPath = `${targetBaseUrl}/config.json`;
  17. const exists = await fse.pathExists(configPath);
  18. if (exists) {
  19. const fromConfig = await fse.readJson(configPath);
  20. const fromPkgConfig = await fse.readJson(configPkgPath);
  21. const docsConfig = await fse.readJson(nutuiDocsConfigPath);
  22. docsConfig.version = fromPkgConfig.version;
  23. docsConfig.nav = fromConfig.nav;
  24. docsConfig.docs = fromConfig.docs;
  25. fse
  26. .writeJson(nutuiDocsConfigPath, docsConfig, {
  27. spaces: 2
  28. })
  29. .then(() => {
  30. console.log(`${docsConfig.version} success!`);
  31. });
  32. fromConfig.nav.forEach(({ packages }) => {
  33. packages.forEach((item) => {
  34. if (item.show) {
  35. let cmpName = item.name.toLowerCase();
  36. let docpath = `src/packages/__VUE/${cmpName}/doc.md`;
  37. let doctaropath = `src/packages/__VUE/${cmpName}/doc.taro.md`;
  38. fse.readFile(docpath, (err, data) => {
  39. if (!err) {
  40. copyFile(docpath, `${targetBaseUrl}/docs/${cmpName}/doc.md`);
  41. }
  42. });
  43. fse.readFile(doctaropath, (err, data) => {
  44. if (!err) {
  45. copyFile(doctaropath, `${targetBaseUrl}/docs/${cmpName}/doc.taro.md`);
  46. }
  47. });
  48. }
  49. });
  50. });
  51. }
  52. };
  53. // copy(reactBaseUrl, 'react');
  54. copy();