1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

feat(init): Generate deno.json by default (#16389)

Updates `deno init` subcommand to create a `deno.json` when initializing
a new project.

Slightly changes the output, to make it more readable.
This commit is contained in:
Bartek Iwańczuk 2022-12-08 06:34:28 +01:00 committed by GitHub
parent 44b2b950fd
commit a6b5d05311
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 2 deletions

View file

@ -28,8 +28,11 @@ mod init {
assert_contains!(stderr, "Project initialized");
assert!(!stderr.contains("cd"));
assert_contains!(stderr, "deno run main.ts");
assert_contains!(stderr, "deno task dev");
assert_contains!(stderr, "deno test");
assert!(cwd.join("deno.json").exists());
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
let output = deno_cmd
.current_dir(cwd)
@ -80,8 +83,11 @@ mod init {
assert_contains!(stderr, "Project initialized");
assert_contains!(stderr, "cd my_dir");
assert_contains!(stderr, "deno run main.ts");
assert_contains!(stderr, "deno task dev");
assert_contains!(stderr, "deno test");
assert!(cwd.join("my_dir/deno.json").exists());
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
let output = deno_cmd
.current_dir(cwd)
@ -131,6 +137,7 @@ mod init {
assert!(output.status.success());
let stdout = String::from_utf8(output.stdout).unwrap();
assert_eq!(stdout, "");
assert!(cwd.join("deno.json").exists());
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
let output = deno_cmd

View file

@ -1,6 +1,7 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
use crate::args::InitFlags;
use crate::colors;
use crate::deno_std;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
@ -40,12 +41,26 @@ pub async fn init_project(init_flags: InitFlags) -> Result<(), AnyError> {
.replace("{CURRENT_STD_URL}", deno_std::CURRENT_STD_URL.as_str());
create_file(&dir, "main_test.ts", &main_test_ts)?;
info!("✅ Project initialized");
info!("Run these commands to get started");
create_file(&dir, "deno.json", include_str!("./templates/deno.json"))?;
info!("✅ {}", colors::green("Project initialized"));
info!("");
info!("{}", colors::gray("Run these commands to get started"));
info!("");
if let Some(dir) = init_flags.dir {
info!(" cd {}", dir);
info!("");
}
info!(" {}", colors::gray("// Run the program"));
info!(" deno run main.ts");
info!("");
info!(
" {}",
colors::gray("// Run the program and watch for file changes")
);
info!(" deno task dev");
info!("");
info!(" {}", colors::gray("// Run the tests"));
info!(" deno test");
Ok(())
}

View file

@ -0,0 +1,5 @@
{
"tasks": {
"dev": "deno run --watch main.ts"
}
}