Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use NodeJS modules #387

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .babelrc

This file was deleted.

3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"extends": ["eslint:recommended", "plugin:prettier/recommended", "plugin:jest/recommended", "plugin:jest/style"],
"plugins": ["jest"],
"parser": "@babel/eslint-parser",
"parserOptions": {
"requireConfigFile": false
},
"env": {
"node": true,
"jest/globals": true
Expand Down
38 changes: 15 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.5.4",
"license": "MIT",
"engines": {
"node": ">=14"
"node": ">=18"
},
"author": "Benoit d'Oncieu <[email protected]>",
"description": "Allow you to commit with more than one person, e.g. Pair programming or Mob programming.",
Expand All @@ -20,17 +20,16 @@
"bugs": {
"url": "https://github.com/bdo/gitpair.git/issues"
},
"type": "module",
"main": "./src/index.js",
"bin": {
"gitpair": "./bin/gitpair.js",
"git-pair": "./bin/gitpair.js"
},
"scripts": {
"prepublishOnly": "yarn build",
"build": "webpack --mode production",
"watch": "yarn build --watch",
"prepublishOnly": "npm build",
"lint": "eslint .",
"test": "jest",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"prepare": "husky install"
},
"lint-staged": {
Expand All @@ -44,38 +43,31 @@
]
},
"jest": {
"transform": {},
"setupFiles": [
"./src/testSetup"
]
},
"devDependencies": {
"@babel/cli": "^7.16.0",
"@babel/core": "^7.16.0",
"@babel/eslint-parser": "^7.16.3",
"@babel/node": "^7.16.0",
"@babel/preset-env": "^7.16.4",
"@babel/register": "^7.16.0",
"@commitlint/cli": "^17.0.0",
"@commitlint/config-conventional": "^17.0.0",
"@semantic-release/changelog": "^6.0.1",
"@babel/eslint-parser": "^7.23.3",
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"babel-loader": "^9.1.2",
"babel-plugin-source-map-support": "^2.1.3",
"chalk": "^4.1.2",
"clipboardy": "^3.0.0",
"core-js": "^3.19.1",
"debug": "^4.3.2",
"eslint": "^8.3.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jest": "^27.2.0",
"eslint-plugin-jest": "^27.6.1",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^8.0.1",
"jest": "^29.2.1",
"jest": "^29.7",
"lint-staged": "^13.0.3",
"prettier": "^2.4.1",
"pretty-quick": "^3.1.2",
"semantic-release": "^19.0.2",
"webpack": "^5.64.3",
"webpack-cli": "^5.0.1"
"semantic-release": "^22.0.12"
},
"dependencies": {
"chalk": "^4.1.2"
}
}
6 changes: 3 additions & 3 deletions src/commands/amend.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bold } from 'chalk'
import format from '../utils/format'
import pairingConfig from '../config/pairing'
import run from '../utils/run'
import stripCoAuthorship from '../utils/strip-co-authorship'
Expand All @@ -24,10 +24,10 @@ export default () => {
const trailers = coAuthoringTrailers(coAuthors)
const rawCommitMessage = stripCoAuthorship(run('git', ['log', '-1', '--pretty=%B']))

log(bold('Rewriting last commit with the following info:'))
log(format.bold('Rewriting last commit with the following info:'))
log(trailers)
run('git', ['commit', '--amend', '-m', `${rawCommitMessage}\n\n${trailers}`], {
GITPAIR_RUNNING: 1,
})
log(bold('👥 Last commit was rewritten! 😎'))
log(format.bold('👥 Last commit was rewritten! 😎'))
}
34 changes: 18 additions & 16 deletions src/commands/help.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bold, red, dim } from 'chalk'
import format from '../utils/format'

const HELP_TEXT = {
amend: `
Expand All @@ -11,14 +11,14 @@ const HELP_TEXT = {

Pauses pairing until you turn it on again.

See also: ${bold('`git pair on`')}
See also: ${format.bold('`git pair on`')}
`,
on: `
Usage: git pair on

Resumes pairing with the previous pair.

See also: ${bold('`git pair off`')}
See also: ${format.bold('`git pair off`')}
`,
info: `
Usage: git pair info
Expand All @@ -32,29 +32,31 @@ const HELP_TEXT = {

List:
A space separated list of the aliases of people you are about to be pairing with.
Aliases are configured in ${bold('.gitpair/authors.json')}.
Aliases are configured in ${format.bold('.gitpair/authors.json')}.
Gitpair will also match authors with parts of their name or email if unique.

Examples:

> git pair with smi
👥 ${dim("you're now pairing with")} ${dim(bold(`John Smith`))}.
👥 ${format.dim("you're now pairing with")} ${format.dim(format.bold(`John Smith`))}.

> git pair with peter paul mary
👥 ${dim("you're now pairing with")} ${dim(bold('Peter Yarrow, Paul Stookey and Mary Travers'))}.
👥 ${format.dim("you're now pairing with")} ${format.dim(
format.bold('Peter Yarrow, Paul Stookey and Mary Travers')
)}.

> git pair with
👤 ${dim(`not pairing with anyone`)}
See also: ${bold('`git pair off`')}
> git pair with
👤 ${format.dim(`not pairing with anyone`)}

See also: ${format.bold('`git pair off`')}
`,
trailers: `
Usage: git pair trailers

Prints the ${bold(`'Co-authored-by'`)} trailer message.
Prints the ${format.bold(`'Co-authored-by'`)} trailer message.
This is useful for your PR's merge commit message 😉

See also: ${bold('`git pair amend`')}
See also: ${format.bold('`git pair amend`')}
`,
version: `
Usage: git pair version
Expand All @@ -81,8 +83,8 @@ const HELP_TEXT = {
- help
- version

Run ${bold('`git pair help COMMAND`')} for more information on specific commands.
Visit ${bold('https://github.com/bdo/gitpair')} to learn more about gitpair.
Run ${format.bold('`git pair help COMMAND`')} for more information on specific commands.
Visit ${format.bold('https://github.com/bdo/gitpair')} to learn more about gitpair.
`,
}

