-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.js
66 lines (53 loc) · 2.82 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { copyTask, parseArgs } from '@jsx6/build'
import { execSync } from 'child_process'
import { existsSync, mkdirSync } from 'fs'
import liveServer from 'live-server'
import {serve} from './serve.js'
import { buildBundle, buildOne } from './src_build/esbuildUtil.js'
// *************** read parameters **********************
const { dev, port = 5120, serve:serveBuild=false, skipDocs=false } = parseArgs()
const watch = dev
const outDir = dev ? 'build_dev' : 'build'
const docsDir = 'jscad/docs'
// if docs dir does not exist, then clone jscad and run `npm run docs` to generate it
if (!skipDocs &&!existsSync(docsDir)) {
console.log('generating docs')
if (!existsSync('jscad')) {
// TODO: faster to fetch https://github.com/jscad/OpenJSCAD.org/archive/refs/heads/master.zip
execSync('git clone https://github.com/jscad/OpenJSCAD.org jscad')
}
execSync('cd jscad && npm install && npm run docs')
}
/******************************* SETUP *************/
mkdirSync(outDir, { recursive: true })
/**************************** COPY STATIC ASSETS *************/
copyTask('static', outDir, { include: [], exclude: [], watch, filters: [] })
copyTask('examples', outDir+'/examples', { include: [], exclude: [], watch, filters: [] })
//in dev mode dont try to sync docs, just copy the first time
if(!skipDocs && !(dev & existsSync(outDir + "/docs"))){
// this task is heavy
copyTask(docsDir, outDir + "/docs", { include: [], exclude: [], watch:false, filters: [] })
}
/**************************** BUILD JS that is static *************/
await buildBundle(outDir + '/build', 'bundle.threejs.js', { globalName: 'THREE', skipExisting: dev })
await buildBundle(outDir + '/build', 'bundle.jscad_modeling.js', { format: 'cjs', skipExisting: dev })
await buildBundle(outDir + '/build', 'bundle.jscad_io.js', { format:'cjs', skipExisting: dev })
await buildBundle(outDir + '/build', 'bundle.V1_api.js', { format:'cjs', skipExisting: dev })
await buildBundle(outDir + '/build', 'bundle.jscadui.transform-babel.js', { globalName: 'jscadui_transform_babel', skipExisting: dev })
/**************************** BUILD JS THAT can change and watch if in dev mode *************/
await buildOne('src_bundle', outDir + '/build', 'bundle.worker.js', watch, { format: 'iife' })
await buildOne('src_bundle', outDir, 'bundle.fs-serviceworker.js', watch, { format: 'iife' })
/**************************** BUILD MAIN JS and watch if in dev mode *************/
const loader = {
'.example.js': 'text', // parse example files as text
'.js': 'tsx',
'.jsx': 'tsx',
}
await buildOne('.', outDir, 'main.js', watch, { format: 'esm', loader })
/**************************** LIVE SERVER if in dev mode *************/
// docs folder is too heavy for watch
if (dev)
liveServer.start({ root: outDir, port, open: false, ignore: outDir+'/docs' })
else
if(serveBuild) serve(port)
//*/