Skip to content

Commit 69a4b51

Browse files
committed
Merge commit '7fd160c016d7b00aca923673004dcdcf4b5a0068' into sahar/update-pkg
# Conflicts: # package.json # src/index.js # src/targets/node/native.js # src/targets/node/unirest.js
2 parents 47981e3 + 7fd160c commit 69a4b51

File tree

176 files changed

+3653
-2343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+3653
-2343
lines changed

.jshintrc

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

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
.jshintrc
21
.editorconfig
32
test

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ language: node_js
33
node_js:
44
- node
55
- lts/*
6-
- 8
76

87
before_install:
98
- sudo apt-get update -qq

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ npm install --save httpsnippet
2323

2424
```
2525
26-
Usage: httpsnippet [options] <file>
26+
Usage: httpsnippet [options] <files ...>
2727
2828
Options:
2929
@@ -32,6 +32,7 @@ npm install --save httpsnippet
3232
-t, --target <target> target output
3333
-c, --client [client] target client library
3434
-o, --output <directory> write output to directory
35+
-x, --extra [{"optionKey": "optionValue"}] provide extra options for the target/client
3536
3637
```
3738

@@ -63,6 +64,13 @@ snippets/
6364
└── endpoint-3.js
6465
```
6566

67+
provide extra options:
68+
69+
```shell
70+
httpsnippet example.json --target http --output ./snippets -x '{"autoHost": false, "autoContentLength": false}'
71+
```
72+
73+
6674
## API
6775

6876
### HTTPSnippet(source)

bin/httpsnippet

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,49 @@
22

33
'use strict'
44

5-
var chalk = require('chalk')
6-
var cmd = require('commander')
7-
var fs = require('fs')
8-
var readFile = require('fs-readfile-promise')
9-
var writeFile = require('fs-writefile-promise')
10-
var HTTPSnippet = require('..')
11-
var path = require('path')
12-
var pkg = require('../package.json')
5+
const chalk = require('chalk')
6+
const cmd = require('commander')
7+
const fs = require('fs')
8+
const readFile = require('fs-readfile-promise')
9+
const writeFile = require('fs-writefile-promise')
10+
const HTTPSnippet = require('..')
11+
const path = require('path')
12+
const pkg = require('../package.json')
1313

1414
cmd
1515
.version(pkg.version)
1616
.usage('[options] <files ...>')
1717
.option('-t, --target <target>', 'target output')
1818
.option('-c, --client [client]', 'target client library')
1919
.option('-o, --output <directory>', 'write output to directory')
20+
.option('-x, --extra [{"optionKey": "optionValue"}]', 'provide extra options for the target/client')
2021
.parse(process.argv)
2122

2223
if (!cmd.args.length || !cmd.target) {
2324
cmd.help()
2425
}
2526

27+
let extraOptions
28+
if (cmd.extra) {
29+
try {
30+
extraOptions = JSON.parse(cmd.extra)
31+
} catch (e) {
32+
console.error('%s failed to parse options %s (should be JSON)', chalk.red('✖'), chalk.cyan.bold(cmd.extra))
33+
process.exit()
34+
}
35+
}
36+
37+
let dir
2638
if (cmd.output) {
27-
var dir = path.resolve(cmd.output)
39+
dir = path.resolve(cmd.output)
2840

2941
if (!fs.existsSync(dir)) {
3042
fs.mkdirSync(dir)
3143
}
3244
}
3345

3446
cmd.args.forEach(function (fileName) {
35-
var file = path.basename(fileName)
47+
const file = path.basename(fileName)
3648

3749
readFile(fileName)
3850
.then(JSON.parse)
@@ -52,19 +64,24 @@ cmd.args.forEach(function (fileName) {
5264
})
5365

5466
.then(function (snippet) {
55-
return snippet.convert(cmd.target, cmd.client)
67+
return snippet.convert(cmd.target, cmd.client, extraOptions)
5668
})
5769

5870
.then(function (output) {
71+
if (!output) {
72+
const targetNames = HTTPSnippet.availableTargets().map(function (t) { return t.key }).join(', ')
73+
return console.error('%s %s is not a valid target. Valid targets: %s', chalk.red('✖'), chalk.red(cmd.target), chalk.cyan(targetNames))
74+
}
75+
5976
// print
6077
if (!cmd.output) {
6178
return console.log('%s %s > %s [%s] :\n%s', chalk.green('✓'), chalk.cyan.bold(file), chalk.yellow(cmd.target), chalk.yellow(cmd.client ? cmd.client : 'default'), output)
6279
}
6380

6481
// write to file
65-
var name = path.basename(file, path.extname(file))
82+
const name = path.basename(file, path.extname(file))
6683

67-
var filename = path.format({
84+
const filename = path.format({
6885
dir: dir,
6986
base: name + HTTPSnippet.extname(cmd.target)
7087
})

0 commit comments

Comments
 (0)