Skip to content

Instantly share code, notes, and snippets.

@bidiu
Created August 14, 2017 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bidiu/38086dac295e7729184a9f517f534403 to your computer and use it in GitHub Desktop.
Save bidiu/38086dac295e7729184a9f517f534403 to your computer and use it in GitHub Desktop.
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const SVN_DIR_PATH = path.join(__dirname, '..', 'svn');
if (!fs.existsSync(SVN_DIR_PATH)) {
fs.mkdirSync(SVN_DIR_PATH);
}
function execCmd(cmd, { fromDir = '.' } = {}) {
return execSync(cmd, {
cwd: fromDir,
stdio: 'inherit'
});
}
/**
* In case of error, this function will throw an object,
* which is the result of child_process.spawnSync(). For
* more info see:
*
* https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_child_process_execsync_command_options
*
* @param {*} url url to checkout
* @param {*} savePath save path, relative to ${SVN_DIR_PATH}
* @param {*} noAuthCache
*/
function checkout(url, savePath, noAuthCache = false) {
execCmd(`svn checkout ${url} ${savePath} ${noAuthCache ? '--no-auth-cache' : ''}`, { fromDir: SVN_DIR_PATH });
}
exports.checkout = checkout;
exports.SVN_DIR_PATH = SVN_DIR_PATH;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment