#! /usr/bin/env node 'use strict' /** * This is a script to git subtree an "org" to its own repo. * ~~This should be invoked within a lerna repository so that the changed modules * can be recognised~~ * * - split.sh, a convenience binary around 'git subtree split' - https://tinyurl.com/z5mmpof */ import {execFileSync} from 'child_process' import path from 'path' const orgs = process.argv.slice(2) if (typeof orgs === 'undefined') throw new Error('Supply org names as parameters') const splitshPath = path.resolve(__dirname, '../../bin/splitsh-lite.osx') const gitPath = '/usr/local/bin/git' const monoroot = path.resolve(__dirname, '../../../../../..') const doSync = (org: string) => { const repo = `git@github.com:elmpp/${org}.git` const prefix = `orgs/${org}` try { const sha1 = execFileSync(splitshPath, ['--prefix', prefix, '--path', monoroot, '--progress']) .toString() .replace(/\r?\n|\r$/, '') if (!sha1.length) { console.debug('no commits found!') return } console.debug(`Generated commit sha1: ${sha1.substring(0, 6)} for org: ${org}; repo: ${repo}`) execFileSync(gitPath, ['push', '-f', repo, `${sha1}:refs/heads/master`], { stdio: 'inherit', env: {HUSKY_SKIP_HOOKS: '1'}, }) console.log(`Pushed commit sha1: ${sha1.substring(0, 6)} to repo: ${repo}`) } catch (err) { console.error(err.message) process.exit(1) } } ;(() => { orgs.forEach(org => doSync(org)) process.exit(0) })()