also looking at this
feat(stx): one-line stx integration (plugins: ['@stacksjs/ts-analytics']) + fix library build
#123
11 files
+331
-13
| @@ -1,10 +1,50 @@ | ||
| 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 dist/index.js (+ every module under ./*) and | |
| 4 | * declarations, so `@stacksjs/ts-analytics` is importable as a package | |
| 5 | * (package.json `module`/`exports`/`types` all point at ./dist). | |
| 6 | * | |
| 7 | * The static dashboard SITE is a separate deploy artifact — see build-site.ts | |
| 8 | * (`bun run build:site` → dist-site/). Keeping them apart stops the SSG's | |
| 9 | * cleanOutput from wiping the library and vice-versa. | |
| 10 | * | |
| 11 | * Mirrors the sibling stacks library builds: every source module is built so | |
| 12 | * the `./*` subpath export resolves to real JS (not just a .d.ts stub), with | |
| 13 | * node_modules left external (`packages: 'external'`). | |
| 14 | */ | |
| 15 | import { rmSync } from 'node:fs' | |
| 16 | import { dts } from 'bun-plugin-dtsx' | |
| 17 | import stx from 'bun-plugin-stx' | |
| 18 | ||
| 19 | rmSync('./dist', { recursive: true, force: true }) | |
| 20 | ||
| 21 | // Build from the public entry only and let Bun follow the import graph, so the | |
| 22 | // dashboard-UI shims (src/components/dashboard re-exports repo-root `.stx`) that | |
| 23 | // aren't part of the library API are excluded automatically. `splitting` keeps | |
| 24 | // shared code in chunks instead of duplicating it into index.js. | |
| 25 | const result = await Bun.build({ | |
| 26 | entrypoints: ['./src/index.ts'], | |
| 27 | splitting: true, | |
| 28 | outdir: './dist', | |
| 29 | root: './src', | |
| 30 | // bun-plugin-stx resolves the `.stx` imports a few library modules carry | |
| 31 | // (e.g. handlers render dashboard views server-side); dts() emits declarations. | |
| 32 | plugins: [stx(), dts()], | |
| 33 | target: 'bun', | |
| 34 | format: 'esm', | |
| 35 | packages: 'external', | |
| 10 | 36 | }) |
| 37 | ||
| 38 | if (!result.success) { | |
| 39 | console.error('[ts-analytics] library build failed:') | |
| 40 | for (const log of result.logs) | |
| 41 | console.error(log) | |
| 42 | process.exit(1) | |
| 43 | } | |
| 44 | ||
| 45 | const hasIndex = await Bun.file('./dist/index.js').exists() | |
| 46 | if (!hasIndex) { | |
| 47 | console.error('[ts-analytics] build succeeded but dist/index.js is missing — check src/index.ts') | |
| 48 | process.exit(1) | |
| 49 | } | |
| 50 | console.log(`[ts-analytics] library built → dist/ (${result.outputs.length} files, dist/index.js present)`) | |