-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add building to single executable
- add build script with compilation to binary - update tsconfig for correct compilation - bump bun version to 1.1.30 to make it work with compilation and running compiled version - add sourcemaps to compiled file to make errors & stacktraces point to their original locations instead of the transpiled location - add gh release action for building binary on push of version tag - fix some type errors - update readme to reflect build and distribution process - add required bun version to package.json and readme. - describe packages installation thoublesheeting for dynamic imports and bun --compile
- Loading branch information
1 parent
5ec826f
commit 9a8e493
Showing
9 changed files
with
289 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Build and Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- "v*.*.*" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Bun | ||
uses: oven-sh/setup-bun@v1 | ||
with: | ||
bun-version: latest | ||
|
||
- name: Install dependencies | ||
run: bun install | ||
|
||
- name: Build project | ||
run: bun run build | ||
|
||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: Release ${{ github.ref }} | ||
draft: false | ||
prerelease: false | ||
|
||
- name: Upload Release Asset | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./dist/ai-console-agent | ||
asset_name: ai-console-agent | ||
asset_content_type: application/octet-stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { spawnSync } from "child_process"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
const PROJECT_ROOT = process.cwd(); | ||
const DIST_DIR = path.join(PROJECT_ROOT, "dist"); | ||
const MAIN_FILE = path.join(PROJECT_ROOT, "src", "index.ts"); | ||
const OUTPUT_FILE = path.join(DIST_DIR, "ai-console-agent"); | ||
|
||
async function build() { | ||
checkBunVersion(); | ||
|
||
console.log("Starting build process..."); | ||
|
||
if (!fs.existsSync(DIST_DIR)) { | ||
fs.mkdirSync(DIST_DIR); | ||
} | ||
|
||
console.log("Installing dependencies..."); | ||
spawnSync("bun", ["install"], { stdio: "inherit" }); | ||
|
||
console.log("Compiling project..."); | ||
const result = spawnSync( | ||
"bun", | ||
[ | ||
"build", | ||
MAIN_FILE, | ||
"--compile", | ||
"--minify", | ||
"--outfile", | ||
OUTPUT_FILE, | ||
"--target", | ||
"bun", | ||
"--format", | ||
"esm", | ||
], | ||
{ stdio: "inherit" }, | ||
); | ||
|
||
if (result.status !== 0) { | ||
console.error("Compilation failed"); | ||
process.exit(1); | ||
} | ||
|
||
console.log(`Build completed successfully. Executable: ${OUTPUT_FILE}`); | ||
} | ||
|
||
function checkBunVersion() { | ||
const result = spawnSync("bun", ["--version"], { encoding: "utf8" }); | ||
const version = result.stdout.trim(); | ||
const requiredVersion = "1.1.30"; | ||
|
||
if (version !== requiredVersion) { | ||
console.warn( | ||
`Warning: This project is tested with Bun version ${requiredVersion}. You are using ${version}.`, | ||
); | ||
} | ||
} | ||
|
||
build().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
// Enable latest features | ||
"lib": ["ESNext", "DOM"], | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleDetection": "force", | ||
"jsx": "react-jsx", | ||
"allowJs": true, | ||
|
||
// Bundler mode | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"verbatimModuleSyntax": true, | ||
"noEmit": true, | ||
|
||
// Best practices | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"noFallthroughCasesInSwitch": true, | ||
|
||
// Some stricter flags (disabled by default) | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"noPropertyAccessFromIndexSignature": false | ||
} | ||
"noEmit": true, | ||
"allowJs": true, | ||
"ignoreDeprecations": "5.0", | ||
"isolatedModules": true, | ||
"resolveJsonModule": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": false, | ||
"strictNullChecks": true, | ||
"allowSyntheticDefaultImports": true | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules"] | ||
} |