-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(postinstall): automatically add itself as plugin on install, close
- Loading branch information
Showing
3 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |