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