diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..db25b5e --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,9 @@ +# These are supported funding model platforms + +github: [romakita] +patreon: # Replace with a single Patreon username +open_collective: tsed +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +custom: # Replace with a single custom sponsorship URL diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..df92fe0 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: "npm" + directory: "/" + schedule: + interval: "monthly" + assignees: + - "Romakita" + reviewers: + - "Romakita" diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 0000000..dc90e5a --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,17 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 60 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 7 +# Issues with these labels will never be considered stale +exemptLabels: + - pinned + - security +# Label to use when marking an issue as stale +staleLabel: wontfix +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: false diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..9ad642f --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,52 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Build & Release + +on: + push: + pull_request: + branches: + - master + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [ 14.x ] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: yarn install --frozen-lockfile --network-timeout 500000 + - name: Run lint + run: yarn test:lint + + deploy-packages: + runs-on: ubuntu-latest + needs: [lint] + if: ${{ github.event_name != 'pull_request' && (contains(github.ref, 'master') || contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc')) }} + + strategy: + matrix: + node-version: [ 14.x ] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: yarn install --frozen-lockfile --network-timeout 500000 + - name: Release packages + env: + CI: true + GH_TOKEN: ${{ secrets.GH_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: yarn release diff --git a/.github/workflows/rebase.yml b/.github/workflows/rebase.yml new file mode 100644 index 0000000..e5bae3c --- /dev/null +++ b/.github/workflows/rebase.yml @@ -0,0 +1,18 @@ +on: + issue_comment: + types: [created] +name: Automatic Rebase +jobs: + rebase: + name: Rebase + if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase') + runs-on: ubuntu-latest + steps: + - name: Checkout the latest code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Automatic Rebase + uses: cirrus-actions/rebase@1.3.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e47fb3a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: node_js -cache: - directories: - - ~/.npm -node_js: - - '12' -after_success: - - npm run travis-deploy-once "npm run semantic-release" -branches: - except: - - /^v\d+\.\d+\.\d+$/ diff --git a/bin/gflow-branches.js b/bin/gflow-branches.js index 9c34c3e..3a19e8c 100755 --- a/bin/gflow-branches.js +++ b/bin/gflow-branches.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -const { branches, config } = require('../src'); +const { branches, config } = require("../src"); branches(config.toObject()); diff --git a/bin/gflow-config.js b/bin/gflow-config.js index 31e19ec..b7fccab 100644 --- a/bin/gflow-config.js +++ b/bin/gflow-config.js @@ -1,28 +1,28 @@ #!/usr/bin/env node -const commander = require('commander'); -const { config } = require('../src'); +const commander = require("commander"); +const { config } = require("../src"); const options = {}; commander - .usage('') - .alias('gflow config ') - .arguments('') + .usage("") + .alias("gflow config ") + .arguments("") .action(action => { options.action = action; }) - .on('--help', () => { - console.log(''); - console.log(' Examples:'); - console.log(''); - console.log(' $ gflow config list'); - console.log(''); + .on("--help", () => { + console.log(""); + console.log(" Examples:"); + console.log(""); + console.log(" $ gflow config list"); + console.log(""); }) .parse(process.argv); switch (options.action) { default: - case 'list': + case "list": console.log(config.toObject()); } diff --git a/bin/gflow-fetch.js b/bin/gflow-fetch.js index a8796a2..9cdcc3f 100644 --- a/bin/gflow-fetch.js +++ b/bin/gflow-fetch.js @@ -1,4 +1,4 @@ #!/usr/bin/env nodegg -const { commands } = require('../src'); +const { commands } = require("../src"); commands.Fetch.fetch(); diff --git a/bin/gflow-finish.js b/bin/gflow-finish.js index 28e093d..fa1c569 100644 --- a/bin/gflow-finish.js +++ b/bin/gflow-finish.js @@ -1,14 +1,14 @@ #!/usr/bin/env node -const commander = require('commander'); -const { commands, config } = require('../src'); +const commander = require("commander"); +const { commands, config } = require("../src"); const options = {}; commander - .alias('gflow finish ') - .arguments('') - .option('-s, --skip', 'Skip the unit test.', (v, t) => t + 1, 0) + .alias("gflow finish ") + .arguments("") + .option("-s, --skip", "Skip the unit test.", (v, t) => t + 1, 0) .action(fromBranch => { options.fromBranch = fromBranch; }) diff --git a/bin/gflow-init.js b/bin/gflow-init.js index da877c2..424d38c 100644 --- a/bin/gflow-init.js +++ b/bin/gflow-init.js @@ -1,4 +1,4 @@ #!/usr/bin/env node -const { commands } = require('../src'); +const { commands } = require("../src"); commands.Init.askQuestions(); diff --git a/bin/gflow-merge.js b/bin/gflow-merge.js index fb84acc..e671060 100644 --- a/bin/gflow-merge.js +++ b/bin/gflow-merge.js @@ -1,15 +1,15 @@ #!/usr/bin/env node -const commander = require('commander'); -const { config } = require('../src'); -const { mergeBranch } = require('../src/command/merge'); +const commander = require("commander"); +const { config } = require("../src"); +const { mergeBranch } = require("../src/command/merge"); const options = {}; commander - .alias('gflow merge ') - .arguments('') - .option('-s, --skip', 'Skip the unit test.', (v, t) => t + 1, 0) + .alias("gflow merge ") + .arguments("") + .option("-s, --skip", "Skip the unit test.", (v, t) => t + 1, 0) .action(fromBranch => { options.fromBranch = fromBranch; }) diff --git a/bin/gflow-new.js b/bin/gflow-new.js index e7e033f..1b7a580 100644 --- a/bin/gflow-new.js +++ b/bin/gflow-new.js @@ -1,30 +1,34 @@ #!/usr/bin/env node -const commander = require('commander'); -const { config } = require('../src'); -const { commands } = require('../src'); +const commander = require("commander"); +const { config } = require("../src"); +const { commands } = require("../src"); const options = {}; -const branches = Object.keys(config.branchTypes).join('|'); +const branches = Object.keys(config.branchTypes).join("|"); commander .usage(`[${branches}] [fromBranch]`) - .arguments(' [fromBranch]') - .alias('gflow new') + .arguments(" [fromBranch]") + .alias("gflow new") .action((...args) => { const [_type_, _branchName_, _fromBranch_] = args.slice(0, args.length - 1); if (!config.branchTypes[_type_]) { - options.type = ''; + options.type = ""; options.branchName = _type_; - const type = Object.keys(config.branchTypes) - .find((t) => options.branchName.startsWith(t)); + const type = Object.keys(config.branchTypes).find(t => + options.branchName.startsWith(t) + ); if (type) { options.type = type; - options.branchName = options.branchName.replace(new RegExp(`^${type}[-_/]`), ''); + options.branchName = options.branchName.replace( + new RegExp(`^${type}[-_/]`), + "" + ); } } else { options.type = _type_; diff --git a/bin/gflow-push.js b/bin/gflow-push.js index c79a1b6..0f7cbc8 100644 --- a/bin/gflow-push.js +++ b/bin/gflow-push.js @@ -1,25 +1,25 @@ #!/usr/bin/env node -const commander = require('commander'); -const { config, commands } = require('../src'); +const commander = require("commander"); +const { config, commands } = require("../src"); const options = {}; commander - .usage(' [options]') - .alias('gflow push ') - .arguments('') - .option('-f, --force', 'Force pushing branch.', (v, t) => t + 1, 0) - .option('-s, --skip', 'Skip the unit test.', (v, t) => t + 1, 0) + .usage(" [options]") + .alias("gflow push ") + .arguments("") + .option("-f, --force", "Force pushing branch.", (v, t) => t + 1, 0) + .option("-s, --skip", "Skip the unit test.", (v, t) => t + 1, 0) .action(fromBranch => { options.fromBranch = fromBranch; }) - .on('--help', () => { - console.log(''); - console.log(' Examples:'); - console.log(''); - console.log(' $ gflow push'); - console.log(''); + .on("--help", () => { + console.log(""); + console.log(" Examples:"); + console.log(""); + console.log(" $ gflow push"); + console.log(""); }) .parse(process.argv); diff --git a/bin/gflow-rebase-all.js b/bin/gflow-rebase-all.js index 5f2c760..fb4d3bd 100644 --- a/bin/gflow-rebase-all.js +++ b/bin/gflow-rebase-all.js @@ -1,11 +1,14 @@ #!/usr/bin/env node -const commander = require('commander'); -const { rebaseAll, config } = require('../src'); +const commander = require("commander"); +const { rebaseAll, config } = require("../src"); commander - .alias('gflow rebase-all') - .option('-o, --from ', 'Rebase all branch from a branch. By default origin/production.') + .alias("gflow rebase-all") + .option( + "-o, --from ", + "Rebase all branch from a branch. By default origin/production." + ) .action(() => {}) .parse(process.argv); diff --git a/bin/gflow-rebase.js b/bin/gflow-rebase.js index 8e5662e..1eb6bc0 100644 --- a/bin/gflow-rebase.js +++ b/bin/gflow-rebase.js @@ -1,24 +1,24 @@ #!/usr/bin/env node -const commander = require('commander'); -const { commands, config } = require('../src'); +const commander = require("commander"); +const { commands, config } = require("../src"); const options = {}; commander - .alias('gflow rebase ') - .arguments('') + .alias("gflow rebase ") + .arguments("") .action(fromBranch => { options.fromBranch = fromBranch; }) - .on('--help', () => { - console.log(''); - console.log(' Examples:'); - console.log(''); - console.log(' $ gflow rebase'); - console.log(' Is shortcut to: '); + .on("--help", () => { + console.log(""); + console.log(" Examples:"); + console.log(""); + console.log(" $ gflow rebase"); + console.log(" Is shortcut to: "); console.log(` $ gflow rebase ${config.remoteProduction}`); - console.log(''); + console.log(""); }) .parse(process.argv); diff --git a/bin/gflow-release.js b/bin/gflow-release.js index 5a6bab1..496dea5 100644 --- a/bin/gflow-release.js +++ b/bin/gflow-release.js @@ -1,19 +1,19 @@ #!/usr/bin/env node -const commander = require('commander'); -const { release, config } = require('../src'); +const commander = require("commander"); +const { release, config } = require("../src"); const options = { - action: 'post' + action: "post" }; commander - .alias('gflow release') - .usage('gflow release [pre|prepare|success|post]') - .arguments('') + .alias("gflow release") + .usage("gflow release [pre|prepare|success|post]") + .arguments("") .action(action => { - options.action = action || 'post'; + options.action = action || "post"; }) .parse(process.argv); -console.log('[Gflow release] Start', options.action, 'action'); +console.log("[Gflow release] Start", options.action, "action"); release[options.action](config.toObject()); diff --git a/bin/gflow-sync.js b/bin/gflow-sync.js index c57f6c3..4884d71 100644 --- a/bin/gflow-sync.js +++ b/bin/gflow-sync.js @@ -1,12 +1,11 @@ #!/usr/bin/env node -const commander = require('commander'); -const { commands, config } = require('../src'); +const commander = require("commander"); +const { commands, config } = require("../src"); commander - .usage('gflow sync') - .action(() => { - }) + .usage("gflow sync") + .action(() => {}) .parse(process.argv); commands.Sync.syncBranches(config.toObject()); diff --git a/bin/gflow.js b/bin/gflow.js index 4105974..205091b 100755 --- a/bin/gflow.js +++ b/bin/gflow.js @@ -1,27 +1,42 @@ #!/usr/bin/env node -const commander = require('commander'); -const updateNotifier = require('update-notifier'); -const cliPkg = require('../package.json'); -const pkg = require('../package.json'); +const commander = require("commander"); +const updateNotifier = require("update-notifier"); +const cliPkg = require("../package.json"); +const pkg = require("../package.json"); updateNotifier({ pkg, updateCheckInterval: 0 }).notify(); commander .version(cliPkg.version) - .command('branches', 'List all branches status') - .command('finish', 'Merge the current branch on the referenced branch (production or ancestor) and delete it') - .command('merge', 'Merge the current branch on the referenced branch (production or ancestor) without deleting branch') + .command("branches", "List all branches status") .command( - 'release', - 'Create the release tag on the production branch. Synchronize the dev branch and production branch (for CI like travis)' + "finish", + "Merge the current branch on the referenced branch (production or ancestor) and delete it" ) - .command('init', 'Create a new git flow project') - .command('new', 'Create a new branch from the latest commit of production branch') - .command('push', 'Rebase the current branch from production and push all commit (run test before)') - .command('rebase', 'Rebase the current branch from production') - .command('rebase-all', 'Rebase all branches from production') - .command('fetch', 'Download objects and refs from another repository (--all and --prune)') - .command('sync', 'Synchronize dev branch and production') - .command('config', 'Operation about configuration') + .command( + "merge", + "Merge the current branch on the referenced branch (production or ancestor) without deleting branch" + ) + .command( + "release", + "Create the release tag on the production branch. Synchronize the dev branch and production branch (for CI like travis)" + ) + .command("init", "Create a new git flow project") + .command( + "new", + "Create a new branch from the latest commit of production branch" + ) + .command( + "push", + "Rebase the current branch from production and push all commit (run test before)" + ) + .command("rebase", "Rebase the current branch from production") + .command("rebase-all", "Rebase all branches from production") + .command( + "fetch", + "Download objects and refs from another repository (--all and --prune)" + ) + .command("sync", "Synchronize dev branch and production") + .command("config", "Operation about configuration") .parse(process.argv); diff --git a/bin/utils/assert.js b/bin/utils/assert.js index aa79cfd..7259260 100644 --- a/bin/utils/assert.js +++ b/bin/utils/assert.js @@ -1,5 +1,5 @@ -const commander = require('commander'); -const chalk = require('chalk'); +const commander = require("commander"); +const chalk = require("chalk"); module.exports = { assert(test, msg) { diff --git a/package.json b/package.json index 07b5ea9..93a803e 100644 --- a/package.json +++ b/package.json @@ -6,16 +6,17 @@ "bin": "bin/gflow.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 0", - "lint": "eslint \"{bin,src,test}/**/*.js\"", - "lint:fix": "eslint --fix \"{bin,src,test}/**/*.js\"", + "test:lint": "eslint \"{bin,src,test}/**/*.js\"", + "test:lint:fix": "eslint --fix \"{bin,src,test}/**/*.js\"", "prettier": "prettier '{bin,src,test}/**/*.js' --write", - "travis-deploy-once": "travis-deploy-once", - "semantic-release": "semantic-release", - "semantic-release:dryRun": "semantic-release --dryRun" + "release": "semantic-release", + "release:dryRun": "semantic-release --dryRun" }, "husky": { - "pre-commit": "lint-staged", - "post-commit": "git update-index --again" + "hooks": { + "pre-commit": "lint-staged", + "post-commit": "git update-index --again" + } }, "author": "Romain Lenzotti", "license": "MIT", @@ -59,10 +60,10 @@ }, "repository": { "type": "git", - "url": "https://github.com/Romakita/gflow.git" + "url": "https://github.com/tsed/gflow.git" }, "bugs": { - "url": "https://github.com/Romakita/gflow/issues" + "url": "https://github.com/tsedio/gflow/issues" }, - "homepage": "https://github.com/Romakita/gflow" + "homepage": "https://github.com/tsedio/gflow" } \ No newline at end of file diff --git a/src/command/branches.js b/src/command/branches.js index cbee76b..e4c89da 100644 --- a/src/command/branches.js +++ b/src/command/branches.js @@ -1,26 +1,30 @@ /* eslint-disable no-shadow */ -const chalk = require('chalk'); -const figures = require('figures'); -const inquirer = require('inquirer'); -const config = require('../config/config'); -const git = require('../git/index'); +const chalk = require("chalk"); +const figures = require("figures"); +const inquirer = require("inquirer"); +const config = require("../config/config"); +const git = require("../git/index"); const BRANCHES = new Map(); function runInteractive() { - const choices = buildBranchesList().map(info => ({ value: info.branch, name: info.message, short: info.branch })); + const choices = buildBranchesList().map(info => ({ + value: info.branch, + name: info.message, + short: info.branch + })); inquirer .prompt([ { - type: 'list', - name: 'branchChoice', - message: 'Select branch to switch on', - choices: choices.concat([new inquirer.Separator(), 'exit']) + type: "list", + name: "branchChoice", + message: "Select branch to switch on", + choices: choices.concat([new inquirer.Separator(), "exit"]) } ]) .then(answers => { - if (answers.branchChoice !== 'exit') { + if (answers.branchChoice !== "exit") { switchBranch(answers.branchChoice); } }) @@ -36,14 +40,16 @@ function switchBranch(branch) { let observable; if (branchInfo) { - observable = git.checkout(branchInfo.local ? branchInfo.local.branch : branchInfo.branch); + observable = git.checkout( + branchInfo.local ? branchInfo.local.branch : branchInfo.branch + ); } else { - const branchName = branch.split('/')[1]; + const branchName = branch.split("/")[1]; branchInfo = BRANCHES.get(branchName); if (branchInfo.local) { observable = git.checkout(branchInfo.local.branch); } else { - observable = git.checkout('-b', branchName, branchInfo.branch); + observable = git.checkout("-b", branchName, branchInfo.branch); } } @@ -59,11 +65,11 @@ function switchBranch(branch) { * @returns {Array.<*>} */ function branches() { - const remoteBranches = git.branchesInfos('-r'); + const remoteBranches = git.branchesInfos("-r"); const localBranches = git.branchesInfos(); remoteBranches.forEach(branchInfo => { - const branch = branchInfo.branch.split('/')[1]; + const branch = branchInfo.branch.split("/")[1]; if (branch === config.production) { branchInfo.$order = -1; @@ -112,21 +118,28 @@ function buildBranchesList() { const currentBranch = git.currentBranchName(); return branches().map(info => { - const branch = info.branch.split('/')[1] || info.branch; - const line = `${info.date} ${column(info.creation, 15)} ${column(info.author, 20)} ${info.branch}`; - let current = ' '; + const branch = info.branch.split("/")[1] || info.branch; + const line = `${info.date} ${column(info.creation, 15)} ${column( + info.author, + 20 + )} ${info.branch}`; + let current = " "; if (currentBranch === branch) { current = chalk.yellow(figures.star); } if (branch === config.production) { isUnderProduction = true; - info.message = `${current} ${chalk.yellow(figures.warning)} ${chalk.yellow(line)}`; + info.message = `${current} ${chalk.yellow( + figures.warning + )} ${chalk.yellow(line)}`; return info; } if (branch === config.remoteDevelop) { - info.message = `${current} ${chalk.gray(figures.bullet)} ${chalk.gray(line)}`; + info.message = `${current} ${chalk.gray(figures.bullet)} ${chalk.gray( + line + )}`; return info; } @@ -140,7 +153,7 @@ function buildBranchesList() { }); } -function line(str = '', length = 100, char = '-') { +function line(str = "", length = 100, char = "-") { let finalStr = str; for (let i = str.length; i < length; i++) { finalStr += char; @@ -148,7 +161,7 @@ function line(str = '', length = 100, char = '-') { return finalStr; } -function column(str = '', length = 30, char = ' ') { +function column(str = "", length = 30, char = " ") { return line(str, length, char); } diff --git a/src/command/branches/index.js b/src/command/branches/index.js index 20c438f..84ee3f6 100644 --- a/src/command/branches/index.js +++ b/src/command/branches/index.js @@ -1,27 +1,38 @@ -const inquirer = require('inquirer'); -const config = require('../../config/index'); -const git = require('../../git/index'); -const { toRemote } = require('../../utils/to-remote'); +const inquirer = require("inquirer"); +const config = require("../../config/index"); +const git = require("../../git/index"); +const { toRemote } = require("../../utils/to-remote"); -module.exports = ({ fromBranch, message = 'Start your branch from:' }) => { +module.exports = ({ fromBranch, message = "Start your branch from:" }) => { const currentBranch = git.currentBranchName(); let startFromBranches = [config.remoteProduction]; - if (startFromBranches.indexOf(toRemote(currentBranch)) === -1 && git.branchExists(currentBranch, config.remote)) { + if ( + startFromBranches.indexOf(toRemote(currentBranch)) === -1 && + git.branchExists(currentBranch, config.remote) + ) { startFromBranches = startFromBranches.concat(toRemote(currentBranch)); } - const remoteBranches = git.branchesInfos('-r') + const remoteBranches = git + .branchesInfos("-r") .map(info => info.branch) - .filter(name => startFromBranches.indexOf(name) === -1 && !(name === config.remoteDevelop || name === config.remoteProduction)); + .filter( + name => + startFromBranches.indexOf(name) === -1 && + !(name === config.remoteDevelop || name === config.remoteProduction) + ); if (remoteBranches.length) { - startFromBranches = startFromBranches.concat(new inquirer.Separator(), remoteBranches); + startFromBranches = startFromBranches.concat( + new inquirer.Separator(), + remoteBranches + ); } return { - type: 'list', - name: 'fromBranch', + type: "list", + name: "fromBranch", message, default: startFromBranches.indexOf(fromBranch || config.remoteProduction), choices: startFromBranches, diff --git a/src/command/create-branch/index.js b/src/command/create-branch/index.js index fb58a81..a3789b3 100644 --- a/src/command/create-branch/index.js +++ b/src/command/create-branch/index.js @@ -1,7 +1,7 @@ -const chalk = require('chalk'); -const git = require('../../git/index'); +const chalk = require("chalk"); +const git = require("../../git/index"); module.exports = ({ fromBranch, featureBranch }) => ({ title: `Create branch from ${chalk.green(fromBranch)}`, - task: () => git.checkout('--no-track', '-b', featureBranch, fromBranch) + task: () => git.checkout("--no-track", "-b", featureBranch, fromBranch) }); diff --git a/src/command/fetch.js b/src/command/fetch.js index 0164c8c..7492f86 100644 --- a/src/command/fetch.js +++ b/src/command/fetch.js @@ -1,6 +1,6 @@ -const chalk = require('chalk'); -const Listr = require('listr'); -const refreshRepository = require('./refresh-repository'); +const chalk = require("chalk"); +const Listr = require("listr"); +const refreshRepository = require("./refresh-repository"); module.exports = { getOptions(options = {}) { @@ -11,9 +11,7 @@ module.exports = { }, getTasks(options) { - return new Listr([ - refreshRepository(options) - ]); + return new Listr([refreshRepository(options)]); }, async fetch(options) { @@ -21,7 +19,7 @@ module.exports = { options = module.exports.getOptions(options); await module.exports.getTasks(options).run(); - console.log(options.output.filter(l => !l.match('Fetching')).join('\n')); + console.log(options.output.filter(l => !l.match("Fetching")).join("\n")); } catch (err) { console.error(chalk.red(String(err.all || err))); } diff --git a/src/command/finish.js b/src/command/finish.js index 81d58de..d2e6c06 100644 --- a/src/command/finish.js +++ b/src/command/finish.js @@ -1,21 +1,21 @@ -const Listr = require('listr'); -const chalk = require('chalk'); -const figures = require('figures'); -const execa = require('execa'); -const Sync = require('./sync'); -const config = require('../config'); -const { getRebaseInfo } = require('../utils/get-rebase-info'); -const runInstall = require('./install'); -const runTest = require('./test/index'); -const runRefreshRepository = require('./refresh-repository'); -const runPrepareWorkspace = require('./prepare-workspace'); -const runPushAndClean = require('./push-and-clean'); -const runRebaseBranch = require('./rebase-branch'); +const Listr = require("listr"); +const chalk = require("chalk"); +const figures = require("figures"); +const execa = require("execa"); +const Sync = require("./sync"); +const config = require("../config"); +const { getRebaseInfo } = require("../utils/get-rebase-info"); +const runInstall = require("./install"); +const runTest = require("./test/index"); +const runRefreshRepository = require("./refresh-repository"); +const runPrepareWorkspace = require("./prepare-workspace"); +const runPushAndClean = require("./push-and-clean"); +const runRebaseBranch = require("./rebase-branch"); const DEFAULT_OPTIONS = { checkStatus: false, test: !config.skipTest, - rebase: config.flow === 'gflow' + rebase: config.flow === "gflow" }; module.exports = { @@ -48,16 +48,25 @@ module.exports = { // Can't finish a production branch if (options.featureBranch === config.production) { - console.error(chalk.red(`${figures.cross} ${config.production} cannot be finished`)); + console.error( + chalk.red(`${figures.cross} ${config.production} cannot be finished`) + ); return; } await module.exports.getTasks(options).run(); - console.log(chalk.green(figures.tick), 'Branch', chalk.green(options.featureBranch), ' is finished'); + console.log( + chalk.green(figures.tick), + "Branch", + chalk.green(options.featureBranch), + " is finished" + ); if (config.postFinish) { - await execa.shell(config.postFinish, { stdio: ['inherit', 'inherit', 'inherit'] }); + await execa.shell(config.postFinish, { + stdio: ["inherit", "inherit", "inherit"] + }); } if (config.syncAfterFinish) { diff --git a/src/command/init.js b/src/command/init.js index 15b074e..1f9aa74 100644 --- a/src/command/init.js +++ b/src/command/init.js @@ -1,15 +1,11 @@ -const inquirer = require('inquirer'); -const config = require('../config/index'); -const { ConfigSchema } = require('../config/base-config'); +const inquirer = require("inquirer"); +const config = require("../config/index"); +const { ConfigSchema } = require("../config/base-config"); -const QUESTIONS = ConfigSchema - .filter(c => !!c.message) - .map((c) => ( - { - ...c, - default: config.get(c.name) || c.default - } - )); +const QUESTIONS = ConfigSchema.filter(c => !!c.message).map(c => ({ + ...c, + default: config.get(c.name) || c.default +})); module.exports = { QUESTIONS, diff --git a/src/command/install/check-install.js b/src/command/install/check-install.js index 42b9e2f..724c1f1 100644 --- a/src/command/install/check-install.js +++ b/src/command/install/check-install.js @@ -1,12 +1,11 @@ -const readPkgUp = require('read-pkg-up'); -const md5 = require('md5'); -const git = require('../../git'); +const readPkgUp = require("read-pkg-up"); +const md5 = require("md5"); +const git = require("../../git"); module.exports = { - getHash() { const { pkg = {} } = readPkgUp.sync(); - let hash = ''; + let hash = ""; if (pkg.dependencies) { hash += JSON.stringify(pkg.dependencies); @@ -20,12 +19,12 @@ module.exports = { }, getDate() { - const date = git.config('--local', 'npm.date'); + const date = git.config("--local", "npm.date"); return date ? new Date(date) : undefined; }, requiredInstall() { - const hashFromConfig = git.config('--local', 'npm.hash'); + const hashFromConfig = git.config("--local", "npm.hash"); const currentHash = module.exports.getHash(); const latestUpdate = module.exports.getDate(); const diff = Math.abs(new Date() - latestUpdate) / (24 * 3600 * 1000); @@ -34,7 +33,7 @@ module.exports = { }, refresh() { - git.config('--local', 'npm.hash', `${module.exports.getHash()}`); - git.config('--local', 'npm.date', `${new Date().toISOString()}`); + git.config("--local", "npm.hash", `${module.exports.getHash()}`); + git.config("--local", "npm.date", `${new Date().toISOString()}`); } }; diff --git a/src/command/install/index.js b/src/command/install/index.js index 414bc0a..b3c4054 100644 --- a/src/command/install/index.js +++ b/src/command/install/index.js @@ -1,39 +1,54 @@ -const hasYarn = require('has-yarn'); -const Listr = require('listr'); -const { catchError, throwError } = require('rxjs/operators'); -const exec = require('../../exec'); -const checkInstall = require('./check-install'); +const hasYarn = require("has-yarn"); +const Listr = require("listr"); +const { catchError, throwError } = require("rxjs/operators"); +const exec = require("../../exec"); +const checkInstall = require("./check-install"); module.exports = () => ({ - title: 'Install', + title: "Install", enabled: () => checkInstall.requiredInstall(), - task: () => new Listr( - [ - { - title: 'Installing dependencies using Yarn', - enabled: () => hasYarn() === true, - task: () => exec('yarn', ['install', '--frozen-lockfile', '--production=false']) - .pipe(catchError(error => { - if (error.stderr.startsWith('error Your lockfile needs to be updated')) { - throwError(new Error('yarn.lock file is outdated. Run yarn, commit the updated lockfile and try again.')); - } + task: () => + new Listr( + [ + { + title: "Installing dependencies using Yarn", + enabled: () => hasYarn() === true, + task: () => + exec("yarn", [ + "install", + "--frozen-lockfile", + "--production=false" + ]).pipe( + catchError(error => { + if ( + error.stderr.startsWith( + "error Your lockfile needs to be updated" + ) + ) { + throwError( + new Error( + "yarn.lock file is outdated. Run yarn, commit the updated lockfile and try again." + ) + ); + } - throwError(error); - })) - }, - { - title: 'Installing dependencies using npm', - enabled: () => hasYarn() === false, - task: () => { - const args = ['install', '--no-package-lock', '--no-production']; - return exec('npm', args); + throwError(error); + }) + ) + }, + { + title: "Installing dependencies using npm", + enabled: () => hasYarn() === false, + task: () => { + const args = ["install", "--no-package-lock", "--no-production"]; + return exec("npm", args); + } + }, + { + title: "Refresh metadata", + task: () => checkInstall.refresh() } - }, - { - title: 'Refresh metadata', - task: () => checkInstall.refresh() - } - ], - { concurrency: false } - ) + ], + { concurrency: false } + ) }); diff --git a/src/command/merge.js b/src/command/merge.js index 96ba634..d07b1a8 100644 --- a/src/command/merge.js +++ b/src/command/merge.js @@ -1,13 +1,13 @@ -const Listr = require('listr'); -const chalk = require('chalk'); -const figures = require('figures'); -const config = require('../config'); -const { getRebaseInfo } = require('../utils/get-rebase-info'); -const runInstall = require('./install/index'); -const runTest = require('./test/index'); -const runRefreshRepository = require('./refresh-repository'); -const runPrepareWorkspace = require('./prepare-workspace'); -const runPushBranch = require('./push-branch'); +const Listr = require("listr"); +const chalk = require("chalk"); +const figures = require("figures"); +const config = require("../config"); +const { getRebaseInfo } = require("../utils/get-rebase-info"); +const runInstall = require("./install/index"); +const runTest = require("./test/index"); +const runRefreshRepository = require("./refresh-repository"); +const runPrepareWorkspace = require("./prepare-workspace"); +const runPushBranch = require("./push-branch"); const DEFAULT_OPTIONS = { test: true, @@ -42,7 +42,12 @@ module.exports = { runPrepareWorkspace(options), runInstall(options), runTest(options), - runPushBranch({ ...options, force: true, noVerify: true, upstream: true }) + runPushBranch({ + ...options, + force: true, + noVerify: true, + upstream: true + }) ], {} ); @@ -57,12 +62,19 @@ module.exports = { options = module.exports.getOptions(options); if (options.featureBranch === config.production) { - console.error(chalk.red(`${figures.cross} ${config.production} cannot be merged`)); + console.error( + chalk.red(`${figures.cross} ${config.production} cannot be merged`) + ); return; } await module.exports.getTasks(options).run(); - console.log(chalk.green(figures.tick), 'Branch', chalk.green(options.featureBranch), ' is merged'); + console.log( + chalk.green(figures.tick), + "Branch", + chalk.green(options.featureBranch), + " is merged" + ); } catch (err) { console.error(chalk.red(String(err.all || err))); } diff --git a/src/command/new.js b/src/command/new.js index 16c064b..9bbac1c 100644 --- a/src/command/new.js +++ b/src/command/new.js @@ -1,18 +1,18 @@ -const Listr = require('listr'); -const chalk = require('chalk'); -const figures = require('figures'); -const inquirer = require('inquirer'); -const branches = require('./branches/index'); -const config = require('../config/index'); -const git = require('../git/index'); -const { normalizeBranchName } = require('../utils/normalize-branch'); -const runInstall = require('./install/index'); -const runRefreshRepository = require('./refresh-repository'); -const runCreateBranch = require('./create-branch'); +const Listr = require("listr"); +const chalk = require("chalk"); +const figures = require("figures"); +const inquirer = require("inquirer"); +const branches = require("./branches/index"); +const config = require("../config/index"); +const git = require("../git/index"); +const { normalizeBranchName } = require("../utils/normalize-branch"); +const runInstall = require("./install/index"); +const runRefreshRepository = require("./refresh-repository"); +const runCreateBranch = require("./create-branch"); const DEFAULT_OPTIONS = { - branchName: 'branch_name', - type: 'feat' + branchName: "branch_name", + type: "feat" }; module.exports = { @@ -38,20 +38,20 @@ module.exports = { async askQuestions(options = {}) { const questions = [ { - type: 'list', - name: 'type', - message: 'Choose the type of your branch:', + type: "list", + name: "type", + message: "Choose the type of your branch:", choices: config.getBranchTypes(), default: options.type, when: !options.type }, { - type: 'input', - name: 'branchName', - message: 'What is the branch name ?', + type: "input", + name: "branchName", + message: "What is the branch name ?", validate(branch) { if (!branch.length) { - return 'Branch name is required'; + return "Branch name is required"; } if (git.branchExists(branch, config.remote)) { @@ -93,7 +93,12 @@ module.exports = { options = module.exports.getOptions(options); await module.exports.getTasks(options).run(); - console.log(chalk.green(figures.tick), `New branch ${chalk.green(options.featureBranch)} created from ${chalk.green(options.fromBranch)} HEAD`); + console.log( + chalk.green(figures.tick), + `New branch ${chalk.green( + options.featureBranch + )} created from ${chalk.green(options.fromBranch)} HEAD` + ); } catch (err) { console.error(chalk.red(String(err.all || err))); } diff --git a/src/command/prepare-workspace/index.js b/src/command/prepare-workspace/index.js index ab0997c..f56e4ba 100644 --- a/src/command/prepare-workspace/index.js +++ b/src/command/prepare-workspace/index.js @@ -1,31 +1,36 @@ -const Listr = require('listr'); -const chalk = require('chalk'); -const { catchError } = require('rxjs/operators'); -const { of } = require('rxjs'); -const git = require('../../git'); - +const Listr = require("listr"); +const chalk = require("chalk"); +const { catchError } = require("rxjs/operators"); +const { of } = require("rxjs"); +const git = require("../../git"); module.exports = ({ featureBranch, fromBranch, fromLocalBranch }) => ({ - title: 'Prepare workspace', - task: () => new Listr( - [ - { - title: `Delete locale branch ${chalk.green(fromLocalBranch)}`, - task: (ctx, task) => git.branch('-D', fromLocalBranch) - .pipe(catchError(() => { - task.skip(`Local branch ${chalk.green(fromLocalBranch)} not found`); - return of(undefined); - })) - }, - { - title: `Checkout branch ${chalk.green(fromLocalBranch)}`, - task: () => git.checkout('-b', fromLocalBranch, fromBranch) - }, - { - title: `Merging branch ${chalk.green(featureBranch)}`, - task: () => git.merge('--no-ff', '-m', `Merge ${featureBranch}`, featureBranch) - } - ], - { concurrency: false } - ) + title: "Prepare workspace", + task: () => + new Listr( + [ + { + title: `Delete locale branch ${chalk.green(fromLocalBranch)}`, + task: (ctx, task) => + git.branch("-D", fromLocalBranch).pipe( + catchError(() => { + task.skip( + `Local branch ${chalk.green(fromLocalBranch)} not found` + ); + return of(undefined); + }) + ) + }, + { + title: `Checkout branch ${chalk.green(fromLocalBranch)}`, + task: () => git.checkout("-b", fromLocalBranch, fromBranch) + }, + { + title: `Merging branch ${chalk.green(featureBranch)}`, + task: () => + git.merge("--no-ff", "-m", `Merge ${featureBranch}`, featureBranch) + } + ], + { concurrency: false } + ) }); diff --git a/src/command/push-and-clean/index.js b/src/command/push-and-clean/index.js index 0d49ef2..cfe904c 100644 --- a/src/command/push-and-clean/index.js +++ b/src/command/push-and-clean/index.js @@ -1,17 +1,21 @@ -const Listr = require('listr'); -const runPushBranch = require('../push-branch'); -const runRemoveRemoteBranch = require('../remove-remote-branch'); -const runRemoveLocaleBranch = require('../remove-locale-branch'); +const Listr = require("listr"); +const runPushBranch = require("../push-branch"); +const runRemoveRemoteBranch = require("../remove-remote-branch"); +const runRemoveLocaleBranch = require("../remove-locale-branch"); -module.exports = ({ featureBranch, fromLocalBranch } = {}) => ( - { - title: 'Push and clean', - task: () => new Listr( +module.exports = ({ featureBranch, fromLocalBranch } = {}) => ({ + title: "Push and clean", + task: () => + new Listr( [ - runPushBranch({ featureBranch: fromLocalBranch, force: false, noVerify: true }), + runPushBranch({ + featureBranch: fromLocalBranch, + force: false, + noVerify: true + }), runRemoveRemoteBranch({ featureBranch }), runRemoveLocaleBranch({ featureBranch }) ], { concurrency: false } ) - }); +}); diff --git a/src/command/push-branch/index.js b/src/command/push-branch/index.js index 90827b5..7340df0 100644 --- a/src/command/push-branch/index.js +++ b/src/command/push-branch/index.js @@ -1,13 +1,19 @@ -const git = require('../../git/index'); -const config = require('../../config/index'); +const git = require("../../git/index"); +const config = require("../../config/index"); -module.exports = ({ featureBranch, upstream = true, noVerify = true, force = false }) => ({ +module.exports = ({ + featureBranch, + upstream = true, + noVerify = true, + force = false +}) => ({ title: `Push ${featureBranch}`, - task: () => git.push( - upstream ? '-u' : '', - force ? '-f' : '', - config.remote, - featureBranch, - noVerify ? '--no-verify' : '' - ) + task: () => + git.push( + upstream ? "-u" : "", + force ? "-f" : "", + config.remote, + featureBranch, + noVerify ? "--no-verify" : "" + ) }); diff --git a/src/command/push.js b/src/command/push.js index c93fbd9..e690c47 100644 --- a/src/command/push.js +++ b/src/command/push.js @@ -1,21 +1,21 @@ /* eslint-disable global-require */ -const Listr = require('listr'); -const chalk = require('chalk'); -const figures = require('figures'); -const config = require('../config'); -const { getRebaseInfo } = require('../utils/get-rebase-info'); -const runRefreshRepository = require('./refresh-repository'); -const runInstall = require('./install'); -const runTest = require('./test'); -const runRebaseBranch = require('./rebase-branch'); -const runPushBranch = require('./push-branch'); +const Listr = require("listr"); +const chalk = require("chalk"); +const figures = require("figures"); +const config = require("../config"); +const { getRebaseInfo } = require("../utils/get-rebase-info"); +const runRefreshRepository = require("./refresh-repository"); +const runInstall = require("./install"); +const runTest = require("./test"); +const runRebaseBranch = require("./rebase-branch"); +const runPushBranch = require("./push-branch"); const DEFAULT_OPTIONS = { checkStatus: true, force: false, fromBranch: undefined, test: !config.skipTest, - rebase: config.flow === 'gflow' + rebase: config.flow === "gflow" }; module.exports = { @@ -52,7 +52,12 @@ module.exports = { try { options = module.exports.getOptions(options); await module.exports.getTasks(options).run(); - console.log(chalk.green(figures.tick), 'Branch', chalk.green(options.featureBranch), 'rebased and pushed.'); + console.log( + chalk.green(figures.tick), + "Branch", + chalk.green(options.featureBranch), + "rebased and pushed." + ); } catch (err) { console.error(chalk.red(String(err.all || err))); } diff --git a/src/command/rebase-branch/index.js b/src/command/rebase-branch/index.js index 4e71a54..96b80a1 100644 --- a/src/command/rebase-branch/index.js +++ b/src/command/rebase-branch/index.js @@ -1,7 +1,7 @@ -const Listr = require('listr'); -const chalk = require('chalk'); -const git = require('../../git/index'); -const config = require('../../config/index'); +const Listr = require("listr"); +const chalk = require("chalk"); +const git = require("../../git/index"); +const config = require("../../config/index"); /** * @@ -14,32 +14,38 @@ async function checkBranchRemoteStatus({ featureBranch, force }) { if (isBranchExists && !force) { const result = git.checkBranchRemoteStatusSync(featureBranch); if (!result) { - throw new Error('Remote branch changed, check diff before continue'); + throw new Error("Remote branch changed, check diff before continue"); } } } - -module.exports = ({ featureBranch, fromBranch, force, checkStatus = true, rebase = true }) => ({ - title: 'Rebase branch', - task: () => new Listr( - [ - { - title: 'Remote info', - enabled: () => rebase, - task: () => git.remote('-v') - }, - { - title: 'Check status', - enabled: () => checkStatus, - task: () => checkBranchRemoteStatus({ force, featureBranch }) - }, - { - title: `Rebase from ${chalk.green(fromBranch)}`, - enabled: () => rebase, - task: () => git.rebase(fromBranch) - } - ], - { concurrent: false } - ) +module.exports = ({ + featureBranch, + fromBranch, + force, + checkStatus = true, + rebase = true +}) => ({ + title: "Rebase branch", + task: () => + new Listr( + [ + { + title: "Remote info", + enabled: () => rebase, + task: () => git.remote("-v") + }, + { + title: "Check status", + enabled: () => checkStatus, + task: () => checkBranchRemoteStatus({ force, featureBranch }) + }, + { + title: `Rebase from ${chalk.green(fromBranch)}`, + enabled: () => rebase, + task: () => git.rebase(fromBranch) + } + ], + { concurrent: false } + ) }); diff --git a/src/command/rebase.js b/src/command/rebase.js index 73cd73c..9a867ff 100644 --- a/src/command/rebase.js +++ b/src/command/rebase.js @@ -1,11 +1,11 @@ /* eslint-disable global-require */ -const Listr = require('listr'); -const chalk = require('chalk'); -const figures = require('figures'); -const { getRebaseInfo } = require('../utils/get-rebase-info'); -const runRefreshRepository = require('./refresh-repository'); -const runRebaseBranch = require('./rebase-branch'); -const runInstall = require('./install'); +const Listr = require("listr"); +const chalk = require("chalk"); +const figures = require("figures"); +const { getRebaseInfo } = require("../utils/get-rebase-info"); +const runRefreshRepository = require("./refresh-repository"); +const runRebaseBranch = require("./rebase-branch"); +const runInstall = require("./install"); const DEFAULT_OPTIONS = { test: false, @@ -41,7 +41,12 @@ module.exports = { options = module.exports.getOptions(options); await this.getTasks(options).run(); - console.log(chalk.green(figures.tick), `Branch ${chalk.green(options.featureBranch)} rebased from ${chalk.green(options.fromBranch)} HEAD`); + console.log( + chalk.green(figures.tick), + `Branch ${chalk.green( + options.featureBranch + )} rebased from ${chalk.green(options.fromBranch)} HEAD` + ); } catch (err) { console.error(chalk.red(String(err.all || err))); } diff --git a/src/command/rebaseAll.js b/src/command/rebaseAll.js index e88b6c2..d02745d 100644 --- a/src/command/rebaseAll.js +++ b/src/command/rebaseAll.js @@ -1,13 +1,13 @@ /* eslint-disable no-shadow */ -const { catchError } = require('rxjs/operators'); -const Listr = require('listr'); -const chalk = require('chalk'); -const figures = require('figures'); -const config = require('../config'); -const git = require('../git/index'); -const { getBrancheName } = require('../utils/get-branche-name'); -const { getRebaseInfo } = require('../utils/get-rebase-info'); -const refreshRepository = require('./refresh-repository'); +const { catchError } = require("rxjs/operators"); +const Listr = require("listr"); +const chalk = require("chalk"); +const figures = require("figures"); +const config = require("../config"); +const git = require("../git/index"); +const { getBrancheName } = require("../utils/get-branche-name"); +const { getRebaseInfo } = require("../utils/get-rebase-info"); +const refreshRepository = require("./refresh-repository"); /** * @@ -15,63 +15,71 @@ const refreshRepository = require('./refresh-repository'); * @returns {Listr} */ function rebaseBranches(options) { - const remoteBranches = git.branchesInfos('-r'); + const remoteBranches = git.branchesInfos("-r"); const rules = Object.concat( - [options.production, options.develop, 'legacy', /\d+\.\d+\.\d+/gi], + [options.production, options.develop, "legacy", /\d+\.\d+\.\d+/gi], (options.ignores || []).map(o => new RegExp(o)) ); const branchesFailed = []; - const tasks = remoteBranches.filter(branchInfo => !rules.find(rule => getBrancheName(branchInfo.branch).match(rule))).map(branchInfo => { - const branchName = getBrancheName(branchInfo.branch); + const tasks = remoteBranches + .filter( + branchInfo => + !rules.find(rule => getBrancheName(branchInfo.branch).match(rule)) + ) + .map(branchInfo => { + const branchName = getBrancheName(branchInfo.branch); - return { - title: `${branchInfo.branch}`, - task: () => new Listr([ - { - title: 'Checkout', - task: (ctx) => { - ctx.branchesFailed = branchesFailed; - ctx.skipPush = false; - return git.checkout('-b', `branch-${branchName}`, branchInfo.branch); - } - }, - { - title: 'Rebase', - task: (ctx, task) => { - const { fromBranch } = getRebaseInfo(); + return { + title: `${branchInfo.branch}`, + task: () => + new Listr([ + { + title: "Checkout", + task: ctx => { + ctx.branchesFailed = branchesFailed; + ctx.skipPush = false; + return git.checkout( + "-b", + `branch-${branchName}`, + branchInfo.branch + ); + } + }, + { + title: "Rebase", + task: (ctx, task) => { + const { fromBranch } = getRebaseInfo(); - return git - .rebase(fromBranch) - .pipe( - catchError(() => { - ctx.skipPush = true; - branchesFailed.push(branchInfo); - task.skip('Rebase failed'); + return git.rebase(fromBranch).pipe( + catchError(() => { + ctx.skipPush = true; + branchesFailed.push(branchInfo); + task.skip("Rebase failed"); - return git.rebase('--abort'); - }) - ); - } - }, - { - title: 'Push', - skip: ctx => ctx.skipPush, - task: () => git.push('-f', config.remote, `HEAD:${branchName}`) - }, - { - title: 'Clean', - task: () => git.checkout(options.production) - }, - { - title: 'Remove', - task: () => git.branch('-D', `branch-${branchName}`) - } - ]) - }; - }); + return git.rebase("--abort"); + }) + ); + } + }, + { + title: "Push", + skip: ctx => ctx.skipPush, + task: () => git.push("-f", config.remote, `HEAD:${branchName}`) + }, + { + title: "Clean", + task: () => git.checkout(options.production) + }, + { + title: "Remove", + task: () => git.branch("-D", `branch-${branchName}`) + } + ]) + }; + }); return new Listr(tasks); } @@ -80,7 +88,7 @@ function runInteractive(options) { const tasks = new Listr([ refreshRepository(options), { - title: 'Rebase branches', + title: "Rebase branches", task: () => rebaseBranches(options) } ]); @@ -89,10 +97,19 @@ function runInteractive(options) { .run() .then(ctx => { if (ctx.branchesFailed.length) { - console.log(chalk.red(` ${chalk.red(figures.cross)} Rebasing on some branches have failed:`)); + console.log( + chalk.red( + ` ${chalk.red( + figures.cross + )} Rebasing on some branches have failed:` + ) + ); ctx.branchesFailed.forEach(info => { - const line = `${info.date} ${column(info.creation, 15)} ${column(info.author, 20)} ${info.branch}`; + const line = `${info.date} ${column(info.creation, 15)} ${column( + info.author, + 20 + )} ${info.branch}`; console.log(` ${chalk.red(line)}`); }); } @@ -102,7 +119,7 @@ function runInteractive(options) { }); } -function line(str = '', length = 100, char = '-') { +function line(str = "", length = 100, char = "-") { let finalStr = str; for (let i = str.length; i < length; i++) { finalStr += char; @@ -110,7 +127,7 @@ function line(str = '', length = 100, char = '-') { return finalStr; } -function column(str = '', length = 30, char = ' ') { +function column(str = "", length = 30, char = " ") { return line(str, length, char); } diff --git a/src/command/refresh-repository/index.js b/src/command/refresh-repository/index.js index d7822d2..392583c 100644 --- a/src/command/refresh-repository/index.js +++ b/src/command/refresh-repository/index.js @@ -1,14 +1,16 @@ -const { EMPTY } = require('rxjs'); -const { catchError } = require('rxjs/operators'); -const Listr = require('listr'); +const { EMPTY } = require("rxjs"); +const { catchError } = require("rxjs/operators"); +const Listr = require("listr"); -const git = require('../../git/index'); +const git = require("../../git/index"); function pipe(observable, output) { - observable.pipe(catchError((err) => { - output.push(err); - return EMPTY; - })); + observable.pipe( + catchError(err => { + output.push(err); + return EMPTY; + }) + ); observable.subscribe(result => { output.push(result); @@ -18,15 +20,24 @@ function pipe(observable, output) { } module.exports = ({ output = [] } = {}) => ({ - title: 'Refresh local repository', - task: () => new Listr([ - { - title: 'Git fetch', - task: () => pipe(git.fetch(), output) - }, - { - title: 'Git prune', - task: () => pipe(git.prune(), output) - } - ]) + title: "Refresh local repository", + task: () => + new Listr([ + { + title: "Git fetch", + task: () => + pipe( + git.fetch(), + output + ) + }, + { + title: "Git prune", + task: () => + pipe( + git.prune(), + output + ) + } + ]) }); diff --git a/src/command/release.js b/src/command/release.js index d29c5c7..a6eb6d0 100644 --- a/src/command/release.js +++ b/src/command/release.js @@ -1,21 +1,26 @@ -const fs = require('fs'); -const chalk = require('chalk'); -const logger = require('fancy-log'); -const figures = require('figures'); -const git = require('../git/index'); -const CI = require('../config/ci'); -const config = require('../config'); +const fs = require("fs"); +const chalk = require("chalk"); +const logger = require("fancy-log"); +const figures = require("figures"); +const git = require("../git/index"); +const CI = require("../config/ci"); +const config = require("../config"); /** * * @returns {any} */ -const readPackage = () => writePackage(JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf8' }))); +const readPackage = () => + writePackage( + JSON.parse(fs.readFileSync("./package.json", { encoding: "utf8" })) + ); /** * * @param pkg */ const writePackage = pkg => { - fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2), { encoding: 'utf8' }); + fs.writeFileSync("./package.json", JSON.stringify(pkg, null, 2), { + encoding: "utf8" + }); return pkg; }; @@ -29,16 +34,27 @@ module.exports = { if (CI) { if (EMAIL && USER) { - git.config('--global', 'user.email', EMAIL); - git.config('--global', 'user.name', USER); + git.config("--global", "user.email", EMAIL); + git.config("--global", "user.name", USER); } git.checkoutSync(config.production); - git.branchSync(`--set-upstream-to=${config.remoteProduction}`, config.production); - - logger('[Gflow release]', chalk.green(figures.tick), `${CI.NAME} CI Installed`); + git.branchSync( + `--set-upstream-to=${config.remoteProduction}`, + config.production + ); + + logger( + "[Gflow release]", + chalk.green(figures.tick), + `${CI.NAME} CI Installed` + ); } else { - logger('[Gflow release]', chalk.yellow(figures.cross), 'Not in CI environment'); + logger( + "[Gflow release]", + chalk.yellow(figures.cross), + "Not in CI environment" + ); } return Promise.resolve(); @@ -53,7 +69,7 @@ module.exports = { nextRelease: { version } } = context; - logger('[Gflow release] Write package.json'); + logger("[Gflow release] Write package.json"); const pkg = readPackage(); pkg.version = version; @@ -71,32 +87,39 @@ module.exports = { version, repository: { url } } = pkg; - const repository = url.replace('https://', ''); + const repository = url.replace("https://", ""); if (!CI) { - logger('[Gflow release]', chalk.yellow(figures.cross), 'Not in CI environment'); + logger( + "[Gflow release]", + chalk.yellow(figures.cross), + "Not in CI environment" + ); return Promise.resolve(); } - logger('[Gflow release]', `Generate release tag for v${version}`); - logger('[Gflow release]', `REPOSITORY: ${repository}`); - logger('[Gflow release]', `RELEASE_BRANCH: ${config.production}`); - logger('[Gflow release]', `DEVELOP_BRANCH: ${config.develop}`); - logger('[Gflow release]', `BUILD: ${CI.BUILD_NUMBER}`); + logger("[Gflow release]", `Generate release tag for v${version}`); + logger("[Gflow release]", `REPOSITORY: ${repository}`); + logger("[Gflow release]", `RELEASE_BRANCH: ${config.production}`); + logger("[Gflow release]", `DEVELOP_BRANCH: ${config.develop}`); + logger("[Gflow release]", `BUILD: ${CI.BUILD_NUMBER}`); if (GH_TOKEN) { - logger('[Gflow release]', `Configure remote repository ${repository}`); - git.remoteSync('add', CI.ORIGIN, `https://${GH_TOKEN}@${repository}`); + logger("[Gflow release]", `Configure remote repository ${repository}`); + git.remoteSync("add", CI.ORIGIN, `https://${GH_TOKEN}@${repository}`); } - logger('[Gflow release]', 'Adding files to commit'); - git.addSync('-A'); + logger("[Gflow release]", "Adding files to commit"); + git.addSync("-A"); - logger('[Gflow release]', 'Reset .npmrc'); - git.resetSync('--', '.npmrc'); + logger("[Gflow release]", "Reset .npmrc"); + git.resetSync("--", ".npmrc"); - logger('[Gflow release]', 'Commit files'); - git.commitSync('-m', `${CI.NAME} build: ${CI.BUILD_NUMBER} v${version} [ci skip]`); + logger("[Gflow release]", "Commit files"); + git.commitSync( + "-m", + `${CI.NAME} build: ${CI.BUILD_NUMBER} v${version} [ci skip]` + ); return undefined; }, @@ -111,13 +134,20 @@ module.exports = { success() { try { - logger('[Gflow release]', `Push to ${config.production}`); - git.pushSync('--quiet', '--set-upstream', CI.ORIGIN, config.production); - - logger('[Gflow release]', `Sync ${config.develop} with ${config.production}`); - git.pushSync('-f', CI.ORIGIN, `${config.production}:refs/heads/${config.develop}`); - - logger(chalk.green(figures.tick), 'Release tag are applied on git'); + logger("[Gflow release]", `Push to ${config.production}`); + git.pushSync("--quiet", "--set-upstream", CI.ORIGIN, config.production); + + logger( + "[Gflow release]", + `Sync ${config.develop} with ${config.production}` + ); + git.pushSync( + "-f", + CI.ORIGIN, + `${config.production}:refs/heads/${config.develop}` + ); + + logger(chalk.green(figures.tick), "Release tag are applied on git"); } catch (er) { logger(chalk.red(figures.cross), String(er), er.stack); } diff --git a/src/command/remove-locale-branch/index.js b/src/command/remove-locale-branch/index.js index 9dfff3d..9adb0f9 100644 --- a/src/command/remove-locale-branch/index.js +++ b/src/command/remove-locale-branch/index.js @@ -1,6 +1,6 @@ -const chalk = require('chalk'); -const config = require('../../config'); -const git = require('../../git'); +const chalk = require("chalk"); +const config = require("../../config"); +const git = require("../../git"); /** * @@ -8,11 +8,13 @@ const git = require('../../git'); * @returns {boolean} */ function removeBranch(featureBranch) { - return featureBranch !== config.develop && featureBranch !== config.production; + return ( + featureBranch !== config.develop && featureBranch !== config.production + ); } module.exports = ({ featureBranch }) => ({ title: `Remove ${chalk.green(featureBranch)}`, enabled: () => removeBranch(featureBranch), - task: () => git.branch('-d', featureBranch) + task: () => git.branch("-d", featureBranch) }); diff --git a/src/command/remove-remote-branch/index.js b/src/command/remove-remote-branch/index.js index dc63c39..59a91b6 100644 --- a/src/command/remove-remote-branch/index.js +++ b/src/command/remove-remote-branch/index.js @@ -1,6 +1,6 @@ -const chalk = require('chalk'); -const config = require('../../config'); -const git = require('../../git'); +const chalk = require("chalk"); +const config = require("../../config"); +const git = require("../../git"); /** * @@ -8,11 +8,14 @@ const git = require('../../git'); * @returns {*|boolean} */ function removeRemoteBranch(featureBranch) { - return git.branchExists(featureBranch, config.remote) && featureBranch !== config.develop; + return ( + git.branchExists(featureBranch, config.remote) && + featureBranch !== config.develop + ); } module.exports = ({ featureBranch }) => ({ title: `Remove ${chalk.green(`${config.remote}/${featureBranch}`)}`, enabled: () => removeRemoteBranch(featureBranch), - task: () => git.push(config.remote, `:${featureBranch}`, '--no-verify') + task: () => git.push(config.remote, `:${featureBranch}`, "--no-verify") }); diff --git a/src/command/sync.js b/src/command/sync.js index eb0d793..6607b93 100644 --- a/src/command/sync.js +++ b/src/command/sync.js @@ -1,66 +1,83 @@ -const Listr = require('listr'); -const chalk = require('chalk'); -const figures = require('figures'); -const { catchError } = require('rxjs/operators'); -const { of } = require('rxjs'); -const config = require('../config'); -const git = require('../git/index'); -const refreshRepository = require('./refresh-repository'); -const runPushBranch = require('./push-branch'); +const Listr = require("listr"); +const chalk = require("chalk"); +const figures = require("figures"); +const { catchError } = require("rxjs/operators"); +const { of } = require("rxjs"); +const config = require("../config"); +const git = require("../git/index"); +const refreshRepository = require("./refresh-repository"); +const runPushBranch = require("./push-branch"); module.exports = { getTasks() { return new Listr([ refreshRepository(), { - title: 'Synchronize', - task: () => new Listr( - [ - { - title: `Checkout branch ${config.develop}`, - task: (ctx, task) => git.checkout('-b', config.develop, `${config.remote}/${config.develop}`) - .pipe(catchError(() => { - task.skip(`Local branch ${config.develop} exists`); - return of(undefined); - })) - }, - { - title: `Checkout branch ${config.develop}`, - task: (ctx, task) => git.checkout(config.develop) - .pipe(catchError(() => { - task.skip(`Already on branch ${config.develop}`); - return of(undefined); - })) - }, - { - title: `Delete locale branch ${config.production}`, - task: (ctx, task) => git.branch('-D', config.production) - .pipe(catchError(() => { - task.skip(`Local branch ${config.production} not found`); - return of(undefined); - })) - }, - { - title: `Checkout branch ${config.production}`, - task: () => git.checkout('-b', config.production, config.remoteProduction) - }, - { - title: `Checkout branch ${config.develop}`, - task: (ctx, task) => git.checkout(config.develop) - .pipe(catchError(() => { - task.skip(`Already on branch ${config.develop}`); - return of(undefined); - })) - }, - { - title: `Reset hard ${config.develop}`, - task: () => git.reset('--hard', `refs/heads/${config.production}`) - }, + title: "Synchronize", + task: () => + new Listr( + [ + { + title: `Checkout branch ${config.develop}`, + task: (ctx, task) => + git + .checkout( + "-b", + config.develop, + `${config.remote}/${config.develop}` + ) + .pipe( + catchError(() => { + task.skip(`Local branch ${config.develop} exists`); + return of(undefined); + }) + ) + }, + { + title: `Checkout branch ${config.develop}`, + task: (ctx, task) => + git.checkout(config.develop).pipe( + catchError(() => { + task.skip(`Already on branch ${config.develop}`); + return of(undefined); + }) + ) + }, + { + title: `Delete locale branch ${config.production}`, + task: (ctx, task) => + git.branch("-D", config.production).pipe( + catchError(() => { + task.skip(`Local branch ${config.production} not found`); + return of(undefined); + }) + ) + }, + { + title: `Checkout branch ${config.production}`, + task: () => + git.checkout("-b", config.production, config.remoteProduction) + }, + { + title: `Checkout branch ${config.develop}`, + task: (ctx, task) => + git.checkout(config.develop).pipe( + catchError(() => { + task.skip(`Already on branch ${config.develop}`); + return of(undefined); + }) + ) + }, + { + title: `Reset hard ${config.develop}`, + task: () => + git.reset("--hard", `refs/heads/${config.production}`) + }, - runPushBranch({ featureBranch: config.develop, force: true }) - ], - { concurrency: false } - ) + runPushBranch({ featureBranch: config.develop, force: true }) + ], + { concurrency: false } + ) } ]); }, @@ -68,7 +85,13 @@ module.exports = { async syncBranches() { try { await module.exports.getTasks().run(); - console.log(chalk.green(figures.tick), 'Branch', config.develop, 'synchronized with', config.production); + console.log( + chalk.green(figures.tick), + "Branch", + config.develop, + "synchronized with", + config.production + ); } catch (err) { console.error(chalk.red(String(err.all || err))); } diff --git a/src/command/test/index.js b/src/command/test/index.js index b5d7cbb..8e3b5c3 100644 --- a/src/command/test/index.js +++ b/src/command/test/index.js @@ -1,12 +1,13 @@ -const exec = require('../../exec'); -const hasYarn = require('has-yarn'); +const exec = require("../../exec"); +const hasYarn = require("has-yarn"); module.exports = options => ({ - title: 'Test', + title: "Test", skip: () => !options.test, - task: () => exec(hasYarn ? 'yarn' : 'npm', ['test'], { - env: { - CI: 'GFLOW' - } - }) + task: () => + exec(hasYarn ? "yarn" : "npm", ["test"], { + env: { + CI: "GFLOW" + } + }) }); diff --git a/src/config/base-config.js b/src/config/base-config.js index 7f6183a..33ddd13 100644 --- a/src/config/base-config.js +++ b/src/config/base-config.js @@ -1,22 +1,24 @@ -const CONFIG_BASENAME = '.gflowrc'; +const CONFIG_BASENAME = ".gflowrc"; const ConfigSchema = [ /** * Value: gitflow or gflow */ { - default: 'gflow', - type: 'list', - name: 'flow', - message: 'What flow do you want to use?', + default: "gflow", + type: "list", + name: "flow", + message: "What flow do you want to use?", choices: [ { - label: 'GFlow - Use rebase command when pushing/finishing branch on remote', - value: 'gflow' + label: + "GFlow - Use rebase command when pushing/finishing branch on remote", + value: "gflow" }, { - label: 'GFlow - Use rebase command when pushing/finishing branch on remote', - value: 'gitflow' + label: + "GFlow - Use rebase command when pushing/finishing branch on remote", + value: "gitflow" } ] }, @@ -24,91 +26,93 @@ const ConfigSchema = [ * */ { - default: 'origin', - type: 'input', - name: 'remote', - message: 'What is your remote alias name?' + default: "origin", + type: "input", + name: "remote", + message: "What is your remote alias name?" }, /** * */ { - default: 'master', - type: 'input', - name: 'develop', - message: 'What is your development branch name?' + default: "master", + type: "input", + name: "develop", + message: "What is your development branch name?" }, /** * */ { - default: 'production', - type: 'input', - name: 'production', - message: 'What is your production branch name?' + default: "production", + type: "input", + name: "production", + message: "What is your production branch name?" }, /** * */ { default: [], - name: 'ignores' + name: "ignores" }, /** * */ { default: false, - type: 'confirm', - name: 'syncAfterFinish', - enable: (ctx) => ctx.production !== ctx.develop, - message: 'Reset development branch over production after gflow finish?' + type: "confirm", + name: "syncAfterFinish", + enable: ctx => ctx.production !== ctx.develop, + message: "Reset development branch over production after gflow finish?" }, /** * */ { - default: '', - name: 'postFinish' + default: "", + name: "postFinish" }, /** * */ { default: false, - type: 'confirm', - name: 'skipTest', - message: 'Skip unit test when pushing/finishing branch?' + type: "confirm", + name: "skipTest", + message: "Skip unit test when pushing/finishing branch?" }, /** * */ { - default: '-', - name: 'charReplacement' + default: "-", + name: "charReplacement" }, /** * */ { default: { - feat: 'feat', - fix: 'fix', - chore: 'chore', - docs: 'docs', - release: 'release' + feat: "feat", + fix: "fix", + chore: "chore", + docs: "docs", + release: "release" }, - name: 'branchTypes' + name: "branchTypes" } ]; module.exports = { ConfigSchema, CONFIG_BASENAME, - DEFAULT_CONFIG: ConfigSchema - .reduce((acc, { name, default: defaultValue }) => { + DEFAULT_CONFIG: ConfigSchema.reduce( + (acc, { name, default: defaultValue }) => { acc[name] = defaultValue; return acc; - }, {}) + }, + {} + ) }; diff --git a/src/config/ci.js b/src/config/ci.js index 3538b90..d68bf29 100644 --- a/src/config/ci.js +++ b/src/config/ci.js @@ -6,11 +6,11 @@ module.exports = (() => { const { TRAVIS_BUILD_NUMBER } = env; return { - NAME: 'Travis CI', - USER: GIT_USER_NAME || 'Travis CI', - EMAIL: GIT_USER_EMAIL || 'travis@travis-ci.org', + NAME: "Travis CI", + USER: GIT_USER_NAME || "Travis CI", + EMAIL: GIT_USER_EMAIL || "travis@travis-ci.org", BUILD_NUMBER: TRAVIS_BUILD_NUMBER, - ORIGIN: 'origin-git' + ORIGIN: "origin-git" }; } @@ -18,34 +18,34 @@ module.exports = (() => { const { CI_BUILD_ID, CI_JOB_ID } = env; return { - NAME: 'GitLab CI', - USER: GIT_USER_NAME || 'GitLab CI', - email: GIT_USER_EMAIL || 'gitlab@gitlab.com', + NAME: "GitLab CI", + USER: GIT_USER_NAME || "GitLab CI", + EMAIL: GIT_USER_EMAIL || "gitlab@gitlab.com", BUILD_NUMBER: CI_BUILD_ID || CI_JOB_ID, - ORIGIN: 'origin-git' + ORIGIN: "origin-git" }; } if (env.CIRCLECI) { const { CIRCLE_BUILD_NUM } = env; return { - NAME: 'Circle CI', - USER: GIT_USER_NAME || 'Circle CI', - EMAIL: GIT_USER_EMAIL || 'circle@circleci.com', + NAME: "Circle CI", + USER: GIT_USER_NAME || "Circle CI", + EMAIL: GIT_USER_EMAIL || "circle@circleci.com", BUILD_NUMBER: CIRCLE_BUILD_NUM, - ORIGIN: 'origin-git' + ORIGIN: "origin-git" }; } return { - NAME: 'Unsupported CI', - BUILD_NUMBER: '', - ORIGIN: 'origin-git' + NAME: "Unsupported CI", + BUILD_NUMBER: "", + ORIGIN: "origin-git" }; } // / local return { - NAME: 'LOCAL', - BUILD_NUMBER: '', - ORIGIN: 'origin' + NAME: "LOCAL", + BUILD_NUMBER: "", + ORIGIN: "origin" }; })(); diff --git a/src/config/config.js b/src/config/config.js index dfd3f28..ce48405 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -1,6 +1,6 @@ -const path = require('path'); -const fs = require('fs'); -const { DEFAULT_CONFIG, CONFIG_BASENAME } = require('./base-config'); +const path = require("path"); +const fs = require("fs"); +const { DEFAULT_CONFIG, CONFIG_BASENAME } = require("./base-config"); class Config extends Map { constructor() { @@ -9,7 +9,7 @@ class Config extends Map { } get charReplacement() { - return this.get('charReplacement'); + return this.get("charReplacement"); } /** @@ -17,7 +17,7 @@ class Config extends Map { * @returns {*} */ get remote() { - return this.get('remote'); + return this.get("remote"); } /** @@ -25,7 +25,7 @@ class Config extends Map { * @returns {*} */ get production() { - return this.get('production'); + return this.get("production"); } /** @@ -33,7 +33,7 @@ class Config extends Map { * @returns {*} */ get flow() { - return this.get('flow') || 'gflow'; + return this.get("flow") || "gflow"; } /** @@ -41,7 +41,7 @@ class Config extends Map { * @returns {string} */ get remoteProduction() { - return `${this.get('remote')}/${this.get('production')}`; + return `${this.get("remote")}/${this.get("production")}`; } /** @@ -49,7 +49,7 @@ class Config extends Map { * @returns {*|string} */ get develop() { - return this.get('develop'); + return this.get("develop"); } /** @@ -57,7 +57,7 @@ class Config extends Map { * @returns {string} */ get remoteDevelop() { - return `${this.get('remote')}/${this.get('develop')}`; + return `${this.get("remote")}/${this.get("develop")}`; } /** @@ -65,7 +65,7 @@ class Config extends Map { * @returns {*} */ get syncAfterFinish() { - return this.get('syncAfterFinish'); + return this.get("syncAfterFinish"); } /** @@ -73,15 +73,15 @@ class Config extends Map { * @returns {*} */ get postFinish() { - return this.get('postFinish'); + return this.get("postFinish"); } get skipTest() { - return this.get('skipTest'); + return this.get("skipTest"); } get branchTypes() { - return this.get('branchTypes') || {}; + return this.get("branchTypes") || {}; } /** @@ -115,8 +115,8 @@ class Config extends Map { Object.keys(config).forEach(key => { const value = config[key]; - if (key === 'master') { - key = 'develop'; + if (key === "master") { + key = "develop"; } if (this[`_${key}`] instanceof Map) { @@ -134,7 +134,9 @@ class Config extends Map { */ readConfiguration() { if (this.hasConfiguration()) { - const conf = JSON.parse(fs.readFileSync(path.join(process.cwd(), CONFIG_BASENAME), 'utf8')); + const conf = JSON.parse( + fs.readFileSync(path.join(process.cwd(), CONFIG_BASENAME), "utf8") + ); this.setConfig(conf); } } @@ -144,7 +146,7 @@ class Config extends Map { * @returns {boolean} */ hasConfiguration() { - return fs.existsSync(path.join(process.cwd(), CONFIG_BASENAME), 'utf8'); + return fs.existsSync(path.join(process.cwd(), CONFIG_BASENAME), "utf8"); } /** @@ -153,7 +155,11 @@ class Config extends Map { writeConfiguration() { const conf = this.toObject(); - fs.writeFileSync(path.join(process.cwd(), CONFIG_BASENAME), JSON.stringify(conf, null, 2), { encoding: 'utf8' }); + fs.writeFileSync( + path.join(process.cwd(), CONFIG_BASENAME), + JSON.stringify(conf, null, 2), + { encoding: "utf8" } + ); } /** @@ -161,20 +167,19 @@ class Config extends Map { * @returns {K} */ toObject() { - return Array.from(this.keys()) - .reduce((acc, key) => { - if (this[`_${key}`] instanceof Map) { - acc[key] = {}; - - this[`_${key}`].forEach((v, k) => { - acc[key][k] = v; - }); - } else { - acc[key] = this.get(key); - } - - return acc; - }, {}); + return Array.from(this.keys()).reduce((acc, key) => { + if (this[`_${key}`] instanceof Map) { + acc[key] = {}; + + this[`_${key}`].forEach((v, k) => { + acc[key][k] = v; + }); + } else { + acc[key] = this.get(key); + } + + return acc; + }, {}); } } diff --git a/src/config/index.js b/src/config/index.js index f390caf..7a7c7c0 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -1 +1 @@ -module.exports = require('./config'); +module.exports = require("./config"); diff --git a/src/exec/index.js b/src/exec/index.js index 5598b52..07cf7ac 100644 --- a/src/exec/index.js +++ b/src/exec/index.js @@ -1,9 +1,9 @@ -require('any-observable/register/rxjs-all'); // eslint-disable-line import/no-unassigned-import -const streamToObservable = require('@samverschueren/stream-to-observable'); -const { merge } = require('rxjs'); -const { filter } = require('rxjs/operators'); -const execa = require('execa'); -const split = require('split'); +require("any-observable/register/rxjs-all"); // eslint-disable-line import/no-unassigned-import +const streamToObservable = require("@samverschueren/stream-to-observable"); +const { merge } = require("rxjs"); +const { filter } = require("rxjs/operators"); +const execa = require("execa"); +const split = require("split"); module.exports = (cmd, args, opts) => { // Use `Observable` support if merged https://github.com/sindresorhus/execa/pull/26 diff --git a/src/git/index.js b/src/git/index.js index 1cb86b7..e882be5 100644 --- a/src/git/index.js +++ b/src/git/index.js @@ -1,9 +1,9 @@ /* eslint-disable prefer-arrow-callback */ -const { spawnSync, execSync } = require('child_process'); -const exec = require('../exec'); +const { spawnSync, execSync } = require("child_process"); +const exec = require("../exec"); function gitSync(cmd, ...args) { - const response = spawnSync('git', [cmd].concat(args)); + const response = spawnSync("git", [cmd].concat(args)); if (response.error) { throw response.error; } @@ -11,7 +11,7 @@ function gitSync(cmd, ...args) { } function gitAsync(cmd, ...args) { - return exec('git', [cmd].concat(args.filter(o => !!o))); + return exec("git", [cmd].concat(args.filter(o => !!o))); } module.exports = { @@ -37,7 +37,9 @@ module.exports = { * @returns {*} */ config(...args) { - return gitSync('config', ...args).join('').trim(); + return gitSync("config", ...args) + .join("") + .trim(); }, /** @@ -45,7 +47,7 @@ module.exports = { * @param args */ checkout(...args) { - return gitAsync('checkout', ...args); + return gitAsync("checkout", ...args); }, /** * @@ -53,14 +55,14 @@ module.exports = { * @returns {*} */ checkoutSync(...args) { - return gitSync('checkout', ...args); + return gitSync("checkout", ...args); }, /** * * @param args */ branch(...args) { - return gitAsync('branch', ...args); + return gitAsync("branch", ...args); }, /** * @@ -68,28 +70,28 @@ module.exports = { * @returns {*} */ branchSync(...args) { - return gitSync('branch', ...args); + return gitSync("branch", ...args); }, /** * * @param args */ merge(...args) { - return gitAsync('merge', ...args); + return gitAsync("merge", ...args); }, /** * * @param args */ mergeSync(...args) { - return gitSync('merge', ...args); + return gitSync("merge", ...args); }, /** * * @param args */ remote(...args) { - return gitAsync('remote', ...args); + return gitAsync("remote", ...args); }, /** * @@ -97,14 +99,14 @@ module.exports = { * @returns {*} */ remoteSync(...args) { - return gitSync('remote', ...args); + return gitSync("remote", ...args); }, /** * * @param args */ fetch(...args) { - return gitAsync('fetch', ...args); + return gitAsync("fetch", ...args); }, /** * @@ -112,14 +114,14 @@ module.exports = { * @returns {*} */ fetchSync(...args) { - return gitSync('fetch', ...args); + return gitSync("fetch", ...args); }, /** * * @param args */ prune(...args) { - return gitAsync('prune', ...args); + return gitAsync("prune", ...args); }, /** * @@ -127,35 +129,35 @@ module.exports = { * @returns {*} */ pruneSync(...args) { - return gitSync('prune', ...args); + return gitSync("prune", ...args); }, /** * * @returns {*} */ refreshRepository() { - return gitAsync('fetch', '--prune'); + return gitAsync("fetch", "--prune"); }, /** * * @returns {*} */ refreshRepositorySync() { - return gitSync('fetch', '--all', '--prune', '--tags'); + return gitSync("fetch", "--all", "--prune", "--tags"); }, /** * * @param args */ push(...args) { - return gitAsync('push', ...args); + return gitAsync("push", ...args); }, /** * * @param args */ pushSync(...args) { - return gitSync('push', ...args); + return gitSync("push", ...args); }, /** * @@ -163,7 +165,7 @@ module.exports = { * @returns {*} */ add(...args) { - return gitAsync('add', ...args); + return gitAsync("add", ...args); }, /** * @@ -171,7 +173,7 @@ module.exports = { * @returns {*} */ addSync(...args) { - return gitSync('add', ...args); + return gitSync("add", ...args); }, /** * @@ -179,7 +181,7 @@ module.exports = { * @returns {*} */ reset(...args) { - return gitAsync('reset', ...args); + return gitAsync("reset", ...args); }, /** * @@ -187,7 +189,7 @@ module.exports = { * @returns {*} */ resetSync(...args) { - return gitSync('reset', ...args); + return gitSync("reset", ...args); }, /** * @@ -195,7 +197,7 @@ module.exports = { * @returns {*} */ commit(...args) { - return gitAsync('commit', ...args); + return gitAsync("commit", ...args); }, /** * @@ -203,7 +205,7 @@ module.exports = { * @returns {*} */ commitSync(...args) { - return gitSync('commit', ...args); + return gitSync("commit", ...args); }, /** * @@ -211,7 +213,7 @@ module.exports = { * @returns {*} */ removeSync(...args) { - return gitSync('remote', ...args); + return gitSync("remote", ...args); }, /** @@ -219,17 +221,17 @@ module.exports = { * @returns {string} */ currentBranchName() { - return gitSync('rev-parse', '--abbrev-ref', 'HEAD')[0].trim(); + return gitSync("rev-parse", "--abbrev-ref", "HEAD")[0].trim(); }, /** * * @param branch * @returns {boolean} */ - branchExists(branch, remote = 'origin') { + branchExists(branch, remote = "origin") { return ( - gitSync('branch', '-a') - .join('\n') + gitSync("branch", "-a") + .join("\n") .trim() .indexOf(`remotes/${remote}/${branch}`) > -1 ); @@ -239,7 +241,9 @@ module.exports = { * @param branch */ checkBranchRemoteStatus(branch) { - return gitAsync('cherry', branch, `origin/${branch}`).join('').trim(); + return gitAsync("cherry", branch, `origin/${branch}`) + .join("") + .trim(); }, /** * @@ -247,14 +251,14 @@ module.exports = { * @returns {*} */ checkBranchRemoteStatusSync(branch) { - return gitSync('cherry', branch, `origin/${branch}`); + return gitSync("cherry", branch, `origin/${branch}`); }, /** * * @param args */ rebase(...args) { - return gitAsync('rebase', ...args); + return gitAsync("rebase", ...args); }, /** @@ -262,18 +266,18 @@ module.exports = { * @param args */ rebaseAsync(...args) { - return gitSync('rebase', ...args); + return gitSync("rebase", ...args); }, /** * * @returns {Array} */ branches(...args) { - const branches = gitSync('branch', ...args)[0].split('\n'); + const branches = gitSync("branch", ...args)[0].split("\n"); return branches - .map(branch => branch.replace('* ', '')) - .filter(branch => String(branch).indexOf('HEAD') === -1) + .map(branch => branch.replace("* ", "")) + .filter(branch => String(branch).indexOf("HEAD") === -1) .filter(branch => !!branch) .map(o => o.trim()); }, @@ -285,7 +289,7 @@ module.exports = { const response = execSync(`git show --format="%ci|%cr|%an" ${branch} --`); return response .toString() - .split('\n')[0] + .split("\n")[0] .trim(); }, /** @@ -297,7 +301,9 @@ module.exports = { .branches(...args) .map(branch => { try { - const [date, creation, author] = module.exports.show(branch).split('|'); + const [date, creation, author] = module.exports + .show(branch) + .split("|"); return { branch, date, @@ -308,12 +314,14 @@ module.exports = { return undefined; } }) - .filter((b) => !!b) + .filter(b => !!b) .sort((info1, info2) => info1.date < info2.date); }, hasStagedChanges(cb) { - const list = gitSync('status', '-s').filter(o => !!o).map(o => o.trim()); + const list = gitSync("status", "-s") + .filter(o => !!o) + .map(o => o.trim()); if (list.length > 0) { if (cb) { diff --git a/src/index.js b/src/index.js index 18ba34e..05d8890 100644 --- a/src/index.js +++ b/src/index.js @@ -1,19 +1,19 @@ -const config = require('./config'); -const git = require('./git'); -const Fetch = require('./command/fetch'); -const NewBranch = require('./command/new'); -const Rebase = require('./command/rebase'); -const Merge = require('./command/rebase'); -const Push = require('./command/push'); -const Finish = require('./command/finish'); -const Sync = require('./command/sync'); -const Init = require('./command/init'); -const branches = require('./command/branches'); -const rebaseAll = require('./command/rebaseAll'); -const release = require('./command/release'); +const config = require("./config"); +const git = require("./git"); +const Fetch = require("./command/fetch"); +const NewBranch = require("./command/new"); +const Rebase = require("./command/rebase"); +const Merge = require("./command/rebase"); +const Push = require("./command/push"); +const Finish = require("./command/finish"); +const Sync = require("./command/sync"); +const Init = require("./command/init"); +const branches = require("./command/branches"); +const rebaseAll = require("./command/rebaseAll"); +const release = require("./command/release"); // TODO do not remove -process.on('unhandledRejection', () => { +process.on("unhandledRejection", () => { // console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); // application specific logging, throwing an error, or other logic here }); diff --git a/src/utils/get-branche-name.js b/src/utils/get-branche-name.js index b93d14d..0d0ce8b 100644 --- a/src/utils/get-branche-name.js +++ b/src/utils/get-branche-name.js @@ -1,7 +1,7 @@ -const config = require('../config'); +const config = require("../config"); module.exports = { getBranchName(branch) { - return branch.replace(`${config.remote}/`, ''); + return branch.replace(`${config.remote}/`, ""); } }; diff --git a/src/utils/get-rebase-info.js b/src/utils/get-rebase-info.js index 1cd2b79..f07b780 100644 --- a/src/utils/get-rebase-info.js +++ b/src/utils/get-rebase-info.js @@ -1,7 +1,7 @@ -const { getBranchName } = require('./get-branche-name'); +const { getBranchName } = require("./get-branche-name"); -const git = require('../git'); -const config = require('../config'); +const git = require("../git"); +const config = require("../config"); module.exports = { getRebaseInfo(fromBranch) { diff --git a/src/utils/normalize-branch.js b/src/utils/normalize-branch.js index c9f906a..409d9f3 100644 --- a/src/utils/normalize-branch.js +++ b/src/utils/normalize-branch.js @@ -1,10 +1,10 @@ -const config = require('../config'); +const config = require("../config"); module.exports = { normalizeBranchName({ branchName, type }) { const branchType = config.branchTypes[type] || config.branchTypes.default; const branchPath = branchName.replace(/[- _/]/gi, config.charReplacement); - return [branchType, branchPath].join(config.charReplacement).replace('\\/'); + return [branchType, branchPath].join(config.charReplacement).replace("\\/"); } }; diff --git a/src/utils/to-remote.js b/src/utils/to-remote.js index 3c0e7b1..54f95a9 100644 --- a/src/utils/to-remote.js +++ b/src/utils/to-remote.js @@ -1,4 +1,4 @@ -const config = require('../config'); +const config = require("../config"); module.exports = { /** diff --git a/yarn.lock b/yarn.lock index 564a248..6814967 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1769,7 +1769,7 @@ debug@^4.0.0, debug@^4.0.1: dependencies: ms "^2.1.1" -debuglog@*, debuglog@^1.0.1: +debuglog@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492" integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI= @@ -2931,7 +2931,7 @@ import-lazy@^2.1.0: resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-2.1.0.tgz#05698e3d45c88e8d7e9d92cb0584e77f096f3e43" integrity sha1-BWmOPUXIjo1+nZLLBYTnfwlvPkM= -imurmurhash@*, imurmurhash@^0.1.4: +imurmurhash@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" integrity sha1-khi5srkoojixPcT7a21XbyMUU+o= @@ -3660,11 +3660,6 @@ lockfile@^1.0.4: dependencies: signal-exit "^3.0.2" -lodash._baseindexof@*: - version "3.1.0" - resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c" - integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw= - lodash._baseuniq@~4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8" @@ -3673,33 +3668,11 @@ lodash._baseuniq@~4.6.0: lodash._createset "~4.0.0" lodash._root "~3.0.0" -lodash._bindcallback@*: - version "3.0.1" - resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e" - integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4= - -lodash._cacheindexof@*: - version "3.0.2" - resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92" - integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI= - -lodash._createcache@*: - version "3.1.2" - resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093" - integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM= - dependencies: - lodash._getnative "^3.0.0" - lodash._createset@~4.0.0: version "4.0.3" resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26" integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY= -lodash._getnative@*, lodash._getnative@^3.0.0: - version "3.9.1" - resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5" - integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U= - lodash._root@~3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/lodash._root/-/lodash._root-3.0.1.tgz#fba1c4524c19ee9a5f8136b4609f017cf4ded692" @@ -3740,11 +3713,6 @@ lodash.isstring@^4.0.1: resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451" integrity sha1-1SfftUVuynzJu5XV2ur4i6VKVFE= -lodash.restparam@*: - version "3.6.1" - resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" - integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU= - lodash.set@^4.3.2: version "4.3.2" resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"