Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
executable file
·
86 lines (68 loc) · 2.46 KB

File metadata and controls

executable file
·
86 lines (68 loc) · 2.46 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env node
'use strict'
const chalk = require('chalk')
const cmd = require('commander')
const fs = require('fs')
const readFile = require('fs-readfile-promise')
const writeFile = require('fs-writefile-promise')
const HTTPSnippet = require('..')
const path = require('path')
const pkg = require('../package.json')
cmd
.version(pkg.version)
.usage('[options] <files ...>')
.option('-t, --target <target>', 'target output')
.option('-c, --client [client]', 'target client library')
.option('-o, --output <directory>', 'write output to directory')
.parse(process.argv)
if (!cmd.args.length || !cmd.target) {
cmd.help()
}
let dir
if (cmd.output) {
dir = path.resolve(cmd.output)
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir)
}
}
cmd.args.forEach(function (fileName) {
const file = path.basename(fileName)
readFile(fileName)
.then(JSON.parse)
.catch(function (e) {
console.error('%s %s failed to read JSON: %s', chalk.red('✖'), chalk.cyan.bold(file), chalk.red(e.message))
})
.then(function (data) {
return new HTTPSnippet(data)
})
.catch(function (e) {
e.errors.forEach(function (err) {
console.error('%s %s failed validation: (%s: %s) %s', chalk.red('✖'), chalk.cyan.bold(file), chalk.cyan.italic(err.field), chalk.magenta.italic(err.value), chalk.red(err.message))
})
})
.then(function (snippet) {
return snippet.convert(cmd.target, cmd.client)
})
.then(function (output) {
if (!output) {
const targetNames = HTTPSnippet.availableTargets().map(function (t) { return t.key }).join(', ')
return console.error('%s %s is not a valid target. Valid targets: %s', chalk.red('✖'), chalk.red(cmd.target), chalk.cyan(targetNames))
}
// print
if (!cmd.output) {
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)
}
// write to file
const name = path.basename(file, path.extname(file))
const filename = path.format({
dir: dir,
base: name + HTTPSnippet.extname(cmd.target)
})
return writeFile(filename, output + '\n', function () {
console.log('%s %s > %s', chalk.green('✓'), chalk.cyan.bold(file), filename)
})
})
.catch(function (e) {
console.error('%s %s fail: %s', chalk.red('✖'), chalk.cyan.bold(file), chalk.red(e.message))
})
})
Morty Proxy This is a proxified and sanitized view of the page, visit original site.