diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-03-11 02:56:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-10 20:56:14 -0500 |
commit | 47f22777beb7eb98a07fa56fbbd40ab5c1fa231e (patch) | |
tree | aa61065f07df3c1ad5a28326801720593a8cdd19 /cli/config_file.rs | |
parent | 808f797633ba82c0e9198481ddd742284a03cb9c (diff) |
feat: "deno task" subcommand (#13725)
Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'cli/config_file.rs')
-rw-r--r-- | cli/config_file.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/cli/config_file.rs b/cli/config_file.rs index 9d5ae84a0..a2bdbe1d3 100644 --- a/cli/config_file.rs +++ b/cli/config_file.rs @@ -530,6 +530,7 @@ pub struct ConfigFileJson { pub import_map: Option<String>, pub lint: Option<Value>, pub fmt: Option<Value>, + pub tasks: Option<Value>, } #[derive(Clone, Debug)] @@ -648,6 +649,19 @@ impl ConfigFile { } } + pub fn to_tasks_config( + &self, + ) -> Result<Option<BTreeMap<String, String>>, AnyError> { + if let Some(config) = self.json.tasks.clone() { + let tasks_config: BTreeMap<String, String> = + serde_json::from_value(config) + .context("Failed to parse \"tasks\" configuration")?; + Ok(Some(tasks_config)) + } else { + Ok(None) + } + } + /// If the configuration file contains "extra" modules (like TypeScript /// `"types"`) options, return them as imports to be added to a module graph. pub fn to_maybe_imports(&self) -> MaybeImportsResult { @@ -784,6 +798,10 @@ mod tests { "singleQuote": true, "proseWrap": "preserve" } + }, + "tasks": { + "build": "deno run --allow-read --allow-write build.ts", + "server": "deno run --allow-net --allow-read server.ts" } }"#; let config_dir = ModuleSpecifier::parse("file:///deno/").unwrap(); @@ -841,6 +859,16 @@ mod tests { assert_eq!(fmt_config.options.line_width, Some(80)); assert_eq!(fmt_config.options.indent_width, Some(4)); assert_eq!(fmt_config.options.single_quote, Some(true)); + + let tasks_config = config_file.to_tasks_config().unwrap().unwrap(); + assert_eq!( + tasks_config["build"], + "deno run --allow-read --allow-write build.ts", + ); + assert_eq!( + tasks_config["server"], + "deno run --allow-net --allow-read server.ts" + ); } #[test] |