From 51e937eed4acdf26a8215e364ab5eb7ea7687c54 Mon Sep 17 00:00:00 2001 From: suxiaoxin Date: Tue, 26 Sep 2017 20:47:19 +0800 Subject: [PATCH] =?UTF-8?q?opti:=20=E4=BF=AE=E6=94=B9install.js=20?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/install.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/server/install.js b/server/install.js index 5552c488..ec6c82b2 100755 --- a/server/install.js +++ b/server/install.js @@ -10,13 +10,19 @@ yapi.connect = dbModule.connect(); function install() { - let exist = yapi.commons.fileExist(yapi.path.join(yapi.WEBROOT_RUNTIME, 'init.lock')); + try { + let exist = yapi.commons.fileExist(yapi.path.join(yapi.WEBROOT_RUNTIME, 'init.lock')); - if (exist) { - throw new Error('init.lock文件已存在,请确认您是否已安装。如果需要重新安装,请删掉init.lock文件'); + if (exist) { + throw new Error('init.lock文件已存在,请确认您是否已安装。如果需要重新安装,请删掉init.lock文件'); + } + fs.ensureFileSync(yapi.path.join(yapi.WEBROOT_RUNTIME, 'init.lock')); + + setupSql(); + } catch (err) { + console.error(err.message); } - setupSql(); } function setupSql() { @@ -123,14 +129,12 @@ function setupSql() { followCol.ensureIndex({ project_id: 1 }) - + result.then(function () { - fs.ensureFileSync(yapi.path.join(yapi.WEBROOT_RUNTIME, 'init.lock')); - console.log(`初始化管理员账号 "${yapi.WEBCONFIG.adminAccount}" 成功`); // eslint-disable-line + console.log(`初始化管理员账号成功,账号名: "${yapi.WEBCONFIG.adminAccount}",默认密码:qunar.com`); // eslint-disable-line process.exit(0); }, function (err) { - console.error(`初始化管理员账号 "${yapi.WEBCONFIG.adminAccount}" 失败, ${err.message}`); // eslint-disable-line - process.exit(); + throw new Error(`初始化管理员账号 "${yapi.WEBCONFIG.adminAccount}" 失败, ${err.message}`); // eslint-disable-line }); })