rush-archive-project-plugin
Version:
Rush plugin to archive project
76 lines • 2.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.pushGitBranch = exports.getCheckpointBranch = exports.gitCheckIgnored = exports.gitFullClean = exports.getGitPathOrThrow = exports.getGitPath = void 0;
var node_core_library_1 = require("@rushstack/node-core-library");
var checkedGitPath = false;
var gitPath;
var getGitPath = function () {
if (!checkedGitPath) {
checkedGitPath = true;
gitPath = node_core_library_1.Executable.tryResolve("git");
}
return gitPath;
};
exports.getGitPath = getGitPath;
var getGitPathOrThrow = function () {
var gitPath = (0, exports.getGitPath)();
if (!gitPath) {
throw new Error("Unable to find git.");
}
return gitPath;
};
exports.getGitPathOrThrow = getGitPathOrThrow;
var gitFullClean = function (cwd) {
var gitPath = (0, exports.getGitPathOrThrow)();
node_core_library_1.Executable.spawnSync(gitPath, ["clean", "-fdx"], {
currentWorkingDirectory: cwd,
});
};
exports.gitFullClean = gitFullClean;
var gitCheckIgnored = function (cwd, filePath) {
var gitPath = (0, exports.getGitPathOrThrow)();
var result = "";
try {
var process_1 = node_core_library_1.Executable.spawnSync(gitPath, ["check-ignore", "-v", filePath], {
currentWorkingDirectory: cwd,
});
if (process_1.status === 0) {
result = process_1.stdout.toString();
}
}
catch (e) {
if (e.message.includes("The command failed with exit code 1")) {
// ignore
}
else {
// rethrow
throw e;
}
}
return result;
};
exports.gitCheckIgnored = gitCheckIgnored;
var getCheckpointBranch = function (cwd, branchName) {
var gitPath = (0, exports.getGitPathOrThrow)();
var currDate = new Date().toISOString().substring(0, 10);
var branchNameToCreate = "".concat(branchName, "-checkpoint-").concat(currDate);
var process = node_core_library_1.Executable.spawnSync(gitPath, ["branch", branchNameToCreate], {
currentWorkingDirectory: cwd,
});
if (process.status === 128) {
throw new Error("The passed branch name is invalid: ".concat(branchNameToCreate));
}
return branchNameToCreate;
};
exports.getCheckpointBranch = getCheckpointBranch;
var pushGitBranch = function (cwd, branchName) {
var gitPath = (0, exports.getGitPathOrThrow)();
var process = node_core_library_1.Executable.spawnSync(gitPath, ["push", "origin", "".concat(branchName, ":").concat(branchName)], {
currentWorkingDirectory: cwd,
});
if (process.status !== 0) {
console.error('Could not push branch to origin');
}
};
exports.pushGitBranch = pushGitBranch;
//# sourceMappingURL=git.js.map