@thisismanta/semantic-version 7.0.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,6 @@
1
- Once installed, this package verifies your upcoming **Git commit messages** against the convention below.
1
+ # `npx lint-commit-message <path>`
2
+
3
+ The `<path>` must point to a text file containing commit message that complies with the following pattern:
2
4
 
3
5
  ```
4
6
  <type>[!]: <subject>
@@ -8,9 +10,18 @@ Where
8
10
  - `!` indicates that the commit contains breaking changes.
9
11
  - `<subject>` is the actual commit message where the first word must be written in lower cases.
10
12
 
11
- ---
13
+ > Usage example with [**lefthook**](https://www.npmjs.com/package/lefthook)
14
+ > ```yml
15
+ > # lefthook.yml
16
+ > commit-msg:
17
+ > commands:
18
+ > lint:
19
+ > run: npx lint-commit-message {1}
20
+ > ```
21
+
22
+ # `npx auto-npm-version`
12
23
 
13
- Additionally, you can run `npx auto-npm-version` on **GitHub Actions** to trigger `npm version` based on your commit messages and create a GitHub release (optional).
24
+ This command is supposed to be run on CI, such as **GitHub Actions**. It will run `npm version <new-version>`, which `<new-version>` is automatically derived from your commit messages according to the table below and then it creates a new entry on [**GitHub releases**](https://docs.github.com/en/repositories/releasing-projects-on-github/about-releases).
14
25
 
15
26
  |Commit message type|Post-commit command|
16
27
  |---|---|
@@ -19,25 +30,24 @@ Additionally, you can run `npx auto-npm-version` on **GitHub Actions** to trigge
19
30
  |`fix`|`npm version patch`|
20
31
  |Others|Does not run `npm version`|
21
32
 
22
- Here's an example of **GitHub Actions** workflow file:
23
-
24
- ```yml
25
- on:
26
- push:
27
- branches: [master]
28
- jobs:
29
- release:
30
- runs-on: ubuntu-latest
31
- steps:
32
- - uses: actions/checkout@v3
33
- with:
34
- fetch-depth: 0 # Ensure Git tags are fetched
35
- - uses: actions/setup-node@v3
36
- with:
37
- node-version-file: 'package.json'
38
- cache: npm
39
- - run: npm ci # Install semantic-version as part of the dependencies
40
- - run: npx auto-npm-version
41
- env:
42
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Make it possible to create a new release using GitHub API
43
- ```
33
+ > Usage example with **GitHub Actions**
34
+ > ```yml
35
+ > on:
36
+ > push:
37
+ > branches: [master]
38
+ > jobs:
39
+ > release:
40
+ > runs-on: ubuntu-latest
41
+ > steps:
42
+ > - uses: actions/checkout@v4
43
+ > with:
44
+ > fetch-depth: 0 # Ensure Git tags are fetched
45
+ > - uses: actions/setup-node@v4
46
+ > with:
47
+ > node-version-file: 'package.json'
48
+ > cache: npm
49
+ > - run: npm ci # Install semantic-version as part of the dependencies
50
+ > - run: npx auto-npm-version
51
+ > env:
52
+ > GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Make it possible to create a new release using GitHub API
53
+ > ```
@@ -83,8 +83,13 @@ async function main() {
83
83
  console.log('Done with a new release at', releaseCreationRespond.data.html_url);
84
84
  }
85
85
  async function getLastVersion() {
86
- return (semver_1.default.valid(await (0, run_1.run)('git describe --tags --abbrev=0').catch(() => '')) ||
87
- semver_1.default.valid(JSON.parse(await (0, run_1.run)('npm pkg get version'))));
86
+ const versionFromGit = await (0, run_1.run)('git describe --tags --abbrev=0').catch(() => null);
87
+ const versionFromPackageJSON = JSON.parse(await (0, run_1.run)('npm pkg get version'));
88
+ const versions = [versionFromGit, versionFromPackageJSON]
89
+ .map(version => semver_1.default.valid(version))
90
+ .filter((version) => !!version);
91
+ // Choose the higher version
92
+ return semver_1.default.sort(versions).pop();
88
93
  }
89
94
  async function getGitHistory(version) {
90
95
  const tagFound = !!(await (0, run_1.run)(`git tag --list v${version}`));
@@ -105,10 +110,16 @@ function getCommits(gitLog) {
105
110
  });
106
111
  }
107
112
  function getReleaseType(commits) {
108
- return (commits.find(({ breaking }) => breaking) && 'major' ||
109
- commits.find(({ type }) => type === 'feat') && 'minor' ||
110
- commits.find(({ type }) => type === 'fix' || type === 'build') && 'patch' ||
111
- null);
113
+ if (commits.find(({ breaking }) => breaking)) {
114
+ return 'major';
115
+ }
116
+ if (commits.find(({ type }) => type === 'feat')) {
117
+ return 'minor';
118
+ }
119
+ if (commits.find(({ type }) => type === 'fix' || type === 'build')) {
120
+ return 'patch';
121
+ }
122
+ return null;
112
123
  }
113
124
  function getReleaseNote(commits) {
114
125
  const groups = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thisismanta/semantic-version",
3
- "version": "7.0.0",
3
+ "version": "8.0.0",
4
4
  "author": "Anantachai Saothong <thisismanta@gmail.com>",
5
5
  "license": "ISC",
6
6
  "repository": {
@@ -24,15 +24,14 @@
24
24
  "test": "jest",
25
25
  "build": "rm -rf lib && tsc",
26
26
  "preversion": "npm run build",
27
- "version": "npm publish --access public",
28
- "postinstall": "node ./lib/install-git-hooks.js"
27
+ "version": "npm publish --access public"
29
28
  },
30
29
  "devDependencies": {
31
30
  "@types/jest": "^29.5.11",
32
31
  "@types/node": "^20.0.0",
33
32
  "@types/semver": "^7.5.6",
34
33
  "jest": "^29.7.0",
35
- "lefthook": "^1.6.0",
34
+ "lefthook": "^1.6.1",
36
35
  "ts-jest": "^29.1.1",
37
36
  "ts-node": "^10.9.2",
38
37
  "typescript": "^5.3.3"
@@ -1 +0,0 @@
1
- export {};
@@ -1,68 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const fs = __importStar(require("fs/promises"));
27
- const fp = __importStar(require("path"));
28
- const run_1 = require("./run");
29
- const debug_1 = require("./debug");
30
- main();
31
- const packageName = require('../package.json').name;
32
- async function main() {
33
- const rootDirectoryPath = await (0, run_1.run)('git rev-parse --show-toplevel');
34
- (0, debug_1.debug)('rootDirectoryPath »', rootDirectoryPath);
35
- if (!rootDirectoryPath) {
36
- throw new Error('Could not find a Git directory.');
37
- }
38
- const packageJSON = JSON.parse(await fs.readFile(fp.join(rootDirectoryPath, 'package.json'), 'utf-8'));
39
- if (packageJSON.name === packageName) {
40
- console.warn('Skip installing Git hooks as it is supposed to be done on a consumer repository.');
41
- return;
42
- }
43
- const hookDirectoryPath = await (0, run_1.run)('git config --get core.hooksPath').catch(() => '') || '.git/hooks';
44
- const hookFilePath = fp.join(rootDirectoryPath, hookDirectoryPath, 'commit-msg');
45
- (0, debug_1.debug)('hookFilePath »', hookFilePath);
46
- try {
47
- await fs.access(hookFilePath, fs.constants.R_OK | fs.constants.W_OK);
48
- (0, debug_1.debug)('Found', hookFilePath);
49
- }
50
- catch {
51
- await fs.mkdir(fp.dirname(hookFilePath), { recursive: true });
52
- await fs.writeFile(hookFilePath, '#!/bin/sh\n', 'utf-8');
53
- (0, debug_1.debug)('Created', hookFilePath);
54
- }
55
- const hookFileText = await fs.readFile(hookFilePath, 'utf-8');
56
- if (/(^|\s|\/)lint-commit-message(\s|$)/m.test(hookFileText)) {
57
- console.log('Skipped adding commit-msg Git hook.');
58
- }
59
- else {
60
- await fs.appendFile(hookFilePath, [
61
- '',
62
- 'dir="$(git rev-parse --show-toplevel)"',
63
- '"$dir/node_modules/.bin/lint-commit-message" "$@"',
64
- '',
65
- ].join('\n'), 'utf-8');
66
- console.log('Done adding commit-msg Git hook.');
67
- }
68
- }