From bbb7bcd41a98291d59e60c0cf4cf703f640dd7cd Mon Sep 17 00:00:00 2001 From: welefen Date: Mon, 10 Aug 2015 10:54:25 +0800 Subject: [PATCH] add bin file --- bin/index.js | 69 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 16 ++++++----- template/.thinkjsrc | 5 ++++ 3 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 bin/index.js create mode 100644 template/.thinkjsrc diff --git a/bin/index.js b/bin/index.js new file mode 100644 index 00000000..c63de046 --- /dev/null +++ b/bin/index.js @@ -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] '); +program.option('-e, --es6', 'use es6 for project, in `new` command'); +program.option('-m, --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 ').description('create project').action(function(projectPath){ + createProject(projectPath); +}); + +//create module +program.command('module ').description('add module').action(function(module){ + +}); + +//create controlelr +program.command('controller ').description('add controller').action(function(controller){ + +}); + +//create model +program.command('model ').description('add model').action(function(model){ + +}); + +program.parse(process.argv); \ No newline at end of file diff --git a/package.json b/package.json index 683d7d13..f4bf869f 100644 --- a/package.json +++ b/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", diff --git a/template/.thinkjsrc b/template/.thinkjsrc new file mode 100644 index 00000000..6810e55a --- /dev/null +++ b/template/.thinkjsrc @@ -0,0 +1,5 @@ +{ + createAt: "", + mode: "", + es6: "" +} \ No newline at end of file