-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Bun support * Tweak README * Tweak README for clarity
- Loading branch information
1 parent
a6964f3
commit e308e76
Showing
8 changed files
with
118 additions
and
26 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
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,2 @@ | ||
web: env RUBY_DEBUG_OPEN=true bin/rails server | ||
js: bun run build --watch |
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,37 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
|
||
const config = { | ||
sourcemap: "external", | ||
entrypoints: ["app/javascript/application.js"], | ||
outdir: path.join(process.cwd(), "app/assets/builds"), | ||
}; | ||
|
||
const build = async (config) => { | ||
const result = await Bun.build(config); | ||
|
||
if (!result.success) { | ||
if (process.argv.includes('--watch')) { | ||
console.error("Build failed"); | ||
for (const message of result.logs) { | ||
console.error(message); | ||
} | ||
return; | ||
} else { | ||
throw new AggregateError(result.logs, "Build failed"); | ||
} | ||
} | ||
}; | ||
|
||
(async () => { | ||
await build(config); | ||
|
||
if (process.argv.includes('--watch')) { | ||
fs.watch(path.join(process.cwd(), "app/javascript"), { recursive: true }, (eventType, filename) => { | ||
console.log(`File changed: ${filename}. Rebuilding...`); | ||
build(config); | ||
}); | ||
} else { | ||
process.exit(0); | ||
} | ||
})(); |
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,20 @@ | ||
require 'json' | ||
|
||
if Rails.root.join("Procfile.dev").exist? | ||
append_to_file "Procfile.dev", "js: bun build --watch\n" | ||
else | ||
say "Add default Procfile.dev" | ||
copy_file "#{__dir__}/Procfile.dev", "Procfile.dev" | ||
|
||
say "Ensure foreman is installed" | ||
run "gem install foreman" | ||
end | ||
|
||
say "Add default bun.config.js" | ||
copy_file "#{__dir__}/bun.config.js", "bun.config.js" | ||
|
||
say "Add build script to package.json" | ||
package_json = JSON.parse(File.read("package.json")) | ||
package_json["scripts"] ||= {} | ||
package_json["scripts"]["build"] = "bun bun.config.js" | ||
File.write("package.json", JSON.pretty_generate(package_json)) |
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,9 @@ | ||
if Rails.root.join("Procfile.dev").exist? | ||
append_to_file "Procfile.dev", "js: yarn build --watch\n" | ||
else | ||
say "Add default Procfile.dev" | ||
copy_file "#{__dir__}/Procfile.dev", "Procfile.dev" | ||
|
||
say "Ensure foreman is installed" | ||
run "gem install foreman" | ||
end |
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