Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 83 lines (68 sloc) 1.8 KB
#!/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
});