@daiyu-5577/quickbuild
Version:
front-end build service
38 lines (37 loc) • 2.06 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { execPms } from "./exec.js";
import chalk from "chalk";
export function checkBaranch(branchName, cwd, option) {
return __awaiter(this, void 0, void 0, function* () {
const localBranchesResult = yield execPms('git branch', Object.assign({ cwd, encoding: 'utf-8' }, option));
const localBranches = localBranchesResult.stdout.split('\n');
const localBranchExists = localBranches.some(v => v.includes(branchName));
if (localBranchExists) {
const command = `git checkout ${branchName}`;
console.log(chalk.green(`------ ${command} ------`));
yield execPms(`${command}`, Object.assign({ cwd, encoding: 'utf-8' }, option));
}
else {
const command = `git checkout -b ${branchName} origin/${branchName}`;
console.log(chalk.green(`------ ${command} ------`));
yield execPms(`${command}`, Object.assign({ cwd, encoding: 'utf-8' }, option));
}
const command = `git pull`;
console.log(chalk.green(`------ ${command} ------`));
yield execPms(`${command}`, { cwd });
});
}
export function gitClean(cwd, option) {
return __awaiter(this, void 0, void 0, function* () {
yield execPms(`git checkout .`, Object.assign({ cwd }, option));
yield execPms(`git clean -df`, Object.assign({ cwd }, option));
});
}