git-semver-tags 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 +46 -35
- package/package.json +20 -18
- package/{cli.mjs → src/cli.js} +2 -2
- package/src/index.js +42 -0
- package/index.js +0 -71
package/README.md
CHANGED
|
@@ -1,54 +1,65 @@
|
|
|
1
|
-
#
|
|
1
|
+
# git-semver-tags
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[![ESM-only package][package]][package-url]
|
|
4
|
+
[![NPM version][npm]][npm-url]
|
|
5
|
+
[![Node version][node]][node-url]
|
|
6
|
+
[![Dependencies status][deps]][deps-url]
|
|
7
|
+
[![Install size][size]][size-url]
|
|
8
|
+
[![Build status][build]][build-url]
|
|
9
|
+
[![Coverage status][coverage]][coverage-url]
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
[package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg
|
|
12
|
+
[package-url]: https://nodejs.org/api/esm.html
|
|
6
13
|
|
|
14
|
+
[npm]: https://img.shields.io/npm/v/git-semver-tags.svg
|
|
15
|
+
[npm-url]: https://npmjs.com/package/git-semver-tags
|
|
7
16
|
|
|
8
|
-
|
|
17
|
+
[node]: https://img.shields.io/node/v/git-semver-tags.svg
|
|
18
|
+
[node-url]: https://nodejs.org
|
|
9
19
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
```
|
|
20
|
+
[deps]: https://img.shields.io/librariesio/release/npm/git-semver-tags
|
|
21
|
+
[deps-url]: https://libraries.io/npm/git-semver-tags/tree
|
|
13
22
|
|
|
14
|
-
|
|
23
|
+
[size]: https://packagephobia.com/badge?p=git-semver-tags
|
|
24
|
+
[size-url]: https://packagephobia.com/result?p=git-semver-tags
|
|
25
|
+
|
|
26
|
+
[build]: https://img.shields.io/github/actions/workflow/status/conventional-changelog/conventional-changelog/tests.yaml?branch=master
|
|
27
|
+
[build-url]: https://github.com/conventional-changelog/conventional-changelog/actions
|
|
28
|
+
|
|
29
|
+
[coverage]: https://coveralls.io/repos/github/conventional-changelog/conventional-changelog/badge.svg?branch=master
|
|
30
|
+
[coverage-url]: https://coveralls.io/github/conventional-changelog/conventional-changelog?branch=master
|
|
15
31
|
|
|
16
|
-
|
|
17
|
-
var gitSemverTags = require('git-semver-tags');
|
|
32
|
+
Get all git semver tags of your repository in reverse chronological order.
|
|
18
33
|
|
|
19
|
-
|
|
34
|
+
*Note:* since lightweight tags do not store date information, the date of a tag is the date of the commit that is tagged on. If two tags on one commit, the order is not guaranteed.
|
|
20
35
|
|
|
21
|
-
|
|
36
|
+
## Install
|
|
22
37
|
|
|
23
|
-
|
|
24
|
-
|
|
38
|
+
```bash
|
|
39
|
+
# pnpm
|
|
40
|
+
pnpm add git-semver-tags
|
|
41
|
+
# yarn
|
|
42
|
+
yarn add git-semver-tags
|
|
43
|
+
# npm
|
|
44
|
+
npm i git-semver-tags
|
|
25
45
|
```
|
|
26
46
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
## CLI
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Example
|
|
51
|
+
git-semver-tags
|
|
52
|
+
# Output:
|
|
53
|
+
# v2.0.0
|
|
54
|
+
# v1.0.0
|
|
55
|
+
# For more details
|
|
56
|
+
git-semver-tags --help
|
|
32
57
|
```
|
|
33
58
|
|
|
34
|
-
##
|
|
59
|
+
## API
|
|
35
60
|
|
|
36
|
-
|
|
37
|
-
git history, rather than `v1.0.0` format.
|
|
38
|
-
* `opts.package`: what package should lerna style tags be listed for, e.g.,
|
|
39
|
-
`foo-package`.
|
|
40
|
-
* `opts.tagPrefix`: specify a prefix for the git tag to be ignored from the semver checks
|
|
61
|
+
For JS API see [@conventional-changelog/git-client](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/git-client).
|
|
41
62
|
|
|
42
63
|
## License
|
|
43
64
|
|
|
44
65
|
MIT © [Steve Mao](https://github.com/stevemao)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
[npm-image]: https://badge.fury.io/js/git-semver-tags.svg
|
|
48
|
-
[npm-url]: https://npmjs.org/package/git-semver-tags
|
|
49
|
-
[travis-image]: https://travis-ci.org/conventional-changelog/git-semver-tags.svg?branch=master
|
|
50
|
-
[travis-url]: https://travis-ci.org/conventional-changelog/git-semver-tags
|
|
51
|
-
[daviddm-image]: https://david-dm.org/stevemao/git-semver-tags.svg?theme=shields.io
|
|
52
|
-
[daviddm-url]: https://david-dm.org/stevemao/git-semver-tags
|
|
53
|
-
[coverage-image]: https://coveralls.io/repos/github/conventional-changelog/conventional-changelog/badge.svg?branch=master
|
|
54
|
-
[coverage-url]: https://coveralls.io/github/conventional-changelog/conventional-changelog?branch=master
|
package/package.json
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "git-semver-tags",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"url": "https://github.com/conventional-changelog/conventional-changelog/issues"
|
|
7
|
-
},
|
|
8
|
-
"homepage": "https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/git-semver-tags#readme",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "8.0.0",
|
|
5
|
+
"description": "Get all git semver tags of your repository in reverse chronological order.",
|
|
9
6
|
"author": {
|
|
10
7
|
"name": "Steve Mao",
|
|
11
8
|
"email": "maochenyan@gmail.com",
|
|
12
9
|
"url": "https://github.com/stevemao"
|
|
13
10
|
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"homepage": "https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/git-semver-tags#readme",
|
|
14
13
|
"repository": {
|
|
15
14
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/conventional-changelog/conventional-changelog.git"
|
|
15
|
+
"url": "https://github.com/conventional-changelog/conventional-changelog.git",
|
|
16
|
+
"directory": "packages/git-semver-tags"
|
|
17
17
|
},
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
"node": ">=16"
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/conventional-changelog/conventional-changelog/issues"
|
|
21
20
|
},
|
|
22
|
-
"files": [
|
|
23
|
-
"index.js",
|
|
24
|
-
"cli.mjs"
|
|
25
|
-
],
|
|
26
21
|
"keywords": [
|
|
27
22
|
"git-semver-tags",
|
|
28
23
|
"order",
|
|
@@ -31,11 +26,18 @@
|
|
|
31
26
|
"git-tag",
|
|
32
27
|
"git"
|
|
33
28
|
],
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"semver": "^7.5.2"
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18"
|
|
37
31
|
},
|
|
38
32
|
"bin": {
|
|
39
|
-
"git-semver-tags": "cli.
|
|
33
|
+
"git-semver-tags": "./src/cli.js"
|
|
34
|
+
},
|
|
35
|
+
"exports": "./src/index.js",
|
|
36
|
+
"files": [
|
|
37
|
+
"src"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"meow": "^13.0.0",
|
|
41
|
+
"@conventional-changelog/git-client": "^1.0.0"
|
|
40
42
|
}
|
|
41
43
|
}
|
package/{cli.mjs → src/cli.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import meow from 'meow'
|
|
3
|
-
import
|
|
3
|
+
import { getSemverTags } from './index.js'
|
|
4
4
|
|
|
5
5
|
const args = meow(`
|
|
6
6
|
Usage
|
|
@@ -33,7 +33,7 @@ const args = meow(`
|
|
|
33
33
|
}
|
|
34
34
|
})
|
|
35
35
|
|
|
36
|
-
const tags = await
|
|
36
|
+
const tags = await getSemverTags({
|
|
37
37
|
lernaTags: args.flags.lerna,
|
|
38
38
|
package: args.flags.package,
|
|
39
39
|
tagPrefix: args.flags.tagPrefix,
|
package/src/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConventionalGitClient,
|
|
3
|
+
packagePrefix
|
|
4
|
+
} from '@conventional-changelog/git-client'
|
|
5
|
+
|
|
6
|
+
function getFinalOptions (options = {}) {
|
|
7
|
+
if (options.package && !options.lernaTags) {
|
|
8
|
+
throw new Error('opts.package should only be used when running in lerna mode')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const finalOptions = {
|
|
12
|
+
cwd: options.cwd || process.cwd(),
|
|
13
|
+
prefix: options.lernaTags ? packagePrefix(options.package) : options.tagPrefix,
|
|
14
|
+
skipUnstable: options.skipUnstable
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return finalOptions
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get semver tags from git.
|
|
22
|
+
* @param {*} options
|
|
23
|
+
* @param {string} [options.cwd=process.cwd()] - Current working directory to run git.
|
|
24
|
+
* @param {boolean} [options.lernaTags=false] - Extract lerna style tags.
|
|
25
|
+
* @param {string} [options.package] - Filter lerna style tags by package.
|
|
26
|
+
* @param {string} [options.tagPrefix] - Filter semver tags by prefix.
|
|
27
|
+
* @returns Semver tags.
|
|
28
|
+
*/
|
|
29
|
+
export async function getSemverTags (options = {}) {
|
|
30
|
+
const {
|
|
31
|
+
cwd,
|
|
32
|
+
...finalOptions
|
|
33
|
+
} = getFinalOptions(options)
|
|
34
|
+
const client = new ConventionalGitClient(cwd)
|
|
35
|
+
const tags = []
|
|
36
|
+
|
|
37
|
+
for await (const tag of client.getSemverTags(finalOptions)) {
|
|
38
|
+
tags.push(tag)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return tags
|
|
42
|
+
}
|
package/index.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
const { exec } = require('child_process')
|
|
2
|
-
const { valid: semverValid } = require('semver')
|
|
3
|
-
|
|
4
|
-
const regex = /tag:\s*(.+?)[,)]/gi
|
|
5
|
-
const cmd = 'git log --decorate --no-color'
|
|
6
|
-
const unstableTagTest = /.+-\w+\.\d+$/
|
|
7
|
-
|
|
8
|
-
function lernaTag (tag, pkg) {
|
|
9
|
-
if (pkg && !tag.startsWith(`${pkg}@`)) {
|
|
10
|
-
return false
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return /^.+@[0-9]+\.[0-9]+\.[0-9]+(-.+)?$/.test(tag)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function gitSemverTags (opts = {}) {
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
const options = {
|
|
19
|
-
maxBuffer: Infinity,
|
|
20
|
-
cwd: process.cwd(),
|
|
21
|
-
...opts
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (options.package && !options.lernaTags) {
|
|
25
|
-
throw new Error('opts.package should only be used when running in lerna mode')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
exec(cmd, options, (err, data) => {
|
|
29
|
-
if (err) {
|
|
30
|
-
reject(err)
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const tags = []
|
|
35
|
-
let match
|
|
36
|
-
let tag
|
|
37
|
-
let unprefixedTag
|
|
38
|
-
|
|
39
|
-
data.split('\n').forEach((decorations) => {
|
|
40
|
-
while ((match = regex.exec(decorations))) {
|
|
41
|
-
tag = match[1]
|
|
42
|
-
|
|
43
|
-
if (options.skipUnstable && unstableTagTest.test(tag)) {
|
|
44
|
-
// skip unstable tag
|
|
45
|
-
continue
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (options.lernaTags) {
|
|
49
|
-
if (lernaTag(tag, options.package)) {
|
|
50
|
-
tags.push(tag)
|
|
51
|
-
}
|
|
52
|
-
} else if (options.tagPrefix) {
|
|
53
|
-
if (tag.startsWith(options.tagPrefix)) {
|
|
54
|
-
unprefixedTag = tag.replace(options.tagPrefix, '')
|
|
55
|
-
|
|
56
|
-
if (semverValid(unprefixedTag)) {
|
|
57
|
-
tags.push(tag)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
} else if (semverValid(tag)) {
|
|
61
|
-
tags.push(tag)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
resolve(tags)
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
module.exports = gitSemverTags
|