Permalink
Browse files

feat(global): add --global flag for global installation

  • Loading branch information...
zkat committed Dec 3, 2017
1 parent 00d0f15 commit b9c131f367293f33295a8210045b410a0ac7fa3e
Showing with 47 additions and 12 deletions.
  1. +5 −0 README.md
  2. +38 −8 index.js
  3. +1 −3 package-lock.json
  4. +3 −1 package.json
@@ -8,6 +8,11 @@
To start using it right away:
```
$ npx npm-merge-driver install --global
```
**Or** install it locally, per-project:
```
$ cd /path/to/git/repository
$ npx npm-merge-driver install
@@ -3,6 +3,7 @@
const cp = require('child_process')
const fs = require('fs')
const mkdirp = require('mkdirp')
const path = require('path')
const yargs = require('yargs')
@@ -16,6 +17,11 @@ function parseArgs () {
'install',
'Set up the merge driver in the current git repository.',
{
global: {
type: 'boolean',
default: false,
description: 'install to your user-level git configuration'
},
driver: {
type: 'string',
default: 'npx npm-merge-driver merge %A %O %B %P',
@@ -58,17 +64,41 @@ function parseArgs () {
}
function configureGit (argv) {
let attrFile
let opts = ''
if (argv.global) {
opts = '--global'
try {
attrFile = cp
.execSync(`git config --global core.attributesfile`)
.toString('utf8')
.trim()
} catch (e) {}
if (!attrFile) {
if (process.env.XDG_CONFIG_HOME) {
attrFile = path.join(process.env.XDG_CONFIG_HOME, 'git', 'attributes')
} else {
attrFile = path.join(process.env.HOME, '.config', 'git', 'attributes')
}
}
} else {
opts = '--local'
const gitDir = cp
.execSync(`git rev-parse --git-dir`, {
encoding: 'utf8'
})
.trim()
attrFile = path.join(gitDir, 'info', 'attributes')
}
cp.execSync(
`git config ${opts} merge."${argv.driverName}".name "automatically merge npm lockfiles"`
)
cp.execSync(
`git config merge."${argv.driverName}".name "automatically merge npm lockfiles"`
`git config ${opts} merge."${argv.driverName}".driver "${argv.driver}"`
)
cp.execSync(`git config merge."${argv.driverName}".driver "${argv.driver}"`)
const gitDir = cp
.execSync(`git rev-parse --git-dir`, {
encoding: 'utf8'
})
.trim()
mkdirp.sync(path.dirname(attrFile))
fs.appendFileSync(
path.join(gitDir, 'info', 'attributes'),
attrFile,
'\n' + argv.files.map(f => `${f} merge=${argv.driverName}`).join('\n')
)
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -42,6 +42,7 @@
},
"license": "ISC",
"dependencies": {
"mkdirp": "^0.5.1",
"yargs": "^10.0.3"
},
"devDependencies": {
@@ -71,6 +72,7 @@
]
},
"bundleDependencies": [
"yargs"
"yargs",
"mkdirp"
]
}

0 comments on commit b9c131f

Please sign in to comment.