Skip to content

Commit 094fbc4

Browse files
authored
build: use esbuild (#277)
1 parent 8f62648 commit 094fbc4

14 files changed

+698
-43
lines changed

.github/workflows/build-check.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,11 @@ jobs:
176176
run: wasm-pack build rs --target=nodejs --out-dir ../src/wasm
177177

178178
- name: Build node
179+
env:
180+
CLIENTID: ${{ secrets.OAUTHCLIENTID }}
181+
CLIENTSECRET: ${{ secrets.OAUTHCLIENTSECRET }}
179182
run: |
180-
npm run package -- --env CLIENTID="${{ secrets.OAUTHCLIENTID }}" --env CLIENTSECRET="${{ secrets.OAUTHCLIENTSECRET }}" && npm run ui:package
183+
npm run package
181184
182185
- name: Version
183186
id: version

.github/workflows/marketplace-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484

8585
- name: Build node
8686
run: |
87-
npm run package -- --env CLIENTID="${{ secrets.OAUTHCLIENTID }}" --env CLIENTSECRET="${{ secrets.OAUTHCLIENTSECRET }}" && npm run ui:package
87+
npm run package -- --env CLIENTID="${{ secrets.OAUTHCLIENTID }}" --env CLIENTSECRET="${{ secrets.OAUTHCLIENTSECRET }}"
8888
8989
- name: Version
9090
id: version

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"eslint.debug": false,
3535
"eslint.format.enable": true,
3636
"editor.codeActionsOnSave": {
37-
"source.fixAll": true
37+
"source.fixAll": "explicit"
3838
},
3939
"jest.jestCommandLine": "npm run test:unit -- "
4040
}

build.mjs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import esbuild from 'esbuild'
2+
import copyPluginPkg from '@sprout2000/esbuild-copy-plugin'
3+
import { lessLoader } from 'esbuild-plugin-less'
4+
import * as process from 'node:process'
5+
6+
const { copyPlugin } = copyPluginPkg
7+
const isProduction = !process.argv.includes('--development')
8+
const OUT_DIR = 'dist'
9+
10+
const defaultOptions = {
11+
format: 'cjs',
12+
resolveExtensions: ['.ts', '.js', '.mjs', '.tsx'],
13+
bundle: true,
14+
sourcemap: !isProduction,
15+
minify: isProduction,
16+
platform: 'node',
17+
outdir: OUT_DIR,
18+
}
19+
20+
async function buildExtension() {
21+
const options = {
22+
...defaultOptions,
23+
entryPoints: ['./src/extension.ts'],
24+
external: ['vscode', '@mapbox/node-pre-gyp', 'sequelize'],
25+
define: {
26+
// eslint-disable-next-line @typescript-eslint/naming-convention
27+
CNBLOGS_CLIENTID: JSON.stringify(process.env.CLIENTID),
28+
// eslint-disable-next-line @typescript-eslint/naming-convention
29+
CNBLOGS_CLIENTSECRET: JSON.stringify(process.env.CLIENTSECRET),
30+
},
31+
plugins: [
32+
copyPlugin({
33+
src: 'src/assets',
34+
dest: `${OUT_DIR}/assets`,
35+
}),
36+
copyPlugin({
37+
src: 'node_modules/@mapbox/node-pre-gyp',
38+
dest: `${OUT_DIR}/node_modules/@mapbox/node-pre-gyp`,
39+
}),
40+
copyPlugin({
41+
src: 'node_modules/sequelize',
42+
dest: `${OUT_DIR}/node_modules/sequelize`,
43+
}),
44+
copyPlugin({
45+
src: 'node_modules/@fluentui/font-icons-mdl2/fonts/',
46+
dest: `${OUT_DIR}/assets/fonts`,
47+
}),
48+
copyPlugin({
49+
src: 'src/wasm/rs_bg.wasm',
50+
dest: `${OUT_DIR}/rs_bg.wasm`,
51+
}),
52+
],
53+
}
54+
55+
await esbuild.build(options)
56+
}
57+
58+
async function buildUI(...apps) {
59+
const srcPath = './ui/'
60+
const outPath = `${OUT_DIR}/assets/ui/`
61+
for (const app of apps) {
62+
const options = {
63+
...defaultOptions,
64+
define: {
65+
'process.env.NODE_ENV': JSON.stringify('production'),
66+
},
67+
entryPoints: [`${srcPath}${app}/index.tsx`],
68+
outdir: `${outPath}${app}`,
69+
plugins: [
70+
lessLoader(),
71+
copyPlugin({
72+
src: `${srcPath}${app}/index.html`,
73+
dest: `${outPath}${app}/index.html`,
74+
}),
75+
],
76+
}
77+
78+
await esbuild.build(options)
79+
}
80+
}
81+
82+
try {
83+
await Promise.allSettled([buildExtension(), buildUI('ing', 'post-cfg')])
84+
} catch (ex) {
85+
// eslint-disable-next-line no-undef
86+
console.error(ex)
87+
process.exit(1)
88+
}

0 commit comments

Comments
 (0)