From d50712ddac4e4d065f39896858a778995554f484 Mon Sep 17 00:00:00 2001 From: Alexandru Mariuti Date: Tue, 9 May 2023 10:29:32 +0200 Subject: [PATCH 1/4] [feat] exrc config extra arguments - add "target" argument to exrc config --- README.md | 2 ++ doc/flutter-tools.txt | 2 ++ lua/flutter-tools/commands.lua | 2 ++ lua/flutter-tools/config.lua | 1 + tests/commands_spec.lua | 10 ++++++++++ 5 files changed, 17 insertions(+) diff --git a/README.md b/README.md index c1f48ac5..e16380ea 100644 --- a/README.md +++ b/README.md @@ -311,6 +311,7 @@ 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 = { API_URL = 'https://dev.example.com/api', @@ -332,6 +333,7 @@ require('flutter-tools').setup_project({ name = 'Development', flavor = 'DevFlavor', device = 'pixel6pro', + target = 'lib/main_dev.dart', dart_defines = { ... } }) ``` diff --git a/doc/flutter-tools.txt b/doc/flutter-tools.txt index 90c31af1..490c18c9 100644 --- a/doc/flutter-tools.txt +++ b/doc/flutter-tools.txt @@ -350,6 +350,7 @@ _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 = { API_URL = 'https://dev.example.com/api', @@ -370,6 +371,7 @@ 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 = { ... } }) diff --git a/lua/flutter-tools/commands.lua b/lua/flutter-tools/commands.lua index 0a3a7a02..d9231d62 100644 --- a/lua/flutter-tools/commands.lua +++ b/lua/flutter-tools/commands.lua @@ -130,6 +130,7 @@ 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 dev_url = dev_tools.get_url() @@ -137,6 +138,7 @@ local function get_run_args(opts, conf) 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_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..77a6026b 100644 --- a/lua/flutter-tools/config.lua +++ b/lua/flutter-tools/config.lua @@ -6,6 +6,7 @@ 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} local M = {} diff --git a/tests/commands_spec.lua b/tests/commands_spec.lua index a41491d4..19832ce3 100644 --- a/tests/commands_spec.lua +++ b/tests/commands_spec.lua @@ -27,6 +27,16 @@ 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 multiple dart_defines", function() local args = commands.__get_run_args({}, { flavor = "Production", From b09a492c551f7ed0b13bb96b1b5b4b73315cd0bb Mon Sep 17 00:00:00 2001 From: Alexandru Mariuti Date: Wed, 10 May 2023 10:33:22 +0200 Subject: [PATCH 2/4] fix typo in readme --- README.md | 4 ++-- doc/flutter-tools.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e16380ea..c0d42f76 100644 --- a/README.md +++ b/README.md @@ -313,7 +313,7 @@ require('flutter-tools').setup_project({ 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, } @@ -334,7 +334,7 @@ require('flutter-tools').setup_project({ flavor = 'DevFlavor', device = 'pixel6pro', target = 'lib/main_dev.dart', - dart_defines = { ... } + dart_define = { ... } }) ``` diff --git a/doc/flutter-tools.txt b/doc/flutter-tools.txt index 490c18c9..1f6e8b08 100644 --- a/doc/flutter-tools.txt +++ b/doc/flutter-tools.txt @@ -352,7 +352,7 @@ _conceptually_ to vscode’s `launch.json` file. 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, } @@ -373,7 +373,7 @@ you can also specify the configuration as an object if there is only one flavor = 'DevFlavor', target = 'lib/main_dev.dart', device = 'pixel6pro', - dart_defines = { ... } + dart_define = { ... } }) < From 9e85cb3b16e1d4db32cbbc2e7af30961c112b403 Mon Sep 17 00:00:00 2001 From: Alexandru Mariuti Date: Wed, 10 May 2023 10:41:19 +0200 Subject: [PATCH 3/4] add dart define from file --- README.md | 6 ++++-- doc/flutter-tools.txt | 6 ++++-- lua/flutter-tools/commands.lua | 6 +++++- lua/flutter-tools/config.lua | 1 + tests/commands_spec.lua | 10 ++++++++++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c0d42f76..68fbfa9f 100644 --- a/README.md +++ b/README.md @@ -316,7 +316,8 @@ require('flutter-tools').setup_project({ 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', @@ -334,7 +335,8 @@ require('flutter-tools').setup_project({ flavor = 'DevFlavor', device = 'pixel6pro', target = 'lib/main_dev.dart', - dart_define = { ... } + dart_define = { ... }, + dart_define_from_file = 'config.json' }) ``` diff --git a/doc/flutter-tools.txt b/doc/flutter-tools.txt index 1f6e8b08..309ab36e 100644 --- a/doc/flutter-tools.txt +++ b/doc/flutter-tools.txt @@ -355,7 +355,8 @@ _conceptually_ to vscode’s `launch.json` file. 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', @@ -373,7 +374,8 @@ you can also specify the configuration as an object if there is only one flavor = 'DevFlavor', target = 'lib/main_dev.dart', device = 'pixel6pro', - dart_define = { ... } + dart_define = { ... }, + dart_define_from_file = 'config.json' }) < diff --git a/lua/flutter-tools/commands.lua b/lua/flutter-tools/commands.lua index d9231d62..554d0824 100644 --- a/lua/flutter-tools/commands.lua +++ b/lua/flutter-tools/commands.lua @@ -132,6 +132,7 @@ local function get_run_args(opts, conf) 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 @@ -139,9 +140,12 @@ local function get_run_args(opts, conf) 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) }) + vim.list_extend(args, { "c-dart-define", ("%s=%s"):format(key, value) }) end end if dev_url then vim.list_extend(args, { "--devtools-server-address", dev_url }) end diff --git a/lua/flutter-tools/config.lua b/lua/flutter-tools/config.lua index 77a6026b..c4d38fc9 100644 --- a/lua/flutter-tools/config.lua +++ b/lua/flutter-tools/config.lua @@ -8,6 +8,7 @@ local ui = lazy.require("flutter-tools.ui") ---@module "flutter-tools.ui" ---@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 19832ce3..de737a9b 100644 --- a/tests/commands_spec.lua +++ b/tests/commands_spec.lua @@ -37,6 +37,16 @@ describe("commands", function() 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", From e41438ec8fd35d9c423b7ce41e803ea64a3d07e3 Mon Sep 17 00:00:00 2001 From: Alexandru Mariuti Date: Wed, 10 May 2023 10:42:41 +0200 Subject: [PATCH 4/4] fix typo --- lua/flutter-tools/commands.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/flutter-tools/commands.lua b/lua/flutter-tools/commands.lua index 554d0824..f81685d1 100644 --- a/lua/flutter-tools/commands.lua +++ b/lua/flutter-tools/commands.lua @@ -145,7 +145,7 @@ local function get_run_args(opts, conf) end if dart_defines then for key, value in pairs(dart_defines) do - vim.list_extend(args, { "c-dart-define", ("%s=%s"):format(key, value) }) + vim.list_extend(args, { "--dart-define", ("%s=%s"):format(key, value) }) end end if dev_url then vim.list_extend(args, { "--devtools-server-address", dev_url }) end