@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 +4 -0
- package/buildinfo.txt +1 -1
- package/package.json +1 -1
- package/template/scripts/buildinfo.ts +7 -3
- package/template/tests/buildinfo.test.ts +12 -18
package/CHANGELOG.md
CHANGED
package/buildinfo.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.5.0+68f9673
|
package/package.json
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
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
|
|
23
|
-
|
|
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
|
+
});
|