-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdenoinit.ts
48 lines (40 loc) · 1.01 KB
/
denoinit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//deno install -f --allow-write -n denoinit denoinit.ts
if (import.meta.main) {
const mainContent =
`import * as path from "https://deno.land/std/path/mod.ts";
console.log(path.normalizeGlob("/*"));
const port = parseInt(Deno.env.get("PORT") || "8080");
const body = new TextEncoder().encode("Hello World");
console.info(\`Listen on :\${port}...\`);
for await (const conn of Deno.listen({ port })) {
(async () => {
for await (const { respondWith } of Deno.serveHttp(conn)) {
respondWith(new Response(body));
}
})();
}
`;
await Deno.writeFile("main.ts", new TextEncoder().encode(mainContent));
const vscodeSettingContent = `
// .vscode/settings.json
{
"deno.enable": true,
"deno.unstable": true,
"deno.lint": true,
"deno": {
"suggest": {
"imports": {
"hosts": {
"https://deno.land": true
}
}
}
}
}
`;
await Deno.mkdir(".vscode");
await Deno.writeFile(
".vscode/settings.json",
new TextEncoder().encode(vscodeSettingContent),
);
}