Skip to content

Commit e8af7d7

Browse files
committed
Move worker build to TypeScript script
1 parent c24fbff commit e8af7d7

File tree

6 files changed

+37
-18
lines changed

6 files changed

+37
-18
lines changed

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ services:
33
build:
44
context: .
55
dockerfile: ./worker/Dockerfile
6-
volumes:
7-
- ./worker-dist/:/home/worker-dist/
86
stdin_open: true
97
tty: true
108
serve-webpack-example:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"serve": "ts-node ./scripts/serve-directory.ts -p 9090 demo-dist",
2727
"bundle": "rm -rf dist && webpack --mode=production",
2828
"compile:middleware": "tsc -d src/middleware/index.ts --outDir middleware --lib ES6,DOM,esnext.asynciterable",
29-
"build:worker": "rm -rf worker-dist && docker compose up --abort-on-container-exit --build build-worker",
29+
"build:worker": "ts-node scripts/bundle_worker.ts",
3030
"build:release": "rm -rf middleware && npm run build:worker && npm run bundle && npm run compile:middleware && npm run declarations",
3131
"build:demo": "npm run build:release && rm -rf demo-dist && cp -R demo/ demo-dist/ && cp dist/voyager.css* dist/voyager.standalone.js* demo-dist/",
3232
"stats": "NODE_ENV=production webpack --json --mode=production > stats.json",

scripts/bundle_worker.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as assert from 'node:assert';
2+
import * as crypto from 'node:crypto';
3+
import * as fs from 'node:fs';
4+
import * as path from 'node:path';
5+
6+
import { spawnOutput } from './utils';
7+
8+
// Clean up existing worker-dist directory
9+
const outputDir = 'worker-dist';
10+
fs.rmSync(outputDir, { recursive: true, force: true });
11+
12+
console.error('Building worker with Docker...');
13+
const dockerOutput = spawnOutput('docker', [
14+
'compose',
15+
'up',
16+
'--abort-on-container-exit',
17+
'--build',
18+
'build-worker',
19+
]);
20+
21+
// Process the Docker output
22+
const hash = crypto.createHash('sha256').update(dockerOutput).digest('hex');
23+
24+
assert(dockerOutput.includes('`') === false);
25+
const processedOutput = `
26+
export const VizWorkerSource = String.raw \`${dockerOutput}\`;
27+
export const VizWorkerHash = \`${hash}\`;
28+
`;
29+
30+
fs.mkdirSync(outputDir, { recursive: true });
31+
const outputFile = path.join(outputDir, 'voyager.worker.js');
32+
fs.writeFileSync(outputFile, processedOutput.trim());
33+
34+
console.error(`Worker built successfully: ${outputFile}`);

scripts/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ interface SpawnOptions {
4242
env?: typeof process.env;
4343
}
4444

45-
function spawnOutput(
45+
export function spawnOutput(
4646
command: string,
4747
args: ReadonlyArray<string>,
4848
options?: SpawnOptions,

worker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ RUN emcc \
7878
--post-js worker/post.js \
7979
worker/viz.cpp ;
8080

81-
CMD node worker/bundle.js < emscripten_worker.js > worker-dist/voyager.worker.js
81+
CMD ["cat", "emscripten_worker.js"]

worker/bundle.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)