Skip to content

Commit

Permalink
feat(postinstall): automatically add itself as plugin on install, close
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Jul 26, 2017
1 parent b560869 commit c3ec08a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ See [inquirer](https://www.npmjs.com/package/inquirer) for details.

This module can function as [analyzeCommits plugin](https://github.com/semantic-release/semantic-release#analyzecommits)
for [semantic-release](https://github.com/semantic-release/semantic-release).
Just add to the `package.json`
Just add to the `package.json` (during install this will be done automatically)

```json
{
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
"version": "0.0.0-development",
"scripts": {
"ban": "node node_modules/.bin/ban",
"deps": "deps-ok && dependency-check --no-dev . --entry src/postinstall.js",
"test": "rocha src/*-spec.js",
"lint": "standard --verbose --fix bin/*.js src/*.js",
"commit": "commit-wizard",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
"wizard": "node bin/simple-wizard.js",
"issues": "git-issues"
"issues": "git-issues",
"postinstall": "node src/postinstall.js"
},
"repository": {
"type": "git",
Expand All @@ -41,6 +43,8 @@
"homepage": "https://github.com/bahmutov/simple-commit-message#readme",
"devDependencies": {
"ban-sensitive-files": "1.9.0",
"dependency-check": "2.9.1",
"deps-ok": "1.2.0",
"git-issues": "1.3.1",
"github-post-release": "1.12.1",
"next-update-travis": "1.5.2",
Expand All @@ -67,6 +71,7 @@
}
},
"dependencies": {
"am-i-a-dependency": "1.0.0",
"check-more-types": "2.24.0",
"debug": "2.6.8",
"ggit": "1.22.1",
Expand Down
54 changes: 54 additions & 0 deletions src/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env node

'use strict'

const debug = require('debug')('simple')
const amIaDependency = require('am-i-a-dependency')
const isForced = process.argv.some(a => a === '--force')

if (!amIaDependency() && !isForced) {
// top level install (we are running `npm i` in this project)
debug('we are installing own dependencies')
process.exit(0)
}

debug('installing this module as a dependency')

const path = require('path')
const fs = require('fs')

function clientPackageJsonFilename () {
return path.join(process.cwd(), '..', '..', 'package.json')
}

function alreadyInstalled () {
const filename = clientPackageJsonFilename()
const pkg = require(filename)
if (!pkg.release) {
return false
}
if (!pkg.release.analyzeCommits) {
return false
}
return true
}

function addPlugin () {
const filename = clientPackageJsonFilename()
const pkg = require(filename)
if (!pkg.release) {
pkg.release = {}
}
pkg.release.analyzeCommits = 'simple-commit-message'
const text = JSON.stringify(pkg, null, 2) + '\n'
fs.writeFileSync(filename, text, 'utf8')
console.log('✅ set generate notes plugin in', filename)
}

if (alreadyInstalled()) {
debug('plugin analyzeCommits already set')
process.exit(0)
}

console.log('⚠️ Installing release analyzeCommits plugin simple-commit-message')
addPlugin()

0 comments on commit c3ec08a

Please sign in to comment.