diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7beb393..002cd30 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,13 +1,8 @@ -name: Deploy site +name: Deploy to GitHub Pages on: push: - branches: [main, master] - paths: - - 'web/**' - - 'src/**' - - 'package.json' - - '.github/workflows/deploy.yml' + branches: [main] workflow_dispatch: permissions: @@ -17,37 +12,41 @@ permissions: concurrency: group: pages - cancel-in-progress: true + cancel-in-progress: false jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - name: Setup Node + uses: actions/setup-node@v4 with: - node-version: '24' + node-version: '20' + cache: 'npm' - - name: Install library dependencies - run: npm install + - name: Install dependencies + run: npm ci - - name: Test library - run: npm test -- --run + - name: Build library + run: npm run build - - name: Install site dependencies - working-directory: web - run: npm install + - name: Install web dependencies + working-directory: ./web + run: npm ci - - name: Build site - working-directory: web + - name: Build web + working-directory: ./web run: npm run build + env: + BASE_PATH: '/funcio/' - - uses: actions/configure-pages@v5 - - - uses: actions/upload-pages-artifact@v3 + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 with: - path: web/dist + path: ./web/dist deploy: needs: build @@ -58,4 +57,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v4 + uses: actions/deploy-pages@v4 \ No newline at end of file diff --git a/web/index.html b/web/index.html index e103d12..e295f0c 100644 --- a/web/index.html +++ b/web/index.html @@ -37,7 +37,7 @@ - +
diff --git a/web/package.json b/web/package.json index d1f95f1..c344a90 100644 --- a/web/package.json +++ b/web/package.json @@ -9,7 +9,7 @@ "prebuild": "npm --prefix .. run build", "pretypecheck": "npm --prefix .. run build", "build": "npm run verify && tsc --noEmit -p tsconfig.json && npm run lint && vite build", - "postbuild": "tsx scripts/generate-sitemap.ts", + "postbuild": "tsx scripts/generate-sitemap.ts && tsx scripts/update-version.ts", "preview": "vite preview", "typecheck": "tsc --noEmit -p tsconfig.json", "verify": "esbuild scripts/verify-examples.ts --bundle --platform=node --format=esm --log-level=warning --alias:funcio=../src/main.ts --outfile=node_modules/.cache/verify.mjs && node node_modules/.cache/verify.mjs", diff --git a/web/scripts/update-version.ts b/web/scripts/update-version.ts new file mode 100644 index 0000000..1c376ba --- /dev/null +++ b/web/scripts/update-version.ts @@ -0,0 +1,41 @@ +import { readFileSync, writeFileSync } from 'node:fs' +import { resolve } from 'node:path' + +async function getLatestVersion(): Promise { + const response = await fetch('https://registry.npmjs.org/funcio/latest') + if (!response.ok) { + throw new Error(`Failed to fetch latest version: ${response.status}`) + } + const data = await response.json() + return data.version +} + +async function updateIndexHtml(version: string): Promise { + const indexPath = resolve('dist', 'index.html') + let html = readFileSync(indexPath, 'utf-8') + + const importmapRegex = /"funcio":\s*"https:\/\/cdn\.jsdelivr\.net\/npm\/funcio@[^"]+"/ + const newImport = `"funcio": "https://cdn.jsdelivr.net/npm/funcio@${version}/lib/esm/main.js"` + + if (importmapRegex.test(html)) { + html = html.replace(importmapRegex, newImport) + } else { + const fallbackRegex = /("imports":\s*\{[^}]*?)("funcio":\s*"[^"]*")/ + html = html.replace(fallbackRegex, `$1${newImport}`) + } + + writeFileSync(indexPath, html) + console.log(`Updated importmap to funcio@${version}`) +} + +async function main(): Promise { + try { + const version = await getLatestVersion() + await updateIndexHtml(version) + } catch (error) { + console.error('Failed to update version:', error) + process.exit(1) + } +} + +main() diff --git a/web/vite.config.ts b/web/vite.config.ts index c56a336..80de1ed 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -1,6 +1,5 @@ import { existsSync } from 'node:fs' import { dirname, resolve } from 'node:path' -import { fileURLToPath, URL } from 'node:url' import { defineConfig, type Plugin } from 'vite' import react from '@vitejs/plugin-react' @@ -20,23 +19,29 @@ const cssModule = (): Plugin => ({ export default defineConfig({ base: process.env.BASE_PATH ?? '/funcio/', plugins: [cssModule(), react()], - resolve: { - alias: { - funcio: fileURLToPath(new URL('../src/main.ts', import.meta.url)) - } - }, build: { outDir: 'dist', target: 'es2020', sourcemap: true, - emptyOutDir: true + emptyOutDir: true, + rollupOptions: { + external: ['funcio'], + output: { + globals: { + funcio: 'Funcio' + } + } + } }, worker: { - format: 'es' - }, - server: { - fs: { - allow: ['..'] + format: 'es', + rollupOptions: { + external: ['funcio'], + output: { + globals: { + funcio: 'Funcio' + } + } } } })