From 1ffbd561642d05a05e18ada764d50581dea779ef Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Sat, 20 Aug 2022 01:37:05 +0200 Subject: feat: add "deno init" subcommand (#15469) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds an init subcommand to that creates a project starter similar to cargo init. ``` $ deno init my_project Project initialized Run these commands to get started: cd my_project deno run main.ts deno run main_test.ts $ deno run main.ts Add 2 + 3 5 $ cat main.ts export function add(a: number, b: number): number { return a + b; } if (import.meta.main) { console.log("Add 2 + 3", add(2, 3)); } $ cat main_test.ts import { assertEquals } from "https://deno.land/std@0.151.0/testing/asserts.ts"; import { add } from "./main.ts"; Deno.test(function addTest() { assertEquals(add(2, 3), 5); }); ``` Co-authored-by: Bartek IwaƄczuk --- cli/tools/init/templates/main.ts | 8 ++++++++ cli/tools/init/templates/main_test.ts | 6 ++++++ 2 files changed, 14 insertions(+) create mode 100644 cli/tools/init/templates/main.ts create mode 100644 cli/tools/init/templates/main_test.ts (limited to 'cli/tools/init/templates') diff --git a/cli/tools/init/templates/main.ts b/cli/tools/init/templates/main.ts new file mode 100644 index 000000000..be043e97c --- /dev/null +++ b/cli/tools/init/templates/main.ts @@ -0,0 +1,8 @@ +export function add(a: number, b: number): number { + return a + b; +} + +// Learn more at https://deno.land/manual/examples/module_metadata#concepts +if (import.meta.main) { + console.log("Add 2 + 3 =", add(2, 3)); +} diff --git a/cli/tools/init/templates/main_test.ts b/cli/tools/init/templates/main_test.ts new file mode 100644 index 000000000..5f60b571c --- /dev/null +++ b/cli/tools/init/templates/main_test.ts @@ -0,0 +1,6 @@ +import { assertEquals } from "{CURRENT_STD_URL}testing/asserts.ts"; +import { add } from "./main.ts"; + +Deno.test(function addTest() { + assertEquals(add(2, 3), 5); +}); -- cgit v1.2.3