增加 code 分支 build 分支

master
xiejianxiong 4 years ago
parent 58f4e785b0
commit 78e9feecaf

@ -4,6 +4,12 @@
1. npm link 1. npm link
2. 在 /Users 文件夹下添加 config.js 文件 2. 在 /Users 文件夹下添加 config.js 文件
3. 在 config.js 文件中更改对应的 codePath、buildPath 地址 3. 在 config.js 文件中更改对应的 codePath、buildPath 地址
2. auto p test 发布 测试 test-build 版本 4. auto p test 发布 测试 test-build 版本
2. auto p pre 发布 预上线 pre-build 版本 5. auto p pre 发布 预上线 pre-build 版本
2. auto p pro 发布 正式 build 版本 6. auto p pro 发布 正式 build 版本
# auto p 参数
1. auto p test dev_xjx dev_aliyun
- test: 环境变量
- dev_xjx: 代码分支
- dev_aliyun: build 代码分支

@ -11,6 +11,10 @@ const codePath = Config.codePath;
program.parse(process.argv); program.parse(process.argv);
const env = program.args[0]; 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); console.log('env: ', env);
const mapping = { const mapping = {
@ -19,6 +23,12 @@ const mapping = {
'pro': { cmd: 'build', codeBranch: 'dev', buildBranch: 'develop' }, '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]) { if (!mapping[env]) {
console.log(chalk.red(`not exist ${env} branch`)); console.log(chalk.red(`not exist ${env} branch`));
return; return;
@ -27,9 +37,9 @@ if (!mapping[env]) {
const runBuild = (task) => new Promise(async resolve => { const runBuild = (task) => new Promise(async resolve => {
try { try {
shell.cd(codePath); shell.cd(codePath);
await execa('git', ['checkout', mapping[env].codeBranch]); await execa('git', ['checkout', codeBranch]);
await execa('git', ['pull', 'origin', mapping[env].codeBranch]); await execa('git', ['pull', 'origin', codeBranch]);
await execa('npm', ['run', mapping[env].cmd]); await execa('npm', ['run', cmd]);
resolve(); resolve();
} catch (e) { } catch (e) {
console.log('run build error: ', 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 => { const deleteBuild = (task) => new Promise(async resolve => {
try { try {
shell.cd(buildPath); shell.cd(buildPath);
await execa('git', ['checkout', mapping[env].buildBranch]); await execa('git', ['checkout', buildBranch]);
await execa('git', ['pull', 'origin', mapping[env].buildBranch]); await execa('git', ['pull', 'origin', buildBranch]);
shell.rm(`${buildPath}/*`); shell.rm(`${buildPath}/*`);
shell.rm('-rf', `${buildPath}/static`); shell.rm('-rf', `${buildPath}/static`);
await execa('git', ['add', '.']); await execa('git', ['add', '.']);
await execa('git', ['commit', '-m', `'自动发布'`]); await execa('git', ['commit', '-m', `'自动发布'`]);
await execa('git', ['push', 'origin', mapping[env].buildBranch]); await execa('git', ['push', 'origin', buildBranch]);
resolve(); resolve();
} catch (e) { } catch (e) {
console.log('delete build error: ', e); console.log('delete build error: ', e);
@ -65,7 +75,7 @@ const copyBuild = (task) => new Promise(async resolve => {
shell.cd(buildPath); shell.cd(buildPath);
await execa('git', ['add', '.']); await execa('git', ['add', '.']);
await execa('git', ['commit', '-m', `'自动发布'`]); await execa('git', ['commit', '-m', `'自动发布'`]);
await execa('git', ['push', 'origin', mapping[env].buildBranch]); await execa('git', ['push', 'origin', buildBranch]);
resolve(); resolve();
} catch (e) { } catch (e) {
console.log('copyBuild error: ', e); console.log('copyBuild error: ', e);

2
package-lock.json generated

@ -1,6 +1,6 @@
{ {
"name": "zq_auto_publish", "name": "zq_auto_publish",
"version": "1.0.3", "version": "1.0.4",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

@ -1,6 +1,6 @@
{ {
"name": "zq_auto_publish", "name": "zq_auto_publish",
"version": "1.0.4", "version": "1.0.5",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"bin": { "bin": {

Loading…
Cancel
Save