UNPKG

gitstrap-cli

Version:

A cli tool that allows you to easily sync with your upstream git repository

53 lines (43 loc) 1.45 kB
var child_process = require("child_process"); var fs = require('fs'); module.exports = function (forkRepo) { if(!fs.existsSync(process.cwd() + '/package.json')) { console.log('Could not find package.json in this directory. Make sure you in the root of your project directory.'); process.exit(1); } var packageJson = JSON.parse(fs.readFileSync(process.cwd() + '/package.json', 'utf8')); var upstreamRepo = packageJson.upstreamRepo; if(!upstreamRepo) { console.log("Property 'upstreamRepo' could not be found in package.json. Please enter the correct upstream repo in the package.json"); } if(forkRepo) { var originCmd = child_process.spawnSync( "git", ["remote", "add", "origin", forkRepo], {encoding: 'utf8'}); if(originCmd.status != 0) { var originSetUrlCmd = child_process.spawnSync( "git", ["remote", "set-url", "origin", forkRepo], {encoding: 'utf8'}); // console.log(originSetUrlCmd.output[1]); } else { // console.log(originCmd.output[1]); } } var upstreamCmd = child_process.spawnSync( "git", ["remote", "add", "upstream", upstreamRepo], {encoding: 'utf8'}); if(upstreamCmd.status != 0) { var upstreamSetUrlCmd = child_process.spawnSync( "git", ["remote", "set-url", "upstream", upstreamRepo], {encoding: 'utf8'}); // console.log(upstreamSetUrlCmd.output[1]); } else { // console.log(upstreamCmd.output[1]); } }