mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-14 18:47:42 +01:00
ci: add ci detection for web component packaging (#927)
* build: add web build ci * chore: remove test code * Update .github/workflows/frontend-ci.yml Co-authored-by: SteveLauC <stevelauc@outlook.com> --------- Co-authored-by: SteveLauC <stevelauc@outlook.com>
This commit is contained in:
31
.github/workflows/frontend-ci.yml
vendored
31
.github/workflows/frontend-ci.yml
vendored
@@ -5,6 +5,8 @@ on:
|
||||
# Only run it when Frontend code changes
|
||||
paths:
|
||||
- 'src/**'
|
||||
- 'tsup.config.ts'
|
||||
- 'package.json'
|
||||
|
||||
jobs:
|
||||
check:
|
||||
@@ -30,5 +32,34 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Switch platformAdapter to Web adapter
|
||||
shell: bash
|
||||
run: >
|
||||
node -e "const fs=require('fs');const f='src/utils/platformAdapter.ts';
|
||||
let s=fs.readFileSync(f,'utf8');
|
||||
s=s.replace(/import\\s*\\{\\s*createTauriAdapter\\s*\\}\\s*from\\s*\\\"\\.\\/tauriAdapter\\\";/,'import { createWebAdapter } from \\\"./webAdapter\\\";');
|
||||
s=s.replace(/let\\s+platformAdapter\\s*=\\s*createTauriAdapter\\(\\);/,'let platformAdapter = createWebAdapter();');
|
||||
fs.writeFileSync(f,s);"
|
||||
|
||||
- name: Build web (Tauri dependency check)
|
||||
run: pnpm build:web
|
||||
|
||||
- name: Verify no Tauri refs in web output
|
||||
run: |
|
||||
if grep -R -n -E '@tauri-apps|tauri-plugin' out/search-chat; then
|
||||
echo 'Tauri references found in web build output';
|
||||
exit 1;
|
||||
else
|
||||
echo 'No Tauri references found';
|
||||
fi
|
||||
|
||||
- name: Restore platformAdapter to Tauri adapter
|
||||
run: >
|
||||
node -e "const fs=require('fs');const f='src/utils/platformAdapter.ts';
|
||||
let s=fs.readFileSync(f,'utf8');
|
||||
s=s.replace(/import\\s*\\{\\s*createWebAdapter\\s*\\}\\s*from\\s*\\\"\\.\\/webAdapter\\\";/,'import { createTauriAdapter } from \\\"./tauriAdapter\\\";');
|
||||
s=s.replace(/let\\s+platformAdapter\\s*=\\s*createWebAdapter\\(\\);/,'let platformAdapter = createTauriAdapter();');
|
||||
fs.writeFileSync(f,s);"
|
||||
|
||||
- name: Build frontend
|
||||
run: pnpm build
|
||||
|
||||
@@ -1,11 +1,30 @@
|
||||
import { defineConfig } from 'tsup';
|
||||
import { writeFileSync, readFileSync } from 'fs';
|
||||
import { writeFileSync, readFileSync, readdirSync, statSync } from 'fs';
|
||||
import { join, resolve } from 'path';
|
||||
|
||||
const projectPackageJson = JSON.parse(
|
||||
readFileSync(join(__dirname, 'package.json'), 'utf-8')
|
||||
);
|
||||
|
||||
function walk(dir: string): string[] {
|
||||
const entries = readdirSync(dir);
|
||||
const files: string[] = [];
|
||||
for (const name of entries) {
|
||||
const full = join(dir, name);
|
||||
const stat = statSync(full);
|
||||
if (stat.isDirectory()) {
|
||||
files.push(...walk(full));
|
||||
} else {
|
||||
files.push(full);
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
function hasTauriRefs(content: string): boolean {
|
||||
return /@tauri-apps|tauri-plugin/i.test(content);
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
entry: ['src/pages/web/index.tsx'],
|
||||
format: ['esm'],
|
||||
@@ -66,6 +85,18 @@ export default defineConfig({
|
||||
outDir: 'out/search-chat',
|
||||
|
||||
async onSuccess() {
|
||||
const outDir = join(__dirname, 'out/search-chat');
|
||||
const files = walk(outDir).filter(f => /\.(m?js|cjs)$/i.test(f));
|
||||
const tauriFiles = files.filter(f => {
|
||||
const content = readFileSync(f, 'utf-8');
|
||||
return hasTauriRefs(content);
|
||||
});
|
||||
|
||||
if (tauriFiles.length) {
|
||||
throw new Error(
|
||||
`Build output contains Tauri references:\n${tauriFiles.map(f => ` - ${f}`).join('\n')}`
|
||||
);
|
||||
}
|
||||
const projectPackageJson = JSON.parse(
|
||||
readFileSync(join(__dirname, 'package.json'), 'utf-8')
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user