also looking at this
fix: emit a real library build (dist/index.js + ./stx) so the package is importable
#124
6 files
+72
-13
| @@ -1,10 +1,46 @@ | ||
| 1 | 1 | #!/usr/bin/env bun |
| 2 | import { generateStaticSite } from '@stacksjs/stx/ssg' | |
| 3 | ||
| 4 | await generateStaticSite({ | |
| 5 | pagesDir: 'pages', | |
| 6 | outputDir: 'dist', | |
| 7 | publicDir: 'public', | |
| 8 | sitemap: true, | |
| 9 | cleanOutput: true, | |
| 2 | /** | |
| 3 | * Library build — emits the package's JS + declarations so `@stacksjs/ts-analytics` | |
| 4 | * is importable (package.json's `module`/`exports`/`types` all point at ./dist). | |
| 5 | * | |
| 6 | * Builds two entrypoints so both exports resolve: | |
| 7 | * `.` → dist/index.js + dist/index.d.ts | |
| 8 | * `./stx` → dist/integrations/stx.js + dist/integrations/stx.d.ts (the tsAnalytics() module) | |
| 9 | * | |
| 10 | * The static dashboard SITE is a separate deploy artifact — `bun run build:site` | |
| 11 | * (build-site.ts → dist-site/). Keeping them apart stops the SSG's cleanOutput | |
| 12 | * from wiping the library and vice-versa. node_modules stays external. | |
| 13 | */ | |
| 14 | import { rmSync } from 'node:fs' | |
| 15 | import { dts } from 'bun-plugin-dtsx' | |
| 16 | import stx from 'bun-plugin-stx' | |
| 17 | ||
| 18 | rmSync('./dist', { recursive: true, force: true }) | |
| 19 | ||
| 20 | const result = await Bun.build({ | |
| 21 | entrypoints: ['./src/index.ts', './src/integrations/stx.ts'], | |
| 22 | splitting: true, | |
| 23 | outdir: './dist', | |
| 24 | root: './src', | |
| 25 | // bun-plugin-stx resolves the `.stx` imports a few library modules carry | |
| 26 | // (e.g. handlers render dashboard views server-side); dts() emits declarations. | |
| 27 | plugins: [stx(), dts()], | |
| 28 | target: 'bun', | |
| 29 | format: 'esm', | |
| 30 | packages: 'external', | |
| 10 | 31 | }) |
| 32 | ||
| 33 | if (!result.success) { | |
| 34 | console.error('[ts-analytics] library build failed:') | |
| 35 | for (const log of result.logs) | |
| 36 | console.error(log) | |
| 37 | process.exit(1) | |
| 38 | } | |
| 39 | ||
| 40 | for (const f of ['./dist/index.js', './dist/integrations/stx.js']) { | |
| 41 | if (!(await Bun.file(f).exists())) { | |
| 42 | console.error(`[ts-analytics] build succeeded but ${f} is missing — check the entrypoints/exports`) | |
| 43 | process.exit(1) | |
| 44 | } | |
| 45 | } | |
| 46 | console.log(`[ts-analytics] library built → dist/ (${result.outputs.length} files; index.js + integrations/stx.js present)`) | |