Skip to content

Commit 9e56f94

Browse files
committed
Add version-only option
1 parent 3ddb9de commit 9e56f94

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ Otherwise, the name of the current folder is used as the `name` and `version` is
5252
}
5353
```
5454

55+
or with `--version-only`:
56+
```json
57+
{
58+
"name": "get-git-version",
59+
"version": "0.1.4"
60+
}
61+
```
62+
5563
## Command-line Options
5664

5765
* `-w [path]` or `--working-dir [path]` overrides the working directory (defaults to the current directory)
@@ -60,6 +68,7 @@ Otherwise, the name of the current folder is used as the `name` and `version` is
6068
* `--app-id [id]` overrides the application `id` (defaults to `app`)
6169
* `--version-tag-prefix [prefix]` overrides the default version tag prefix (defaults to `v[0-9]*`)
6270
* `--no-pretty` disables pretty printing the output JSON
71+
* `--version-only` returns only the version, without git information
6372
* `-h` or `--help` outputs usage information
6473

6574
## Configuration file example

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "get-git-version",
3-
"version": "0.1.4",
3+
"version": "0.2.0",
44
"author": "Polys Georgiou",
55
"license": "MIT",
66
"homepage": "https://github.com/polys/git-version",

version.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ commander
1212
.option('--app-id [id]', 'override default application id', 'app')
1313
.option('--version-tag-prefix [prefix]', 'override default version tag prefix', 'v[0-9]*')
1414
.option('--no-pretty', 'disable pretty printing the output JSON')
15+
.option('--version-only', 'return only the version without git information')
1516
.parse(process.argv);
1617

1718
const {
@@ -20,7 +21,8 @@ const {
2021
configFile,
2122
appId,
2223
versionTagPrefix,
23-
pretty
24+
pretty,
25+
versionOnly
2426
} = commander;
2527

2628
if (!workingDir || !fs.existsSync(workingDir) || !fs.lstatSync(workingDir).isDirectory()) {
@@ -103,13 +105,18 @@ Promise.all(config.map(async item => (
103105
const app = versions.find(c => c.id === appId);
104106
const components = versions.filter(c => c.id !== appId);
105107

106-
const version = {
108+
let version = {
107109
name: app.name,
108-
version: app.version || appConfig.version,
109-
git: app.git,
110-
components
110+
version: app.version || appConfig.version
111111
};
112112

113+
if (!versionOnly) {
114+
version = Object.assign(version, {
115+
git: app.git,
116+
components
117+
});
118+
}
119+
113120
const json = JSON.stringify(version, undefined, pretty ? 2 : 0);
114121

115122
if (outFilePath) {

0 commit comments

Comments
 (0)