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