@temir.ra/create-workspace 0.3.1 → 0.4.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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # Version 0
2
2
 
3
+ ## 0.4.1
4
+
5
+ 1. Cleaned up coding-specific aspects.
6
+ 2. Updated the description in `package.json`.
7
+
8
+ ## 0.4.0
9
+
10
+ 1. Updated `.gitignore`: added `buildinfo-template.txt`, `CHANGELOG-template.md`, `README-template.md`, `buildinfo.txt`, and `*.tsbuildinfo`; replaced nested `template/.gitignore` with `template/gitignore` to prevent template files from being excluded during distribution.
11
+ 2. Overhauled the generated `package.json`: added `keywords`, `repository`, and `devDependencies` fields; fixed recursive script execution; replaced propagating `clean` with `clean:dist` + `clean:tsbuildinfo` sub-scripts; removed `build` and workspace-propagating `tests`/`typecheck` (propagation is now opt-in, documented in the README); added `reinstall` script.
12
+ 3. Updated the generated `tsconfig.json`: removed `DOM` from `lib`; added `types: ["bun"]`.
13
+ 4. Improved CLI error message for missing package name argument.
14
+ 5. Overhauled `README.md`: rewritten intro, added `tsconfig.json` documentation section, updated `package.json` documentation, added Script Propagation section, added `create-doc` to the template family table; removed publishing section from `template/README.md`.
15
+ 6. Renamed `scripts/build-lib-bundle.ts` to `scripts/build-bundle.ts`; updated to produce both ESM and IIFE browser bundles; removed `tsconfig.build.json` and `build:lib` step; added build scripts to published `files`; set `private: false`.
16
+ 7. Updated from `@temir.ra/template@0.1.3` template.
17
+
3
18
  ## 0.3.1
4
19
 
5
20
  1. Fixed create commands in the **Quick Start** section of the `README.md` to reflect the create-template conventions.
package/README.md CHANGED
@@ -1,56 +1,62 @@
1
1
  # Introduction
2
2
 
3
- A template for a package with build metadata, tests, and workspace-aware scripts. The generated package works standalone; add a `workspaces` field to scale it into a monorepo.
3
+ The base template of the family. Scaffolds a Bun package: `package.json`, TypeScript configuration, and conventions for testing, change management, and git versioning. Use it as-is, extend it into a monorepo, or choose a more specific template from the family for common upgrade paths.
4
4
 
5
- The following templates are available in this ecosystem:
5
+ For some use cases a purpose-built template already exists and reduces the amount of manual adjustment needed. Use the table to decide whether to start here or with a more specific template.
6
+
7
+ Templates in this family:
6
8
 
7
9
  | Template | Purpose |
8
10
  |---|---|
