Skip to content

Commit

Permalink
Merge pull request #6 from jlegrone/feature/better-postinstall-message
Browse files Browse the repository at this point in the history
Better postinstall message
  • Loading branch information
jlegrone authored Aug 8, 2017
2 parents c06a74a + 1f7e103 commit 82bb0ef
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
"scripts": {
"commit": "git-cz",
"commitmsg": "validate-commit-msg",
"remove-config": "sed -i.backup '/jlegrone.gitconfig/d' ~/.gitconfig",
"add-config": "git config --global --add include.path $PWD/src/jlegrone.gitconfig",
"postinstall": "npm run remove-config && npm run add-config && npm run validate-git-version",
"preuninstall": "npm run remove-config",
"semantic-release": "semantic-release pre && npm publish --access public && semantic-release post",
"validate-git-version": "node scripts/validate-git-version"
"postinstall": "node scripts/bootstrap-config",
"preuninstall": "node scripts/remove-config",
"semantic-release": "semantic-release pre && npm publish --access public && semantic-release post"
},
"config": {
"commitizen": {
Expand Down
11 changes: 11 additions & 0 deletions scripts/add-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { exec } = require('child_process')

exec(
`git config --global --add include.path ${process.cwd()}/src/jlegrone.gitconfig`,
(err, stdout, stderr) => {
const error = err || stderr
if (error) {
throw new Error(error)
}
}
)
3 changes: 3 additions & 0 deletions scripts/bootstrap-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require('./remove-config')
require('./add-config')
require('./validate-git-version')
11 changes: 11 additions & 0 deletions scripts/remove-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { exec } = require('child_process')

exec(
'sed -i.backup "/jlegrone.gitconfig/d" ~/.gitconfig',
(err, stdout, stderr) => {
const error = err || stderr
if (error) {
throw new Error(error)
}
}
)
28 changes: 18 additions & 10 deletions scripts/validate-git-version.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
const validateGitVersion = require('validate-git-version')
const { blue, yellow } = require('chalk')
const { blue, yellow, red, green, reset } = require('chalk')
const { name: moduleName } = require('../package')

const minimumVersion = '2.6.0'

validateGitVersion(
`^${minimumVersion}`,
(currentVersion) => console.log(yellow(
`⚠️ Git version ${currentVersion} is not compatible with ${moduleName}. Please upgrade to git ${minimumVersion} or later.`
)),
(currentVersion) => console.log(blue(
`🎉 Git version ${currentVersion} is compatible with ${moduleName}.`
))
)
const onInValid = (currentVersion) => console.log(yellow(
`
⚠️ Git version ${red(currentVersion)} is not compatible with ${moduleName}.
Please upgrade to git ${green(minimumVersion)} or later.
`
))

const onValid = () => console.log(blue(
`
🎉 ${moduleName} install successful!
Type ${yellow('git aliases')} to view available aliases.
${reset('More documentation is available at https://github.com/jlegrone/git-config.')}
`
))

validateGitVersion(`^${minimumVersion}`, onInValid, onValid)

0 comments on commit 82bb0ef

Please sign in to comment.