@temir.ra/create-ts-lib 0.4.1 → 0.5.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
@@ -1,5 +1,9 @@
1
1
  # Version 0
2
2
 
3
+ ## 0.5.0
4
+
5
+ 1. Changed `buildinfo.txt` generation and testing to align with [https://semver.org](https://semver.org).
6
+
3
7
  ## 0.4.1
4
8
 
5
9
  1. Fixed `destinationPath` resolution in `cli.ts` to use the full resolved path instead of just the basename.
package/buildinfo.txt CHANGED
@@ -1 +1 @@
1
- 0.4.1+afad763
1
+ 0.5.0+68f9673
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temir.ra/create-ts-lib",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Typescript library template",
5
5
  "author": "temir.ra",
6
6
  "license": "MIT",
@@ -5,7 +5,7 @@ import { readFileSync, writeFileSync } from 'fs';
5
5
  const BUILD_INFO_FILE = 'buildinfo.txt';
6
6
  const GIT_COMMAND = 'git rev-parse --short HEAD';
7
7
 
8
- const { version } = JSON.parse(readFileSync('package.json', 'utf-8'));
8
+ const version: string = JSON.parse(readFileSync('package.json', 'utf-8')).version;
9
9
 
10
10
  let gitHash = '';
11
11
  try {
@@ -14,8 +14,12 @@ try {
14
14
  .trim();
15
15
  } catch { }
16
16
 
17
- const buildinfo = gitHash ? `${version}+${gitHash}` : version;
17
+ const buildinfo = gitHash
18
+ ? version.includes('+')
19
+ ? `${version}.${gitHash}`
20
+ : `${version}+${gitHash}`
21
+ : version;
18
22
 
19
- writeFileSync(BUILD_INFO_FILE, buildinfo);
23
+ writeFileSync(BUILD_INFO_FILE, buildinfo.trim(), 'utf-8');
20
24
 
21
25
  console.log(`'${BUILD_INFO_FILE}' has been updated with build info: ${buildinfo}`);
@@ -2,28 +2,22 @@ import { describe, it, expect } from 'bun:test';
2
2
  import { readFileSync } from 'fs';
3
3
  import { fileURLToPath } from 'url';
4
4
 
5
- const buildinfoUrl = new URL('../buildinfo.txt', import.meta.url);
6
5
 
6
+ const buildinfoUrl = new URL('../buildinfo.txt', import.meta.url);
7
7
 
8
- describe('buildInfo', () => {
8
+ // taken from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
9
+ // Captures: [1]=major, [2]=minor, [3]=patch, [4]=pre-release, [5]=build-metadata
10
+ const SEMVER_REGEX =
11
+ /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
9
12
 
10
- it('should follow semantic versioning format with optional commit hash', () => {
11
- const buildinfoPath = fileURLToPath(buildinfoUrl);
12
- const buildinfo = readFileSync(buildinfoPath, 'utf-8').trim();
13
- expect(buildinfo).toMatch(/^\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$/);
14
- });
13
+ function readBuildinfo(): string {
14
+ return readFileSync(fileURLToPath(buildinfoUrl), 'utf-8').trim();
15
+ }
15
16
 
16
- it('should not contain whitespace', () => {
17
- const buildinfoPath = fileURLToPath(buildinfoUrl);
18
- const buildinfo = readFileSync(buildinfoPath, 'utf-8').trim();
19
- expect(buildinfo).not.toMatch(/\s/);
20
- });
17
+ describe('buildInfo', () => {
21
18
 
22
- it('should not be empty or dash', () => {
23
- const buildinfoPath = fileURLToPath(buildinfoUrl);
24
- const buildinfo = readFileSync(buildinfoPath, 'utf-8').trim();
25
- expect(buildinfo.length).toBeGreaterThan(0);
26
- expect(buildinfo).not.toBe('-');
19
+ it('should be a valid semver string', () => {
20
+ expect(readBuildinfo()).toMatch(SEMVER_REGEX);
27
21
  });
28
22
 
29
- });
23
+ });