-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
98 lines (74 loc) · 1.75 KB
/
main.js
File metadata and controls
98 lines (74 loc) · 1.75 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
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
96
97
98
var Path = require('path');
var Fs = require('fs');
var Optimist = require('optimist');
var Util = require(__dirname + '/util');
var TASK_MAP = {
build : true,
min : true,
list : true,
cleanup : true,
check : true,
vm : true,
iconfont : true,
};
Optimist.usage([
'Usage: ytpm [COMMAND] --config=[CONFIG_FILE]\n\n',
'Examples:\n',
'ytpm src/js/g.js\n',
'ytpm src/css/g.less\n',
'ytpm min build/js/g.js\n',
'ytpm cleanup\n',
].join(''));
var ARGV = Optimist.argv;
if (ARGV.help || ARGV.h) {
Optimist.showHelp();
process.exit();
}
if (ARGV.version || ARGV.v) {
var packageInfo = JSON.parse(Util.readFileSync(__dirname + '/package.json', 'utf-8'));
console.log(packageInfo.version);
process.exit();
}
var cmd;
var args;
if (ARGV._.length > 0 && TASK_MAP[ARGV._[0]]) {
cmd = ARGV._[0];
args = ARGV._.slice(1);
} else {
cmd = 'build';
args = ARGV._;
}
var config = null;
var dirPath = args.length > 0 ? args[0] : '.';
if (!Fs.existsSync(dirPath)) {
dirPath = '.';
}
var dirStat = Fs.statSync(dirPath);
if (!dirStat.isDirectory()) {
dirPath = Path.dirname(dirPath);
}
dirPath = Path.resolve(dirPath);
var path = Util.undef(ARGV.config, './tpm-config.js');
path = Path.resolve(path);
if (Fs.existsSync(path)) {
config = require(path);
}else{
while (true) {
path = Path.resolve(dirPath + '/tpm-config.js');
if (Fs.existsSync(path)) {
config = require(path);
break;
}
var parentPath = Path.dirname(dirPath);
if (parentPath == dirPath) {
break;
}
dirPath = parentPath;
}
}
if (config === null) {
Util.error('File not found: tpm-config.js');
process.exit();
}
var Task = require(__dirname + '/tasks/' + cmd);
Task.run(args, config);