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
·
80 lines (63 loc) · 2.16 KB

File metadata and controls

executable file
·
80 lines (63 loc) · 2.16 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
#!/usr/bin/env node
'use strict'
var chalk = require('chalk')
var cmd = require('commander')
var fs = require('fs')
var readFile = require('fs-readfile-promise')
var writeFile = require('fs-writefile-promise')
var HTTPSnippet = require('..')
var path = require('path')
var 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()
}
if (cmd.output) {
var dir = path.resolve(cmd.output)
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir)
}
}
cmd.args.forEach(function (fileName) {
var 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) {
// 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
var name = path.basename(file, path.extname(file))
var 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.