Skip to content

Commit 1f414c8

Browse files
committed
Add cli script
1 parent 3bafa10 commit 1f414c8

3 files changed

Lines changed: 43 additions & 30 deletions

File tree

bin/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env node
2+
3+
var fs = require('fs')
4+
var pdf = require('../')
5+
6+
var args = process.argv.slice(2)
7+
8+
if (args.length >= 2) {
9+
htmlpdf(args[0], args[1])
10+
} else {
11+
help()
12+
}
13+
14+
function help () {
15+
var help = [
16+
'Usage: html-pdf <source> <destination>',
17+
'e.g.: html-pdf source.html destination.pdf'
18+
].join('\n')
19+
20+
console.log(help)
21+
}
22+
23+
function htmlpdf (source, destination) {
24+
var html = fs.readFileSync(source, 'utf8')
25+
pdf.create(html).toFile(destination, function (err, res) {
26+
if (err) throw err
27+
})
28+
}

cli/index.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

package.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@
77
"test": "test"
88
},
99
"bin": {
10-
"htmlpdf": "cli/index.js"
10+
"html-pdf": "bin/index.js"
1111
},
1212
"scripts": {
13-
"test": "coffee --compile --output lib/ src/ && coffee test/index.coffee -n"
13+
"build": "coffee --compile --output lib/ src/",
14+
"standard": "standard bin/index.js",
15+
"exectest": "coffee test/index.coffee -n",
16+
"test": "npm run standard && npm run build && npm run exectest"
1417
},
1518
"author": "Marc Bachmann",
1619
"license": "MIT",
1720
"devDependencies": {
1821
"coffee-script": "^1.7.1",
19-
"tape": "^3.4.0",
20-
"tap-spec": "^2.2.0"
22+
"standard": "^5.1.1",
23+
"tap-spec": "^2.2.0",
24+
"tape": "^3.4.0"
2125
},
2226
"optionalDependencies": {
2327
"phantomjs": "^1.9.16"
@@ -26,7 +30,13 @@
2630
"type": "git",
2731
"url": "git://github.com/marcbachmann/node-html-pdf.git"
2832
},
29-
"keywords": ["html", "pdf", "phantom", "phantomjs", "nodejs"],
33+
"keywords": [
34+
"html",
35+
"pdf",
36+
"phantom",
37+
"phantomjs",
38+
"nodejs"
39+
],
3040
"bugs": {
3141
"url": "https://github.com/marcbachmann/node-html-pdf/issues"
3242
},

0 commit comments

Comments
 (0)