commit-and-tag-version 12.2.0 → 12.3.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,18 @@
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.3.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.2.0...v12.3.0) (2024-04-19)
6
+
7
+
8
+ ### Features
9
+
10
+ * **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))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * 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))
16
+
5
17
  ## [12.2.0](https://github.com/absolute-version/commit-and-tag-version/compare/v12.1.0...v12.2.0) (2024-01-15)
6
18
 
7
19
 
package/README.md CHANGED
@@ -108,6 +108,15 @@ This is going to read and update only the `<Version>` tag in the file.
108
108
  commit-and-tag-version --packageFiles <YOUR-PROJECT-NAME>.csproj --bumpFiles <YOUR-PROJECT-NAME>.csproj
109
109
  ```
110
110
 
111
+ ### YAML Support
112
+
113
+ If you are using YAML files.
114
+ This is going to read and update only the `version:` tag in the file.
115
+
116
+ ```sh
117
+ commit-and-tag-version --packageFiles file.yaml --bumpFiles file.yaml
118
+ ```
119
+
111
120
  ## Installing `commit-and-tag-version`
112
121
 
113
122
  ### 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,7 @@ 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'),
9
10
  };
10
11
  const PLAIN_TEXT_BUMP_FILES = ['VERSION.txt', 'version.txt'];
11
12
 
@@ -33,6 +34,9 @@ function getUpdaterByFilename(filename) {
33
34
  if (filename.endsWith('.csproj')) {
34
35
  return getUpdaterByType('csproj');
35
36
  }
37
+ if (/\.ya?ml$/.test(filename)) {
38
+ return getUpdaterByType('yaml');
39
+ }
36
40
  throw Error(
37
41
  `Unsupported file (${filename}) provided for bumping.\n Please specify the updater \`type\` or use a custom \`updater\`.`,
38
42
  );
@@ -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.3.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
@@ -1365,6 +1365,78 @@ describe('cli', function () {
1365
1365
  verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '1.1.0' });
1366
1366
  });
1367
1367
 
1368
+ it('bumps version in Dart `pubspec.yaml` file', async function () {
1369
+ const expected = fs.readFileSync(
1370
+ './test/mocks/pubspec-6.4.0.yaml',
1371
+ 'utf-8',
1372
+ );
1373
+
1374
+ const filename = 'pubspec.yaml';
1375
+ mock({
1376
+ bump: 'minor',
1377
+ realTestFiles: [
1378
+ {
1379
+ filename,
1380
+ path: './test/mocks/pubspec-6.3.1.yaml',
1381
+ },
1382
+ ],
1383
+ });
1384
+
1385
+ await exec({
1386
+ packageFiles: [{ filename, type: 'yaml' }],
1387
+ bumpFiles: [{ filename, type: 'yaml' }],
1388
+ });
1389
+
1390
+ // filePath is the first arg passed to writeFileSync
1391
+ const packageJsonWriteFileSynchCall = findWriteFileCallForPath({
1392
+ writeFileSyncSpy,
1393
+ filename,
1394
+ });
1395
+
1396
+ if (!packageJsonWriteFileSynchCall) {
1397
+ throw new Error(`writeFileSynch not invoked with path ${filename}`);
1398
+ }
1399
+
1400
+ const calledWithContentStr = packageJsonWriteFileSynchCall[1];
1401
+ expect(calledWithContentStr).toEqual(expected);
1402
+ });
1403
+
1404
+ it('bumps version in Dart `pubspec.yaml` file with CRLF line endings', async function () {
1405
+ const expected = fs.readFileSync(
1406
+ './test/mocks/pubspec-6.4.0-crlf.yaml',
1407
+ 'utf-8',
1408
+ );
1409
+
1410
+ const filename = 'pubspec.yaml';
1411
+ mock({
1412
+ bump: 'minor',
1413
+ realTestFiles: [
1414
+ {
1415
+ filename,
1416
+ path: './test/mocks/pubspec-6.3.1-crlf.yaml',
1417
+ },
1418
+ ],
1419
+ });
1420
+
1421
+ await exec({
1422
+ packageFiles: [{ filename, type: 'yaml' }],
1423
+ bumpFiles: [{ filename, type: 'yaml' }],
1424
+ });
1425
+
1426
+ // filePath is the first arg passed to writeFileSync
1427
+ const packageJsonWriteFileSynchCall = findWriteFileCallForPath({
1428
+ writeFileSyncSpy,
1429
+ filename,
1430
+ });
1431
+
1432
+ if (!packageJsonWriteFileSynchCall) {
1433
+ throw new Error(`writeFileSynch not invoked with path ${filename}`);
1434
+ }
1435
+
1436
+ const calledWithContentStr = packageJsonWriteFileSynchCall[1];
1437
+ expect(calledWithContentStr).toEqual(expected);
1438
+ });
1439
+
1368
1440
  describe('skip', function () {
1369
1441
  it('allows bump and changelog generation to be skipped', async function () {
1370
1442
  const changelogContent = 'legacy header format<a name="1.0.0">\n';
@@ -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/