Skip to content

Commit fb6fefd

Browse files
committed
Update packages and reformat
1 parent c7a3f5a commit fb6fefd

6 files changed

Lines changed: 263 additions & 680 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.github/workflows/npm-publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ jobs:
99
publish-npm:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
13-
- uses: actions/setup-node@v2
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-node@v3
1414
with:
15-
node-version: 12
15+
node-version: 14
1616
registry-url: https://registry.npmjs.org/
1717
- run: yarn install --frozen-lockfile
1818
- run: npm publish

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
Gets Git version and commit information for one or more repositories. This is useful for applications that span multiple repositories or use submodules.
77

88
## Prerequisites
9+
910
[Git](https://git-scm.com/) is expected to be preinstalled (and in `PATH`).
1011

1112
The script simply runs shell commands similar to:
1213

13-
- repository: `git config --get remote.origin.url`
14-
- branch: `git rev-parse --abbrev-ref HEAD`
15-
- sha1: `git rev-parse HEAD`
16-
- date: `git --no-pager log --pretty=format:"%at" -n1`
17-
- clean: `git diff-index --quiet HEAD --`
18-
- version: `git describe --tags --match "v[0-9]*" HEAD`
14+
- repository: `git config --get remote.origin.url`
15+
- branch: `git rev-parse --abbrev-ref HEAD`
16+
- sha1: `git rev-parse HEAD`
17+
- date: `git --no-pager log --pretty=format:"%at" -n1`
18+
- clean: `git diff-index --quiet HEAD --`
19+
- version: `git describe --tags --match "v[0-9]*" HEAD`
1920

2021
## Install
2122

@@ -53,6 +54,7 @@ Otherwise, the name of the current folder is used as the `name` and `version` is
5354
```
5455

5556
or with `--version-only`:
57+
5658
```json
5759
{
5860
"name": "get-git-version",
@@ -62,14 +64,14 @@ or with `--version-only`:
6264

6365
## Command-line Options
6466

65-
* `-w [path]` or `--working-dir [path]` overrides the working directory (defaults to the current directory)
66-
* `-o [path]` or `--out-file [path]` writes the output to a file instead of `stdout`
67-
* `-c [path]` or `--config-file [path]` overrides the config file name (defaults to `.git-version.config.json`)
68-
* `--app-id [id]` overrides the application `id` (defaults to `app`)
69-
* `--version-tag-prefix [prefix]` overrides the default version tag prefix (defaults to `v[0-9]*`)
70-
* `--no-pretty` disables pretty printing the output JSON
71-
* `--version-only` returns only the version, without git information
72-
* `-h` or `--help` outputs usage information
67+
- `-w [path]` or `--working-dir [path]` overrides the working directory (defaults to the current directory)
68+
- `-o [path]` or `--out-file [path]` writes the output to a file instead of `stdout`
69+
- `-c [path]` or `--config-file [path]` overrides the config file name (defaults to `.git-version.config.json`)
70+
- `--app-id [id]` overrides the application `id` (defaults to `app`)
71+
- `--version-tag-prefix [prefix]` overrides the default version tag prefix (defaults to `v[0-9]*`)
72+
- `--no-pretty` disables pretty printing the output JSON
73+
- `--version-only` returns only the version, without git information
74+
- `-h` or `--help` outputs usage information
7375

7476
## Configuration file example
7577

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "get-git-version",
3-
"version": "0.5.2",
3+
"version": "0.5.3",
44
"author": "Polys Georgiou",
55
"license": "MIT",
66
"homepage": "https://github.com/polys/git-version",
@@ -21,10 +21,10 @@
2121
"node": ">= 8.3.0"
2222
},
2323
"devDependencies": {
24-
"eslint": "^8.3.0",
24+
"eslint": "^8.28.0",
2525
"eslint-config-airbnb-base": "^15.0.0",
26-
"eslint-plugin-import": "^2.22.1",
27-
"nodemon": "^2.0.6"
26+
"eslint-plugin-import": "^2.26.0",
27+
"nodemon": "^2.0.20"
2828
},
2929
"dependencies": {
3030
"commander": "^6.2.0"
@@ -38,4 +38,4 @@
3838
"commit",
3939
"sha"
4040
]
41-
}
41+
}

version.js

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@ commander
1717
.parse(process.argv);
1818

