UNPKG

@buildo/hophop

Version:

![](https://img.shields.io/npm/v/@buildo/hophop.svg)

53 lines (44 loc) 1.85 kB
import fs from 'fs'; import R from 'ramda'; import { checkForUpdates, parseArgs, getHophopDir, error, HophopError } from './utils'; import { ghCommit, ghFeature, ghPR, ghSetup, openPullRequestOnGitHub } from './gh'; import { togglStart, togglMisc, togglTest, togglStop, togglInstallHooks, togglSetup } from './toggl'; import * as _migrations from './migrations'; import runValidations from './validations'; const commands = [ [R.whereEq({ cmd: 'gh', cmd_gh: 'setup' }), ghSetup], [R.whereEq({ cmd: 'gh', cmd_gh: 'feature' }), ghFeature], [R.whereEq({ cmd: 'gh', cmd_gh: 'pr' }), ghPR], [R.whereEq({ cmd: 'gh', cmd_gh: 'commit' }), ghCommit], [R.whereEq({ cmd: 'gh', cmd_gh: 'open' }), openPullRequestOnGitHub], [R.whereEq({ cmd: 'toggl', cmd_toggl: 'setup' }), togglSetup], [R.whereEq({ cmd: 'toggl', cmd_toggl: 'start' }), togglStart], [R.whereEq({ cmd: 'toggl', cmd_toggl: 'misc' }), togglMisc], [R.whereEq({ cmd: 'toggl', cmd_toggl: 'test' }), togglTest], [R.whereEq({ cmd: 'toggl', cmd_toggl: 'stop' }), togglStop], [R.whereEq({ cmd: 'toggl', cmd_toggl: 'install-hooks' }), togglInstallHooks] ]; async function main() { // create ~/.hophop dir if it doesn't exist yet const hophopDir = getHophopDir(); !fs.existsSync(hophopDir) && fs.mkdirSync(hophopDir); // RUN migrations const migrations = Object.keys(_migrations) .filter(key => typeof _migrations[key] === 'function') .map(key => _migrations[key]); migrations.forEach(migration => migration()); // CHECK for updates await checkForUpdates(); // RUN validations runValidations(); const args = parseArgs(); await R.find((x) => x[0](args))(commands)[1](args); } main().catch(e => { if (e instanceof HophopError) { e.message && error('\n', e.message, '\n'); } else { error('\n', e.stack, '\n'); } process.exit(0); });