-
Notifications
You must be signed in to change notification settings - Fork 21
/
command.js
executable file
·77 lines (70 loc) · 1.67 KB
/
command.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
75
76
77
#!/usr/bin/env node
const jsxbin = require( './index' )
const cmdArgs = require( 'command-line-args' )
const log = require( './src/logger' )
// Called from command line
const optionDefinitions = [
{ name: 'input', alias: 'i', type: String, multiple: true },
{ name: 'output', alias: 'o', type: String },
{ name: 'verbose', alias: 'v', type: Boolean },
{ name: 'debug', type: Boolean },
{ name: 'help', alias: 'h', type: Boolean }
]
const options = cmdArgs( optionDefinitions, { partial: true })
if ( options.verbose ) {
log.level = 'verbose'
}
if ( options.debug ) {
log.level = 'debug'
}
log.debug( 'options', { options })
if ( options.help ) {
showUsage()
} else {
if ( !options.input || !options.output ) {
showUsage()
}
jsxbin( options.input, options.output )
.catch( log.error )
}
function showUsage() {
const getUsage = require( 'command-line-usage' )
const sections = [
{
header: 'jsxbin',
content: 'Converts Extendscript .jsx files into jsxbin files using ExtendScript Toolkit'
},
{
header: 'Options',
optionList: [
{
name: 'input',
alias: 'i',
typeLabel: '{underline file(s)}',
description: 'The file or files to convert'
},
{
name: 'output',
alias: 'o',
typeLabel: '{underline file}|{underline folder}',
description: 'The file or folder where the converted file will be placed'
},
{
name: 'verbose',
alias: 'v',
description: 'Show more info while running'
},
{
name: 'debug',
description: 'Show even more info while running'
},
{
name: 'help',
alias: 'h',
description: 'Show this help'
}
]
}
]
console.log( getUsage( sections ) )
}