-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add "deno init" subcommand #15469
Conversation
cli/main.rs
Outdated
|
||
if (import.meta.main) { | ||
console.log("Add 2 + 3", add(2, 3)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should exclude the if statement, but keep the console.log? I think the if statement might confuse some beginners into thinking it's required (or not know what it is).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be also confusing if you run the test and then you get a console.log :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn’t that be obvious looking at the code? Most people are familiar with console.log, but import.meta.main is not something used often. Anyway, I don’t have strong feelings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the way the test runner works, it would show as test output, letting users know they get this sort of stuff managed for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the way the test runner works, it would show as test output, letting users know they get this sort of stuff managed for them.
Not really - since it would be a console.log at the top level of the file it would be printed just after "Check ..." like so:
Check file:///Users/ib/dev/deno/mod_test.ts
Add 2 + 3 5
running 1 test from ./mod_test.ts
addTest ... ok (4ms)
ok | 1 passed | 0 failed (24ms)
I'm fine with removing import.meta.main
conditional, or we could add a comment that explains its purpose or linking to the manual.
can we prompt to add tasks for esm.sh cli script? deno task npm:add [package...] # deno run -A https://esm.sh/v91
deno task npm:update [package...] # upgrade packages
deno task npm:remove[package...] # remove packages since i added the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of comments but LGTM
let mut file = std::fs::OpenOptions::new() | ||
.write(true) | ||
.create_new(true) | ||
.open(dir.join(filename)) | ||
.with_context(|| format!("Failed to create {} file", filename))?; | ||
file.write_all(content.as_bytes())?; | ||
Ok(()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::fs::write(dir.join(filename), content.as_bytes())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will overwrite existing files and doesn't provide useful error message if something goes wrong
This adds an
init
subcommand to that creates a project starter similar tocargo init
.Related to #12781 but takes entirely different approach.
This is just an MVP that enables developers to get started even quicker (similarly to
cargo init
); it boils down to 9 keystrokes to get going, without the need to manually create files from the terminal or IDE.Potential features that could be added should this be landed:
cc @bartlomieju