make.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env node
  2. const fs = require('fs')
  3. const path = require('path')
  4. const ZH_CN = path.join(__dirname, '../zh_CN')
  5. const EN_US = path.join(__dirname, '../en_US')
  6. // [[match: regexp | fn | string, replace: regexp fn| string]]
  7. const replaceRule = [
  8. [
  9. '[English](README.md) | [简体中文](README-CN.md)',
  10. ''
  11. ],
  12. [
  13. '![arch](docs/resources/arch.png)',
  14. '![arch](../resources/arch.png)'
  15. ],
  16. [
  17. /]\(docs\/zh_CN\//gim,
  18. '](./'
  19. ],
  20. [
  21. /]\(docs\/en_US\//gim,
  22. '](./'
  23. ],
  24. [
  25. '(fvt_scripts/edgex/benchmark/pub.go)',
  26. 'https://github.com/emqx/kuiper/blob/master/fvt_scripts/edgex/pub.go'
  27. ],
  28. [
  29. '[Apache 2.0](LICENSE)',
  30. '[Apache 2.0](https://github.com/emqx/kuiper/blob/master/LICENSE)'
  31. ]
  32. ]
  33. const readmeMoveRule = [
  34. {
  35. from: path.join(__dirname, '../../README.md'),
  36. to: path.join(EN_US, './README.md'),
  37. },
  38. {
  39. from: path.join(__dirname, '../../README-CN.md'),
  40. to: path.join(ZH_CN, './README.md'),
  41. }
  42. ]
  43. function generateReadme() {
  44. readmeMoveRule.forEach(fileInfo => {
  45. const { from, to } = fileInfo
  46. // read
  47. let content = fs.readFileSync(from).toString()
  48. replaceRule.forEach(rule => {
  49. content = content.replace(rule[0], rule[1])
  50. })
  51. fs.writeFileSync(
  52. to,
  53. content,
  54. )
  55. console.log(`move ${from} to ${to}`)
  56. })
  57. }
  58. generateReadme()