@releaseotto/core
Version:
OTTO performs your action on new versioning of APIs, packages, schemas, etc. Keepings things nice and neatly automated.
66 lines • 2.5 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.commit = exports.cloneRepository = void 0;
const Shell = __importStar(require("shelljs"));
function cloneRepository({ repository, branch, toLocation }) {
let options = [];
if (branch !== undefined) {
options.push(`--branch ${branch}`);
}
if (!Shell.which('git')) {
Shell.echo('Sorry, this script requires git');
Shell.exit(1);
}
const exec = Shell.exec(`git clone ${options.join(" ")} ${repository} ${toLocation}`);
if (exec.code !== 0) {
throw new Error(exec.stderr);
}
}
exports.cloneRepository = cloneRepository;
function commit({ location, commitMessage, push }) {
if (!Shell.which('git')) {
Shell.echo('Sorry, this script requires git');
Shell.exit(1);
}
Shell.cd(location);
const somethingToCommit = Shell.exec('git diff-index --quiet HEAD --');
if (somethingToCommit.code === 0) {
console.info('Nothing to commit, exits');
return;
}
const commit = Shell.exec(`git add --all && git commit -a -m"${commitMessage}"`);
if (commit.code !== 0) {
throw new Error(commit.stderr);
}
if (push) {
const pushExec = Shell.exec(`git push --set-upstream ${push.origin} ${push.branch}`);
if (pushExec.code !== 0) {
throw new Error(pushExec.stderr);
}
}
}
exports.commit = commit;
//# sourceMappingURL=git.js.map