diff --git a/README.md b/README.md index c1f48ac5..68fbfa9f 100644 --- a/README.md +++ b/README.md @@ -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', @@ -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' }) ``` diff --git a/doc/flutter-tools.txt b/doc/flutter-tools.txt index 90c31af1..309ab36e 100644 --- a/doc/flutter-tools.txt +++ b/doc/flutter-tools.txt @@ -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', @@ -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' }) < diff --git a/lua/flutter-tools/commands.lua b/lua/flutter-tools/commands.lua index 0a3a7a02..f81685d1 100644 --- a/lua/flutter-tools/commands.lua +++ b/lua/flutter-tools/commands.lua @@ -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) }) diff --git a/lua/flutter-tools/config.lua b/lua/flutter-tools/config.lua index faf8edb0..c4d38fc9 100644 --- a/lua/flutter-tools/config.lua +++ b/lua/flutter-tools/config.lua @@ -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 = {} diff --git a/tests/commands_spec.lua b/tests/commands_spec.lua index a41491d4..de737a9b 100644 --- a/tests/commands_spec.lua +++ b/tests/commands_spec.lua @@ -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",