Skip to content

Commit

Permalink
feat: board bundle
Browse files Browse the repository at this point in the history
automatically generate a bundle with all boards
  • Loading branch information
urish committed Dec 29, 2023
1 parent c922dc2 commit 211ee95
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/boards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ jobs:
runs-on: ubuntu-20.04
name: Build build boards index
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
- run: npm ci --prefix tools
- name: Generate board index
run: node ./tools/make-index.js
- name: Generate board bundle
run: node ./tools/make-bundle.js
- name: Upload pages artifact
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v3
with:
path: 'boards'

Expand All @@ -38,4 +40,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
uses: actions/deploy-pages@v4
21 changes: 21 additions & 0 deletions tools/make-bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const fs = require('fs');
const path = require('path');
const jsonc = require('jsonc-parser');
const { execSync } = require('child_process');

const boardsRoot = path.join(__dirname, '..', 'boards');
const bundleFile = path.join(boardsRoot, 'bundle.json');

const bundle = {};
for (const boardId of fs.readdirSync(boardsRoot)) {
try {
const boardPath = path.join(boardsRoot, boardId);
const boardJson = jsonc.parse(fs.readFileSync(path.join(boardPath, 'board.json'), 'utf-8'));
const rev = execSync(`git log -1 --pretty=format:"%h" ${boardPath}`).toString().trim();

bundle[boardId] = { rev, def: boardJson, svg: fs.readFileSync(path.join(boardPath, 'board.svg'), 'utf-8') };
} catch (err) {
console.error(`Error reading ${boardId}: ${err}`);
}
}
fs.writeFileSync(bundleFile, JSON.stringify(bundle));

0 comments on commit 211ee95

Please sign in to comment.