add bin file

This commit is contained in:
welefen 2015-08-10 10:54:25 +08:00
parent 3cb6328801
commit bbb7bcd41a
3 changed files with 83 additions and 7 deletions

69
bin/index.js Normal file
View File

@ -0,0 +1,69 @@
'use strict';
var fs = require('fs');
var path = require('path');
var program = require('commander');
require('../lib/core/think.js');
var modeType = 'module';
var modeTypeList = ['mini', 'normal', 'module'];
/**
* get version
* @return {String} []
*/
var getVersion = function(){
var filepath = path.normalize(__dirname + '/../package.json');
var version = JSON.parse(fs.readFileSync(filepath)).version;
return version;
};
/**
* create project
* @param {String} projectPath []
* @return {} []
*/
var createProject = function(projectPath){
if(think.isDir(projectPath)){
var filepath = projectPath + '/.thinkjsrc';
if(think.isFile(filepath)){
console.log('path `' + projectPath + '` is already thinkjs project.');
return;
}
}
};
program.version(getVersion()).usage('[command] <options ...>');
program.option('-e, --es6', 'use es6 for project, in `new` command');
program.option('-m, --mode <mode>', 'project mode type, in `new` command', function(mode){
if(modeTypeList.indexOf(mode) === -1){
throw new Error('mode value must one of mini,normal,module');
}
modeType = mode;
});
//create project
program.command('new <projectPath>').description('create project').action(function(projectPath){
createProject(projectPath);
});
//create module
program.command('module <moduleName>').description('add module').action(function(module){
});
//create controlelr
program.command('controller <controllerName>').description('add controller').action(function(controller){
});
//create model
program.command('model <modelName>').description('add model').action(function(model){
});
program.parse(process.argv);

View File

@ -13,12 +13,13 @@
"watch-compile": "npm run compile -- --watch",
"prepublish": "npm run compile"
},
"contributors": [
{
"name": "welefen",
"email": "welefen@gmail.com"
}
],
"bin": {
"thinkjs": "./bin/index.js"
},
"contributors": [{
"name": "welefen",
"email": "welefen@gmail.com"
}],
"main": "lib/index.js",
"dependencies": {
"swig": "1.4.2",
@ -36,7 +37,8 @@
"mocha": "1.20.1",
"muk": "0.3.1",
"istanbul": "*",
"babel": "*"
"babel": "*",
"commander": ""
},
"keywords": [
"thinkjs",

5
template/.thinkjsrc Normal file
View File

@ -0,0 +1,5 @@
{
createAt: "<createAt>",
mode: "<mode>",
es6: "<es6>"
}