From 205286df1a175953c2e7960f2aadf42ac5129874 Mon Sep 17 00:00:00 2001 From: wchen Date: Thu, 28 May 2015 16:44:34 +0800 Subject: [PATCH 1/3] =?UTF-8?q?bugfix:=20=E9=A1=B9=E7=9B=AE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E6=A3=80=E6=B5=8B=E7=9A=84=E5=A4=84=E7=90=86=E4=B8=8D?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 项目类型检测导致很多命令会提前检测当前关联的应用,会导致应用提前失败。 所以修改为必要时才执行。 --- bin/avoscloud | 201 +++++++++++++++++++++++++++----------------------- 1 file changed, 109 insertions(+), 92 deletions(-) diff --git a/bin/avoscloud b/bin/avoscloud index e9e1361..0954712 100755 --- a/bin/avoscloud +++ b/bin/avoscloud @@ -73,22 +73,69 @@ run.queryLatestVersion(); run.sendStats(CMD); //Execute command. -// 不需要在项目目录执行的命令 if(CMD) { switch (CMD) { - case "search": + case 'new': + run.createNewProject(callback); + break; + + case "deploy": + run.logProjectHome(); + if (program.git) { + run.deployGitCloudCode(program.revision || 'master', program.giturl, callback); + } else { + if (path.resolve(CLOUD_PATH) != path.resolve('.')) + return exitWith("'avoscloud deploy' 命令必须在 LeanEngine 项目目录中使用"); + runtime.detect(CLOUD_PATH, function(err, runtimeInfo) { + if (err) { + return callback(err); + } + run.deployLocalCloudCode(runtimeInfo, CLOUD_PATH, program.log, callback); + }); + } + break; + + case "undeploy": + run.logProjectHome(); + run.undeployCloudCode(callback); + break; + + case "publish": + run.logProjectHome(); + run.publishCloudCode(callback); + break; + + case "status": + run.logProjectHome(); + run.queryStatus(callback); + break; + + case 'logs': + run.logProjectHome(); + run.viewCloudLog(program.lines, program.tailf, null, callback); + break; + + case "upload": + run.initAVOSCloudSDK(); + run.logProjectHome(); if (!program.args[1]) { - console.log("请使用:avoscloud search <关键字>"); + console.log("请使用:avoscloud upload <文件或目录>"); process.exit(1); } program.args.shift(); - exec('open https://leancloud.cn/search.html?q=' + encodeURIComponent(program.args.join(' '))); - return callback(); - case 'new': - return run.createNewProject(callback); - case "clear": - run.deleteMasterKeys(); - return callback(); + run.importFiles(program.args, function(err) { + if (err) + console.log(err); + }, callback); + break; + + case "app": + //app + var isList = program.args[1] == 'list'; + run.appStatus(isList); + callback(); + break; + case "add": // add var name = program.args[1]; @@ -98,96 +145,66 @@ if(CMD) { if (!appId) return exitWith("请使用:avoscloud add "); run.addApp(name, appId); - return callback(); + callback(); + break; + + case "rm": + //rm + var name = program.args[1]; + if (!name) + return exitWith("请使用:avoscloud rm "); + run.removeApp(name); + callback(); + break; + + case "checkout": + //checkout + var name = program.args[1]; + if (!name) + return exitWith("请使用:avoscloud checkout "); + run.checkoutApp(name); + callback(); + break; + + case "cql": + run.doCloudQuery(callback); + break; + + case "clear": + run.deleteMasterKeys(); + callback(); + break; + + case "search": + if (!program.args[1]) { + console.log("请使用:avoscloud search <关键字>"); + process.exit(1); + } + program.args.shift(); + exec('open https://leancloud.cn/search.html?q=' + encodeURIComponent(program.args.join(' '))); + callback(); + break; + case "lint": run.doLint(); - return callback(); - } -} + callback(); + break; -// 需要在项目目录执行的命令 -runtime.detect(CLOUD_PATH, function(err, runtimeInfo) { - if (err) { - return callback(err); + default: + program.help(); + break; } - - runtimeInfo.setDebug(program.debug); - if(CMD) { - switch (CMD) { - case "deploy": - run.logProjectHome(); - if (program.git) { - run.deployGitCloudCode(program.revision || 'master', program.giturl, callback); - } else { - if (path.resolve(CLOUD_PATH) != path.resolve('.')) - return exitWith("'avoscloud deploy' 命令必须在 LeanEngine 项目目录中使用"); - run.deployLocalCloudCode(runtimeInfo, CLOUD_PATH, program.log, callback); - } - break; - case "undeploy": - run.logProjectHome(); - run.undeployCloudCode(callback); - break; - case "publish": - run.logProjectHome(); - run.publishCloudCode(callback); - break; - case "status": - run.logProjectHome(); - run.queryStatus(callback); - break; - case 'logs': - run.logProjectHome(); - run.viewCloudLog(program.lines, program.tailf, null, callback); - break; - case "upload": - run.initAVOSCloudSDK(); - run.logProjectHome(); - if (!program.args[1]) { - console.log("请使用:avoscloud upload <文件或目录>"); - process.exit(1); - } - program.args.shift(); - run.importFiles(program.args, function(err) { - if (err) - console.log(err); - }, callback); - break; - case "app": - //app - var isList = program.args[1] == 'list'; - run.appStatus(isList); - callback(); - break; - case "rm": - //rm - var name = program.args[1]; - if (!name) - return exitWith("请使用:avoscloud rm "); - run.removeApp(name); - callback(); - break; - case "checkout": - //checkout - var name = program.args[1]; - if (!name) - return exitWith("请使用:avoscloud checkout "); - run.checkoutApp(name); - callback(); - break; - case "cql": - run.doCloudQuery(callback); - break; - default: - program.help(); - break; +} else { + runtime.detect(CLOUD_PATH, function(err, runtimeInfo) { + if (err) { + return callback(err); } - } else { + runtimeInfo.setDebug(program.debug); var monconfig = runtimeInfo.getMonconfig(args); console.log(color.green('提示:您可以敲入 rs 命令并回车来重启本进程')); nodemon(monconfig); nodemon.on('restart', function (files) { console.log('[INFO] 因为文件变更而项目重启:', files); }); - } -}); + }); +} From 09c389a71de449ed98e0b4dcca084367813b82f9 Mon Sep 17 00:00:00 2001 From: wchen Date: Thu, 28 May 2015 23:39:47 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Python=20=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=9A=84=E6=9C=AC=E5=9C=B0=E8=BF=90=E8=A1=8C=E5=92=8C?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/runtime.js | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/lib/runtime.js b/lib/runtime.js index 2aec98c..7b74943 100644 --- a/lib/runtime.js +++ b/lib/runtime.js @@ -4,18 +4,13 @@ var path = require('path'), run = require('../bin/run'); exports.detect = function(appPath, cb) { - var innerCb = function(err, runtimeInfo) { - cb(err, runtimeInfo); - }; if (fs.existsSync(path.join(appPath, 'cloud', 'main.js'))){ // cloud code v2.0 - return getCloudCodeRuntimeInfo(appPath, innerCb); + return getCloudCodeRuntimeInfo(appPath, cb); } else if (fs.existsSync(path.join(appPath, 'server.js'))) { // Node.js - return getNodeRuntimeInfo(appPath, innerCb); + return getNodeRuntimeInfo(appPath, cb); } else if (fs.existsSync(path.join(appPath, 'requirements.txt')) && fs.existsSync(path.join(appPath, 'wsgi.py'))) { // Python - return { - // TODO Python - } + return getPythonRuntimeInfo(appPath, cb); } else { cb(new Error('不在 LeanEngine 项目根目录,或目录结构不对。')); } @@ -85,3 +80,37 @@ var getNodeRuntimeInfo = function(appPath, cb) { }); }); } + +var getPythonRuntimeInfo = function(appPath, cb) { + var app = run.getAppSync(); + run.initMasterKey(function(masterKey) { + cb(null, { + exec: 'python', + setDebug: function(debug) { + if (debug) { + this.exec = 'python -m pdb'; + } + }, + getMonconfig: function(args) { + return { + exec: this.exec, + ignore: [ + '.git' + ], + "env": { + LC_APP_ID: app.appId, + LC_APP_KEY: masterKey, + LC_APP_MASTER_KEY: masterKey, + LC_APP_PORT: run.getPort() + }, + ext: 'py', + script: 'wsgi.py', + args: args + }; + }, + bulk: function() { + return [{ src: ['**']}] + } + }); + }); +} From f36c33645aa46b23ab4c30b988132e8d78e6118d Mon Sep 17 00:00:00 2001 From: wchen Date: Thu, 28 May 2015 23:51:50 +0800 Subject: [PATCH 3/3] =?UTF-8?q?bugfix:=20lint=20=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E6=97=A0=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/avoscloud | 3 +-- bin/run.js | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/avoscloud b/bin/avoscloud index 0954712..82b2d14 100755 --- a/bin/avoscloud +++ b/bin/avoscloud @@ -186,8 +186,7 @@ if(CMD) { break; case "lint": - run.doLint(); - callback(); + run.doLint(callback); break; default: diff --git a/bin/run.js b/bin/run.js index 99dfda5..ea019c4 100755 --- a/bin/run.js +++ b/bin/run.js @@ -919,15 +919,16 @@ exports.doCloudQuery = doCloudQuery = function(cb) { }); } -exports.doLint = function() { +exports.doLint = function(cb) { console.log("linting ..."); - var cmd = path.join(__dirname, '..', 'node_modules', 'jshint', 'bin', 'jshint') + ' cloud'; + var cmd = path.join(__dirname, '..', 'node_modules', 'jshint', 'bin', 'jshint') + ' . --exclude node_modules'; exec(cmd, function(err, stdout, stderr) { console.log(stdout); if (err) { process.exit(err.code); } else { console.log('lint ok'); + cb(); } }); }