Skip to content

Commit

Permalink
Merge pull request #49 from bldrs-ai/server-conway-and-webifc
Browse files Browse the repository at this point in the history
Print time and mem stats for webifc
  • Loading branch information
pablo-mayrgundter committed Aug 7, 2024
2 parents 2653c0c + acd9f6f commit df4555b
Show file tree
Hide file tree
Showing 23 changed files with 152,115 additions and 269 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ RUN yarn install
RUN yarn build

EXPOSE 8001
CMD ["xvfb-run", "--error-file=/dev/stderr", "--listen-tcp", "--server-args", "-ac -screen 0 1024x768x24 +extension GLX +render", "node", "build/server-bundle.js"]
CMD ["xvfb-run", "--error-file=/dev/stderr", "--listen-tcp", "--server-args", "-ac -screen 0 1024x768x24 +extension GLX +render", "node", "build/server.node.js"]
Binary file removed bldrs-ai-conway-0.1.440.tgz
Binary file not shown.
Binary file added bldrs-ai-conway-0.1.553.tgz
Binary file not shown.
Binary file added bldrs-ai-conway-0.1.560.tgz
Binary file not shown.
42 changes: 0 additions & 42 deletions esbuild/build.esb.js

This file was deleted.

62 changes: 62 additions & 0 deletions esbuild/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import esbuild from 'esbuild'
import {webIfcShimAliasPlugin} from './web-ifc-shim-alias-plugin.js'
import {webIfcThreeImportFixupPlugin} from './web-ifc-three-import-fixup.js'


export function doBuild(entryPoints, outfile, isConway = true) {
const plugins = [webIfcThreeImportFixupPlugin]
const defines = {}
if (isConway) {
defines['process.env.ENGINE'] = '"conway"'
defines['process.env.INCLUDE_WEB_IFC_SHIM_ALIAS_PLUGIN'] = 'true'
plugins.push(webIfcShimAliasPlugin(isConway))
console.log('Using conway backend')
} else {
defines['process.env.ENGINE'] = '"webifc"'
console.log('Using web-ifc backend')
}

esbuild.build({
entryPoints: entryPoints,
outfile: outfile,
bundle: true,
format: 'esm',
target: ['node18'],
platform: 'node',
minify: false,
external: externalPackages,
sourcemap: true,
logLevel: 'info',
plugins: plugins,
define: defines,
banner:{
js: `
import { createRequire as topLevelCreateRequire } from 'node:module';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
const require = topLevelCreateRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
`
},
})
}


// These usually have dynamic requires that make the bundler or node
// interpreter unhappy unless they're linked at runtime.
const externalPackages = [
'bindings',
'form-data',
'combined-stream',
'express',
'follow-redirects',
'gl',
'jsdom',
'pngjs',
'proxy-from-env',
'winston',
'@colors',
'@sentry',
// '../external/web-ifc-api-node.cjs',
]
3 changes: 3 additions & 0 deletions esbuild/headless-webifc.esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {doBuild} from './common.js'

doBuild(['./src/headless.js'], './build/headless-webifc.node.js', false)
3 changes: 3 additions & 0 deletions esbuild/headless.esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {doBuild} from './common.js'

doBuild(['./src/headless.js'], './build/headless.node.js')
3 changes: 3 additions & 0 deletions esbuild/server-webifc.esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {doBuild} from './common.js'

doBuild(['./src/server/index.js'], './build/server-webifc.node.js', false)
3 changes: 3 additions & 0 deletions esbuild/server.esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {doBuild} from './common.js'

doBuild(['./src/server/index.js'], './build/server.node.js')
22 changes: 13 additions & 9 deletions esbuild/web-ifc-shim-alias-plugin.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import path from 'node:path'


const webIfcShimAliasPlugin = {
name: 'web-ifc-shim-alias',
setup(build) {
build.onResolve({ filter: /^web-ifc$/ }, (args) => {
return {
path: path.resolve('./node_modules/@bldrs-ai/conway/compiled/src/shim/ifc_api.js'),
}
});
},
function webIfcShimAliasPlugin(isConway = true) {
return {
name: 'web-ifc-shim-alias',
setup(build) {
build.onResolve({ filter: /^web-ifc$/ }, (args) => {
return {
path: isConway ?
path.resolve('./node_modules/@bldrs-ai/conway/compiled/src/shim/ifc_api.js') :
path.resolve('../external/web-ifc-api.js'),
}
});
},
}
}


Expand Down
2 changes: 0 additions & 2 deletions esbuild/web-ifc-three-import-fixup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ const webIfcThreeImportFixupPlugin = {
setup(build) {
build.onLoad({ filter: /web-ifc-three\/IFCLoader.js/ }, async (args) => {
let contents = await fs.promises.readFile(args.path, 'utf8')

contents = contents.replace(
"import { mergeBufferGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils';",
"import { mergeBufferGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils.js';",
)

return { contents, loader: 'js' }
});
},
Expand Down
Loading

0 comments on commit df4555b

Please sign in to comment.