|
|
@ -13,9 +13,9 @@ program.parse(process.argv);
|
|
|
|
const env = program.args[0];
|
|
|
|
const env = program.args[0];
|
|
|
|
const codeBranchArg = program.args[1];
|
|
|
|
const codeBranchArg = program.args[1];
|
|
|
|
const buildBranchArg = program.args[2];
|
|
|
|
const buildBranchArg = program.args[2];
|
|
|
|
console.log('codeBranchArg: ', codeBranchArg);
|
|
|
|
|
|
|
|
console.log('buildBranchArg: ', buildBranchArg);
|
|
|
|
|
|
|
|
console.log('env: ', env);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const mapping = {
|
|
|
|
const mapping = {
|
|
|
|
'test': { cmd: 'test-build', codeBranch: 'dev', buildBranch: 'dev_aliyun' },
|
|
|
|
'test': { cmd: 'test-build', codeBranch: 'dev', buildBranch: 'dev_aliyun' },
|
|
|
@ -23,17 +23,18 @@ 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const cmd = mapping[env].cmd;
|
|
|
|
|
|
|
|
const codeBranch = codeBranchArg || mapping[env].codeBranch;
|
|
|
|
|
|
|
|
const buildBranch = buildBranchArg || mapping[env].buildBranch;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const runBuild = (task) => new Promise(async resolve => {
|
|
|
|
const runBuild = (task) => new Promise(async resolve => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
shell.cd(codePath);
|
|
|
|
shell.cd(codePath);
|
|
|
@ -42,7 +43,7 @@ const runBuild = (task) => new Promise(async resolve => {
|
|
|
|
await execa('npm', ['run', cmd]);
|
|
|
|
await execa('npm', ['run', cmd]);
|
|
|
|
resolve();
|
|
|
|
resolve();
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
console.log('run build error: ', e);
|
|
|
|
|
|
|
|
task.skip('Failed run build');
|
|
|
|
task.skip('Failed run build');
|
|
|
|
resolve();
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -58,11 +59,12 @@ const deleteBuild = (task) => new Promise(async resolve => {
|
|
|
|
shell.rm('-rf', `${buildPath}/static`);
|
|
|
|
shell.rm('-rf', `${buildPath}/static`);
|
|
|
|
|
|
|
|
|
|
|
|
await execa('git', ['add', '.']);
|
|
|
|
await execa('git', ['add', '.']);
|
|
|
|
await execa('git', ['commit', '-m', `'自动发布'`]);
|
|
|
|
const text = `xjx auto publish ${new Date().toLocaleString()}`;
|
|
|
|
|
|
|
|
await execa('git', ['commit', '-m', `'${text}'`]);
|
|
|
|
await execa('git', ['push', 'origin', buildBranch]);
|
|
|
|
await execa('git', ['push', 'origin', buildBranch]);
|
|
|
|
resolve();
|
|
|
|
resolve();
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
console.log('delete build error: ', e);
|
|
|
|
|
|
|
|
task.skip('Failed delete build');
|
|
|
|
task.skip('Failed delete build');
|
|
|
|
resolve();
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -74,11 +76,12 @@ 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', `'自动发布'`]);
|
|
|
|
const text = `xjx auto publish ${new Date().toLocaleString()}`;
|
|
|
|
|
|
|
|
await execa('git', ['commit', '-m', `'${text}'`]);
|
|
|
|
await execa('git', ['push', 'origin', buildBranch]);
|
|
|
|
await execa('git', ['push', 'origin', buildBranch]);
|
|
|
|
resolve();
|
|
|
|
resolve();
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
console.log('copyBuild error: ', e);
|
|
|
|
|
|
|
|
task.skip('Failed copy build');
|
|
|
|
task.skip('Failed copy build');
|
|
|
|
resolve();
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -100,5 +103,5 @@ const tasks = new Listr([
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
tasks.run().catch(err => {
|
|
|
|
tasks.run().catch(err => {
|
|
|
|
console.log(err)
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|