Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def deps do
end
```

Once installed, change your config (i.e. `config/config.exs` or
`config/runtime.exs`) to pick your bun version of choice:
Once installed, change your `config/config.exs` to pick your
bun version of choice:

```elixir
config :bun, version: "1.1.22"
Expand Down
24 changes: 19 additions & 5 deletions lib/mix/tasks/bun.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,33 @@ defmodule Mix.Tasks.Bun do
If bun is not installed, it is automatically downloaded.
Note the arguments given to this task will be appended
to any configured arguments.

## Options

* `--runtime-config` - load the runtime configuration
before executing command

Note flags to control this Mix task must be given before the
profile:

$ mix bun --runtime-config default assets/js/app.js

"""

@shortdoc "Invokes bun with the profile and args"
use Mix.Task

@requirements ["app.config"]
use Mix.Task

@impl true
def run(args) do
switches = []
{_opts, remaining_args} = OptionParser.parse_head!(args, switches: switches)
switches = [runtime_config: :boolean]
{opts, remaining_args} = OptionParser.parse_head!(args, switches: switches)

Application.ensure_all_started(:bun)
if opts[:runtime_config] do
Mix.Task.run("app.config")
else
Application.ensure_all_started(:bun)
end

Mix.Task.reenable("bun")
install_and_run(remaining_args)
Expand Down
8 changes: 6 additions & 2 deletions lib/mix/tasks/bun.install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ defmodule Mix.Tasks.Bun.Install do

## Options

* `--runtime-config` - load the runtime configuration
before executing command

* `--if-missing` - install only if the given version
does not exist
"""

@shortdoc "Installs bun under _build"
use Mix.Task

@requirements ["app.config"]

@impl true
def run(args) do
valid_options = [runtime_config: :boolean, if_missing: :boolean]

case OptionParser.parse_head!(args, strict: valid_options) do
{opts, []} ->
if opts[:runtime_config], do: Mix.Task.run("app.config")

if opts[:if_missing] && latest_version?() do
:ok
else
Expand All @@ -40,6 +43,7 @@ defmodule Mix.Tasks.Bun.Install do
Invalid arguments to bun.install, expected one of:

mix bun.install
mix bun.install --runtime-config
mix bun.install --if-missing
""")
end
Expand Down