-
Notifications
You must be signed in to change notification settings - Fork 1
/
bin.js
executable file
·74 lines (58 loc) · 1.53 KB
/
bin.js
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
#!/usr/bin/env node
const { argv, cwd } = process
const { join } = require('path')
const assert = require('assert')
const { readFileSync, writeFileSync } = require('fs')
const dent = require('endent')
const parse_args = require('minimist')
const Jseda = require('./')
const jseda = Jseda()
var args = parse_args(argv.slice(2))
var command_name = args._[0]
var input_file = args._[1]
var output_file = args._[2]
var commands = jseda
main()
function main () {
if (command_name == null || input_file == null || args.h || args.help) {
console.log(usage())
return
}
var command = commands[command_name]
if (command == null) {
console.error(`jseda: command not found: ${command_name}`)
return
}
if (command_name === 'json' || command_name === 'js') {
var input = readFileSync(input_file, 'utf8')
} else {
try {
var input = require(join(cwd(), input_file))
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
console.error(`jseda: input file not found: ${input_file}`)
console.log(usage())
return
} else {
throw err
}
}
}
var output = command(input)
if (output_file == null) {
console.log(output)
} else {
writeFileSync(output_file, output, 'utf8')
}
}
function usage () {
return dent`
jseda <command> <input_file> [<output_file>]
Commands:
- pcb
- json
Examples:
jseda pcb ./example/index.js ./example/example.kicad_pcb
jseda pcb ./example/index.js > ./exmple/example.kicad_pcb
`
}