conventional-release-setup
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -5,2 +5,10 @@ # Changelog | ||
### [1.2.1](https://github.com/remarkablemark/conventional-release-setup/compare/v1.2.0...v1.2.1) (2021-02-28) | ||
### Bug Fixes | ||
* **index:** add husky hooks and commit only if git repo exists ([0821957](https://github.com/remarkablemark/conventional-release-setup/commit/082195750a233460099e6f99f4dfade5915533ac)) | ||
* **index:** prepend package.json scripts instead of overriding them ([f8dd146](https://github.com/remarkablemark/conventional-release-setup/commit/f8dd146aabd31e22930bbc2965f2bf05d25043d6)) | ||
## [1.2.0](https://github.com/remarkablemark/conventional-release-setup/compare/v1.1.1...v1.2.0) (2021-02-16) | ||
@@ -7,0 +15,0 @@ |
77
index.js
@@ -19,4 +19,4 @@ #!/usr/bin/env node | ||
* | ||
* @param {String} command | ||
* @return {String} | ||
* @param {string} command | ||
* @return {string} | ||
*/ | ||
@@ -35,3 +35,3 @@ const exec = command => execSync(command, execSyncOptions); | ||
* | ||
* @param {String} file | ||
* @param {string} file | ||
* @param {*} data | ||
@@ -45,2 +45,5 @@ */ | ||
/** | ||
* Display exit code. | ||
*/ | ||
process.on('exit', code => { | ||
@@ -56,9 +59,10 @@ log(`Exiting with code: ${code}`); | ||
/** | ||
* Check if current working directory is git repository. | ||
* Check if current working directory is a git repository. | ||
*/ | ||
let isGitRepository = true; | ||
let isGit; | ||
try { | ||
exec(`git -C ${cwd} rev-parse`); | ||
} catch (err) { | ||
isGitRepository = false; | ||
isGit = true; | ||
} catch (error) { | ||
isGit = false; | ||
} | ||
@@ -71,5 +75,5 @@ | ||
if (existsSync(packageJsonPath)) { | ||
log('Found `package.json`'); | ||
log('`package.json` found'); | ||
} else { | ||
log('Unable to find `package.json`, initializing new package...'); | ||
log('`package.json` not found, initializing `package.json`...'); | ||
exec('npm init --yes'); | ||
@@ -93,9 +97,29 @@ } | ||
packageJson.scripts = packageJson.scripts || {}; | ||
packageJson.scripts.release = 'standard-version --no-verify'; | ||
packageJson.scripts.postinstall = 'husky install'; | ||
const { postinstall, release } = packageJson.scripts; | ||
const huskyInstall = 'husky install'; | ||
packageJson.scripts.postinstall = postinstall | ||
? `${huskyInstall} && ${postinstall}` | ||
: huskyInstall; | ||
const standardVersion = 'standard-version --no-verify'; | ||
packageJson.scripts.release = release | ||
? `${standardVersion} && ${release}` | ||
: standardVersion; | ||
if (!packageJson.private) { | ||
devDependencies.push('pinst'); | ||
packageJson.scripts.prepublishOnly = 'pinst --disable'; | ||
packageJson.scripts.postpublish = 'pinst --enable'; | ||
const { postpublish, prepublishOnly } = packageJson.scripts; | ||
const pinstEnable = 'pinst --enable'; | ||
packageJson.scripts.postpublish = postpublish | ||
? `${pinstEnable} && ${postpublish}` | ||
: pinstEnable; | ||
const pinstDisable = 'pinst --disable'; | ||
packageJson.scripts.prepublishOnly = prepublishOnly | ||
? `${pinstDisable} && ${prepublishOnly}` | ||
: pinstDisable; | ||
} | ||
write(packageJsonPath, packageJson); | ||
@@ -108,3 +132,3 @@ | ||
exec(`npm install --save-dev ${devDependencies.join(' ')}`); | ||
isGitRepository && exec('git add package.json'); | ||
isGit && exec('git add package.json'); | ||
@@ -121,12 +145,14 @@ /** | ||
copyFileSync(source, destination); | ||
isGitRepository && exec(`git add ${filename}`); | ||
isGit && exec(`git add ${filename}`); | ||
}); | ||
/** | ||
* Add Git hook. | ||
* Add hooks. | ||
*/ | ||
log('Adding Git hooks...'); | ||
exec('npx husky install'); | ||
exec(`npx husky add .husky/commit-msg 'npx commitlint --edit $1'`); | ||
exec('git add .husky/'); | ||
if (isGit) { | ||
log('Adding hooks...'); | ||
exec(`npx ${huskyInstall}`); | ||
exec(`npx husky add .husky/commit-msg 'npx commitlint --edit $1'`); | ||
exec('git add .husky/'); | ||
} | ||
@@ -136,8 +162,9 @@ /** | ||
*/ | ||
log('Committing changes...'); | ||
isGitRepository && exec(`git commit -m "chore: run ${name} v${version}"`); | ||
if (isGit) { | ||
log('Committing changes...'); | ||
exec( | ||
`git commit -m 'chore: set up conventional release' -m '${name} v${version}'` | ||
); | ||
} | ||
/** | ||
* Done. | ||
*/ | ||
log(`Finished ${name}`); |
{ | ||
"name": "conventional-release-setup", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Sets up package for committing/releasing with conventional commits.", | ||
@@ -28,4 +28,4 @@ "author": "Mark <mark@remarkablemark.org>", | ||
"devDependencies": { | ||
"@commitlint/cli": "^11.0.0", | ||
"@commitlint/config-conventional": "^11.0.0", | ||
"@commitlint/cli": "^12.0.0", | ||
"@commitlint/config-conventional": "^12.0.0", | ||
"eslint": "^7.20.0", | ||
@@ -32,0 +32,0 @@ "eslint-plugin-prettier": "^3.3.1", |
@@ -6,5 +6,5 @@ # conventional-release-setup | ||
[![NPM version](https://img.shields.io/npm/v/conventional-release-setup.svg)](https://www.npmjs.com/package/conventional-release-setup) | ||
[![Build Status](https://github.com/remarkablemark/conventional-release-setup/workflows/build/badge.svg?branch=master)](https://github.com/remarkablemark/conventional-release-setup/actions?query=workflow%3Abuild) | ||
[![build](https://github.com/remarkablemark/conventional-release-setup/actions/workflows/build.yml/badge.svg)](https://github.com/remarkablemark/conventional-release-setup/actions/workflows/build.yml) | ||
Sets up an npm package for committing and releasing with [conventional commits](https://www.conventionalcommits.org/): | ||
Sets up an npm project for committing and releasing with [Conventional Commits](https://www.conventionalcommits.org/): | ||
@@ -17,3 +17,3 @@ ```sh | ||
To install the package globally: | ||
Install the CLI globally: | ||
@@ -30,3 +30,3 @@ ```sh | ||
If the package is installed globally, you can execute it in the command-line: | ||
If the CLI is installed globally, you can execute it in the command-line: | ||
@@ -37,3 +37,3 @@ ```sh | ||
Otherwise, you can install and execute the package binary like so: | ||
Otherwise, you can install and execute the CLI like so: | ||
@@ -46,21 +46,26 @@ ```sh | ||
What does the script do? | ||
The script: | ||
It updates `package.json`: | ||
- updates `package.json`: | ||
- `version` | ||
- appends `-alpha` | ||
- `scripts` | ||
- prepends `release` with `husky install` | ||
- installs devDependencies: | ||
- [@commitlint/cli](https://www.npmjs.com/package/@commitlint/cli) - lints commit messages | ||
- [@commitlint/config-conventional](https://www.npmjs.com/package/@commitlint/config-conventional) - config with [conventional commits](https://conventionalcommits.org/) rules | ||
- [husky](https://www.npmjs.com/package/husky) - sets up git hooks | ||
- [standard-version](https://www.npmjs.com/package/standard-version) - generates changelog, bumps version, and creates git commit and tag | ||
- copies the config: | ||
- [.commitlintrc.json](https://github.com/remarkablemark/conventional-release-setup/blob/master/files/.commitlintrc.json) | ||
- adds husky hook `commit-msg` | ||
- appends `-alpha` to version | ||
- adds script `release` | ||
If the package is not `private`, the script also: | ||
Installs devDependencies: | ||
- updates `package.json` scripts: | ||
- prepends `pinst --enable` to `postpublish` | ||
- prepends `pinst --disable` to `prepublishOnly` | ||
- installs devDependency: | ||
- [pinst](https://www.npmjs.com/package/pinst) - lets you have `postinstall` hook that runs only in dev | ||
- [@commitlint/cli](https://www.npmjs.com/package/@commitlint/cli) - lints commit messages | ||
- [@commitlint/config-conventional](https://www.npmjs.com/package/@commitlint/config-conventional) - config with [conventional commits](https://conventionalcommits.org/) rules | ||
- [husky](https://www.npmjs.com/package/husky) - sets up Git hooks | ||
- [standard-version](https://www.npmjs.com/package/standard-version) - generates changelog, bumps version, creates Git commit and tag | ||
Copies configs to your project: | ||
- [.commitlintrc.json](https://github.com/remarkablemark/conventional-release-setup/blob/master/files/.commitlintrc.json) | ||
- [.huskyrc.json](https://github.com/remarkablemark/conventional-release-setup/blob/master/files/.huskyrc.json) | ||
## Release | ||
@@ -67,0 +72,0 @@ |
11943
140
120