commit-and-tag-version 12.2.0 → 12.4.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/CHANGELOG.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [12.4.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.3.0...v12.4.0) (2024-04-19)
6
+
7
+
8
+ ### Features
9
+
10
+ * Add OpenAPI version support ([#136](https://github.com/absolute-version/commit-and-tag-version/issues/136)) ([007b1b0](https://github.com/absolute-version/commit-and-tag-version/commit/007b1b0386651f2fbd6e8a9f552a2a34702086ca))
11
+
12
+ ## [12.3.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.2.0...v12.3.0) (2024-04-19)
13
+
14
+
15
+ ### Features
16
+
17
+ * **updater:** add YAML support ([#137](https://github.com/absolute-version/commit-and-tag-version/issues/137)) ([b9dccc2](https://github.com/absolute-version/commit-and-tag-version/commit/b9dccc23ec05e4026899c676f3275d4dedf8c686))
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * Add debug messages for exclusions during bump lifecycle ([#131](https://github.com/absolute-version/commit-and-tag-version/issues/131)) ([a9191f2](https://github.com/absolute-version/commit-and-tag-version/commit/a9191f293eb9302afb1093ad37e9fa076f6b37a2))
23
+
5
24
  ## [12.2.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.1.0...v12.2.0) (2024-01-15)
6
25
 
7
26
 
package/README.md CHANGED
@@ -22,6 +22,7 @@ _Having problems? Want to contribute? Join us on the [node-tooling community Sla
22
22
  - [Maven Support (Java/Kotlin)](#maven-support-javakotlin)
23
23
  - [Gradle Support (Java/Kotlin)](#gradle-support-javakotlin)
24
24
  - [.NET Support](#net-support)
25
+ - [OpenAPI Support](#openapi-support)
25
26
  - [Installing `commit-and-tag-version`](#installing-commit-and-tag-version)
26
27
  - [As a local `npm run` script](#as-a-local-npm-run-script)
27
28
  - [As global `bin`](#as-global-bin)
@@ -108,6 +109,23 @@ This is going to read and update only the `<Version>` tag in the file.
108
109
  commit-and-tag-version --packageFiles <YOUR-PROJECT-NAME>.csproj --bumpFiles <YOUR-PROJECT-NAME>.csproj
109
110
  ```
110
111
 
112
+ ### YAML Support
113
+
114
+ If you are using YAML files.
115
+ This is going to read and update only the `version:` tag in the file.
116
+
117
+ ```sh
118
+ commit-and-tag-version --packageFiles file.yaml --bumpFiles file.yaml
119
+ ```
120
+
121
+ ### OpenAPI Support
122
+
123
+ If you are using OpenAPI, then just point to your `openapi.yaml` file.
124
+
125
+ ```sh
126
+ commit-and-tag-version --packageFiles openapi.yaml --bumpFiles openapi.yaml
127
+ ```
128
+
111
129
  ## Installing `commit-and-tag-version`
112
130
 
113
131
  ### As a local `npm run` script
@@ -222,10 +222,20 @@ function updateConfigs(args, newVersion) {
222
222
  }
223
223
  const configPath = path.resolve(process.cwd(), updater.filename);
224
224
  try {
225
- if (dotgit.ignore(updater.filename)) return;
225
+ if (dotgit.ignore(updater.filename)) {
226
+ console.debug(
227
+ `Not updating file '${updater.filename}', as it is ignored in Git`,
228
+ );
229
+ return;
230
+ }
226
231
  const stat = fs.lstatSync(configPath);
227
232
 
228
- if (!stat.isFile()) return;
233
+ if (!stat.isFile()) {
234
+ console.debug(
235
+ `Not updating '${updater.filename}', as it is not a file`,
236
+ );
237
+ return;
238
+ }
229
239
  const contents = fs.readFileSync(configPath, 'utf8');
230
240
  const newContents = updater.updater.writeVersion(contents, newVersion);
231
241
  const realNewVersion = updater.updater.readVersion(newContents);
@@ -6,6 +6,8 @@ const updatersByType = {
6
6
  maven: require('./types/maven'),
7
7
  gradle: require('./types/gradle'),
8
8
  csproj: require('./types/csproj'),
9
+ yaml: require('./types/yaml'),
10
+ openapi: require('./types/openapi'),
9
11
  };
10
12
  const PLAIN_TEXT_BUMP_FILES = ['VERSION.txt', 'version.txt'];
11
13
 
@@ -33,6 +35,12 @@ function getUpdaterByFilename(filename) {
33
35
  if (filename.endsWith('.csproj')) {
34
36
  return getUpdaterByType('csproj');
35
37
  }
38
+ if (/\.ya?ml$/.test(filename)) {
39
+ return getUpdaterByType('yaml');
40
+ }
41
+ if (/openapi.yaml/.test(filename)) {
42
+ return getUpdaterByType('openapi');
43
+ }
36
44
  throw Error(
37
45
  `Unsupported file (${filename}) provided for bumping.\n Please specify the updater \`type\` or use a custom \`updater\`.`,
38
46
  );
@@ -0,0 +1,15 @@
1
+ const yaml = require('yaml');
2
+ const detectNewline = require('detect-newline');
3
+
4
+ module.exports.readVersion = function (contents) {
5
+ return yaml.parse(contents).info.version;
6
+ };
7
+
8
+ module.exports.writeVersion = function (contents, version) {
9
+ const newline = detectNewline(contents);
10
+ const document = yaml.parseDocument(contents);
11
+
12
+ document.get('info').set('version', version);
13
+
14
+ return document.toString().replace(/\r?\n/g, newline);
15
+ };
@@ -0,0 +1,15 @@
1
+ const yaml = require('yaml');
2
+ const detectNewline = require('detect-newline');
3
+
4
+ module.exports.readVersion = function (contents) {
5
+ return yaml.parse(contents).version;
6
+ };
7
+
8
+ module.exports.writeVersion = function (contents, version) {
9
+ const newline = detectNewline(contents);
10
+ const document = yaml.parseDocument(contents);
11
+
12
+ document.set('version', version);
13
+
14
+ return document.toString().replace(/\r?\n/g, newline);
15
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commit-and-tag-version",
3
- "version": "12.2.0",
3
+ "version": "12.4.0",
4
4
  "description": "replacement for `npm version` with automatic CHANGELOG generation",
5
5
  "bin": "bin/cli.js",
6
6
  "scripts": {
@@ -52,6 +52,7 @@
52
52
  "jsdom": "^23.2.0",
53
53
  "semver": "^7.5.4",
54
54
  "w3c-xmlserializer": "^5.0.0",
55
+ "yaml": "^2.4.1",
55
56
  "yargs": "^17.7.2"
56
57
  },
57
58
  "devDependencies": {
package/test/core.spec.js CHANGED
@@ -1180,6 +1180,74 @@ describe('cli', function () {
1180
1180
  });
1181
1181
  });
1182
1182
 
1183
+ it('bumps version in OpenAPI `openapi.yaml` file with CRLF Line Endings', async function () {
1184
+ const expected = fs.readFileSync(
1185
+ './test/mocks/openapi-1.3.0-crlf.yaml',
1186
+ 'utf-8',
1187
+ );
1188
+ const filename = 'openapi.yaml';
1189
+ mock({
1190
+ bump: 'minor',
1191
+ realTestFiles: [
1192
+ {
1193
+ filename,
1194
+ path: './test/mocks/openapi-1.2.3-crlf.yaml',
1195
+ },
1196
+ ],
1197
+ });
1198
+ await exec({
1199
+ packageFiles: [{ filename, type: 'openapi' }],
1200
+ bumpFiles: [{ filename, type: 'openapi' }],
1201
+ });
1202
+
1203
+ // filePath is the first arg passed to writeFileSync
1204
+ const packageJsonWriteFileSynchCall = findWriteFileCallForPath({
1205
+ writeFileSyncSpy,
1206
+ filename,
1207
+ });
1208
+
1209
+ if (!packageJsonWriteFileSynchCall) {
1210
+ throw new Error(`writeFileSynch not invoked with path ${filename}`);
1211
+ }
1212
+
1213
+ const calledWithContentStr = packageJsonWriteFileSynchCall[1];
1214
+ expect(calledWithContentStr).toEqual(expected);
1215
+ });
1216
+
1217
+ it('bumps version in OpenAPI `openapi.yaml` file with LF Line Endings', async function () {
1218
+ const expected = fs.readFileSync(
1219
+ './test/mocks/openapi-1.3.0-lf.yaml',
1220
+ 'utf-8',
1221
+ );
1222
+ const filename = 'openapi.yaml';
1223
+ mock({
1224
+ bump: 'minor',
1225
+ realTestFiles: [
1226
+ {
1227
+ filename,
1228
+ path: './test/mocks/openapi-1.2.3-lf.yaml',
1229
+ },
1230
+ ],
1231
+ });
1232
+ await exec({
1233
+ packageFiles: [{ filename, type: 'openapi' }],
1234
+ bumpFiles: [{ filename, type: 'openapi' }],
1235
+ });
1236
+
1237
+ // filePath is the first arg passed to writeFileSync
1238
+ const packageJsonWriteFileSynchCall = findWriteFileCallForPath({
1239
+ writeFileSyncSpy,
1240
+ filename,
1241
+ });
1242
+
1243
+ if (!packageJsonWriteFileSynchCall) {
1244
+ throw new Error(`writeFileSynch not invoked with path ${filename}`);
1245
+ }
1246
+
1247
+ const calledWithContentStr = packageJsonWriteFileSynchCall[1];
1248
+ expect(calledWithContentStr).toEqual(expected);
1249
+ });
1250
+
1183
1251
  it('bumps version in Maven `pom.xml` file with CRLF Line Endings', async function () {
1184
1252
  const expected = fs.readFileSync(
1185
1253
  './test/mocks/pom-6.4.0-crlf.xml',
@@ -1365,6 +1433,78 @@ describe('cli', function () {
1365
1433
  verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '1.1.0' });
1366
1434
  });
1367
1435
 
1436
+ it('bumps version in Dart `pubspec.yaml` file', async function () {
1437
+ const expected = fs.readFileSync(
1438
+ './test/mocks/pubspec-6.4.0.yaml',
1439
+ 'utf-8',
1440
+ );
1441
+
1442
+ const filename = 'pubspec.yaml';
1443
+ mock({
1444
+ bump: 'minor',
1445
+ realTestFiles: [
1446
+ {
1447
+ filename,
1448
+ path: './test/mocks/pubspec-6.3.1.yaml',
1449
+ },
1450
+ ],
1451
+ });
1452
+
1453
+ await exec({
1454
+ packageFiles: [{ filename, type: 'yaml' }],
1455
+ bumpFiles: [{ filename, type: 'yaml' }],
1456
+ });
1457
+
1458
+ // filePath is the first arg passed to writeFileSync
1459
+ const packageJsonWriteFileSynchCall = findWriteFileCallForPath({
1460
+ writeFileSyncSpy,
1461
+ filename,
1462
+ });
1463
+
1464
+ if (!packageJsonWriteFileSynchCall) {
1465
+ throw new Error(`writeFileSynch not invoked with path ${filename}`);
1466
+ }
1467
+
1468
+ const calledWithContentStr = packageJsonWriteFileSynchCall[1];
1469
+ expect(calledWithContentStr).toEqual(expected);
1470
+ });
1471
+
1472
+ it('bumps version in Dart `pubspec.yaml` file with CRLF line endings', async function () {
1473
+ const expected = fs.readFileSync(
1474
+ './test/mocks/pubspec-6.4.0-crlf.yaml',
1475
+ 'utf-8',
1476
+ );
1477
+
1478
+ const filename = 'pubspec.yaml';
1479
+ mock({
1480
+ bump: 'minor',
1481
+ realTestFiles: [
1482
+ {
1483
+ filename,
1484
+ path: './test/mocks/pubspec-6.3.1-crlf.yaml',
1485
+ },
1486
+ ],
1487
+ });
1488
+
1489
+ await exec({
1490
+ packageFiles: [{ filename, type: 'yaml' }],
1491
+ bumpFiles: [{ filename, type: 'yaml' }],
1492
+ });
1493
+
1494
+ // filePath is the first arg passed to writeFileSync
1495
+ const packageJsonWriteFileSynchCall = findWriteFileCallForPath({
1496
+ writeFileSyncSpy,
1497
+ filename,
1498
+ });
1499
+
1500
+ if (!packageJsonWriteFileSynchCall) {
1501
+ throw new Error(`writeFileSynch not invoked with path ${filename}`);
1502
+ }
1503
+
1504
+ const calledWithContentStr = packageJsonWriteFileSynchCall[1];
1505
+ expect(calledWithContentStr).toEqual(expected);
1506
+ });
1507
+
1368
1508
  describe('skip', function () {
1369
1509
  it('allows bump and changelog generation to be skipped', async function () {
1370
1510
  const changelogContent = 'legacy header format<a name="1.0.0">\n';
@@ -0,0 +1,12 @@
1
+ openapi: "3.0.2"
2
+ info:
3
+ title: Mock API
4
+ description: >-
5
+ Description of Mock API
6
+ version: "1.2.3"
7
+ termsOfService: http://swagger.io/terms/
8
+ externalDocs:
9
+ description: Find out more
10
+ url: https://example.com/foo/bar
11
+ servers:
12
+ - url: http://example.com
@@ -0,0 +1,12 @@
1
+ openapi: "3.0.2"
2
+ info:
3
+ title: Mock API
4
+ description: >-
5
+ Description of Mock API
6
+ version: "1.2.3"
7
+ termsOfService: http://swagger.io/terms/
8
+ externalDocs:
9
+ description: Find out more
10
+ url: https://example.com/foo/bar
11
+ servers:
12
+ - url: http://example.com
@@ -0,0 +1,12 @@
1
+ openapi: "3.0.2"
2
+ info:
3
+ title: Mock API
4
+ description: >-
5
+ Description of Mock API
6
+ version: "1.3.0"
7
+ termsOfService: http://swagger.io/terms/
8
+ externalDocs:
9
+ description: Find out more
10
+ url: https://example.com/foo/bar
11
+ servers:
12
+ - url: http://example.com
@@ -0,0 +1,12 @@
1
+ openapi: "3.0.2"
2
+ info:
3
+ title: Mock API
4
+ description: >-
5
+ Description of Mock API
6
+ version: "1.3.0"
7
+ termsOfService: http://swagger.io/terms/
8
+ externalDocs:
9
+ description: Find out more
10
+ url: https://example.com/foo/bar
11
+ servers:
12
+ - url: http://example.com
@@ -0,0 +1,33 @@
1
+ # This is a comment that should be preserved
2
+ name: mock
3
+ description: "A mock YAML file"
4
+ version: 6.3.1
5
+
6
+ environment:
7
+ dart: ">=3.2.6 <4.0.0"
8
+ flutter: ">=1.17.0"
9
+
10
+ dependencies:
11
+ flutter:
12
+ sdk: flutter
13
+
14
+ dev_dependencies:
15
+ flutter_test:
16
+ sdk: flutter
17
+
18
+ # For information on the generic Dart part of this file, see the
19
+ # following page: https://dart.dev/tools/pub/pubspec
20
+
21
+ # The following section is specific to Flutter packages.
22
+ flutter:
23
+ uses-material-design: true
24
+ generate: true
25
+
26
+ # More comments here nested under one entry
27
+ #
28
+ # These comments should also be preserved.
29
+
30
+ # Another comment block, separated from the first one
31
+ assets:
32
+ - assets/icons/
33
+ - assets/images/
@@ -0,0 +1,33 @@
1
+ # This is a comment that should be preserved
2
+ name: mock
3
+ description: "A mock YAML file"
4
+ version: 6.3.1
5
+
6
+ environment:
7
+ dart: ">=3.2.6 <4.0.0"
8
+ flutter: ">=1.17.0"
9
+
10
+ dependencies:
11
+ flutter:
12
+ sdk: flutter
13
+
14
+ dev_dependencies:
15
+ flutter_test:
16
+ sdk: flutter
17
+
18
+ # For information on the generic Dart part of this file, see the
19
+ # following page: https://dart.dev/tools/pub/pubspec
20
+
21
+ # The following section is specific to Flutter packages.
22
+ flutter:
23
+ uses-material-design: true
24
+ generate: true
25
+
26
+ # More comments here nested under one entry
27
+ #
28
+ # These comments should also be preserved.
29
+
30
+ # Another comment block, separated from the first one
31
+ assets:
32
+ - assets/icons/
33
+ - assets/images/
@@ -0,0 +1,33 @@
1
+ # This is a comment that should be preserved
2
+ name: mock
3
+ description: "A mock YAML file"
4
+ version: 6.4.0
5
+
6
+ environment:
7
+ dart: ">=3.2.6 <4.0.0"
8
+ flutter: ">=1.17.0"
9
+
10
+ dependencies:
11
+ flutter:
12
+ sdk: flutter
13
+
14
+ dev_dependencies:
15
+ flutter_test:
16
+ sdk: flutter
17
+
18
+ # For information on the generic Dart part of this file, see the
19
+ # following page: https://dart.dev/tools/pub/pubspec
20
+
21
+ # The following section is specific to Flutter packages.
22
+ flutter:
23
+ uses-material-design: true
24
+ generate: true
25
+
26
+ # More comments here nested under one entry
27
+ #
28
+ # These comments should also be preserved.
29
+
30
+ # Another comment block, separated from the first one
31
+ assets:
32
+ - assets/icons/
33
+ - assets/images/
@@ -0,0 +1,33 @@
1
+ # This is a comment that should be preserved
2
+ name: mock
3
+ description: "A mock YAML file"
4
+ version: 6.4.0
5
+
6
+ environment:
7
+ dart: ">=3.2.6 <4.0.0"
8
+ flutter: ">=1.17.0"
9
+
10
+ dependencies:
11
+ flutter:
12
+ sdk: flutter
13
+
14
+ dev_dependencies:
15
+ flutter_test:
16
+ sdk: flutter
17
+
18
+ # For information on the generic Dart part of this file, see the
19
+ # following page: https://dart.dev/tools/pub/pubspec
20
+
21
+ # The following section is specific to Flutter packages.
22
+ flutter:
23
+ uses-material-design: true
24
+ generate: true
25
+
26
+ # More comments here nested under one entry
27
+ #
28
+ # These comments should also be preserved.
29
+
30
+ # Another comment block, separated from the first one
31
+ assets:
32
+ - assets/icons/
33
+ - assets/images/