-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd.js
More file actions
47 lines (40 loc) · 1.13 KB
/
Copy pathcmd.js
File metadata and controls
47 lines (40 loc) · 1.13 KB
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
var compiler = require('./src/compiler'),
commander = require('commander'),
path = require('path'),
fs = require('fs');
commander
.version('0.1.0')
.usage('<file ...> [options]')
.option('-o, --output', 'Specify output file')
.parse(process.argv);
if ( commander.args.length == 0 ) {
console.log('Please specify input file...');
process.exit(0);
}
var fileName = commander.args[0],
outputFileName = commander.output || path.basename(fileName,'.js') + '.output.js',
fileContent,
outputFileContent;
try {
fileContent = fs.readFileSync(fileName,{
encoding: 'utf-8'
});
} catch ( e ) {
console.log('Couldn\'t read "' + fileName + '"...');
process.exit(0);
}
outputFileContent = compiler.compile(fileName,fileContent);
if ( outputFileContent === null ) {
console.log('Couldn\'t compile "' + fileName + '":');
console.log(compiler.getLastError());
process.exit(0);
}
try {
fs.writeFileSync(outputFileName,outputFileContent,{
encoding : 'utf-8'
});
} catch ( e ) {
console.log('Couldn\'t write file...');
process.exit(0);
}
process.exit(1);