Skip to content

Commit

Permalink
hotfix: 緊急対応
Browse files Browse the repository at this point in the history
  • Loading branch information
r74tech committed Jun 24, 2024
1 parent 9822131 commit eb41dcf
Show file tree
Hide file tree
Showing 4 changed files with 1,365 additions and 9 deletions.
33 changes: 32 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/node
console.time('Bundling time');
const { build } = require('vite');
const { join } = require('path');
const { join, dirname } = require('path');
const fs = require('fs');

/** @type 'production' | 'development' | 'test' */
Expand All @@ -19,10 +19,41 @@ const configs = [
*/
const buildByConfig = (configFile) => build({ configFile, mode });

/**
* Ensure directory exists
* @param {string} filePath
*/
const ensureDirExists = (filePath) => {
const dir = dirname(filePath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
};

Promise.all(configs.map(buildByConfig))
.then(() => {
const distDir = join(process.cwd(), 'dist');

// Paths for the files to copy
const workerSrc = join(process.cwd(), 'src/ftml.web.worker.js');
const workerDest = join(distDir, 'ftml.web.worker.js');

const wasmSrc = join(process.cwd(), 'src/lib/ftml-wasm/esm/wj-ftml-wasm.esm.js');
const wasmDest = join(distDir, 'lib/ftml-wasm/esm/wj-ftml-wasm.esm.js');

// Ensure destination directories exist
ensureDirExists(workerDest);
ensureDirExists(wasmDest);

// Copy the worker file to the dist directory
fs.copyFileSync(workerSrc, workerDest);

// Copy the wasm file to the dist directory
fs.copyFileSync(wasmSrc, wasmDest);

// Copy index.html to 404.html for GitHub Pages
fs.copyFileSync(join(distDir, 'index.html'), join(distDir, '404.html'));

console.timeEnd('Bundling time');
})
.catch(e => {
Expand Down
11 changes: 6 additions & 5 deletions src/ftml.web.worker.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
let ftml = require("@vscode-ftml/ftml-wasm");
ftml.init();
import { init, renderHTML, ready, loading } from './lib/ftml-wasm/esm/wj-ftml-wasm.esm.js';

init();
onmessage = async (e) => {
if (!ftml.ready) await ftml.loading;
if (!ready) await loading;
const ftmlSource = e.data.value;

const { html, styles } = ftml.renderHTML(ftmlSource);
const { html, styles } = renderHTML(ftmlSource);
const type = e.data.type;
postMessage({ html, styles, type });
}
};
Loading

0 comments on commit eb41dcf

Please sign in to comment.