|
|
|
@ -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);
|
|
|
|
|