Skip to content

Commit

Permalink
Move heavy shx to external mts scripts using shelljs
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Jan 6, 2024
1 parent efc305a commit cb0f9dc
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
node-version: '20'
- name: Check Environment
env:
DEPLOY_GHP: ${{ false || github.event.inputs.ghp == 'true' || github.ref_name == 'main' }}
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
if: ${{ env.DEPLOY_GHP == 'true' }}
uses: actions/upload-pages-artifact@v3
with:
path: ./packages/examples/preview/
path: ./packages/examples/production/

deploy:
needs: build
Expand Down
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@ dist
node_modules
docs
bundle

packages/examples/preview
packages/examples/src/worker/external
packages/examples/src/worker/generated

*.tsbuildinfo
*.tgz
3 changes: 3 additions & 0 deletions packages/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
production
src/worker/external
src/worker/generated
2 changes: 1 addition & 1 deletion packages/examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Examples</title>
<link type="text/css" rel="stylesheet" href="./main.css">
<link type="text/css" rel="stylesheet" href="main.css">
</head>
<body>
<div style="padding: 5px">
Expand Down
27 changes: 8 additions & 19 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,14 @@
"clean": "shx rm -fr *.tsbuildinfo dist src/worker/generated",
"doc": "echo 'docs are not generated for examples'",
"compile": "tsc -b",
"copy:worker:OBJLoader2Worker": "shx mkdir -p ./src/worker/generated && shx cp -f ../../node_modules/wwobjloader2/lib/worker/OBJLoader2Worker*.js ./src/worker/generated",
"build:worker:HelloWorldWorker": "shx rm -f ./src/worker/generated/HelloWorldWorker*.js && vite -c build/vite.config.HelloWorldWorker.ts build",
"build:worker:Com1Worker": "shx rm -f ./src/worker/generated/Com1Worker*.js && vite -c build/vite.config.Com1Worker.ts build",
"build:worker:Com2Worker": "shx rm -f ./src/worker/generated/Com2Worker*.js && vite -c build/vite.config.Com2Worker.ts build",
"build:worker:HelloWorldThreeWorker": "shx rm -f ./src/worker/generated/HelloWorldThreeWorker*.js && vite -c build/vite.config.HelloWorldThreeWorker.ts build",
"build:worker:InfiniteWorkerExternalGeometry": "shx rm -f ./src/worker/generated/InfiniteWorkerExternalGeometry*.js && vite -c build/vite.config.InfiniteWorkerExternalGeometry.ts build",
"build:worker:InfiniteWorkerInternalGeometry": "shx rm -f ./src/worker/generated/InfiniteWorkerInternalGeometry*.js && vite -c build/vite.config.InfiniteWorkerInternalGeometry.ts build",
"build:worker:OBJLoaderWorker": "shx rm -f ./src/worker/generated/OBJLoaderWorker*.js && vite -c build/vite.config.OBJLoaderWorker.ts build",
"build:worker:TransferableWorkerTest1": "shx rm -f ./src/worker/generated/TransferableWorkerTest1*.js && vite -c build/vite.config.TransferableWorkerTest1.ts build",
"build:worker:TransferableWorkerTest2": "shx rm -f ./src/worker/generated/TransferableWorkerTest2*.js && vite -c build/vite.config.TransferableWorkerTest2.ts build",
"build:worker:TransferableWorkerTest3": "shx rm -f ./src/worker/generated/TransferableWorkerTest3*.js && vite -c build/vite.config.TransferableWorkerTest3.ts build",
"build:worker:TransferableWorkerTest4": "shx rm -f ./src/worker/generated/TransferableWorkerTest4*.js && vite -c build/vite.config.TransferableWorkerTest4.ts build",
"build:worker": "npm run build:worker:HelloWorldWorker && npm run build:worker:Com1Worker && npm run build:worker:Com2Worker && npm run build:worker:HelloWorldThreeWorker && npm run build:worker:InfiniteWorkerExternalGeometry && npm run build:worker:InfiniteWorkerInternalGeometry && npm run build:worker:OBJLoaderWorker && npm run build:worker:TransferableWorkerTest1 && npm run build:worker:TransferableWorkerTest2 && npm run build:worker:TransferableWorkerTest3 && npm run build:worker:TransferableWorkerTest4",
"build": "npm run clean && npm run copy:worker:OBJLoader2Worker && npm run compile",
"clean:production": "shx rm -fr preview",
"copy:assets:production": "shx mkdir -p ./preview/worker/generated && shx cp -f ./src/worker/generated/*.js ./preview/worker/generated && shx cp -f ./models/obj/female02/*.jpg ./preview/assets",
"build:production": "npm run build && npm run build:worker && npm run build:production:vite",
"build:production:vite": "npm run clean:production && vite --config vite.config.production.ts build && npm run copy:assets:production",
"preview": "http-server ./preview"
"build": "npm run clean && npm run script:copy:assets && npm run compile",
"clean:production": "shx rm -fr production",
"script:build:worker": "vite-node ./scripts/buildWorker.mts",
"script:copy:assets": "vite-node ./scripts/copyAssets.mts",
"script:copy:assets:production": "vite-node ./scripts/copyAssetsProduction.mts",
"build:production": "npm run build && npm run script:build:worker && npm run build:production:vite",
"build:production:vite": "npm run clean:production && vite --config vite.config.production.ts build && npm run script:copy:assets:production",
"serve": "http-server ./production"
},
"dependencies": {
"lil-gui": "~0.19.1",
Expand Down
34 changes: 34 additions & 0 deletions packages/examples/scripts/buildWorker.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import shell from 'shelljs';

shell.rm('-f', './src/worker/generated/HelloWorldWorker*.js');
shell.exec('vite -c build/vite.config.HelloWorldWorker.ts build');

shell.rm('-f', './src/worker/generated/Com1Worker*.js');
shell.exec('vite -c build/vite.config.Com1Worker.ts build');

shell.rm('-f', './src/worker/generated/Com2Worker*.js');
shell.exec('vite -c build/vite.config.Com2Worker.ts build');

shell.rm('-f', './src/worker/generated/HelloWorldThreeWorker*.js');
shell.exec('vite -c build/vite.config.HelloWorldThreeWorker.ts build');

shell.rm('-f', './src/worker/generated/InfiniteWorkerExternalGeometry*.js');
shell.exec('vite -c build/vite.config.InfiniteWorkerExternalGeometry.ts build');

shell.rm('-f', './src/worker/generated/InfiniteWorkerInternalGeometry*.js');
shell.exec('vite -c build/vite.config.InfiniteWorkerInternalGeometry.ts build');

shell.rm('-f', './src/worker/generated/OBJLoaderWorker*.js');
shell.exec('vite -c build/vite.config.OBJLoaderWorker.ts build');

shell.rm('-f', './src/worker/generated/TransferableWorkerTest1*.js');
shell.exec('vite -c build/vite.config.TransferableWorkerTest1.ts build');

shell.rm('-f', './src/worker/generated/TransferableWorkerTest2*.js');
shell.exec('vite -c build/vite.config.TransferableWorkerTest2.ts build');

shell.rm('-f', './src/worker/generated/TransferableWorkerTest3*.js');
shell.exec('vite -c build/vite.config.TransferableWorkerTest3.ts build');

shell.rm('-f', './src/worker/generated/TransferableWorkerTest4*.js');
shell.exec('vite -c build/vite.config.TransferableWorkerTest4.ts build');
4 changes: 4 additions & 0 deletions packages/examples/scripts/copyAssets.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import shell from 'shelljs';

shell.mkdir('-p', './src/worker/generated');
shell.cp('-f', '../../node_modules/wwobjloader2/lib/worker/OBJLoader2Worker*.js', './src/worker/generated');
5 changes: 5 additions & 0 deletions packages/examples/scripts/copyAssetsProduction.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import shell from 'shelljs';

shell.mkdir('-p', './production/worker/generated');
shell.cp('-f', './src/worker/generated/*.js', './production/worker/generated');
shell.cp('-f', './models/obj/female02/*.jpg', './production/assets');
10 changes: 1 addition & 9 deletions packages/examples/vite.config.production.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/* eslint-disable no-undef */
import { defineConfig } from 'vite';
import path from 'path';

// Config Hints:
// https://vitejs.dev/guide/build.html#multi-page-app

export default defineConfig(({ command }) => {
console.log(`Running: ${command}`);
return {
Expand All @@ -26,14 +22,10 @@ export default defineConfig(({ command }) => {
},
minify: false,
assetsInlineLimit: 128,
outDir: path.resolve(__dirname, 'preview'),
outDir: path.resolve(__dirname, 'production'),
emptyOutDir: true,
},
base: 'https://kaisalmen.github.io/wtd/',
server: {
port: 8080,
host: '0.0.0.0'
},
optimizeDeps: {
esbuildOptions: {
target: 'es2022'
Expand Down

0 comments on commit cb0f9dc

Please sign in to comment.