-
Notifications
You must be signed in to change notification settings - Fork 15.7k
feat: add Node.js entry point and build script #18324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env bun | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| import fs from "fs" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import path from "path" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { fileURLToPath } from "url" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const __filename = fileURLToPath(import.meta.url) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const __dirname = path.dirname(__filename) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const dir = path.resolve(__dirname, "..") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| process.chdir(dir) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Load migrations from migration directories | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const migrationDirs = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| await fs.promises.readdir(path.join(dir, "migration"), { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| withFileTypes: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| .filter((entry) => entry.isDirectory() && /^\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}/.test(entry.name)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| .map((entry) => entry.name) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| .sort() | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const migrations = await Promise.all( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| migrationDirs.map(async (name) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const file = path.join(dir, "migration", name, "migration.sql") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const sql = await Bun.file(file).text() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const match = /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/.exec(name) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const timestamp = match | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ? Date.UTC( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Number(match[1]), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Number(match[2]) - 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Number(match[3]), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Number(match[4]), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Number(match[5]), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Number(match[6]), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| : 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return { sql, timestamp, name } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(`Loaded ${migrations.length} migrations`) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| await Bun.build({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| target: "node", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| entrypoints: ["./src/node.ts"], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| outdir: "./dist", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| format: "esm", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| external: ["jsonc-parser"], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| define: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| OPENCODE_MIGRATIONS: JSON.stringify(migrations), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+44
to
+53
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("Build complete") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { Server } from "./server/server" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the repo's style guide, multi-word camelCase names should be avoided in favour of single-word alternatives, and variables used only once should be inlined to reduce total variable count.
migrationDirs→dirs__filenameis used exactly once (to produce__dirname);__dirnameis also used exactly once (to producedir). Both can be collapsed:Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!