Skip to content

Commit 2ed8966

Browse files
committed
remove file parsing and obtain version from git by default
1 parent c0decc1 commit 2ed8966

File tree

6 files changed

+110
-203
lines changed

6 files changed

+110
-203
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ update: node_modules
2727
@touch node_modules
2828

2929
patch: node_modules test
30-
node bin/versions.js -Cc 'make build' patch
30+
node bin/versions.js -c 'make build' patch package.json package-lock.json
3131
@$(MAKE) --no-print-directory publish
3232

3333
minor: node_modules test
34-
node bin/versions.js -Cc 'make build' minor
34+
node bin/versions.js -c 'make build' minor package.json package-lock.json
3535
@$(MAKE) --no-print-directory publish
3636

3737
major: node_modules test
38-
node bin/versions.js -Cc 'make build' major
38+
node bin/versions.js -c 'make build' major package.json package-lock.json
3939
@$(MAKE) --no-print-directory publish
4040

4141
.PHONY: lint test unittest build publish deps update patch minor major

README.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
> CLI to flexibly increment a project's version
55
6-
Supports projects with `package.json` and `pyproject.toml` (poetry).
7-
86
## Installation
97
```
108
npm i -D versions
@@ -15,29 +13,20 @@ npx versions --help
1513
```
1614
usage: versions [options] patch|minor|major [files...]
1715
18-
Semantically increment a project's version in multiple files.
19-
20-
Arguments:
21-
files Files to do version replacement in. The nearest package.json and
22-
package-lock.json will always be included unless the -P argument is given
2316
Options:
24-
-a, --all Add all changed files to the commit instead of only the ones currently modified
25-
-b, --base <version> Base version to use. Default is parsed from the nearest package.json
26-
-C, --changelog Generate a changelog since the base version tag or if absent, the latest tag
27-
-c, --command <cmd> Run a command after files are updated but before git commit and tag
28-
-d, --date [<date>] Replace dates in format YYYY-MM-DD with current or given date
29-
-m, --message <str> Custom tag and commit message. Token _VER_ is available to fill the new version
17+
-a, --all Add all changed files to the commit
18+
-b, --base <version> Base version. Default is from latest git tag or 0.1.0
3019
-p, --prefix Prefix git tags with a "v" character
31-
-r, --replace <str> Additional replacement in the format "s#regexp#replacement#flags"
32-
-g, --gitless Do not perform any git action like creating commit and tag
33-
-G, --globless Do not process globs in the file arguments
34-
-P, --packageless Do not include package.json and package-lock.json unless explicitely given
20+
-c, --command <cmd> Run command after files are updated but before git commit and tag
21+
-d, --date [<date>] Replace dates in format YYYY-MM-DD with current or given date
22+
-m, --message <str> Custom tag and commit message. Token _VER_ is available
23+
-r, --replace <str> Additional replacements in the format "s#regexp#replacement#flags"
3524
-v, --version Print the version
3625
-h, --help Print this help
3726
3827
Examples:
3928
$ versions patch
40-
$ versions -Cc 'npm run build' -m 'Release _VER_' minor file.css
29+
$ versions -c 'npm run build' -m 'Release _VER_' minor file.css
4130
```
4231

4332
## Signing commits and tags
@@ -57,7 +46,7 @@ To automatically sign commits and tags created by `versions` with GPG add this t
5746

5847
## CI environments
5948

60-
CI environments usually do shallow git checkout. To use `--changelog` unshallow the repository first:
49+
CI environments usually do shallow git checkout. Unshallow the repository first:
6150

6251
```bash
6352
git fetch --unshallow --quiet --tags

package-lock.json

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"eslint": "8.25.0",
1919
"eslint-config-silverwind": "59.0.0",
2020
"execa": "6.1.0",
21-
"fast-glob": "3.2.12",
2221
"minimist": "1.2.7",
2322
"toml": "3.0.0",
2423
"updates": "13.1.9",

