Skip to content
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

[feat] exrc config extra arguments #258

Merged
merged 4 commits into from
May 10, 2023
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
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,13 @@ require('flutter-tools').setup_project({
{
name = 'Development', -- an arbitrary name that you provide so you can recognise this config
flavor = 'DevFlavor', -- your flavour
target = 'lib/main_dev.dart', -- your target
device = 'pixel6pro', -- the device ID, which you can get by running `flutter devices`
dart_defines = {
dart_define = {
API_URL = 'https://dev.example.com/api',
IS_DEV = true,
}
},
dart_define_from_file = 'config.json' -- the path to a JSON configuration file
},
{
name = 'Web',
Expand All @@ -332,7 +334,9 @@ require('flutter-tools').setup_project({
name = 'Development',
flavor = 'DevFlavor',
device = 'pixel6pro',
dart_defines = { ... }
target = 'lib/main_dev.dart',
dart_define = { ... },
dart_define_from_file = 'config.json'
})
```

Expand Down
10 changes: 7 additions & 3 deletions doc/flutter-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,13 @@ _conceptually_ to vscode’s `launch.json` file.
{
name = 'Development', -- an arbitrary name that you provide so you can recognise this config
flavor = 'DevFlavor', -- your flavour
target = 'lib/main_dev.dart', -- your target
device = 'pixel6pro', -- the device ID, which you can get by running `flutter devices`
dart_defines = {
dart_define = {
API_URL = 'https://dev.example.com/api',
IS_DEV = true,
}
},
dart_define_from_file = 'config.json' -- the path to a JSON configuration file
},
{
name = 'Web',
Expand All @@ -370,8 +372,10 @@ you can also specify the configuration as an object if there is only one
require('flutter-tools').setup_project({
name = 'Development',
flavor = 'DevFlavor',
target = 'lib/main_dev.dart',
device = 'pixel6pro',
dart_defines = { ... }
dart_define = { ... },
dart_define_from_file = 'config.json'
})
<

Expand Down
6 changes: 6 additions & 0 deletions lua/flutter-tools/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,19 @@ local function get_run_args(opts, conf)
local cmd_args = opts.args
local device = conf and conf.device or (opts.device and opts.device.id)
local flavor = conf and conf.flavor
local target = conf and conf.target
local dart_defines = conf and conf.dart_define
local dart_define_from_file = conf and conf.dart_define_from_file
local dev_url = dev_tools.get_url()

if not use_debugger_runner() then vim.list_extend(args, { "run" }) end
if not cmd_args and device then vim.list_extend(args, { "-d", device }) end
if cmd_args then vim.list_extend(args, cmd_args) end
if flavor then vim.list_extend(args, { "--flavor", flavor }) end
if target then vim.list_extend(args, { "--target", target }) end
if dart_define_from_file then
vim.list_extend(args, { "--dart-define-from-file", dart_define_from_file })
end
if dart_defines then
for key, value in pairs(dart_defines) do
vim.list_extend(args, { "--dart-define", ("%s=%s"):format(key, value) })
Expand Down
2 changes: 2 additions & 0 deletions lua/flutter-tools/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ local ui = lazy.require("flutter-tools.ui") ---@module "flutter-tools.ui"
---@field name string?
---@field device string
---@field flavor string
---@field target string
---@field dart_define {[string]: string}
---@field dart_define_from_file string

local M = {}

Expand Down
20 changes: 20 additions & 0 deletions tests/commands_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ describe("commands", function()
end
)

it(
"should add 'target' config option correctly",
function()
assert.are.same(
{ "run", "--target", "lib/main_dev.dart" },
commands.__get_run_args({}, { target = "lib/main_dev.dart" })
)
end
)

it(
"should add 'dart-define-from-file' config option correctly",
function()
assert.are.same(
{ "run", "--dart-define-from-file", "config.json" },
commands.__get_run_args({}, { dart_define_from_file = "config.json" })
)
end
)

it("should add multiple dart_defines", function()
local args = commands.__get_run_args({}, {
flavor = "Production",
Expand Down