mirror of
https://github.com/thinkjs/thinkjs.git
synced 2026-01-18 14:26:56 +00:00
add bin file
This commit is contained in:
parent
3cb6328801
commit
bbb7bcd41a
69
bin/index.js
Normal file
69
bin/index.js
Normal 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);
|
||||
16
package.json
16
package.json
@ -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
5
template/.thinkjsrc
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
createAt: "<createAt>",
|
||||
mode: "<mode>",
|
||||
es6: "<es6>"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user