9
- | [`create-ts-lib`](#create-ts-lib) | TypeScript library distributed via registry |
10
- | [`create-hono-server`](#create-hono-server) | Bun/Hono HTTP server |
11
- | [`create-hono-spa`](#create-hono-spa) | Frontend SPA as a Hono sub-app library |
11
+ | [`create-workspace`](#packagejson) | Base Bun package; root of the template family *(this template)* |
12
+ | [`create-ts-lib`](#create-ts-lib) | TypeScript library with build pipeline, distributed via registry |
13
+ | [`create-hono-server`](#create-hono-server) | Bun+Hono web server |
14
+ | [`create-hono-spa`](#create-hono-spa) | SPA scaffold, pluggable into a Hono server as a sub-app |
12
15
  | [`create-skill`](#create-skill) | LLM skill package |
13
- | [`create-workspace`](#packagejson) | Package with workspace support *(this template)* |
16
+ | [`create-doc`](#create-doc) | Document as a collection of Markdown sections, compiled to PDF |
14
17
 
15
18
  ## Table of Contents
16
19
 
17
20
  1. [Quick Start](#quick-start)
18
21
  2. [Documentation](#documentation)
19
22
  1. [`package.json`](#packagejson)
20
- 2. [Workspaces](#workspaces)
21
- 3. [Cross-workspace Dependencies](#cross-workspace-dependencies)
22
- 4. [Scaffolding Patterns](#scaffolding-patterns)
23
- 1. [Library](#library)
24
- 2. [Server](#server)
25
- 3. [Server + SPA](#server--spa)
26
- 4. [Full-Stack with Shared Types](#full-stack-with-shared-types)
27
- 5. [Skill](#skill)
23
+ 2. [`Script `scripts/build-bundle.ts`](#script-scriptsbuild-bundlets)
24
+ 3. [`tsconfig.json`](#tsconfigjson)
25
+ 4. [Workspaces](#workspaces)
26
+ 1. [Script Propagation](#script-propagation)
27
+ 2. [Cross-workspace Dependencies](#cross-workspace-dependencies)
28
+ 3. [Scaffolding Patterns](#scaffolding-patterns)
29
+ 1. [Library](#library)
30
+ 2. [Server](#server)
31
+ 3. [Server + SPA](#server--spa)
32
+ 4. [Full-Stack with Shared Types](#full-stack-with-shared-types)
33
+ 5. [Skill](#skill)
28
34
  3. [DevOps](#devops)
29
35
  1. [Change Management](#change-management)
30
36
  2. [Publish](#publish)
31
37
 
32
38
  # Quick Start
33
39
 
34
- *`bun create` caches the template package - a newer published version will not be picked up automatically. Pin the version or clear the cache to use the latest.*
35
-
36
40
  ```bash
37
41
  # placeholder:
42
+ # <TEMPLATE_PACKAGE: @temir.ra/create-workspace
43
+ # <TEMPLATE_NAME: @temir.ra/workspace
38
44
  # <NEW_PACKAGE: <NEW_PACKAGE>
45
+ # is used as:
46
+ # - the path where the package is created
47
+ # - the "name" field in the generated package.json
39
48
  # <@_VERSION: <@_VERSION>
40
49
 
41
- # identify the latest version of the template package as <@_VERSION.
50
+ # pinned version
42
51
  bun info "@temir.ra/create-workspace" version
43
- # create a new package from the template version
44
52
  bun create --no-install --no-git "@temir.ra/workspace<@_VERSION>" <NEW_PACKAGE>
45
53
 
46
- # or
47
-
48
- # clear package manager cache to ensure the latest template version is used
54
+ # latest
55
+ # clear the cache to pick up the latest version
49
56
  bun pm cache rm
50
- # create a new package from the latest template version
51
57
  bun create --no-install --no-git "@temir.ra/workspace" <NEW_PACKAGE>
52
58
 
53
- # dependencies must be installed manually
59
+ # templates only copy files, run install and any setup scripts manually
54
60
  cd <NEW_PACKAGE>
55
61
  bun install
56
62
  ```
@@ -65,6 +71,7 @@ See npmjs documentation on [package.json](https://docs.npmjs.com/cli/v11/configu
65
71
 
66
72
  ```json
67
73
  {
74
+
68
75
  "name": "",
69
76
  "version": "0.0.0",
70
77
 
@@ -72,35 +79,116 @@ See npmjs documentation on [package.json](https://docs.npmjs.com/cli/v11/configu
72
79
  "author": "",
73
80
  "license": "",
74
81
 
75
- // prevents publishing to a registry
76
- "private": true,
82
+ "keywords": [],
77
83
 
78
- "scripts": {
84
+ "repository": {
85
+ "type": "git",
86
+ "url": ""
87
+ },
79
88
 
80
- // removes dist/
81
- "clean:dist": "rm -rf dist/",
89
+ // controls whether the package can be published to a registry
90
+ "private": true,
82
91
 
83
- // removes dist/ and propagates clean to any workspace packages
84
- "clean": "bun run clean:dist && bun run --filter '*' clean",
92
+ "scripts": {
85
93
 
86
- // generates buildinfo.txt before each build
87
- "prebuild": "bun run scripts/buildinfo.ts",
94
+ // deletes node_modules and the lockfile, clears the Bun cache, then reinstalls
95
+ // useful for recovering from a corrupted node_modules or lockfile
96
+ "reinstall": "rm -rf node_modules && rm -f bun.lock && bun pm cache rm && bun install && bunx tsc --version",
88
97
 
89
- // propagates build to any workspace packages
90
- "build": "bun run --filter '*' build",
98
+ // type-checks the project without emitting output
99
+ "typecheck": "tsc --noEmit",
91
100
 
92
- // runs local tests and propagates tests to any workspace packages
93
- "tests": "bun test && bun run --filter '*' tests",
101
+ // generates buildinfo.txt (for use in lifecycle hooks and CI pipelines)
102
+ "buildinfo": "bun run scripts/buildinfo.ts"
94
103
 
95
- // propagates typecheck to any workspace packages
96
- "typecheck": "bun run --filter '*' typecheck"
104
+ },
97
105
 
106
+ "devDependencies": {
107
+ "@types/bun": "latest",
108
+ "typescript": "^6.0.2"
98
109
  }
99
110
 
100
111
  }
101
112
  ```
102
113
 
103
- The `--filter '*'` scripts forward to any workspace packages when a `workspaces` field is present; they are no-ops otherwise. See [Workspaces](#workspaces) for how to opt in.
114
+ ## Script `scripts/buildinfo.ts`
115
+
116
+ Writes `buildinfo.txt` with the package version from `package.json`, appending the git short hash as semver build metadata (`<version>+<hash>`). If the version already contains `+`, the hash is appended as `<version>+<existing>.<hash>` instead. Falls back to the bare version when git is unavailable.
117
+
118
+ ## `tsconfig.json`
119
+
120
+ See the TypeScript documentation on [tsconfig.json](https://www.typescriptlang.org/tsconfig) for detailed explanations of all options.
121
+
122
+ ```json
123
+ {
124
+
125
+ "compilerOptions": {
126
+
127
+ // ECMAScript version of emitted output; ESNext targets the latest JS version supported by the TypeScript compiler
128
+ // if the package must support older runtimes or browsers, pin to a specific year (e.g. "ES2022", "ES2024")
129
+ "target": "ESNext",
130
+
131
+ // output module format; ESNext passes ES module syntax through unchanged
132
+ // ES module syntax: import/export statements (as opposed to CommonJS require()/module.exports)
133
+ "module": "ESNext",
134
+
135
+ // type definitions for built-in APIs
136
+ "lib": [
137
+ "ESNext" // standard JavaScript runtime APIs
138
+ ],
139
+
140
+ // module resolution strategy; bundler mode allows omitting file extensions in imports
141
+ "moduleResolution": "bundler",
142
+
143
+ // enables all strict type-checking options
144
+ "strict": true,
145
+
146
+ // enforces import type for type-only imports; emitted module syntax matches source exactly
147
+ "verbatimModuleSyntax": true,
148
+
149
+ // array indexing and index signature access returns T | undefined instead of T
150
+ "noUncheckedIndexedAccess": true,
151
+
152
+ // distinguishes absent optional properties from those explicitly set to undefined
153
+ "exactOptionalPropertyTypes": true,
154
+
155
+ // requires explicit override keyword when overriding base class methods
156
+ "noImplicitOverride": true,
157
+
158
+ // requires explicit types on all exported declarations; enables parallel .d.ts generation by external tools
159
+ "isolatedDeclarations": true,
160
+
161
+ // allows default imports from CommonJS modules
162
+ "esModuleInterop": true,
163
+
164
+ // enables project references and incremental builds via *.tsbuildinfo
165
+ "composite": true,
166
+
167
+ // do not type-check `.d.ts` files in `node_modules/`
168
+ "skipLibCheck": true,
169
+
170
+ // TS6 defaults types to [] - @types/* packages must be listed explicitly
171
+ "types": ["bun"],
172
+
173
+ // enforce consistent casing across import statements
174
+ "forceConsistentCasingInFileNames": true,
175
+
176
+ // allows importing JSON files as typed modules
177
+ "resolveJsonModule": true
178
+
179
+ },
180
+
181
+ // files matched by include are type-checked and visible to the IDE (IntelliSense, go-to-definition, etc.)
182
+ "include": [
183
+ "scripts/**/*.ts"
184
+ ],
185
+ // files matched by exclude are hidden from the IDE and excluded from type-checking
186
+ "exclude": [
187
+ "node_modules"
188
+ ]
189
+
190
+ }
191
+ ```
104
192
 
105
193
  ## Workspaces
106
194
 
@@ -128,6 +216,30 @@ The execution environment installs all workspace dependencies into a single shar
128
216
  └── ...
129
217
  ```
130
218
 
219
+ ### Script Propagation
220
+
221
+ Append `&& bun run --filter './*' <script>` to any script to propagate the call to all workspace packages:
222
+
223
+ ```json
224
+ {
225
+ "scripts": {
226
+ "clean:dist": "rm -rf dist/ && bun run --filter './*' clean:dist",
227
+ "clean:tsbuildinfo": "rm -f *.tsbuildinfo && bun run --filter './*' clean:tsbuildinfo",
228
+ "tests": "bun test && bun run --filter './*' tests",
229
+ "typecheck": "bun run --filter './*' typecheck"
230
+ }
231
+ }
232
+ ```
233
+
234
+ `./*` targets all direct workspace packages. Replace with a more specific glob to limit propagation to a subset.
235
+
236
+ By default packages are run in sequence. Add `--parallel` to run them concurrently, or `--sequential` to make it explicit:
237
+
238
+ ```bash
239
+ bun run --filter './*' --parallel typecheck
240
+ bun run --filter './*' --sequential clean
241
+ ```
242
+
131
243
  ### Cross-workspace Dependencies
132
244
 
133
245
  To use one workspace package from another, declare it as a dependency using the `workspace:` protocol:
@@ -308,20 +420,15 @@ Starting point for any LLM skill package. See the full documentation at [`@temir
308
420
  # DevOps
309
421
 
310
422
  ```bash
311
- # remove dist/ and tsconfig.tsbuildinfo and tsconfig.build.tsbuildinfo
312
- bun run clean
313
-
314
- # remove dist/ only
315
- bun run clean:dist
316
-
317
- # remove tsconfig.tsbuildinfo and tsconfig.build.tsbuildinfo only
318
- bun run clean:tsbuildinfo
423
+ bun install
319
424
 
320
- # compile + bundle
425
+ bun run clean
321
426
  bun run build
427
+ bun run tests
428
+
429
+ bun run dev
322
430
 
323
- # create a new test package in example/
324
- bun run dist/cli.bundle.js -- example
431
+ # see publish section for publish instructions
325
432
  ```
326
433
 
327
434
  ## Change Management
@@ -331,7 +438,7 @@ bun run dist/cli.bundle.js -- example
331
438
  3. Bump the version in [`package.json`](package.json).
332
439
  4. Add an entry for the new version in [`CHANGELOG.md`](CHANGELOG.md).
333
440
  5. Pull request the branch.
334
- 6. After merge, run `bun run build` - ensures artifacts are current before publish.
441
+ 6. Ensure package artifacts are current.
335
442
  7. Publish.
336
443
 
337
444
  ## Publish
package/buildinfo.txt CHANGED
@@ -1 +1 @@
1
- 0.3.1+96a0e4d
1
+ 0.4.1+f472194
@@ -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}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-workspace <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)}
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('First argument must be the package name (e.g. "my-package" or "@my-scope/my-package").');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=33D8671BE383296E64756E2164756E21
4
+ //# debugId=C4A0E6EEF1219B4364756E2164756E21
@@ -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 } 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-workspace <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",
5
+ "#!/usr/bin/env node\r\n\r\nimport { cpSync, readFileSync, renameSync, writeFileSync } from 'fs';\r\nimport { resolve } 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)\r\n throw new Error('First argument must be the package name (e.g. \"my-package\" or \"@my-scope/my-package\").');\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,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,6EAA6E,EACvH,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": "33D8671BE383296E64756E2164756E21",
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,EACD,MAAU,MAAM,wFAAwF,EAC5G,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": "C4A0E6EEF1219B4364756E2164756E21",
10
10
  "names": []
11
11
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@temir.ra/create-workspace",
3
- "version": "0.3.1",
4
- "description": "Package scaffold with workspace support",
3
+ "version": "0.4.1",
4
+ "description": "Template for a generic TypeScript workspace.",
5
5
  "author": "temir.ra",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -14,12 +14,16 @@
14
14
  "type": "git",
15
15
  "url": "https://git.chimps.quest/trs/create-workspace.git"
16
16
  },
17
+ "private": false,
17
18
  "type": "module",
18
19
  "imports": {
19
20
  "#src/*.js": "./src/*.ts"
20
21
  },
21
22
  "bin": "./dist/cli.bundle.js",
22
23
  "files": [
24
+ "scripts/buildinfo.ts",
25
+ "scripts/build-bundle.ts",
26
+ "scripts/cdn-rewrite-map.json",
23
27
  "dist",
24
28
  "CHANGELOG.md",
25
29
  "buildinfo.txt",
@@ -27,14 +31,15 @@
27
31
  ],
28
32
  "scripts": {
29
33
  "clean:dist": "rm -rf dist/",
30
- "clean:tsbuildinfo": "rm -f tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo",
34
+ "clean:tsbuildinfo": "rm -f *.tsbuildinfo || true",
31
35
  "clean": "bun run clean:dist && bun run clean:tsbuildinfo",
32
- "prebuild": "bun run scripts/buildinfo.ts",
36
+ "buildinfo": "bun run scripts/buildinfo.ts",
33
37
  "tests": "bun test",
34
- "build": "bun run build:lib && bun run build:cli-bundle",
35
- "build:lib": "tsc --project tsconfig.build.json",
36
- "build:cli-bundle": "bun build src/cli.ts --entry-naming \"[dir]/[name].bundle.[ext]\" --outdir dist --target node --format esm --minify --sourcemap=external",
37
- "typecheck": "tsc --noEmit"
38
+ "typecheck": "tsc --noEmit",
39
+ "reinstall": "rm -rf node_modules && rm -f bun.lock && bun pm cache rm && bun install && bunx tsc --version",
40
+ "prebuild": "bun run buildinfo",
41
+ "build": "bun run build:cli-bundle",
42
+ "build:cli-bundle": "bun build src/cli.ts --entry-naming \"[dir]/[name].bundle.[ext]\" --outdir dist --target node --format esm --minify --sourcemap=external"
38
43
  },
39
44
  "devDependencies": {
40
45
  "@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.');
@@ -0,0 +1,25 @@
1
+ import { execSync } from 'child_process';
2
+ import { readFileSync, writeFileSync } from 'fs';
3
+
4
+
5
+ const BUILD_INFO_FILE = 'buildinfo.txt';
6
+ const GIT_COMMAND = 'git rev-parse --short HEAD';
7
+
8
+ const version: string = JSON.parse(readFileSync('package.json', 'utf-8')).version;
9
+
10
+ let gitHash = '';
11
+ try {
12
+ gitHash = execSync(GIT_COMMAND, { stdio: ['ignore', 'pipe', 'ignore'] })
13
+ .toString()
14
+ .trim();
15
+ } catch { }
16
+
17
+ const buildinfo = gitHash
18
+ ? version.includes('+')
19
+ ? `${version}.${gitHash}`
20
+ : `${version}+${gitHash}`
21
+ : version;
22
+
23
+ writeFileSync(BUILD_INFO_FILE, buildinfo.trim(), 'utf-8');
24
+
25
+ console.log(`'${BUILD_INFO_FILE}' has been updated with build info: ${buildinfo}`);
@@ -0,0 +1 @@
1
+ {}
@@ -2,4 +2,4 @@
2
2
 
3
3
  ## 0.0.0
4
4
 
5
- 1. Versioning initialized.
5
+ 1. Package created.
@@ -8,9 +8,6 @@
8
8
  2. [Documentation](#documentation)
9
9
  3. [DevOps](#devops)
10
10
  1. [Change Management](#change-management)
11
- 2. [Publish](#publish)
12
- 1. [npmjs.org](#npmjsorg)
13
- 2. [Custom registry](#custom-registry)
14
11
 
15
12
  # Quick Start
16
13
 
@@ -29,48 +26,5 @@
29
26
  3. Bump the version in [`package.json`](package.json).
30
27
  4. Add an entry for the new version in [`CHANGELOG.md`](CHANGELOG.md).
31
28
  5. Pull request the branch.
32
- 6. After merge, run `bun run build` - ensures artifacts are current before publish.
29
+ 6. Ensure package artifacts are current.
33
30
  7. Publish.
34
-
35
- ## Publish
36
-
37
- See the following sources to configure the target registry and authentication.
38
-
39
- - [Configuring npm - `npmrc`](https://docs.npmjs.com/cli/v10/configuring-npm/npmrc)
40
- - [Bun package manager - `install.registry`](https://bun.com/docs/runtime/bunfig#install-scopes)
41
-
42
- ⚠️ Package Scope and the authentication for the target registry must be aligned.
43
-
44
- ### `npmjs.org`
45
-
46
- Publish to the public npm registry.
47
-
48
- ```powershell
49
- # authenticate
50
- npm login
51
- # publish
52
- bun publish --registry https://registry.npmjs.org/ --access public
53
- ```
54
-
55
- ### Custom registry
56
-
57
- ```bash
58
- # placeholder:
59
- # <SCOPE_WITHOUT_AT: <SCOPE_WITHOUT_AT>
60
- # <REGISTRY_URL: <REGISTRY_URL>
61
- # <BUN_PUBLISH_AUTH_TOKEN: <BUN_PUBLISH_AUTH_TOKEN>
62
- ```
63
-
64
- `~/.bunfig.toml` or `bunfig.toml`:
65
-
66
- ```toml
67
- [install.scopes]
68
- "<SCOPE_WITHOUT_AT>" = { url = "<REGISTRY_URL>", token = "$BUN_PUBLISH_AUTH_TOKEN" }
69
- ```
70
-
71
- ```powershell
72
- # authenticate
73
- $env:BUN_PUBLISH_AUTH_TOKEN = "<BUN_PUBLISH_AUTH_TOKEN>"
74
- # publish
75
- bun publish
76
- ```
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -1 +1,5 @@
1
1
  node_modules
2
+ buildinfo.txt
3
+ buildinfo-template.txt
4
+ CHANGELOG-template.md
5
+ README-template.md
@@ -4,13 +4,19 @@
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "",
7
+ "keywords": [],
8
+ "repository": {
9
+ "type": "git",
10
+ "url": ""
11
+ },
7
12
  "private": true,
8
13
  "scripts": {
9
- "clean:dist": "rm -rf dist/",
10
- "clean": "bun run clean:dist && bun run --filter '*' clean",
11
- "prebuild": "bun run scripts/buildinfo.ts",
12
- "build": "bun run --filter '*' build",
13
- "tests": "bun test && bun run --filter '*' tests",
14
- "typecheck": "bun run --filter '*' typecheck"
14
+ "reinstall": "rm -rf node_modules && rm -f bun.lock && bun pm cache rm && bun install && bunx tsc --version",
15
+ "typecheck": "tsc --noEmit",
16
+ "buildinfo": "bun run scripts/buildinfo.ts"
17
+ },
18
+ "devDependencies": {
19
+ "@types/bun": "latest",
20
+ "typescript": "^6.0.2"
15
21
  }
16
22
  }
@@ -3,8 +3,7 @@
3
3
  "target": "ESNext",
4
4
  "module": "ESNext",
5
5
  "lib": [
6
- "ESNext",
7
- "DOM"
6
+ "ESNext"
8
7
  ],
9
8
  "moduleResolution": "bundler",
10
9
  "strict": true,
@@ -16,11 +15,13 @@
16
15
  "esModuleInterop": true,
17
16
  "composite": true,
18
17
  "skipLibCheck": true,
18
+ "types": [
19
+ "bun"
20
+ ],
19
21
  "forceConsistentCasingInFileNames": true,
20
22
  "resolveJsonModule": true
21
23
  },
22
24
  "include": [
23
- "tests/**/*.ts",
24
25
  "scripts/**/*.ts"
25
26
  ],
26
27
  "exclude": [
package/dist/cli.d.ts DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=cli.d.ts.map
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-workspace <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
- }
@@ -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
@@ -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,23 +0,0 @@
1
- import { describe, it, expect } from 'bun:test';
2
- import { readFileSync } from 'fs';
3
- import { fileURLToPath } from 'url';
4
-
5
-
6
- const buildinfoUrl = new URL('../buildinfo.txt', import.meta.url);
7
-
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-]+)*))?$/;
12
-
13
- function readBuildinfo(): string {
14
- return readFileSync(fileURLToPath(buildinfoUrl), 'utf-8').trim();
15
- }
16
-
17
- describe('buildInfo', () => {
18
-
19
- it('should be a valid semver string', () => {
20
- expect(readBuildinfo()).toMatch(SEMVER_REGEX);
21
- });
22
-
23
- });