1919
const {
20-
workingDir,
21-
outFile,
22-
configFile,
23-
appId,
24-
versionTagPrefix,
25-
pretty,
26-
repository,
27-
versionOnly
20+
workingDir, outFile, configFile, appId, versionTagPrefix, pretty, repository, versionOnly
2821
} = commander;
2922

3023
if (!workingDir || !fs.existsSync(workingDir) || !fs.lstatSync(workingDir).isDirectory()) {
@@ -40,40 +33,40 @@ const getDefaultApp = () => {
4033
id: appId,
4134
name: pack.name,
4235
version: pack.version,
43-
versionTagPrefix
36+
versionTagPrefix,
4437
};
4538
}
4639
return {
4740
id: appId,
4841
name: path.basename(workingDir),
49-
versionTagPrefix
42+
versionTagPrefix,
5043
};
5144
};
5245

5346
const configFilePath = path.join(workingDir, configFile);
54-
const config = fs.existsSync(configFilePath)
55-
? JSON.parse(fs.readFileSync(configFilePath, 'utf8'))
56-
: [getDefaultApp()];
47+
const config = fs.existsSync(configFilePath) ? JSON.parse(fs.readFileSync(configFilePath, 'utf8')) : [getDefaultApp()];
5748

5849
const outFilePath = outFile ? path.join(workingDir, outFile) : null;
5950

60-
const appConfig = config.find(c => c.id === appId);
51+
const appConfig = config.find((c) => c.id === appId);
6152
if (!appConfig) {
6253
console.error(`Expected an item with id '${appId}' in '${configFilePath}'`);
6354
process.exit(1);
6455
}
6556

66-
const execGetOutput = async (command, cwd) => new Promise(resolve => {
67-
exec(command, { cwd }, (error, stdout) => {
68-
resolve(error ? null : (stdout || '').trim());
57+
const execGetOutput = async (command, cwd) =>
58+
new Promise((resolve) => {
59+
exec(command, { cwd }, (error, stdout) => {
60+
resolve(error ? null : (stdout || '').trim());
61+
});
6962
});
70-
});
7163

72-
const execGetExitCode = async (command, cwd) => new Promise(resolve => {
73-
exec(command, { cwd }, (error) => {
74-
resolve(error ? error.code : 0);
64+
const execGetExitCode = async (command, cwd) =>
65+
new Promise((resolve) => {
66+
exec(command, { cwd }, (error) => {
67+
resolve(error ? error.code : 0);
68+
});
7569
});
76-
});
7770

7871
async function getGitInfo(dirPath, describeMatchPrefix) {
7972
const remoteUrl = repository ? await execGetOutput('git config --get remote.origin.url', dirPath) : undefined;
@@ -93,38 +86,40 @@ async function getGitInfo(dirPath, describeMatchPrefix) {
9386
branch,
9487
sha1,
9588
date: dateUnix ? new Date(1000 * dateUnix) : undefined,
96-
clean: (diffExitCode === 0)
97-
}
89+
clean: diffExitCode === 0,
90+
},
9891
};
9992
}
10093

101-
Promise.all(config.map(async item => (
102-
{
94+
Promise.all(
95+
config.map(async (item) => ({
10396
id: item.id,
10497
name: item.name,
105-
...await getGitInfo(path.join(workingDir, item.path || '.'), item.versionTagPrefix),
106-
}
107-
))).then((versions) => {
108-
const app = versions.find(c => c.id === appId);
109-
const components = versions.filter(c => c.id !== appId);
98+
...(await getGitInfo(path.join(workingDir, item.path || '.'), item.versionTagPrefix)),
99+
}))
100+
).then((versions) => {
101+
const app = versions.find((c) => c.id === appId);
102+
const components = versions.filter((c) => c.id !== appId);
110103

111104
let version = {
112105
name: app.name,
113-
version: app.version || appConfig.version
106+
version: app.version || appConfig.version,
114107
};
115108

116109
if (!versionOnly) {
117110
version = Object.assign(version, {
118111
git: app.git,
119-
components: components.length ? components : undefined
112+
components: components.length ? components : undefined,
120113
});
121114
}
122115

123116
const json = JSON.stringify(version, undefined, pretty ? 2 : 0);
124117

125118
if (outFilePath) {
126119
fs.writeFile(outFilePath, json, (err) => {
127-
if (err) { console.error(err); }
120+
if (err) {
121+
console.error(err);
122+
}
128123
});
129124
} else {
130125
console.log(json);

0 commit comments

Comments
 (0)