-
Notifications
You must be signed in to change notification settings - Fork 11
/
ace
executable file
·83 lines (68 loc) · 1.8 KB
/
ace
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
#!/usr/bin/env node
var path = require('path'),
fs = require('fs'),
App = require('../lib/index').App,
optimist = require('optimist');
// Use local ace module if available
if (fs.existsSync('./node_modules/.bin/ace') && !global.local) {
global.local = true;
return require('module')._load('./node_modules/.bin/ace');
}
try {
require('coffee-script');
} catch(e) { }
var copy = function(from, to){
var data = fs.readFileSync(from, 'utf8');
fs.writeFileSync(to, data, 'utf8');
};
var argv = optimist.usage([
' usage: ace COMMAND [PATH]',
' new generate a new application',
' server start the server',
].join("\n"))
.alias('p', 'port')
.argv;
var command = argv._[0];
var filename = argv._[1];
if (filename) {
filename = path.resolve(filename);
}
if (command === 'new' && filename) {
fs.mkdirSync(filename, 0775);
fs.mkdirSync(filename + '/public', 0775);
fs.mkdirSync(filename + '/views', 0775);
var generatorPath = path.join(
__dirname, '..', 'generators'
);
copy(path.join(generatorPath, 'package.json'),
path.join(filename, 'package.json'));
copy(path.join(generatorPath, 'app.coffee'),
path.join(filename, 'app.coffee'));
copy(path.join(generatorPath, 'layout.eco'),
path.join(filename, 'views', 'layout.eco'));
console.log('Generated: ' + filename);
return;
}
if ( !filename ) {
try {
filename = require.resolve(path.resolve('app'));
} catch (e) {}
}
if ( !filename ) {
try {
filename = require.resolve(path.resolve('index'));
} catch (e) {}
}
if ( !filename ) {
console.log("Ace usage:");
console.log("\tace new PATH");
console.log("\tace server PATH");
return;
}
process.chdir(path.dirname(filename));
var app = new App;
global.app = app;
require(filename);
app.serve({
port: process.env.PORT || argv.port
});