Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -58,4 +57,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
uses: actions/deploy-pages@v4
9 changes: 8 additions & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />

<script>
<script>
;(() => {
try {
const stored = localStorage.getItem('funcio-theme')
Expand All @@ -48,6 +48,13 @@
} catch {}
})()
</script>
<script type="importmap">
{
"imports": {
"funcio": "https://cdn.jsdelivr.net/npm/funcio@0.1.0/lib/esm/main.js"
}
}
</script>
</head>
<body>
<div id="root"></div>
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
41 changes: 41 additions & 0 deletions web/scripts/update-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { readFileSync, writeFileSync } from 'node:fs'
import { resolve } from 'node:path'

async function getLatestVersion(): Promise<string> {
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<void> {
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<void> {
try {
const version = await getLatestVersion()
await updateIndexHtml(version)
} catch (error) {
console.error('Failed to update version:', error)
process.exit(1)
}
}

main()
29 changes: 17 additions & 12 deletions web/vite.config.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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'
}
}
}
}
})
Loading