This repository has been archived by the owner on Jan 27, 2018. It is now read-only.
forked from dcodeIO/ClosureCompiler.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ccjs
95 lines (87 loc) · 3.48 KB
/
ccjs
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env node
/*
Copyright 2013 Daniel Wirtz <dcode@dcode.io>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* ClosureCompiler.js: ccjs Command Line Utility (c) 2013 Daniel Wirtz <dcode@dcode.io>
* Released under the Apache License, Version 2.0
* see: https://github.com/dcodeIO/ClosureCompiler.js for details
*/
var pkg = require(__dirname+"/../package.json"),
ClosureCompiler = require(__dirname+"/../ClosureCompiler.js"),
path = require("path");
if (process.argv.length < 3) {
console.error("ClosureCompiler.js "+pkg.version+" - https://github.com/dcodeIO/ClosureCompiler.js\n");
console.error(" Usage: "+path.basename(process.argv[1])+" sourceFiles ... [--option=value --flagOption ...] [> outFile]");
process.exit(1);
}
var files = [];
var options = null;
var help = false;
for (var i=2; i<process.argv.length; i++) {
var arg = process.argv[i];
if (arg.substring(0,2) == '--') {
arg = arg.substring(2);
if (!options) options = {};
arg = arg.split("=", 2);
arg[0] = arg[0].toLowerCase();
if (arg[0] == "help") help = true;
if (arg.length == 2) {
if (typeof options[arg[0]] == 'undefined') options[arg[0]] = [];
if (!(options[arg[0]] instanceof Array)) {
console.error("\n Option used as flag and later as assignment: "+arg[0]+"\n");
process.exit(5);
}
options[arg[0]].push(arg[1]);
} else {
if (typeof options[arg[0]] != 'undefined') {
if (options[arg[0]] instanceof Array) {
console.error("\n Option used as assignment and later as flag: "+arg[0]+"\n");
process.exit(5);
} else {
console.error("\n Duplicate flag option: "+arg[0]+"\n");
}
process.exit(4);
}
options[arg[0]] = true;
}
} else if (arg.substring(0,1) == "-") {
console.error("\n Illegal option: "+arg+" (\"--\" expected)\n");
process.exit(2);
} else {
if (options) {
console.error("\n Illegal source file after options: "+arg+"\n");
process.exit(3);
}
if (files.indexOf(arg) >= 0) {
console.error("\n Duplicate source file: "+arg+"\n");
}
files.push(arg);
}
}
// Run it
ClosureCompiler.compile(files, options, function(error, result) {
if (help && typeof error == 'string') {
error = error.replace(/(\-\-[a-zA-Z0-9_]+) ([^ ])/g, function($, $1, $2) {
return $1+"="+$2;
});
console.error("ClosureCompiler.js "+pkg.version+" - https://github.com/dcodeIO/ClosureCompiler.js\n");
console.error(" Usage: "+path.basename(process.argv[1])+" sourceFiles ... [--option=value --flagOption ...] [> outFile]\n");
console.error(error);
process.exit(1);
}
if (error instanceof Error) {
throw(error);
}
process.stderr.write(error);
process.stdout.write(result);
});