@storyblok/create-demo
Version:
A CLI tool for quickly starting a Storyblok project
51 lines (50 loc) • 1.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const node_child_process_1 = require("node:child_process");
/**
*
* @param {string} repo repo's clone path
* @param {string} targetPath save path
* @param {Object} opts options
* @return {promise}
*/
function default_1(repo, targetPath, opts) {
opts = opts || {};
const git = opts.git || 'git';
const args = ['clone'];
if (opts.shallow) {
args.push('--depth', '1');
}
if (opts.submodules) {
args.push('--recurse-submodules');
}
if (opts.checkout) {
args.push('--branch', opts.checkout);
}
args.push('--', repo, targetPath);
const process = (0, node_child_process_1.spawn)(git, args);
return new Promise((resolve, reject) => {
process.on('close', function (status) {
if (status === 0) {
if (opts.checkout) {
const process = (0, node_child_process_1.spawn)(git, ['checkout', opts.checkout], { cwd: targetPath });
process.on('close', function (status) {
if (status === 0) {
resolve(true);
}
else {
reject(new Error("'git checkout' failed with status " + status));
}
});
}
else {
resolve(true);
}
}
else {
reject(new Error("'git clone' failed with status " + status));
}
});
});
}
exports.default = default_1;