-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathcli.js
executable file
·48 lines (43 loc) · 1.12 KB
/
cli.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
#!/usr/bin/env node
'use strict';
var fs = require('fs');
var HTMLtoJSX = require('./htmltojsx.js');
var yargs = require('yargs');
function getArgs() {
var args = yargs
.usage(
'Converts HTML to JSX for use with React.\n' +
'Usage: $0 [-c ComponentName] file.htm'
)
.describe('className', 'Create a React component (wraps JSX in React.createClass call)')
.alias('className', 'c')
.help('help')
.example(
'$0 -c AwesomeComponent awesome.htm',
'Creates React component "AwesomeComponent" based on awesome.htm'
)
.strict();
var files = args.argv._;
if (!files || files.length === 0) {
console.error('Please provide a file name');
args.showHelp();
process.exit(1);
}
return args.argv;
}
function main() {
var argv = getArgs();
fs.readFile(argv._[0], 'utf-8', function(err, input) {
if (err) {
console.error(err.stack);
process.exit(2);
}
var converter = new HTMLtoJSX({
createClass: !!argv.className,
outputClassName: argv.className
});
var output = converter.convert(input);
console.log(output);
});
}
main();