diff --git a/package.json b/package.json index 13082ac6bdd..246fe0b0b37 100644 --- a/package.json +++ b/package.json @@ -14,12 +14,13 @@ ], "scripts": { "prebuild": "./packages/xlucene-parser/scripts/generate-engine.js", - "build": "tsc --build --verbose && yarn workspace teraslice-cli build --verbose", + "build": "tsc --build --verbose", + "postbuild": "yarn workspace teraslice-cli postbuild", "build:cleanup": "./scripts/build-cleanup.sh", "build:doctor": "./scripts/build-doctor.sh", "build:fix": "echo '[DEPRECATED], use yarn run build:doctor instead'", "build:pkg": "./scripts/build-pkg.sh", - "build:watch": "yarn run build --watch", + "build:watch": "yarn run build --watch & yarn workspace teraslice-cli node build.js --watch", "bump": "ts-scripts bump", "docker:limit": "./scripts/docker-limit-check.sh", "docker:listImages": "ts-scripts images list", diff --git a/packages/teraslice-cli/build.js b/packages/teraslice-cli/build.js index af18f76ec1b..813585bb9ff 100644 --- a/packages/teraslice-cli/build.js +++ b/packages/teraslice-cli/build.js @@ -1,6 +1,6 @@ import esbuild from 'esbuild'; -esbuild.build({ +const ctx = await esbuild.context({ entryPoints: ['src/command.ts'], outfile: 'dist/src/ts-cli.js', // Output file path bundle: true, @@ -9,4 +9,11 @@ esbuild.build({ sourcemap: false, inject: ['cjs-to-esm.js'], external: ['esbuild'] -}).catch(() => process.exit(1)); +}); + +if (process.argv.includes('--watch')) { + await ctx.watch(); +} else { + await ctx.rebuild(); + ctx.dispose(); +} diff --git a/packages/teraslice-cli/package.json b/packages/teraslice-cli/package.json index b760bdb04ca..0595bdb0f76 100644 --- a/packages/teraslice-cli/package.json +++ b/packages/teraslice-cli/package.json @@ -31,8 +31,9 @@ "dist/src/helpers/esm-shims.js" ], "scripts": { - "build": "tsc --build && node build.js", - "build:watch": "tsc --build --watch", + "build": "tsc --build", + "postbuild": "node build.js", + "build:watch": "tsc --build --watch & node build.js --watch", "test": "ts-scripts test . --", "test:debug": "ts-scripts test --debug . --", "test:watch": "ts-scripts test --watch . --"