把 deploy.js 做成通用的,让 package.json 来指定 -H 主机和 -r 目录

This commit is contained in:
luk.lu
2018-11-26 12:31:23 +08:00
parent 0714dc6dc2
commit b0fd6092ee
2 changed files with 7 additions and 7 deletions

View File

@@ -8,15 +8,15 @@ commander
.version('1.0', '-v, --version') // 默认是 -V。如果要 -v就要加 '-v --version'
.option('-H, --host <host>', 'domain name or ip address of the target server')
.option('-P, --port <port>', 'ssh port number of the target server')
.option('-r, --root <root>', 'root path to deploy on the target server')
.option('-r, --root <root>', 'root directory to deploy on the target server')
.option('-d, --dist <dist>', 'dist folder to deploy on the target server')
.option('-u, --user <user>', 'user id to login the target server')
.option('-k, --key <key>', 'user key file to login the target server')
.option('-p, --password <password>', 'user password to login the target server. You may have to enclose the password in ""')
.parse(process.argv)
const root=commander.root||'/home/tic/tic.node/console' // 本地的项目目录。似乎该目录必须已经存在于服务器上
const dist=commander.dist||'dist' // 新系统将发布在这个目录里。建议和npm run build产生的目录一致这样既可以远程自动部署也可以直接登录服务器手动部署。
const root=commander.root // 本地的项目目录。似乎该目录必须已经存在于服务器上
const dist=commander.dist||'dist' // 新系统将发布在这个目录里。建议为dist和npm run build产生的目录一致这样既可以远程自动部署也可以直接登录服务器手动部署。
const privateKeyFile=commander.key||`${process.env.HOME}/.ssh/id_rsa`
const connection = {
@@ -49,9 +49,9 @@ const necessaryPath = (path) => {
};
ssh.connect(connection).then(async () => {
await ssh.execCommand(`mv ${dist} ${dist}-backup-${new Date().toISOString()}`, { root }); // 把服务器上老系统改名成另一个目录
await ssh.execCommand(`mkdir ${dist}`, { root }); // 新建发布目录
const toCreate = necessaryPath('./dist'); // 读取本地项目的发布目录下的子目录,去服务器上建立。
await ssh.execCommand(`mv ${dist} ${dist}-backup-${new Date().toISOString()}`, { root });
await ssh.execCommand(`mkdir ${dist}`, { root });
const toCreate = necessaryPath('./dist');
for (const name of toCreate) {
await ssh.execCommand(`mkdir ${dist}/${name.join('/')}`, { root });
}

View File

@@ -5,7 +5,7 @@
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"deploy": "npm run build && node ./deploy.js -r '/home/tic/tic.node/console' -u tic",
"deploy": "node ./deploy.js -r '/home/tic/console.web.site' -u tic",
"lint": "vue-cli-service lint",
"test:unit": "vue-cli-service test:unit"
},