docs-build.js 825 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env node
  2. var fs = require('fs')
  3. var marked = require('marked-man')
  4. var npm = require('../lib/npm.js')
  5. var args = process.argv.slice(2)
  6. var src = args[0]
  7. var dest = args[1] || src
  8. fs.readFile(src, 'utf8', function (err, data) {
  9. if (err) return console.log(err)
  10. function replacer (match, p1) {
  11. return 'npm help ' + p1.replace(/npm /, '')
  12. }
  13. var result = data.replace(/@VERSION@/g, npm.version)
  14. .replace(/^---([\s\S]+?)---/g, '')
  15. .replace(/\[([^\]]+)\]\(\/cli-commands\/([^)]+)\)/g, replacer)
  16. .replace(/\[([^\]]+)\]\(\/configuring-npm\/([^)]+)\)/g, replacer)
  17. .replace(/\[([^\]]+)\]\(\/using-npm\/([^)]+)\)/g, replacer)
  18. .replace(/(# .*)\s+(## (.*))/g, '$1 - $3')
  19. .trim()
  20. fs.writeFile(dest, marked(result), 'utf8', function (err) {
  21. if (err) return console.log(err)
  22. })
  23. })