From 78e9feecaf30e9e10e6e7b57b323707d1c882413 Mon Sep 17 00:00:00 2001 From: xiejianxiong Date: Wed, 26 Aug 2020 13:55:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20code=20=E5=88=86=E6=94=AF?= =?UTF-8?q?=20build=20=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 +++++++++--- bin/auto-publish.js | 24 +++++++++++++++++------- package-lock.json | 2 +- package.json | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index fd608b7..e498de8 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,12 @@ 1. npm link 2. 在 /Users 文件夹下添加 config.js 文件 3. 在 config.js 文件中更改对应的 codePath、buildPath 地址 -2. auto p test 发布 测试 test-build 版本 -2. auto p pre 发布 预上线 pre-build 版本 -2. auto p pro 发布 正式 build 版本 \ No newline at end of file +4. auto p test 发布 测试 test-build 版本 +5. auto p pre 发布 预上线 pre-build 版本 +6. auto p pro 发布 正式 build 版本 + +# auto p 参数 +1. auto p test dev_xjx dev_aliyun + - test: 环境变量 + - dev_xjx: 代码分支 + - dev_aliyun: build 代码分支 \ No newline at end of file diff --git a/bin/auto-publish.js b/bin/auto-publish.js index 3be739c..923636c 100644 --- a/bin/auto-publish.js +++ b/bin/auto-publish.js @@ -11,6 +11,10 @@ const codePath = Config.codePath; program.parse(process.argv); const env = program.args[0]; +const codeBranchArg = program.args[1]; +const buildBranchArg = program.args[2]; +console.log('codeBranchArg: ', codeBranchArg); +console.log('buildBranchArg: ', buildBranchArg); console.log('env: ', env); const mapping = { @@ -19,6 +23,12 @@ const mapping = { 'pro': { cmd: 'build', codeBranch: 'dev', buildBranch: 'develop' }, } +const cmd = mapping[env].cmd; +const codeBranch = codeBranchArg || mapping[env].codeBranch; +const buildBranch = buildBranchArg || mapping[env].buildBranch; +console.log('codeBranch: ', codeBranch); +console.log('buildBranch: ', buildBranch); + if (!mapping[env]) { console.log(chalk.red(`not exist ${env} branch`)); return; @@ -27,9 +37,9 @@ if (!mapping[env]) { const runBuild = (task) => new Promise(async resolve => { try { shell.cd(codePath); - await execa('git', ['checkout', mapping[env].codeBranch]); - await execa('git', ['pull', 'origin', mapping[env].codeBranch]); - await execa('npm', ['run', mapping[env].cmd]); + await execa('git', ['checkout', codeBranch]); + await execa('git', ['pull', 'origin', codeBranch]); + await execa('npm', ['run', cmd]); resolve(); } catch (e) { console.log('run build error: ', e); @@ -41,15 +51,15 @@ const runBuild = (task) => new Promise(async resolve => { const deleteBuild = (task) => new Promise(async resolve => { try { shell.cd(buildPath); - await execa('git', ['checkout', mapping[env].buildBranch]); - await execa('git', ['pull', 'origin', mapping[env].buildBranch]); + await execa('git', ['checkout', buildBranch]); + await execa('git', ['pull', 'origin', buildBranch]); shell.rm(`${buildPath}/*`); shell.rm('-rf', `${buildPath}/static`); await execa('git', ['add', '.']); await execa('git', ['commit', '-m', `'自动发布'`]); - await execa('git', ['push', 'origin', mapping[env].buildBranch]); + await execa('git', ['push', 'origin', buildBranch]); resolve(); } catch (e) { console.log('delete build error: ', e); @@ -65,7 +75,7 @@ const copyBuild = (task) => new Promise(async resolve => { shell.cd(buildPath); await execa('git', ['add', '.']); await execa('git', ['commit', '-m', `'自动发布'`]); - await execa('git', ['push', 'origin', mapping[env].buildBranch]); + await execa('git', ['push', 'origin', buildBranch]); resolve(); } catch (e) { console.log('copyBuild error: ', e); diff --git a/package-lock.json b/package-lock.json index 6a97d22..c5805df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "zq_auto_publish", - "version": "1.0.3", + "version": "1.0.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 57a8872..328fa75 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zq_auto_publish", - "version": "1.0.4", + "version": "1.0.5", "description": "", "main": "index.js", "bin": {