From e768025b5128f2a062da8d142cd8b9a75a268d07 Mon Sep 17 00:00:00 2001 From: suxiaoxin Date: Tue, 26 Sep 2017 21:05:20 +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 | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/server/install.js b/server/install.js index ec6c82b2..1c6c9bf8 100755 --- a/server/install.js +++ b/server/install.js @@ -10,19 +10,13 @@ yapi.connect = dbModule.connect(); function install() { - try { - let exist = yapi.commons.fileExist(yapi.path.join(yapi.WEBROOT_RUNTIME, 'init.lock')); + let exist = yapi.commons.fileExist(yapi.path.join(yapi.WEBROOT_RUNTIME, '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); + if (exist) { + throw new Error('init.lock文件已存在,请确认您是否已安装。如果需要重新安装,请删掉init.lock文件'); } + setupSql(); } function setupSql() { @@ -38,7 +32,7 @@ function setupSql() { up_time: yapi.commons.time() }); - yapi.connect.then(function () { + yapi.connect.then(function () { let userCol = mongoose.connection.db.collection('user') userCol.ensureIndex({ username: 1 @@ -129,15 +123,20 @@ function setupSql() { followCol.ensureIndex({ project_id: 1 }) - + result.then(function () { - console.log(`初始化管理员账号成功,账号名: "${yapi.WEBCONFIG.adminAccount}",默认密码:qunar.com`); // eslint-disable-line + fs.ensureFileSync(yapi.path.join(yapi.WEBROOT_RUNTIME, 'init.lock')); + console.log(`初始化管理员账号 "${yapi.WEBCONFIG.adminAccount}" 成功`); // eslint-disable-line process.exit(0); }, function (err) { - throw new Error(`初始化管理员账号 "${yapi.WEBCONFIG.adminAccount}" 失败, ${err.message}`); // eslint-disable-line + console.log(`初始化管理员账号 "${yapi.WEBCONFIG.adminAccount}" 失败, ${err.message}`); // eslint-disable-line + process.exit(0); }); + - }) + }.catch(function(err){ + console.log(err.message) + })) }