diff --git a/.gitignore b/.gitignore index b35f7872..8f3a30df 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ node_modules .quasar /dist +# Web workers copied from dependencies. +/public/js + # Cordova related directories and files /src-cordova/node_modules /src-cordova/platforms diff --git a/build_scripts/copyWorkers.mjs b/build_scripts/copyWorkers.mjs new file mode 100644 index 00000000..2f81a299 --- /dev/null +++ b/build_scripts/copyWorkers.mjs @@ -0,0 +1,38 @@ +// +// copyWorkers.js +// +// Copy web-worker scripts from the Web SDK to the application. +// This is for static scripts that cannot be included by `import` or `require`. +// +// Created by Giga on 18 September 2023. +// Copyright 2023 Vircadia contributors. +// Copyright 2023 DigiSomni LLC. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +import { copyFileSync, existsSync, mkdirSync } from "fs"; + +// The workers to copy. +const workers = [ + "vircadia-audio-input.js", + "vircadia-audio-input.js.map", + "vircadia-audio-output.js", + "vircadia-audio-output.js.map" +]; +// The destination for the worker files. +const destination = "public/js/"; + +// Ensure the destination exists. +if (!existsSync(destination)) { + mkdirSync(destination, { recursive: true }); +} + +// Copy the worker files to the destination. +console.log("Copying workers..."); +for (const worker of workers) { + copyFileSync(`node_modules/@vircadia/web-sdk/dist/${worker}`, `${destination}${worker}`); + console.log(" ยป\x1b[32m", worker, "\x1b[0m"); +} +console.log("Done.\n"); diff --git a/package.json b/package.json index cf6848f4..6ba67d2d 100644 --- a/package.json +++ b/package.json @@ -6,12 +6,13 @@ "author": "DigiSomni LLC | Vircadia Contributors", "license": "Apache-2.0", "scripts": { - "build": "npm run create-version && npm run build-quasar", - "dev": "npm run create-version && npm run build-quasar-dev", + "build": "npm run create-version && npm run copy-workers && npm run build-quasar", + "dev": "npm run create-version && npm run copy-workers && npm run build-quasar-dev", "build-quasar": "quasar build", "build-quasar-dev": "quasar dev", "lint": "eslint --ext .js,.ts,.vue ./", "create-version": "node build_scripts/createVersion.js", + "copy-workers": "node build_scripts/copyWorkers.mjs", "update-contributors": "git-authors-cli" }, "dependencies": {