forked from tidev/node-appc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forge
executable file
·64 lines (55 loc) · 1.6 KB
/
forge
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
#!/usr/bin/env node
/**
* forge - make-like tool
*
* @copyright
* Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved.
*
* @license
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
var toolsDir = './forge-tools',
spawn = require('child_process').spawn,
fs = require('fs'),
path = require('path'),
colors = require('colors');
global.which = function which(program, fn) {
if (process.platform == 'win32') {
fn(); // no 'which' on windows
} else {
spawn('which', [ program ]).on('exit', fn);
}
};
global.rootDir = __dirname;
var tools = {};
fs.readdirSync(toolsDir = path.resolve(toolsDir)).forEach(function (name) {
var m, file = path.join(toolsDir, name);
if (!fs.existsSync(file)) return;
if (fs.statSync(file).isDirectory()) {
if (fs.existsSync(m = path.join(file, 'index.js'))) {
tools[name] = m;
}
} else if (m = name.match(/^(?!\.|_)(.+)\.js$/)) {
tools[m[1]] = file;
}
});
function help(err) {
console.log('Forge'.cyan.bold + ' - Copyright (c) 2012-' + (new Date).getFullYear() + ', Appcelerator, Inc. All Rights Reserved.\n');
console.log('Usage: ' + 'forge <tool> [options]'.cyan + '\n');
err && console.error(err.red + '\n');
console.error('Available tools:');
Object.keys(tools).sort().forEach(function (t) {
console.log(' ' + t.cyan);
});
console.log();
process.exit(err ? 1 : 0);
}
var args = process.argv.slice(2),
tool = args.shift();
if (tool && !tools[tool]) {
help('ERROR: Invalid tool "' + tool + '"');
} else if (!tool) {
help();
}
require(tools[tool]).apply(null, args);