move webpack to bin
This commit is contained in:
parent
e6d4823c8e
commit
0022bffc20
6 changed files with 142 additions and 157 deletions
29
app.js
29
app.js
|
|
@ -315,6 +315,15 @@ function handleSetup(req, res, next) {
|
|||
}
|
||||
}
|
||||
|
||||
const productionMap = {
|
||||
'/lib/mesh/work.js' : '/lib/pack/mesh-work.js',
|
||||
'/lib/main/mesh.js' : '/lib/pack/mesh-main.js',
|
||||
'/lib/main/kiri.js' : '/lib/pack/kiri-main.js',
|
||||
'/lib/kiri-run/engine.js' : '/lib/pack/kiri-eng.js',
|
||||
'/lib/kiri-run/minion.js' : '/lib/pack/kiri-pool.js',
|
||||
'/lib/kiri-run/worker.js' : '/lib/pack/kiri-work.js',
|
||||
};
|
||||
|
||||
function handleVersion(req, res, next) {
|
||||
let vstr = oversion || dversion || version;
|
||||
if (["/kiri/","/mesh/"].indexOf(req.app.path) >= 0 && req.url.indexOf(vstr) < 0) {
|
||||
|
|
@ -326,20 +335,9 @@ function handleVersion(req, res, next) {
|
|||
} else if (!debug) {
|
||||
// in production serve packed bundles
|
||||
let { path } = req.app;
|
||||
if (path === '/lib/mesh/work.js') {
|
||||
req.url = '/lib/pack/mesh-work.js';
|
||||
} else if (path === '/lib/main/mesh.js') {
|
||||
req.url = '/lib/pack/mesh-main.js';
|
||||
} else if (path === '/lib/kiri-run/minion.js') {
|
||||
req.url = '/lib/pack/kiri-pool.js';
|
||||
} else if (path === '/lib/kiri-run/worker.js') {
|
||||
req.url = '/lib/pack/kiri-work.js';
|
||||
} else if (path === '/lib/main/kiri.js') {
|
||||
req.url = '/lib/pack/kiri-main.js';
|
||||
}
|
||||
// add cors headers on rewrite
|
||||
if (path !== req.url) {
|
||||
// console.log('rewrite', path, req.url);
|
||||
let mapped = productionMap[path];
|
||||
if (mapped) {
|
||||
req.url = mapped;
|
||||
addCorsHeaders(req, res);
|
||||
}
|
||||
next();
|
||||
|
|
@ -540,7 +538,8 @@ function rewriteHtmlVersion(req, res, next) {
|
|||
"/mesh/",
|
||||
"/lib/mesh/work.js",
|
||||
"/lib/kiri-run/worker.js",
|
||||
"/lib/kiri-run/minion.js"
|
||||
"/lib/kiri-run/minion.js",
|
||||
"/lib/kiri-run/engine.js"
|
||||
].indexOf(req.app.path) >= 0) {
|
||||
addCorsHeaders(req, res);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,16 @@ import { LineGeometry } from '../node_modules/three/examples/jsm/lines/LineGeome
|
|||
import { LineSegments2 } from '../node_modules/three/examples/jsm/lines/LineSegments2.js';
|
||||
import { LineSegmentsGeometry } from '../node_modules/three/examples/jsm/lines/LineSegmentsGeometry.js';
|
||||
|
||||
import * as MeshBVHLib from '../node_modules/three-mesh-bvh/build/index.module.js';
|
||||
|
||||
export {
|
||||
THREE, SVGLoader, BufferGeometryUtils,
|
||||
THREE,
|
||||
SVGLoader,
|
||||
BufferGeometryUtils,
|
||||
LineMaterial,
|
||||
Line2, LineGeometry,
|
||||
LineSegments2, LineSegmentsGeometry
|
||||
};
|
||||
Line2,
|
||||
LineGeometry,
|
||||
LineSegments2,
|
||||
LineSegmentsGeometry,
|
||||
MeshBVHLib
|
||||
};
|
||||
|
|
@ -79,7 +79,7 @@
|
|||
"webpack-cli": "^5.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"setup": "npm i && npm run dev -- --dryrun && npx webpack --config src/webpack/webpack-three-esm.js && node src/webpack/esbuild.config.mjs",
|
||||
"setup": "npm i && npm run dev -- --dryrun && npm run webpack",
|
||||
"dev": "gs-app-server --debug --single",
|
||||
"prod": "gs-app-server",
|
||||
"prod-dryrun": "gs-app-server --dryrun",
|
||||
|
|
@ -96,8 +96,6 @@
|
|||
"build-win-arm": "npm run build -- --win --arm64",
|
||||
"build-mac": "npm run build -- --mac --arm64",
|
||||
"build-mac-intel": "npm run build -- --mac --x64",
|
||||
"mesh-build": "webpack --config webpack.config.js",
|
||||
"mesh-build-dev": "webpack --config webpack.dev.config.js",
|
||||
"mklinks": "find src web -type l | xargs -I{} sh -c 'echo \"{},$(readlink {})\"' > links.csv",
|
||||
"mac-verify": "spctl --assess -vv --type install dist/*/*.app",
|
||||
"clear-cache": "rm -rf data/cache/* dist/ tmp/*",
|
||||
|
|
@ -107,7 +105,8 @@
|
|||
"docs-dev": "docusaurus start --config conf/docusaurus.config.js",
|
||||
"docs-build": "docusaurus build --config conf/docusaurus.config.js",
|
||||
"docs-serve": "docusaurus serve --config conf/docusaurus.config.js",
|
||||
"docs-check": "prettier --config ./conf/prettier.config.js ./docs --check"
|
||||
"docs-check": "prettier --config ./conf/prettier.config.js ./docs --check",
|
||||
"webpack": "npx webpack --config bin/webpack-three-esm.js && node bin/esbuild.config.mjs"
|
||||
},
|
||||
"main": "app-el.js",
|
||||
"build": {
|
||||
|
|
|
|||
|
|
@ -1,53 +1,34 @@
|
|||
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Future imports for src/kiri-run/engine.js when unwrapped from gapp.register()
|
||||
|
||||
// Dependencies from dep: comments
|
||||
// import { moto_license } from 'moto/license.js';
|
||||
// import { load_stl } from 'load/stl.js';
|
||||
// import { kiri_conf } from 'kiri/conf.js';
|
||||
// import { kiri_client } from 'kiri/client.js';
|
||||
// import { kiri_widget } from 'kiri/widget.js';
|
||||
|
||||
// Dependencies from use: comments
|
||||
// import { add_three } from 'add/three.js';
|
||||
// import { add_array } from 'add/array.js';
|
||||
|
||||
// Core dependencies from root
|
||||
import { kiri } from '../../main/gapp.js';
|
||||
|
||||
// Note: This module also depends on:
|
||||
// - moto.license (for licensing functionality)
|
||||
// - load.stl (for STL file loading)
|
||||
// - kiri.conf (for configuration)
|
||||
// - kiri.client (for client functionality)
|
||||
// - kiri.widget (for widget functionality)
|
||||
// - add.three (for Three.js utilities)
|
||||
// - add.array (for array utilities)
|
||||
// - Various kiri API functions injected via root
|
||||
import '../add/array.js';
|
||||
import '../add/class.js';
|
||||
import '../add/three.js';
|
||||
import { api } from '../kiri/api.js';
|
||||
import { conf } from '../kiri/conf.js';
|
||||
import { client } from '../kiri/client.js';
|
||||
import { load } from '../load/file.js';
|
||||
import { newWidget } from '../kiri/widget.js';
|
||||
|
||||
class Engine {
|
||||
constructor() {
|
||||
this.widget = kiri.newWidget();
|
||||
this.widget = newWidget();
|
||||
this.settings = {
|
||||
mode: "FDM",
|
||||
controller: {},
|
||||
render: false,
|
||||
filter: { FDM: "internal" },
|
||||
device: kiri.conf.defaults.fdm.d, // device profile
|
||||
process: kiri.conf.defaults.fdm.p, // slicing settings
|
||||
widget: { [ this.widget.id ]: {} }
|
||||
device: conf.defaults.fdm.d, // device profile
|
||||
process: conf.defaults.fdm.p, // slicing settings
|
||||
widget: { [this.widget.id]: {} }
|
||||
};
|
||||
this.listener = () => {};
|
||||
this.listener = () => { };
|
||||
}
|
||||
|
||||
load(url) {
|
||||
return new Promise((accept, reject) => {
|
||||
try {
|
||||
new load.STL().load(url, vertices => {
|
||||
this.listener({loaded: url, vertices});
|
||||
this.listener({ loaded: url, vertices });
|
||||
this.widget.loadVertices(vertices).center();
|
||||
accept(this);
|
||||
});
|
||||
|
|
@ -58,14 +39,14 @@ class Engine {
|
|||
}
|
||||
|
||||
clear() {
|
||||
kiri.api.platform.clear();
|
||||
api.platform.clear();
|
||||
}
|
||||
|
||||
parse(data) {
|
||||
return new Promise((accept, reject) => {
|
||||
try {
|
||||
let vertices = new load.STL().parse(data);
|
||||
this.listener({parsed: data, vertices});
|
||||
this.listener({ parsed: data, vertices });
|
||||
this.widget.loadVertices(vertices).center();
|
||||
accept(this);
|
||||
} catch (error) {
|
||||
|
|
@ -108,9 +89,9 @@ class Engine {
|
|||
let ctrl = this.settings.controller;
|
||||
Object.assign(ctrl, controller);
|
||||
if (ctrl.threaded) {
|
||||
kiri.client.pool.start();
|
||||
client.pool.start();
|
||||
} else {
|
||||
kiri.client.pool.stop();
|
||||
client.pool.stop();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
@ -157,11 +138,11 @@ class Engine {
|
|||
|
||||
slice() {
|
||||
return new Promise((accept, reject) => {
|
||||
kiri.client.clear();
|
||||
kiri.client.sync([ this.widget ]);
|
||||
kiri.client.rotate(this.settings);
|
||||
kiri.client.slice(this.settings, this.widget, msg => {
|
||||
this.listener({slice:msg});
|
||||
client.clear();
|
||||
client.sync([this.widget]);
|
||||
client.rotate(this.settings);
|
||||
client.slice(this.settings, this.widget, msg => {
|
||||
this.listener({ slice: msg });
|
||||
if (msg.error) {
|
||||
reject(msg.error);
|
||||
}
|
||||
|
|
@ -174,10 +155,10 @@ class Engine {
|
|||
|
||||
prepare() {
|
||||
return new Promise((accept, reject) => {
|
||||
kiri.client.prepare(this.settings, update => {
|
||||
this.listener({prepare:{update}});
|
||||
client.prepare(this.settings, update => {
|
||||
this.listener({ prepare: { update } });
|
||||
}, done => {
|
||||
this.listener({prepare:{done:true}});
|
||||
this.listener({ prepare: { done: true } });
|
||||
accept(this);
|
||||
});
|
||||
});
|
||||
|
|
@ -186,37 +167,21 @@ class Engine {
|
|||
export() {
|
||||
return new Promise((accept, reject) => {
|
||||
let output = [];
|
||||
kiri.client.export(this.settings, segment => {
|
||||
client.export(this.settings, segment => {
|
||||
if (typeof segment === 'string') {
|
||||
this.listener({export:{segment}});
|
||||
this.listener({ export: { segment } });
|
||||
output.push(segment);
|
||||
}
|
||||
}, done => {
|
||||
this.listener({export:{done}});
|
||||
this.listener({ export: { done } });
|
||||
accept(output.join('\r\n'));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function newEngine() {
|
||||
export function newEngine() {
|
||||
return new Engine();
|
||||
}
|
||||
|
||||
gapp.overlay(kiri, {
|
||||
newEngine
|
||||
});
|
||||
|
||||
// Future exports for src/kiri-run/engine.js when unwrapped from gapp.register()
|
||||
|
||||
// Main Engine class
|
||||
export { Engine };
|
||||
|
||||
// Factory function
|
||||
export { newEngine };
|
||||
|
||||
// Default export - the main engine functionality
|
||||
export default {
|
||||
Engine,
|
||||
newEngine
|
||||
};
|
||||
|
|
@ -9,21 +9,10 @@ const isProd = mode === 'prod';
|
|||
console.log(`Building in ${mode} mode...`);
|
||||
|
||||
const MESH_OUTFILE = 'src/pack/mesh-main.js';
|
||||
const MESH_EXTRAS = [
|
||||
// 'mod/*/electron.js',
|
||||
// 'mod/*/tra0m.js',
|
||||
// 'mod/*/src/space.js'
|
||||
];
|
||||
const MESH_EXTRAS = [ ];
|
||||
|
||||
const KIRI_OUTFILE = 'src/pack/kiri-main.js';
|
||||
const KIRI_EXTRAS = [
|
||||
// 'mod/*/electron.js',
|
||||
// 'mod/*/sync.js',
|
||||
// 'mod/*/don8.js',
|
||||
// 'mod/*/onshape.js',
|
||||
// 'mod/*/tra0.js',
|
||||
// 'mod/*/src/space.js'
|
||||
];
|
||||
const KIRI_EXTRAS = [ ];
|
||||
|
||||
async function appendExtraModules(extras, outfile, minify = false) {
|
||||
const files = await glob(extras);
|
||||
|
|
@ -144,6 +133,23 @@ async function buildApp() {
|
|||
logOverride
|
||||
});
|
||||
|
||||
// Bundle kiri engine
|
||||
await build({
|
||||
entryPoints: [ 'src/kiri-run/engine.js' ],
|
||||
bundle: true,
|
||||
outfile: 'src/pack/kiri-eng.js',
|
||||
format: 'esm',
|
||||
external: ['module'],
|
||||
sourcemap: !isProd, // true for dev, false for prod
|
||||
minify: isProd, // false for dev, true for prod
|
||||
target: 'es2020',
|
||||
platform: 'browser',
|
||||
define: {
|
||||
'process.env.NODE_ENV': `"${mode}"`
|
||||
},
|
||||
logOverride
|
||||
});
|
||||
|
||||
console.log(`Build completed successfully in ${mode} mode!`);
|
||||
} catch (error) {
|
||||
console.error('Build failed:', error);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
#loadExample #examples {
|
||||
display:flex;
|
||||
flex-direction: row;
|
||||
|
|
@ -87,8 +86,10 @@
|
|||
}
|
||||
</style>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js"></script>
|
||||
<script src="/code/engine.js"></script>
|
||||
<script>
|
||||
<!-- <script src="/lib/kiri-run/engine.js" type="module"></script> -->
|
||||
<script type="module">
|
||||
import { Engine } from '/lib/kiri-run/engine.js';
|
||||
const engine = new Engine();
|
||||
let edit, saveit = "";
|
||||
function $(id) { return document.getElementById(id) }
|
||||
function onload() {
|
||||
|
|
@ -126,24 +127,24 @@
|
|||
eval(`(function(){${code}})()`);
|
||||
}
|
||||
function demoFDM() {
|
||||
kiri.newEngine()
|
||||
.setListener(display_message)
|
||||
.load("/obj/cube.stl")
|
||||
.then(eng => eng.setProcess({
|
||||
|
||||
}))
|
||||
.then(eng => eng.setDevice({
|
||||
gcodePre: [ "M82", "M104 S220" ],
|
||||
gcodePost: [ "M107" ]
|
||||
}))
|
||||
.then(eng => eng.slice())
|
||||
.then(eng => eng.prepare())
|
||||
.then(eng => eng.export())
|
||||
.then(display_gcode);
|
||||
engine
|
||||
.setListener(display_message)
|
||||
.load("/obj/cube.stl")
|
||||
.then(eng => eng.setProcess({
|
||||
// empty
|
||||
}))
|
||||
.then(eng => eng.setDevice({
|
||||
gcodePre: [ "M82", "M104 S220" ],
|
||||
gcodePost: [ "M107" ]
|
||||
}))
|
||||
.then(eng => eng.slice())
|
||||
.then(eng => eng.prepare())
|
||||
.then(eng => eng.export())
|
||||
.then(display_gcode);
|
||||
}
|
||||
|
||||
function demoCAM(){
|
||||
kiri.newEngine()
|
||||
engine
|
||||
.setListener(display_message)
|
||||
.load("/obj/cube.stl")
|
||||
// should to call widget.setTopZ here ideally
|
||||
|
|
@ -180,7 +181,6 @@
|
|||
camZThru: 1.524,
|
||||
camZBottom:-25, // temp hack to get around setTopZ bug
|
||||
camToolInit: true,
|
||||
|
||||
ops: [{
|
||||
type: "outline",
|
||||
tool: 1000,
|
||||
|
|
@ -202,42 +202,41 @@
|
|||
ov_conv: true
|
||||
}
|
||||
]
|
||||
|
||||
}))
|
||||
.then(eng => eng.setDevice({
|
||||
mode: "CAM",
|
||||
internal: 0,
|
||||
bedHeight: 2.5,
|
||||
bedWidth: 678.18,
|
||||
bedDepth: 1524,
|
||||
maxHeight: 150,
|
||||
originCenter: false,
|
||||
spindleMax: 24000,
|
||||
gcodePre: [
|
||||
"G20 ; set units to inches (required)",
|
||||
"G90 ; absolute position mode (required)"
|
||||
],
|
||||
gcodePost: [
|
||||
"M05 ; spindle off",
|
||||
"M30 ; program end"
|
||||
],
|
||||
gcodeDwell: [
|
||||
"G4 P{time} ; dwell for {time}ms"
|
||||
],
|
||||
gcodeSpindle: [
|
||||
"M3 S{speed} ; spindle on at {spindle} rpm"
|
||||
],
|
||||
gcodeChange: [
|
||||
"M05 ; spindle off",
|
||||
"M6 T{tool} ; change tool to '{tool_name}'",
|
||||
"G37; get tool offset with ETS"
|
||||
],
|
||||
gcodeFExt: "nc",
|
||||
gcodeSpace: true,
|
||||
gcodeStrip: false,
|
||||
deviceName: "Tormach.24R",
|
||||
useLaser: false
|
||||
}))
|
||||
mode: "CAM",
|
||||
internal: 0,
|
||||
bedHeight: 2.5,
|
||||
bedWidth: 678.18,
|
||||
bedDepth: 1524,
|
||||
maxHeight: 150,
|
||||
originCenter: false,
|
||||
spindleMax: 24000,
|
||||
gcodePre: [
|
||||
"G20 ; set units to inches (required)",
|
||||
"G90 ; absolute position mode (required)"
|
||||
],
|
||||
gcodePost: [
|
||||
"M05 ; spindle off",
|
||||
"M30 ; program end"
|
||||
],
|
||||
gcodeDwell: [
|
||||
"G4 P{time} ; dwell for {time}ms"
|
||||
],
|
||||
gcodeSpindle: [
|
||||
"M3 S{speed} ; spindle on at {spindle} rpm"
|
||||
],
|
||||
gcodeChange: [
|
||||
"M05 ; spindle off",
|
||||
"M6 T{tool} ; change tool to '{tool_name}'",
|
||||
"G37; get tool offset with ETS"
|
||||
],
|
||||
gcodeFExt: "nc",
|
||||
gcodeSpace: true,
|
||||
gcodeStrip: false,
|
||||
deviceName: "Tormach.24R",
|
||||
useLaser: false
|
||||
}))
|
||||
.then(eng => eng.slice())
|
||||
.then(eng => eng.prepare())
|
||||
.then(eng => eng.export())
|
||||
|
|
@ -245,7 +244,7 @@
|
|||
}
|
||||
|
||||
function demoLASER(){
|
||||
kiri.newEngine()
|
||||
engine
|
||||
.setListener(display_message)
|
||||
.load("/obj/cube.stl")
|
||||
// should to call widget.setTopZ here ideally
|
||||
|
|
@ -312,7 +311,6 @@
|
|||
.then(eng => eng.export())
|
||||
.then(display_gcode);
|
||||
}
|
||||
|
||||
|
||||
function download() {
|
||||
let blob = new Blob([saveit], {type: "octet/stream"});
|
||||
|
|
@ -321,9 +319,20 @@
|
|||
$('download').innerHTML = `<a id="xo" href="${url}" download="${filename}"></a>`;
|
||||
$('xo').click();
|
||||
}
|
||||
|
||||
onload();
|
||||
|
||||
Object.assign(window, {
|
||||
loadExample,
|
||||
demoFDM,
|
||||
demoCAM,
|
||||
demoLASER,
|
||||
download,
|
||||
run_code
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body onload="onload()">
|
||||
<body>
|
||||
<h2 id="title">Kiri:Moto Javascript Engine <a href="https://docs.grid.space/kiri-moto/engine-apis">API</a></h2>
|
||||
<div id="demo">
|
||||
<div id="jcode">
|
||||
|
|
|
|||
Loading…
Reference in a new issue