Permalink
Fetching contributors…
Cannot retrieve contributors at this time
90 lines (73 sloc) 2.09 KB
#!/usr/bin/env node
var Path = require('path');
var Fs = require('fs');
var async = require('async');
var spawn = require('child_process').spawn;
var confirm = require('../lib/utils').confirm;
var fs = require('../lib/fs');
var mkdir = fs.mkdir;
var copy = fs.copy;
var walk = fs.walk;
var find = fs.find;
var remove = fs.remove;
var node = process.execPath;
var root = process.cwd() + Path.sep;
var modRoot = Path.join(__dirname, '..') + Path.sep;
var eol = require('os').EOL;
var sep = Path.sep;
var version = require('../package').version;
require('colors');
var App = require('commander');
App.command('create')
.description('create new katana application')
.action(function(name) {
if (arguments.length < 2) {
name = null;
}
var path = Path.join(root, name || '');
confirm(' Create app at '+ path.blue +' ? ', function(error, ok) {
if (!ok) { return; }
// TOOD: check if directory already exists and remove on confirmation?
async.series([
function(next) {
copy(Path.join(__dirname, '..', 'template'), path, next);
},
function(next) {
var paths = [
'app/config/production',
'app/models',
'public/images',
'public/scripts',
'public/css',
'modules',
'temp/files'
].map(function(dir) {
return Path.join(path, dir);
});
async.each(paths, mkdir, next);
},
function(next) {
var pack = {
name: 'app',
version: '0.0.1',
dependencies: {
katana: version,
joose: '*',
ejs: '*'
},
katana: {
modules: {}
}
};
Fs.writeFile(Path.join(path, 'package.json'), JSON.stringify(pack, null, 2), next);
}
], function(error) {
if (error) {
return console.log(error);
}
console.log(' Done!'.green, 'Your new app is at', path.blue +'.');
console.log(' Run', '"npm install"'.blue, 'under app root to install dependencies.');
});
});
});
App.parse(process.argv);