|
| 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