copymd.js 1.7 KB

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