Skip to content

Commit

Permalink
Create a build script to copy web-workers from the SDK to the app
Browse files Browse the repository at this point in the history
  • Loading branch information
Gigabyte5671 committed Sep 18, 2023
1 parent 5baa8cb commit d731e26
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions build_scripts/copyWorkers.mjs
Original file line number Diff line number Diff line change
@@ -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");
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit d731e26

Please sign in to comment.