Expand All @@ -92,11 +94,11 @@ const getHelp = (command) => {
}
const helpText = HELP_TEXT[command]
if (!helpText) {
console.error(red(`Unknow command ${bold(`'${command}'`)}`))
console.error(format.red(`Unknow command ${format.bold(`'${command}'`)}`))
return HELP_TEXT.usage
}
return `${helpText}
Visit ${bold('https://github.com/bdo/gitpair')} for more information about this command.
Visit ${format.bold('https://github.com/bdo/gitpair')} for more information about this command.
`
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/info.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dim } from 'chalk'
import format from '../utils/format'
import pairingConfig from '../config/pairing'
import niceJoin from '../utils/nice-join'

Expand All @@ -8,7 +8,7 @@ export default () => {
if (!enabled) {
console.info('👤 Pairing is currently off!')
if (coAuthors.length > 0) {
console.info(dim(`👥 You were previously pairing with ${niceJoin(names)}`))
console.info(format.dim(`👥 You were previously pairing with ${niceJoin(names)}`))
}
} else if (coAuthors.length === 0) {
console.info('👤 Not currently pairing with anyone')
Expand Down
4 changes: 2 additions & 2 deletions src/commands/trailers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bold } from 'chalk'
import format from '../utils/format'
import pairingConfig from '../config/pairing'
import clipboardy from 'clipboardy'
import coAuthoringTrailers from '../utils/co-authoring-trailers'
Expand All @@ -18,5 +18,5 @@ export default () => {
const trailers = coAuthoringTrailers(coAuthors)
console.info(trailers)
clipboardy.writeSync(trailers)
console.info(bold(`👥 Trailer${coAuthors.length > 1 ? 's' : ''} copied to your clipboard!`))
console.info(format.bold(`👥 Trailer${coAuthors.length > 1 ? 's' : ''} copied to your clipboard!`))
}
6 changes: 3 additions & 3 deletions src/config/authors-file.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path'
import fs from 'fs'
import { homedir } from 'os'
import { red } from 'chalk'
import format from '../utils/format'
import closestPath from '../utils/closest-path'
import { GITPAIR_DIR, GITPAIR_AUTHORS_FILE } from './paths'

Expand All @@ -19,8 +19,8 @@ const findAuthorsFilePath = () => {
const authorsFile = findAuthorsFilePath()

if (!authorsFile) {
console.error(red(`Gitpair could not find the ${GITPAIR_AUTHORS_FILE} file!`))
console.error(red('See instructions at https://github.com/bdo/gitpair'))
console.error(format.red(`Gitpair could not find the ${GITPAIR_AUTHORS_FILE} file!`))
console.error(format.red('See instructions at https://github.com/bdo/gitpair'))
process.exit(1)
}

Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { bold, red } from 'chalk'
import format from './utils/format'
import * as commands from './commands'

const [, , command, ...args] = process.argv

if (!Object.keys(commands).includes(command)) {
if (command) {
console.error(red(`Gitpair doesn't know any ${bold(command)} command!`))
console.error(format.red(`Gitpair doesn't know any ${format.bold(command)} command!`))
}
commands.help()
process.exit(command ? 1 : 0)
Expand Down
5 changes: 2 additions & 3 deletions src/utils/__tests__/nice-join.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import format from '../format'
import niceJoin from '../nice-join'

jest.mock('chalk', () => ({
bold: (s) => s,
}))
format.bold = (s) => s

it('returns element if single', () => {
expect(niceJoin(['Peter'])).toBe('Peter')
Expand Down
8 changes: 5 additions & 3 deletions src/utils/find-author.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { red, bold } from 'chalk'
import format from './format'
import niceJoin from './nice-join'
import authorsFile from '../config/authors-file'

Expand All @@ -25,11 +25,13 @@ export default (authors, pattern) => {
aliases.find((alias) => alias.toLowerCase().includes(pattern))
)
if (!matchByPartial) {
throw new AuthorNotFound(red(`Could not find a match for author ${pattern}! Check the ${bold(authorsFile)} file!`))
throw new AuthorNotFound(
format.red(`Could not find a match for author ${pattern}! Check the ${format.bold(authorsFile)} file!`)
)
}
if (matchByPartial.length > 1) {
const names = matchByPartial.map(({ name }) => name)
throw new AuthorNotFound(red(`Ambiguous match for ${pattern}! It matches ${niceJoin(names)}`))
throw new AuthorNotFound(format.red(`Ambiguous match for ${pattern}! It matches ${niceJoin(names)}`))
}
return matchByPartial[0]
}
9 changes: 9 additions & 0 deletions src/utils/format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import chalk from 'chalk'

const format = {
bold: chalk.bold,
dim: chalk.dim,
red: chalk.red,
}

export default format
4 changes: 2 additions & 2 deletions src/utils/nice-join.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { bold } from 'chalk'
import format from './format'

export default (items) => {
const boldItems = items.map((item) => bold(item))
const boldItems = items.map((item) => format.bold(item))
if (items.length === 0) return ''
if (items.length === 1) return boldItems[0]
const last = boldItems.slice(-1)
Expand Down
18 changes: 0 additions & 18 deletions webpack.config.babel.js

This file was deleted.

Loading