forked from tidev/alloy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalloy.js
executable file
·108 lines (90 loc) · 3.51 KB
/
alloy.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
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
99
100
101
102
103
104
105
106
107
108
/**
* Alloy
* Copyright (c) 2012 by Appcelerator, Inc. All Rights Reserved.
* See LICENSE for more information on licensing.
*/
var program = require('commander'),
logger = require("./common/logger"),
U = require('./utils'),
colors = require("colors"),
_ = require("./lib/alloy/underscore")._,
pkginfo = require('pkginfo'),
path = require('path'),
fs = require('fs');
// patch to remove the warning in node >=0.8
path.existsSync = fs.existsSync || path.existsSync;
// setup our module so have the pkginfo version from package.json
pkginfo(module,'name','version');
// TODO: improve help - https://jira.appcelerator.org/browse/ALOY-207
////////////////////////////////////
////////// MAIN EXECUTION //////////
////////////////////////////////////
// Process command line input
program
.version(module.exports.version)
.description('Alloy command line')
.usage('COMMAND [ARGS] [OPTIONS]')
.option('-a, --allStackTrace', 'No limit to the size of stack traces')
.option('-o, --outputPath <outputPath>', 'Output path for generated code')
.option('-l, --logLevel <logLevel>', 'Log level (default: 3 [DEBUG])')
.option('-f, --force','Force the command to execute')
.option('-n, --no-colors','Turn off colors')
.option('-c, --config <config>','Pass in compiler configuration')
.option('-s, --tiSDK <tiSDK>', 'Full path to Titanium SDK to use with run command')
.option('-t, --tiversion <tiversion>', 'Titanium SDK version used for run command');
program.command('new'.blue+' <dir>'.white)
.description(' create a new alloy project'.grey);
program.command('compile'.blue+' [dir]'.white)
.description('compile into titanium sourcecode'.grey);
program.command('run'.blue+' [dir] [platform]'.white)
.description('compile and run alloy. defaults to iphone'.grey);
program.command('generate'.blue+' <type> <name>'.white)
.description(' generate a new alloy type such as a controller'.grey);
program.parse(process.argv);
// Setup up logging output
//if (program.allStackTrace) { Error.stackTraceLimit = Infinity; }
Error.stackTraceLimit = Infinity;
logger.stripColors = program['colors'] === false;
banner();
if (program.args.length === 0)
{
var help = program.helpInformation();
help = help.replace('Usage: alloy COMMAND [ARGS] [OPTIONS]','Usage: '+'alloy'.blue+' COMMAND'.white+' [ARGS] [OPTIONS]'.grey);
help = logger.stripColors ? colors.stripColors(help) : help;
console.log(help);
process.exit(1);
}
// Validate the given command
var command = program.args[0];
if (!_.contains(getCommands(), command)) {
U.die('Unknown command: ' + command.red);
}
// Launch command with given arguments and options
(require('./commands/' + command + '/index'))(program.args.slice(1), program);
///////////////////////////////
////////// FUNCTIONS //////////
///////////////////////////////
function banner() {
var str =
" .__ .__ \n"+
"_____ | | | | ____ ___.__.\n"+
"\\__ \\ | | | | / _ < | |\n"+
" / __ \\| |_| |_( <_> )___ |\n"+
"(____ /____/____/\\____// ____|\n"+
" \\/ \\/";
if (!program.dump) {
console.log(logger.stripColors ? str : str.blue);
var m = "Alloy by Appcelerator. The MVC app framework for Titanium.\n".white;
console.log(logger.stripColors ? colors.stripColors(m) : m);
}
}
function getCommands() {
try {
var commandsPath = path.join(__dirname,'commands');
return _.filter(fs.readdirSync(commandsPath), function(file) {
return path.existsSync(path.join(commandsPath,file,'index.js'));
});
} catch (e) {
U.die('Error getting command list', e);
}
}