@temir.ra/create-ts-lib 0.4.0 → 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 +8 -0
- package/buildinfo.txt +1 -1
- package/dist/cli.bundle.js +2 -2
- package/dist/cli.bundle.js.map +3 -3
- package/dist/cli.js +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
|
@@ -1,5 +1,13 @@
|
|
|
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
|
+
|
|
7
|
+
## 0.4.1
|
|
8
|
+
|
|
9
|
+
1. Fixed `destinationPath` resolution in `cli.ts` to use the full resolved path instead of just the basename.
|
|
10
|
+
|
|
3
11
|
## 0.4.0
|
|
4
12
|
|
|
5
13
|
1. Added support for scoped package names in the CLI argument parsing and asset resolution.
|
package/buildinfo.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.5.0+68f9673
|
package/dist/cli.bundle.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{cpSync as s,readFileSync as f,renameSync as u,writeFileSync as P}from"fs";import{resolve as t
|
|
2
|
+
import{cpSync as s,readFileSync as f,renameSync as u,writeFileSync as P}from"fs";import{resolve as t}from"path";import{resolve as o}from"path";import{fileURLToPath as h}from"url";var d=new URL("../",import.meta.url),n=o(h(d)),m=o(n,"template/"),p=o(n,"CHANGELOG.md"),g=o(n,"buildinfo.txt"),l=o(n,"README.md");try{let r=process.argv[2];if(!r)throw Error("Package name argument is required. Usage: `create-ts-lib <package-name>`");let a=r.replace(/\\/g,"/"),e=t(process.cwd(),a);s(m,e,{recursive:!0}),s(p,t(e,"CHANGELOG-template.md")),s(g,t(e,"buildinfo-template.txt")),s(l,t(e,"README-template.md"));let c=t(e,"package.json"),i=JSON.parse(f(c,"utf-8"));i.name=a,P(c,JSON.stringify(i,null,2)),u(t(e,"gitignore"),t(e,".gitignore")),console.log(`Template has been successfully instantiated at '${e}' with package name '${a}'.`)}catch(r){let a=r instanceof Error?r:Error(String(r));console.error("Error:",a.message),process.exit(1)}
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=05227D46E6CAAF7464756E2164756E21
|
package/dist/cli.bundle.js.map
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["..\\src\\cli.ts", "..\\src\\constants.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"#!/usr/bin/env node\r\n\r\nimport { cpSync, readFileSync, renameSync, writeFileSync } from 'fs';\r\nimport { resolve, basename } from 'path';\r\nimport {\r\n templatePath,\r\n changelogPath,\r\n buildinfoPath,\r\n readmePath\r\n} from './constants.js';\r\n\r\n\r\ntry {\r\n\r\n const packageNameArgument = process.argv[2];\r\n if (!packageNameArgument) throw new Error('Package name argument is required. Usage: `create-ts-lib <package-name>`');\r\n const packageName = packageNameArgument.replace(/\\\\/g, '/');\r\n\r\n const destinationPath =
|
|
5
|
+
"#!/usr/bin/env node\r\n\r\nimport { cpSync, readFileSync, renameSync, writeFileSync } from 'fs';\r\nimport { resolve, basename } from 'path';\r\nimport {\r\n templatePath,\r\n changelogPath,\r\n buildinfoPath,\r\n readmePath\r\n} from './constants.js';\r\n\r\n\r\ntry {\r\n\r\n const packageNameArgument = process.argv[2];\r\n if (!packageNameArgument) throw new Error('Package name argument is required. Usage: `create-ts-lib <package-name>`');\r\n const packageName = packageNameArgument.replace(/\\\\/g, '/');\r\n\r\n const destinationPath = resolve(process.cwd(), packageName);\r\n\r\n cpSync(templatePath, destinationPath, { recursive: true });\r\n cpSync(changelogPath, resolve(destinationPath, 'CHANGELOG-template.md'));\r\n cpSync(buildinfoPath, resolve(destinationPath, 'buildinfo-template.txt'));\r\n cpSync(readmePath, resolve(destinationPath, 'README-template.md'));\r\n\r\n const packageJsonPath = resolve(destinationPath, 'package.json');\r\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));\r\n packageJson.name = packageName;\r\n writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));\r\n\r\n renameSync(resolve(destinationPath, 'gitignore'), resolve(destinationPath, '.gitignore'));\r\n\r\n console.log(`Template has been successfully instantiated at '${destinationPath}' with package name '${packageName}'.`);\r\n\r\n}\r\ncatch (error) {\r\n const err = error instanceof Error ? error : new Error(String(error));\r\n console.error('Error:', err.message);\r\n process.exit(1);\r\n}\r\n",
|
|
6
6
|
"import { resolve } from 'path';\r\nimport { fileURLToPath } from 'url';\r\n\r\n\r\nexport const packageUrl: URL = new URL('../', import.meta.url);\r\nexport const packagePath: string = resolve(fileURLToPath(packageUrl));\r\n\r\nexport const templatePath: string = resolve(packagePath, 'template/');\r\n\r\nexport const changelogPath: string = resolve(packagePath, 'CHANGELOG.md');\r\nexport const buildinfoPath: string = resolve(packagePath, 'buildinfo.txt');\r\nexport const readmePath: string = resolve(packagePath, 'README.md');\r\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": ";AAEA,iBAAS,kBAAQ,gBAAc,mBAAY,WAC3C,kBAAS,
|
|
9
|
-
"debugId": "
|
|
8
|
+
"mappings": ";AAEA,iBAAS,kBAAQ,gBAAc,mBAAY,WAC3C,kBAAS,aCHT,kBAAS,aACT,wBAAS,YAGF,IAAM,EAAkB,IAAI,IAAI,MAAO,YAAY,GAAG,EAChD,EAAsB,EAAQ,EAAc,CAAU,CAAC,EAEvD,EAAuB,EAAQ,EAAa,WAAW,EAEvD,EAAwB,EAAQ,EAAa,cAAc,EAC3D,EAAwB,EAAQ,EAAa,eAAe,EAC5D,EAAqB,EAAQ,EAAa,WAAW,EDClE,GAAI,CAEA,IAAM,EAAsB,QAAQ,KAAK,GACzC,GAAI,CAAC,EAAqB,MAAU,MAAM,0EAA0E,EACpH,IAAM,EAAc,EAAoB,QAAQ,MAAO,GAAG,EAEpD,EAAkB,EAAQ,QAAQ,IAAI,EAAG,CAAW,EAE1D,EAAO,EAAc,EAAiB,CAAE,UAAW,EAAK,CAAC,EACzD,EAAO,EAAe,EAAQ,EAAiB,uBAAuB,CAAC,EACvE,EAAO,EAAe,EAAQ,EAAiB,wBAAwB,CAAC,EACxE,EAAO,EAAY,EAAQ,EAAiB,oBAAoB,CAAC,EAEjE,IAAM,EAAkB,EAAQ,EAAiB,cAAc,EACzD,EAAc,KAAK,MAAM,EAAa,EAAiB,OAAO,CAAC,EACrE,EAAY,KAAO,EACnB,EAAc,EAAiB,KAAK,UAAU,EAAa,KAAM,CAAC,CAAC,EAEnE,EAAW,EAAQ,EAAiB,WAAW,EAAG,EAAQ,EAAiB,YAAY,CAAC,EAExF,QAAQ,IAAI,mDAAmD,yBAAuC,KAAe,EAGzH,MAAO,EAAO,CACV,IAAM,EAAM,aAAiB,MAAQ,EAAY,MAAM,OAAO,CAAK,CAAC,EACpE,QAAQ,MAAM,SAAU,EAAI,OAAO,EACnC,QAAQ,KAAK,CAAC",
|
|
9
|
+
"debugId": "05227D46E6CAAF7464756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
package/dist/cli.js
CHANGED
|
@@ -7,7 +7,7 @@ try {
|
|
|
7
7
|
if (!packageNameArgument)
|
|
8
8
|
throw new Error('Package name argument is required. Usage: `create-ts-lib <package-name>`');
|
|
9
9
|
const packageName = packageNameArgument.replace(/\\/g, '/');
|
|
10
|
-
const destinationPath =
|
|
10
|
+
const destinationPath = resolve(process.cwd(), packageName);
|
|
11
11
|
cpSync(templatePath, destinationPath, { recursive: true });
|
|
12
12
|
cpSync(changelogPath, resolve(destinationPath, 'CHANGELOG-template.md'));
|
|
13
13
|
cpSync(buildinfoPath, resolve(destinationPath, 'buildinfo-template.txt'));
|
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
|
+
});
|