@temir.ra/create-ts-lib 0.6.3 → 0.7.1
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 +18 -0
- package/README.md +173 -189
- package/buildinfo.txt +1 -1
- package/dist/cli.bundle.js +2 -2
- package/dist/cli.bundle.js.map +3 -3
- package/package.json +12 -7
- package/{template/scripts/build-lib-bundle.ts → scripts/build-bundle.ts} +20 -15
- package/scripts/buildinfo.ts +25 -0
- package/scripts/cdn-rewrite-map.json +1 -0
- package/template/CHANGELOG-template.md +49 -0
- package/template/CHANGELOG.md +1 -1
- package/template/README-template.md +453 -0
- package/template/README.md +12 -18
- package/template/buildinfo-template.txt +1 -0
- package/template/buildinfo.txt +1 -0
- package/template/gitignore +2 -2
- package/template/package.json +13 -9
- package/template/scripts/build-bundle.ts +161 -0
- package/template/{src → scripts}/dev.ts +1 -1
- package/template/tsconfig.json +37 -38
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -26
- package/dist/constants.d.ts +0 -7
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -8
- package/template/tsconfig.build.json +0 -19
package/template/README.md
CHANGED
|
@@ -14,31 +14,25 @@
|
|
|
14
14
|
|
|
15
15
|
# Quick Start
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
# remove dist/ and tsconfig.tsbuildinfo and tsconfig.build.tsbuildinfo
|
|
19
|
-
bun run clean
|
|
17
|
+
*<QUICK START INSTRUCTIONS>*
|
|
20
18
|
|
|
21
|
-
#
|
|
22
|
-
bun run clean:dist
|
|
19
|
+
# Documentation
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
bun run clean:tsbuildinfo
|
|
21
|
+
*<DOCUMENTATION>*
|
|
26
22
|
|
|
27
|
-
#
|
|
28
|
-
|
|
23
|
+
# DevOps
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
bun install
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
bun run clean
|
|
29
|
+
bun run build
|
|
31
30
|
bun run tests
|
|
32
31
|
|
|
33
|
-
# run src/dev.ts in watch mode
|
|
34
32
|
bun run dev
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
# Documentation
|
|
38
33
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
# DevOps
|
|
34
|
+
# see publish section for publish instructions
|
|
35
|
+
```
|
|
42
36
|
|
|
43
37
|
## Change Management
|
|
44
38
|
|
|
@@ -47,7 +41,7 @@ bun run dev
|
|
|
47
41
|
3. Bump the version in [`package.json`](package.json).
|
|
48
42
|
4. Add an entry for the new version in [`CHANGELOG.md`](CHANGELOG.md).
|
|
49
43
|
5. Pull request the branch.
|
|
50
|
-
6.
|
|
44
|
+
6. Ensure package artifacts are current.
|
|
51
45
|
7. Publish.
|
|
52
46
|
|
|
53
47
|
## Publish
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.4.1+f472194
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.0
|
package/template/gitignore
CHANGED
package/template/package.json
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": ""
|
|
13
13
|
},
|
|
14
|
+
"private": false,
|
|
14
15
|
"type": "module",
|
|
15
16
|
"exports": {
|
|
16
17
|
".": {
|
|
@@ -24,21 +25,24 @@
|
|
|
24
25
|
"#src/*.js": "./src/*.ts"
|
|
25
26
|
},
|
|
26
27
|
"files": [
|
|
27
|
-
"
|
|
28
|
+
"scripts/buildinfo.ts",
|
|
29
|
+
"scripts/build-bundle.ts",
|
|
30
|
+
"scripts/cdn-rewrite-map.json",
|
|
28
31
|
"CHANGELOG.md",
|
|
29
|
-
"buildinfo.txt"
|
|
32
|
+
"buildinfo.txt",
|
|
33
|
+
"dist"
|
|
30
34
|
],
|
|
31
35
|
"scripts": {
|
|
36
|
+
"reinstall": "rm -rf node_modules && rm -f bun.lock && bun pm cache rm && bun install && bunx tsc --version",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"buildinfo": "bun run scripts/buildinfo.ts",
|
|
32
39
|
"clean:dist": "rm -rf dist/",
|
|
33
|
-
"clean:tsbuildinfo": "rm -f
|
|
40
|
+
"clean:tsbuildinfo": "rm -f *.tsbuildinfo || true",
|
|
34
41
|
"clean": "bun run clean:dist && bun run clean:tsbuildinfo",
|
|
35
|
-
"prebuild": "bun run scripts/buildinfo.ts",
|
|
36
42
|
"tests": "bun test",
|
|
37
|
-
"
|
|
38
|
-
"build
|
|
39
|
-
"build:
|
|
40
|
-
"typecheck": "tsc --noEmit",
|
|
41
|
-
"dev": "bun run --watch src/dev.ts"
|
|
43
|
+
"prebuild": "bun run buildinfo",
|
|
44
|
+
"build": "bun run build:bundle",
|
|
45
|
+
"build:bundle": "bun run scripts/build-bundle.ts"
|
|
42
46
|
},
|
|
43
47
|
"devDependencies": {
|
|
44
48
|
"@types/bun": "latest",
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
|
|
4
|
+
import CDN_REWRITE_MAP from './cdn-rewrite-map.json';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
interface ExportConditions {
|
|
8
|
+
[key: string]: string | undefined;
|
|
9
|
+
entrypoint?: string;
|
|
10
|
+
types?: string;
|
|
11
|
+
browser?: string;
|
|
12
|
+
import?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface DependencyMap {
|
|
16
|
+
[packageName: string]: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface PackageManifest {
|
|
20
|
+
version: string;
|
|
21
|
+
exports?: Record<string, ExportConditions>;
|
|
22
|
+
dependencies?: DependencyMap;
|
|
23
|
+
devDependencies?: DependencyMap;
|
|
24
|
+
peerDependencies?: DependencyMap;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getManifest(packageIdentifier?: string): PackageManifest {
|
|
28
|
+
|
|
29
|
+
const manifestPath = packageIdentifier
|
|
30
|
+
? join('node_modules', packageIdentifier, 'package.json')
|
|
31
|
+
: 'package.json';
|
|
32
|
+
|
|
33
|
+
let manifest: PackageManifest;
|
|
34
|
+
try {
|
|
35
|
+
manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
36
|
+
} catch {
|
|
37
|
+
if (packageIdentifier)
|
|
38
|
+
throw new Error(`[scripts/build-bundle.ts] Could not read manifest for '${packageIdentifier}' at '${manifestPath}'.`);
|
|
39
|
+
else
|
|
40
|
+
throw new Error(`[scripts/build-bundle.ts] Could not read package manifest at '${manifestPath}'.`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return manifest;
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getManifestEntrypoints(packageManifest: PackageManifest): string[] {
|
|
48
|
+
|
|
49
|
+
const exports = packageManifest.exports;
|
|
50
|
+
if (!exports)
|
|
51
|
+
throw new Error(`[scripts/build-bundle.ts] No 'exports' field found in the given package manifest.`);
|
|
52
|
+
|
|
53
|
+
const entrypoints = Object.entries(exports)
|
|
54
|
+
.map(([key, conditions]) => {
|
|
55
|
+
if (!conditions.entrypoint)
|
|
56
|
+
throw new Error(`[scripts/build-bundle.ts] Export '${key}' does not have an 'entrypoint' condition.`);
|
|
57
|
+
return conditions.entrypoint;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return entrypoints;
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getPackageVersion(manifest: PackageManifest, packageIdentifier?: string): string {
|
|
65
|
+
|
|
66
|
+
let version: string | undefined;
|
|
67
|
+
if (packageIdentifier) {
|
|
68
|
+
|
|
69
|
+
const dependencies = {
|
|
70
|
+
...manifest.dependencies,
|
|
71
|
+
...manifest.devDependencies,
|
|
72
|
+
...manifest.peerDependencies,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
version = dependencies[packageIdentifier];
|
|
76
|
+
if (!version)
|
|
77
|
+
throw new Error(`[scripts/build-bundle.ts] Package '${packageIdentifier}' is not listed in dependencies.`);
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
if (!manifest.version)
|
|
82
|
+
throw new Error('[scripts/build-bundle.ts] Package manifest does not contain a version field.');
|
|
83
|
+
version = manifest.version;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return version;
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function resolveCdnUrl(importSpecifier: string, urlTemplate: string): string {
|
|
91
|
+
const manifest = getManifest();
|
|
92
|
+
const version = getPackageVersion(manifest, importSpecifier);
|
|
93
|
+
return urlTemplate.replace('<VERSION>', version);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const cdnRewritePlugin = {
|
|
97
|
+
name: 'cdn-rewrite',
|
|
98
|
+
setup(build: any) {
|
|
99
|
+
|
|
100
|
+
const resolved = new Map<string, string>();
|
|
101
|
+
for (const [importSpecifier, urlTemplate] of Object.entries(CDN_REWRITE_MAP) as [string, string][]) {
|
|
102
|
+
const url = resolveCdnUrl(importSpecifier, urlTemplate);
|
|
103
|
+
resolved.set(importSpecifier, url);
|
|
104
|
+
console.log(`[cdn-rewrite] '${importSpecifier}' → '${url}'`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
build.onResolve({ filter: /\*/ }, (args: any) => {
|
|
108
|
+
const url = resolved.get(args.path);
|
|
109
|
+
if (url) return { path: url, external: true };
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
const entrypoints = getManifestEntrypoints(getManifest());
|
|
117
|
+
console.log('[scripts/build-bundle.ts] Entrypoints:', entrypoints);
|
|
118
|
+
|
|
119
|
+
let buildResult;
|
|
120
|
+
|
|
121
|
+
console.log('[scripts/build-bundle.ts] Starting ESM bundle build...');
|
|
122
|
+
buildResult = await Bun.build({
|
|
123
|
+
entrypoints,
|
|
124
|
+
outdir: 'dist',
|
|
125
|
+
naming: '[dir]/[name].bundle.[ext]',
|
|
126
|
+
target: 'browser',
|
|
127
|
+
format: 'esm',
|
|
128
|
+
minify: true,
|
|
129
|
+
sourcemap: 'external',
|
|
130
|
+
plugins: [cdnRewritePlugin],
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
if (!buildResult.success) {
|
|
134
|
+
console.error('[scripts/build-bundle.ts] Build failed:');
|
|
135
|
+
for (const message of buildResult.logs) {
|
|
136
|
+
console.error(message);
|
|
137
|
+
}
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
console.log('[scripts/build-bundle.ts] ESM bundle build completed successfully.');
|
|
141
|
+
|
|
142
|
+
console.log('[scripts/build-bundle.ts] Starting IIFE bundle build...');
|
|
143
|
+
buildResult = await Bun.build({
|
|
144
|
+
entrypoints,
|
|
145
|
+
outdir: 'dist',
|
|
146
|
+
naming: '[dir]/[name].iife.[ext]',
|
|
147
|
+
target: 'browser',
|
|
148
|
+
format: 'iife',
|
|
149
|
+
minify: true,
|
|
150
|
+
sourcemap: 'external',
|
|
151
|
+
plugins: [cdnRewritePlugin],
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
if (!buildResult.success) {
|
|
155
|
+
console.error('[scripts/build-bundle.ts] Build failed:');
|
|
156
|
+
for (const message of buildResult.logs) {
|
|
157
|
+
console.error(message);
|
|
158
|
+
}
|
|
159
|
+
process.exit(1);
|
|
160
|
+
}
|
|
161
|
+
console.log('[scripts/build-bundle.ts] IIFE bundle build completed successfully.');
|
package/template/tsconfig.json
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"lib": [
|
|
6
|
-
"ESNext"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"lib": [
|
|
6
|
+
"ESNext"
|
|
7
|
+
],
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"verbatimModuleSyntax": true,
|
|
11
|
+
"noUncheckedIndexedAccess": true,
|
|
12
|
+
"exactOptionalPropertyTypes": true,
|
|
13
|
+
"noImplicitOverride": true,
|
|
14
|
+
"isolatedDeclarations": true,
|
|
15
|
+
"esModuleInterop": true,
|
|
16
|
+
"composite": true,
|
|
17
|
+
"skipLibCheck": true,
|
|
18
|
+
"types": [
|
|
19
|
+
"bun"
|
|
20
|
+
],
|
|
21
|
+
"forceConsistentCasingInFileNames": true,
|
|
22
|
+
"resolveJsonModule": true,
|
|
23
|
+
"declaration": true,
|
|
24
|
+
"declarationMap": true,
|
|
25
|
+
"emitDeclarationOnly": true,
|
|
26
|
+
"outDir": "./dist"
|
|
27
|
+
},
|
|
28
|
+
"include": [
|
|
29
|
+
"scripts/**/*.ts",
|
|
30
|
+
"scripts/**/*.json",
|
|
31
|
+
"src/**/*.ts",
|
|
32
|
+
"tests/**/*.ts"
|
|
33
|
+
],
|
|
34
|
+
"exclude": [
|
|
35
|
+
"node_modules",
|
|
36
|
+
"dist"
|
|
37
|
+
]
|
|
39
38
|
}
|
package/dist/cli.d.ts
DELETED
package/dist/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { cpSync, readFileSync, renameSync, writeFileSync } from 'fs';
|
|
3
|
-
import { resolve } from 'path';
|
|
4
|
-
import { templatePath, changelogPath, buildinfoPath, readmePath } from './constants.js';
|
|
5
|
-
try {
|
|
6
|
-
const packageNameArgument = process.argv[2];
|
|
7
|
-
if (!packageNameArgument)
|
|
8
|
-
throw new Error('Package name argument is required. Usage: `create-ts-lib <package-name>`');
|
|
9
|
-
const packageName = packageNameArgument.replace(/\\/g, '/');
|
|
10
|
-
const destinationPath = resolve(process.cwd(), packageName);
|
|
11
|
-
cpSync(templatePath, destinationPath, { recursive: true });
|
|
12
|
-
cpSync(changelogPath, resolve(destinationPath, 'CHANGELOG-template.md'));
|
|
13
|
-
cpSync(buildinfoPath, resolve(destinationPath, 'buildinfo-template.txt'));
|
|
14
|
-
cpSync(readmePath, resolve(destinationPath, 'README-template.md'));
|
|
15
|
-
const packageJsonPath = resolve(destinationPath, 'package.json');
|
|
16
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
17
|
-
packageJson.name = packageName;
|
|
18
|
-
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
19
|
-
renameSync(resolve(destinationPath, 'gitignore'), resolve(destinationPath, '.gitignore'));
|
|
20
|
-
console.log(`Template has been successfully instantiated at '${destinationPath}' with package name '${packageName}'.`);
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
24
|
-
console.error('Error:', err.message);
|
|
25
|
-
process.exit(1);
|
|
26
|
-
}
|
package/dist/constants.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const packageUrl: URL;
|
|
2
|
-
export declare const packagePath: string;
|
|
3
|
-
export declare const templatePath: string;
|
|
4
|
-
export declare const changelogPath: string;
|
|
5
|
-
export declare const buildinfoPath: string;
|
|
6
|
-
export declare const readmePath: string;
|
|
7
|
-
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,EAAE,GAAqC,CAAC;AAC/D,eAAO,MAAM,WAAW,EAAE,MAA2C,CAAC;AAEtE,eAAO,MAAM,YAAY,EAAE,MAA0C,CAAC;AAEtE,eAAO,MAAM,aAAa,EAAE,MAA6C,CAAC;AAC1E,eAAO,MAAM,aAAa,EAAE,MAA8C,CAAC;AAC3E,eAAO,MAAM,UAAU,EAAE,MAA0C,CAAC"}
|
package/dist/constants.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'path';
|
|
2
|
-
import { fileURLToPath } from 'url';
|
|
3
|
-
export const packageUrl = new URL('../', import.meta.url);
|
|
4
|
-
export const packagePath = resolve(fileURLToPath(packageUrl));
|
|
5
|
-
export const templatePath = resolve(packagePath, 'template/');
|
|
6
|
-
export const changelogPath = resolve(packagePath, 'CHANGELOG.md');
|
|
7
|
-
export const buildinfoPath = resolve(packagePath, 'buildinfo.txt');
|
|
8
|
-
export const readmePath = resolve(packagePath, 'README.md');
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "./src",
|
|
5
|
-
"module": "nodenext",
|
|
6
|
-
"moduleResolution": "nodenext",
|
|
7
|
-
"emitDeclarationOnly": false,
|
|
8
|
-
},
|
|
9
|
-
"include": [
|
|
10
|
-
"src/**/*.ts"
|
|
11
|
-
],
|
|
12
|
-
"exclude": [
|
|
13
|
-
"src/dev.ts",
|
|
14
|
-
"node_modules",
|
|
15
|
-
"dist",
|
|
16
|
-
"tests",
|
|
17
|
-
"scripts"
|
|
18
|
-
]
|
|
19
|
-
}
|