copymd.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const computerBase = '';
  2. const vueBaseUrl = `${computerBase}..`;
  3. const reactBaseUrl = `${computerBase}nutui-react`;
  4. const fse = require('fs-extra');
  5. const copyFile = (from, to) => {
  6. fse
  7. .copy(from, to)
  8. .then(() => {
  9. console.log('success!>', to);
  10. })
  11. .catch((err) => {
  12. console.error(err);
  13. });
  14. };
  15. const copy = async (fromGit, type) => {
  16. let configPath = `src/config.json`;
  17. let configPkgPath = `package.json`;
  18. let nutuiDocsConfigPath = `docs/docs_${type}/config.json`;
  19. const exists = await fse.pathExists(configPath);
  20. console.log(exists, configPath);
  21. if (exists) {
  22. const fromConfig = await fse.readJson(configPath);
  23. const fromPkgConfig = await fse.readJson(configPkgPath);
  24. const docsConfig = await fse.readJson(nutuiDocsConfigPath);
  25. console.log(docsConfig);
  26. docsConfig.version = fromPkgConfig.version;
  27. docsConfig.nav = fromConfig.nav;
  28. docsConfig.docs = fromConfig.docs;
  29. console.log(fromConfig.docs);
  30. fse
  31. .writeJson(nutuiDocsConfigPath, docsConfig, {
  32. spaces: 2
  33. })
  34. .then(() => {
  35. console.log(`${docsConfig.version} success!`);
  36. });
  37. fromConfig.nav.forEach(({ packages }) => {
  38. packages.forEach((item) => {
  39. if (item.show) {
  40. let cmpName = item.name.toLowerCase();
  41. let docpath = `src/packages/__VUE/${cmpName}/doc.md`;
  42. if (type == 'react') {
  43. docpath = `${fromGit}/src/packages/${cmpName}/doc.md`;
  44. }
  45. let doctaropath = `src/packages/__VUE/${cmpName}/doc.taro.md`;
  46. fse.readFile(docpath, (err, data) => {
  47. if (!err) {
  48. copyFile(docpath, `docs/docs_${type}/docs/${cmpName}/doc.md`);
  49. }
  50. });
  51. fse.readFile(doctaropath, (err, data) => {
  52. if (!err) {
  53. copyFile(doctaropath, `docs/docs_${type}/docs/${cmpName}/doc.taro.md`);
  54. }
  55. });
  56. }
  57. });
  58. });
  59. }
  60. };
  61. // copy(reactBaseUrl, 'react');
  62. copy(vueBaseUrl, 'vue');