tldraw/apps/vscode/extension/scripts/build.js

67 lines
1.3 KiB
JavaScript
Raw Normal View History

/* eslint-disable */
const fs = require('fs')
2022-09-01 08:49:01 +00:00
const pkg = require('../package.json')
const esbuild = require('esbuild')
2022-09-01 08:49:01 +00:00
const { exec } = require('child_process')
const { log: jslog } = console
2022-09-01 08:49:01 +00:00
async function copyEditor() {
if (fs.existsSync('./editor')) {
fs.rmSync('./editor', { recursive: true }, (e) => {
if (e) {
throw e
}
})
}
try {
exec(`cp -r ../editor/dist editor;`, (error, stdout, stderr) => {
if (error) {
throw new Error(error.message)
}
if (stderr && stderr.search('warning') !== 0) {
throw new Error(stderr)
}
})
} catch (e) {
jslog(`× ${pkg.name}: Build failed due to an error.`)
jslog(e)
}
}
async function main() {
2022-09-01 08:49:01 +00:00
await copyEditor()
if (fs.existsSync('./dist')) {
fs.rmSync('./dist', { recursive: true }, (e) => {
if (e) {
throw e
}
})
}
try {
esbuild.buildSync({
entryPoints: ['./src/extension.ts'],
outdir: 'dist/web',
minify: false,
bundle: true,
format: 'cjs',
target: 'es6',
2022-05-11 15:58:40 +00:00
platform: 'node',
define: {
'process.env.NODE_ENV': '"production"',
},
tsconfig: './tsconfig.json',
external: ['vscode'],
})
jslog(`Built package.`)
} catch (e) {
jslog(`× Build failed due to an error.`)
jslog(e)
}
}
main()