Skip to content

Commit

Permalink
feat(docs): replace docs sh script with node
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiahdz committed Nov 4, 2019
1 parent fa91c4e commit 11a339c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
27 changes: 0 additions & 27 deletions scripts/doc-build.sh

This file was deleted.

32 changes: 32 additions & 0 deletions scripts/docs-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env node

var fs = require('fs')
var marked = require('marked-man')
var npm = require('../lib/npm.js')
var args = process.argv.slice(2)
var src = args[0]
var dest = args[1] || src

fs.readFile(src, 'utf8', function (err, data) {
if (err) return console.log(err)

var fileExt = src.split('.').pop()
var result = data.replace(/@VERSION@/g, npm.version)

if (fileExt === 'md') {
result = marked(
result.replace(/\-\-\-([\s\S]+)\-\-\-/g, '')
.replace(/(npm-)?([a-zA-Z\\\.\-]*)\(1\)/g, 'npm help $2')
.replace(/(npm-)?([a-zA-Z\\\.\-]*)\((5|7)\)/g, 'npm help $2')
.replace(/(npm-)?([a-zA-Z\\\.\-]*)\(3\)/g, 'npm apihelp $2')
.replace(/npm(1)/g, 'npm help npm')
.replace(/npm(3)/g, 'npm apihelp npm')
.trim()
)
}

fs.writeFile(dest, result, 'utf8', function (err) {
if (err) return console.log(err)
})

})

0 comments on commit 11a339c

Please sign in to comment.