test.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import toml from "toml";
77
const pkgFile = new URL("package.json", import.meta.url);
88
const pyFile = new URL("fixtures/pyproject.toml", import.meta.url);
99
const testFile = new URL("testfile", import.meta.url);
10-
const script = `bin/versions.js`;
11-
const prefix = `testfile v`;
12-
const fromSuffix = ` (1999-01-01)`;
13-
const toSuffix = ` (${(new Date()).toISOString().substring(0, 10)})`;
1410
let pkgStr;
1511

1612
afterAll(async () => {
@@ -20,7 +16,7 @@ afterAll(async () => {
2016

2117
test("version", async () => {
2218
const {version: expected} = JSON.parse(readFileSync(new URL("package.json", import.meta.url), "utf8"));
23-
const {stdout, exitCode} = await execa("node", [script, "-v"]);
19+
const {stdout, exitCode} = await execa("node", ["bin/versions.js", "-v"]);
2420
expect(stdout).toEqual(expected);
2521
expect(exitCode).toEqual(0);
2622
});
@@ -47,36 +43,38 @@ test("semver", async () => {
4743
});
4844

4945
async function run(args) {
50-
return await execa(`node ${script} ${args}`, {shell: true});
46+
return await execa(`node bin/versions.js ${args}`, {shell: true});
5147
}
5248

5349
async function verify(version) {
54-
expect(await readFile(testFile, "utf8")).toEqual(`${prefix}${version}${toSuffix}`);
50+
expect(await readFile(testFile, "utf8")).toEqual(
51+
`testfile v${version} (${(new Date()).toISOString().substring(0, 10)})`
52+
);
5553
return version;
5654
}
5755

5856
test("versions", async () => {
5957
pkgStr = await readFile(pkgFile, "utf8");
6058
let {version} = await JSON.parse(pkgStr);
6159

62-
await writeFile(testFile, `${prefix}${version}${fromSuffix}`);
60+
await writeFile(testFile, `testfile v${version} (1999-01-01)`);
6361

64-
await run(`-P patch -d -g testfile`);
62+
await run(`--date --base ${version} --gitless patch testfile`);
6563
version = await verify(incrementSemver(version, "patch"));
6664

67-
await run(`-b ${version} -P -C --date --gitless minor testfile`);
65+
await run(`--date --base ${version} --gitless minor testfile`);
6866
version = await verify(incrementSemver(version, "minor"));
6967

70-
await run(`-b ${version} --packageless --gitless --date major testfile`);
68+
await run(`--date --base ${version} --gitless major testfile`);
7169
version = await verify(incrementSemver(version, "major"));
7270

73-
await run(`-b ${version} -g -C -P -d major t*stf*le`);
71+
await run(`--date --base ${version} --gitless major t*stf*le`);
7472
version = await verify(incrementSemver(version, "major"));
7573

76-
await run(`-b ${version} -d -g -P major testfile testfile`);
74+
await run(`--date --base ${version} --gitless major testfile testfile`);
7775
version = await verify(incrementSemver(version, "major"));
7876

79-
await run(`-b ${version} -dgPGC minor testfile`);
77+
await run(`--date --base ${version} --gitless minor testfile`);
8078
version = await verify(incrementSemver(version, "minor"));
8179
});
8280

@@ -91,7 +89,7 @@ test("pyproject.toml", async () => {
9189
const tmpFile = new URL("pyproject.toml", import.meta.url);
9290
await writeFile(tmpFile, str);
9391
// todo: eliminate need for -b
94-
await run(`-P minor -d -g pyproject.toml -b ${versionBefore}`);
92+
await run(`minor --gitless --date --base ${versionBefore} pyproject.toml`);
9593

9694
const dataAfter = toml.parse(await readFile(tmpFile, "utf8"));
9795
const versionAfter = incrementSemver(versionBefore, "minor");

0 commit comments

Comments
 (0)