summaryrefslogtreecommitdiff
path: root/cli/config_file.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/config_file.rs')
-rw-r--r--cli/config_file.rs28
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]