├── site ├── articles │ ├── backend │ │ └── README.md │ ├── basic │ │ ├── README.md │ │ └── install-and-hello-world.md │ ├── ecology │ │ └── README.md │ ├── frontend │ │ └── README.md │ ├── node │ │ ├── README.md │ │ └── javascript-toolchain-rome.md │ ├── ROADMAP.md │ ├── architecture │ │ ├── README.md │ │ ├── cli │ │ │ └── README.md │ │ └── standard │ │ │ └── README.md │ ├── document │ │ ├── README.md │ │ ├── deno-translation-dictionary.md │ │ ├── deno-cli-handbook.md │ │ └── deno-version-handbook.md │ ├── language │ │ └── README.md │ ├── official │ │ ├── README.md │ │ └── thoroughgoing-deno-in-2020.md │ ├── translation │ │ ├── README.md │ │ ├── why-deno-wrong.md │ │ ├── original-articles │ │ │ ├── why-deno-wrong.md │ │ │ └── from-node-to-deno.md │ │ ├── from-node-to-deno.md │ │ └── deno-chat-app.md │ ├── forward │ │ └── README.md │ ├── THANKS.md │ ├── weekly │ │ └── README.md │ └── README.md └── index.tsx ├── demos ├── ningowood │ └── v1-cli-example │ │ ├── tsconfig.json │ │ ├── lock.json │ │ ├── no-color.ts │ │ ├── import_map.json │ │ ├── main.ts │ │ ├── not-cache.ts │ │ ├── denon.config.ts │ │ └── REAMDE.md ├── scattered │ ├── node-to-deno │ │ ├── myCode.ts │ │ ├── app.sh │ │ ├── abc.ts │ │ ├── oak.ts │ │ ├── http.ts │ │ ├── deno-express.ts │ │ └── webview.ts │ ├── official-examples │ │ ├── testdata │ │ │ ├── cat │ │ │ │ ├── hello.txt │ │ │ │ └── world.txt │ │ │ └── catj │ │ │ │ ├── simple-array.json │ │ │ │ ├── simple-object.json │ │ │ │ ├── array.json │ │ │ │ └── object.json │ │ ├── tests │ │ │ ├── test_test.ts │ │ │ ├── welcome_test.ts │ │ │ ├── colors_test.ts │ │ │ ├── cat_test.ts │ │ │ ├── curl_test.ts │ │ │ ├── echo_server_test.ts │ │ │ ├── xeval_test.ts │ │ │ └── catj_test.ts │ │ ├── flags.ts │ │ ├── colors.ts │ │ ├── cat.ts │ │ ├── welcome.ts │ │ ├── echo_server.ts │ │ ├── curl.ts │ │ ├── test.ts │ │ ├── README.md │ │ ├── gist.ts │ │ ├── chat │ │ │ ├── server_test.ts │ │ │ ├── server.ts │ │ │ └── index.html │ │ ├── xeval.ts │ │ └── catj.ts │ └── the-deno-handbook │ │ └── app.ts └── README.md ├── mod.ts ├── favicon.png ├── .gitignore ├── deps.ts ├── .ningowood └── timeline.md ├── .all-contributorsrc ├── .github └── workflows │ └── gh-pages.yml ├── pagic.config.tsx └── README.md /site/articles/backend/README.md: -------------------------------------------------------------------------------- 1 | # 后端篇 -------------------------------------------------------------------------------- /site/articles/basic/README.md: -------------------------------------------------------------------------------- 1 | # 基础篇 -------------------------------------------------------------------------------- /site/articles/ecology/README.md: -------------------------------------------------------------------------------- 1 | # 生态篇 -------------------------------------------------------------------------------- /site/articles/frontend/README.md: -------------------------------------------------------------------------------- 1 | # 前端篇 -------------------------------------------------------------------------------- /site/articles/node/README.md: -------------------------------------------------------------------------------- 1 | # Node 篇 -------------------------------------------------------------------------------- /site/articles/ROADMAP.md: -------------------------------------------------------------------------------- 1 | # 未来规划 2 | 3 | -------------------------------------------------------------------------------- /site/articles/architecture/README.md: -------------------------------------------------------------------------------- 1 | # 架构篇 -------------------------------------------------------------------------------- /site/articles/document/README.md: -------------------------------------------------------------------------------- 1 | # 文档篇 2 | -------------------------------------------------------------------------------- /site/articles/language/README.md: -------------------------------------------------------------------------------- 1 | # 语言篇 2 | -------------------------------------------------------------------------------- /site/articles/official/README.md: -------------------------------------------------------------------------------- 1 | # 官方篇 2 | -------------------------------------------------------------------------------- /site/articles/translation/README.md: -------------------------------------------------------------------------------- 1 | # 翻译篇 -------------------------------------------------------------------------------- /demos/ningowood/v1-cli-example/tsconfig.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mod.ts: -------------------------------------------------------------------------------- 1 | export { React } from './deps.ts' 2 | -------------------------------------------------------------------------------- /site/articles/architecture/cli/README.md: -------------------------------------------------------------------------------- 1 | # CLI 篇 -------------------------------------------------------------------------------- /site/articles/architecture/standard/README.md: -------------------------------------------------------------------------------- 1 | # 标准库篇 -------------------------------------------------------------------------------- /demos/ningowood/v1-cli-example/lock.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | } -------------------------------------------------------------------------------- /demos/scattered/node-to-deno/myCode.ts: -------------------------------------------------------------------------------- 1 | console.log('Hello World!') -------------------------------------------------------------------------------- /demos/scattered/official-examples/testdata/cat/hello.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/testdata/cat/world.txt: -------------------------------------------------------------------------------- 1 | World 2 | -------------------------------------------------------------------------------- /demos/scattered/node-to-deno/app.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | deno run -A myCode.ts -------------------------------------------------------------------------------- /demos/scattered/official-examples/testdata/catj/simple-array.json: -------------------------------------------------------------------------------- 1 | [1, 2] 2 | -------------------------------------------------------------------------------- /favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justjavac/deno-tutorial/HEAD/favicon.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | public 2 | dist 3 | 4 | # ignore third part demos 5 | deno-playground 6 | -------------------------------------------------------------------------------- /demos/ningowood/v1-cli-example/no-color.ts: -------------------------------------------------------------------------------- 1 | console.log('Deno.noColor', Deno.noColor) 2 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/testdata/catj/simple-object.json: -------------------------------------------------------------------------------- 1 | { "message": "hello" } 2 | -------------------------------------------------------------------------------- /site/articles/forward/README.md: -------------------------------------------------------------------------------- 1 | # 转载篇 2 | 3 | 计划未来会寻找更多授权转载的文章到这里,方便直接阅读 -> 或许并不需要转载,放在 awesome-deno-cn 中就行。 4 | 5 | 待定。 6 | -------------------------------------------------------------------------------- /demos/ningowood/v1-cli-example/import_map.json: -------------------------------------------------------------------------------- 1 | { 2 | "imports": { 3 | "server": "https://deno.land/std/http/server.ts" 4 | } 5 | } -------------------------------------------------------------------------------- /demos/scattered/official-examples/testdata/catj/array.json: -------------------------------------------------------------------------------- 1 | [ 2 | "string", 3 | 100, 4 | { "key": "value", "array": ["foo", "bar"] } 5 | ] 6 | -------------------------------------------------------------------------------- /site/articles/THANKS.md: -------------------------------------------------------------------------------- 1 | # 感谢 2 | 3 | 目前感谢每一位在 [本仓库]() 和 [awesome-deno-cn 仓库]() 中贡献任何代码的伙伴,感谢每一个关注公众号、加入微信群聊一起聊天的伙伴,同时感谢每个路过围观的你们...愿 Deno 社区越来越强壮! 4 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/tests/test_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | import "../test.ts"; 3 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/testdata/catj/object.json: -------------------------------------------------------------------------------- 1 | { 2 | "string": "foobar", 3 | "number": 123, 4 | "array": [{ "message": "hello" }] 5 | } 6 | 7 | -------------------------------------------------------------------------------- /deps.ts: -------------------------------------------------------------------------------- 1 | // @deno-types="https://deno.land/x/pagic@v0.9.1/src/types/react/v16.13.1/react.d.ts" 2 | import React from 'https://dev.jspm.io/react@16.13.1' 3 | 4 | export { React } 5 | -------------------------------------------------------------------------------- /site/articles/weekly/README.md: -------------------------------------------------------------------------------- 1 | # 周报篇 2 | 3 | 计划从 2021 年开始,撰写 Deno 周报。但是——一个人的力量远远不够,届时会在群内招募小伙伴一起搞事情! 4 | 5 | * 一月 4 次周报,4 位伙伴分头搞。 6 | * 周报内容可以先从简单的搞起来,但一定要学会科学上网 -> Discord Deno 社区中内容很多。 7 | * 如果你提前看到了这篇内容,欢迎加群联系(微信号:hylerrix)! 8 | -------------------------------------------------------------------------------- /demos/scattered/node-to-deno/abc.ts: -------------------------------------------------------------------------------- 1 | import { Application } from "https://deno.land/x/abc/mod.ts"; 2 | 3 | const app = new Application(); 4 | 5 | app.static("/static", "assets"); 6 | 7 | app.get("/hello", (c) => "Hello!") 8 | .start({ port: 8080 }); -------------------------------------------------------------------------------- /demos/scattered/node-to-deno/oak.ts: -------------------------------------------------------------------------------- 1 | import { Application, } from "https://deno.land/x/oak/mod.ts"; 2 | 3 | const app = new Application(); 4 | 5 | app.use((ctx) => { 6 | ctx.response.body = "Hello World!"; 7 | }); 8 | 9 | await app.listen({ port: 8000 }); -------------------------------------------------------------------------------- /demos/scattered/official-examples/flags.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | const { args } = Deno; 3 | import { parse } from "../flags/mod.ts"; 4 | 5 | if (import.meta.main) { 6 | console.dir(parse(args)); 7 | } 8 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/colors.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | import { bgBlue, red, bold, italic } from "../fmt/colors.ts"; 3 | 4 | if (import.meta.main) { 5 | console.log(bgBlue(italic(red(bold("Hello world!"))))); 6 | } 7 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/cat.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | const filenames = Deno.args; 3 | for (const filename of filenames) { 4 | const file = await Deno.open(filename); 5 | await Deno.copy(file, Deno.stdout); 6 | file.close(); 7 | } 8 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/welcome.ts: -------------------------------------------------------------------------------- 1 | import { serve } from "https://deno.land/std/http/server.ts"; 2 | const s = serve({ port: 8000 }); 3 | console.log("Welcome to Deno 🦕"); 4 | console.log("http://localhost:8000/"); 5 | for await (const req of s) { 6 | req.respond({ body: "Hello World\n" }); 7 | } -------------------------------------------------------------------------------- /demos/ningowood/v1-cli-example/main.ts: -------------------------------------------------------------------------------- 1 | import { serve } from "https://deno.land/std/http/server.ts"; 2 | // 使用 importmap 时:import { serve } from "server" 3 | const s = serve({ port: 8000 }); 4 | console.log("Welcome to Deno 🦕"); 5 | console.log("http://localhost:8000/"); 6 | for await (const req of s) { 7 | req.respond({ body: "Hello World\n" }); 8 | } 9 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/echo_server.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | const hostname = "0.0.0.0"; 3 | const port = 8080; 4 | const listener = Deno.listen({ hostname, port }); 5 | console.log(`Listening on ${hostname}:${port}`); 6 | for await (const conn of listener) { 7 | Deno.copy(conn, conn); 8 | } 9 | -------------------------------------------------------------------------------- /demos/scattered/node-to-deno/http.ts: -------------------------------------------------------------------------------- 1 | import { ServerRequest } from "https://deno.land/std/http/server.ts"; 2 | import { getCookies } from "https://deno.land/std/http/cookie.ts"; 3 | 4 | let request = new ServerRequest(); 5 | request.headers = new Headers(); 6 | request.headers.set("Cookie", "full=of; tasty=chocolate"); 7 | 8 | const cookies = getCookies(request); 9 | console.log("cookies:", cookies); -------------------------------------------------------------------------------- /demos/scattered/official-examples/curl.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | const url_ = Deno.args[0]; 3 | const res = await fetch(url_); 4 | 5 | // TODO(ry) Re-enable streaming in this example. 6 | // Originally we did: await Deno.copy(res.body, Deno.stdout); 7 | // But maybe more JS-y would be: res.pipeTo(Deno.stdout); 8 | 9 | const body = new Uint8Array(await res.arrayBuffer()); 10 | await Deno.stdout.write(body); 11 | -------------------------------------------------------------------------------- /demos/scattered/node-to-deno/deno-express.ts: -------------------------------------------------------------------------------- 1 | import * as exp from "https://raw.githubusercontent.com/NMathar/deno-express/master/mod.ts"; 2 | 3 | const port = 3000; 4 | const app = new exp.App(); 5 | 6 | app.use(exp.static_("./public")); 7 | app.use(exp.bodyParser.json()); 8 | 9 | app.get("/api/todos", async (req, res) => { 10 | await res.json([{ name: "Buy some milk" }]); 11 | }); 12 | 13 | const server = await app.listen(port); 14 | console.log(`app listening on port ${server.port}`); -------------------------------------------------------------------------------- /demos/ningowood/v1-cli-example/not-cache.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, Area, App } from 'https://deno.land/x/alosaur@v0.21.1/mod.ts'; 2 | 3 | @Controller() // or specific path @Controller("/home") 4 | export class HomeController { 5 | @Get() // or specific path @Get("/hello") 6 | text() { 7 | return 'Hello world'; 8 | } 9 | } 10 | 11 | // Declare module 12 | @Area({ 13 | controllers: [HomeController], 14 | }) 15 | export class HomeArea {} 16 | 17 | // Create alosaur application 18 | const app = new App({ 19 | areas: [HomeArea], 20 | }); 21 | 22 | app.listen(); -------------------------------------------------------------------------------- /site/articles/document/deno-translation-dictionary.md: -------------------------------------------------------------------------------- 1 | # Deno 专业术语翻译手册 2 | 3 | * Incremental type checking 4 | * revamp 5 | * isolated Modules 6 | * test coverage:测试覆盖率 7 | * breaking changes:破坏性更改 8 | * incremental typechecking:增量类型检查 9 | * benchmark system 10 | * compilation pipeline 11 | * technical debt. 12 | * revamp:翻新 13 | * hard to reason about -> 难以理解 14 | * bundler 15 | 16 | ## Rust 17 | 18 | * Rust crate 19 | * bindings 20 | 21 | ## 短语 22 | 23 | * facilitated an interface between V8 engine and Rust code in Deno 24 | 25 | ## 其它 26 | 27 | * in a fortnight:两周内 28 | * Up to this point:与此之前 29 | * the dust had barely settled 30 | -------------------------------------------------------------------------------- /demos/ningowood/v1-cli-example/denon.config.ts: -------------------------------------------------------------------------------- 1 | import { DenonConfig } from "https://deno.land/x/denon/mod.ts" 2 | import { config as env } from "https://deno.land/x/dotenv/mod.ts" 3 | 4 | const config: DenonConfig = { 5 | scripts: { 6 | start: { 7 | cmd: "deno run main.ts", 8 | desc: "start from main.ts file", 9 | importmap: 'import_map.json', 10 | allow: [ "env", "net", "read", "write", "plugin" ], 11 | watch: false, 12 | unstable: true, 13 | }, 14 | }, 15 | logger: { 16 | debug: true, 17 | }, 18 | watcher: { 19 | exts: ["ts", "json", "ini"], 20 | skip: ["super_duper_secret/*"], 21 | }, 22 | env: env(), 23 | } 24 | 25 | export default config 26 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/tests/welcome_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | import { assertStrictEq } from "../../testing/asserts.ts"; 3 | 4 | Deno.test("[examples/welcome] print a welcome message", async () => { 5 | const decoder = new TextDecoder(); 6 | const process = Deno.run({ 7 | cmd: [Deno.execPath(), "run", "welcome.ts"], 8 | cwd: "examples", 9 | stdout: "piped", 10 | }); 11 | try { 12 | const output = await process.output(); 13 | const actual = decoder.decode(output).trim(); 14 | const expected = "Welcome to Deno 🦕"; 15 | assertStrictEq(actual, expected); 16 | } finally { 17 | process.close(); 18 | } 19 | }); 20 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/tests/colors_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | import { assertStrictEq } from "../../testing/asserts.ts"; 3 | 4 | Deno.test("[examples/colors] print a colored text", async () => { 5 | const decoder = new TextDecoder(); 6 | const process = Deno.run({ 7 | cmd: [Deno.execPath(), "run", "colors.ts"], 8 | cwd: "examples", 9 | stdout: "piped", 10 | }); 11 | try { 12 | const output = await process.output(); 13 | const actual = decoder.decode(output).trim(); 14 | const expected = "Hello world!"; 15 | assertStrictEq(actual, expected); 16 | } finally { 17 | process.close(); 18 | } 19 | }); 20 | -------------------------------------------------------------------------------- /demos/scattered/node-to-deno/webview.ts: -------------------------------------------------------------------------------- 1 | import { WebView } from "https://deno.land/x/webview/mod.ts"; 2 | 3 | const sharedOptions = { 4 | width: 400, 5 | height: 200, 6 | resizable: true, 7 | debug: true, 8 | frameless: false, 9 | }; 10 | 11 | const webview1 = new WebView({ 12 | title: "Multiple deno_webview example", 13 | url: `data:text/html, 14 | 15 | 16 |

1

17 | 18 | 19 | `, 20 | ...sharedOptions, 21 | }); 22 | 23 | const webview2 = new WebView({ 24 | title: "Multiple deno_webview example", 25 | url: `data:text/html, 26 | 27 | 28 |

2

29 | 30 | 31 | `, 32 | ...sharedOptions, 33 | }); 34 | 35 | await Promise.all([webview1.run(), webview2.run()]); -------------------------------------------------------------------------------- /demos/scattered/official-examples/tests/cat_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | import { assertStrictEq } from "../../testing/asserts.ts"; 3 | 4 | Deno.test("[examples/cat] print multiple files", async () => { 5 | const decoder = new TextDecoder(); 6 | const process = Deno.run({ 7 | cmd: [ 8 | Deno.execPath(), 9 | "run", 10 | "--allow-read", 11 | "cat.ts", 12 | "testdata/cat/hello.txt", 13 | "testdata/cat/world.txt", 14 | ], 15 | cwd: "examples", 16 | stdout: "piped", 17 | }); 18 | 19 | try { 20 | const output = await process.output(); 21 | const actual = decoder.decode(output).trim(); 22 | assertStrictEq(actual, "Hello\nWorld"); 23 | } finally { 24 | process.close(); 25 | } 26 | }); 27 | -------------------------------------------------------------------------------- /demos/ningowood/v1-cli-example/REAMDE.md: -------------------------------------------------------------------------------- 1 | # 从命令行指令实战 Deno 全特性(v1.x 最新版) 2 | 3 | 玩法如下: 4 | 5 | ``` 6 | $ deno run --allow-net --log-level debug main.ts 7 | $ deno install --unstable --allow-read --allow-write --allow-net https://deno.land/x/pagic/mod.ts 8 | $ deno run --allow-net main.ts --config tsconfig.json 9 | $ deno run --inspect-brk --allow-read --allow-net https://deno.land/std/http/file_server.ts 10 | $ deno run --v8-flags=--help main.ts 11 | $ denon start 12 | $ deno run --allow-net --cached-only not-cache.ts 13 | $ deno run --allow-net --seed 1 main.ts 14 | $ deno run --allow-net --reload main.ts 15 | $ deno run --allow-net --lock lock.json main.ts 16 | $ deno run --allow-net --no-check main.ts 17 | $ deno run --allow-net --no-remote main.ts 18 | $ deno run no-color.ts 19 | ``` 20 | 21 | ``` 22 | $ openssl x509 -in certificate.pem -text -noout 23 | ``` 24 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | const { run } = Deno; 3 | import { assertEquals } from "../testing/asserts.ts"; 4 | 5 | /** Example of how to do basic tests */ 6 | Deno.test("t1", function (): void { 7 | assertEquals("hello", "hello"); 8 | }); 9 | 10 | Deno.test("t2", function (): void { 11 | assertEquals("world", "world"); 12 | }); 13 | 14 | /** A more complicated test that runs a subprocess. */ 15 | Deno.test("catSmoke", async function (): Promise { 16 | const p = run({ 17 | cmd: [ 18 | Deno.execPath(), 19 | "run", 20 | "--allow-read", 21 | "examples/cat.ts", 22 | "README.md", 23 | ], 24 | stdout: "null", 25 | stderr: "null", 26 | }); 27 | const s = await p.status(); 28 | assertEquals(s.code, 0); 29 | p.close(); 30 | }); 31 | -------------------------------------------------------------------------------- /demos/README.md: -------------------------------------------------------------------------------- 1 | # Deno Demos 2 | 3 | 这里收录各大优良的 Deno Demo,来源不止于官方。 4 | 5 | * 社区 Demo:对于已经有 Github 仓库的 Demo 来说,这里不做收录,只做跳转链接; 6 | * 本目录下的 .gitignore 用来防止这些仓库被收录到本仓库,但是可以在 community 目录下 clone 过来学习; 7 | * 零散 Demo:对于零散的 Demo,直接收录在本目录下; 8 | * 钻研 Demo:本仓库的原创 Demo。 9 | 10 | ## NingoWood:自研 Demo 11 | 12 | * v1-cli-example:配合文章:《从命令行指令实战 Deno 全特性(v1.x 最新版)》 13 | 14 | ## Community:社区 Demo 15 | 16 | * [@aralroca/chat-with-deno-and-preact](https://github.com/aralroca/chat-with-deno-and-preact) 17 | * [@adeelibr/deno-playground](https://github.com/adeelibr/deno-playground) 18 | 19 | ## Scattered:零散 Demo 20 | 21 | * [The Deno Handbook: A TypeScript Runtime Tutorial with Code Examples Deno 入门手册](https://www.freecodecamp.org/news/the-deno-handbook/) 22 | * [Learn Deno: Chat app](https://aralroca.com/blog/learn-deno-chat-app) 23 | * [From Node to Deno](https://aralroca.com/blog/from-node-to-deno) -------------------------------------------------------------------------------- /demos/scattered/official-examples/tests/curl_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | import { serve } from "../../http/server.ts"; 3 | import { assertStrictEq } from "../../testing/asserts.ts"; 4 | 5 | Deno.test({ 6 | name: "[examples/curl] send a request to a specified url", 7 | fn: async () => { 8 | const server = serve({ port: 8081 }); 9 | const serverPromise = (async (): Promise => { 10 | for await (const req of server) { 11 | req.respond({ body: "Hello world" }); 12 | } 13 | })(); 14 | 15 | const decoder = new TextDecoder(); 16 | const process = Deno.run({ 17 | cmd: [ 18 | Deno.execPath(), 19 | "run", 20 | "--allow-net", 21 | "curl.ts", 22 | "http://localhost:8081", 23 | ], 24 | cwd: "examples", 25 | stdout: "piped", 26 | }); 27 | 28 | try { 29 | const output = await process.output(); 30 | const actual = decoder.decode(output).trim(); 31 | const expected = "Hello world"; 32 | 33 | assertStrictEq(actual, expected); 34 | } finally { 35 | server.close(); 36 | process.close(); 37 | await serverPromise; 38 | } 39 | }, 40 | }); 41 | -------------------------------------------------------------------------------- /.ningowood/timeline.md: -------------------------------------------------------------------------------- 1 | # 开发日志 2 | 3 | ## 20200924 4 | 5 | * 升级 Pagic v0.9.1 + Github Action 6 | * 重新整理骨架并填充其内容 7 | * 首页支持,二级目录支持 8 | * 彻底解决图床问题 -> 七牛云 9 | 10 | ## 20200805 11 | 12 | * 修复部分图片外链 403 问题 - 切换为七牛云图床 13 | 14 | ## 20200707 15 | 16 | * 更新 Pagic 为最新版本并使用其最新功能 17 | * 每个文件夹填充 README.md 来介绍 18 | * 增加赞助功能 19 | * 细化目录结构 -> 未来等 pagic 1.0 三级目录结构 20 | * 引入 [Gittalk](https://github.com/gitalk/gitalk) 21 | 22 | ## 20200616 23 | 24 | * 这两天合并了 [@justjavac](https://github.com/justjavac) 的若干个关于 Github Actions 的优化与更新: 25 | * 优化:部署方式; 26 | * 更新:根据不同环境分析不同 Google Analysis。 27 | 28 | ## 20200612 29 | 30 | * 随着 Pagic 主题修复 Bug,增加 Google Analytics 分析。 31 | 32 | ## 20200611 33 | 34 | * 向 [js.org](http://js.org/) 提交 PR 注册域名。 35 | * 花费了一些时间来思考 Github Pages 为什么 404,同时显示 `http://hylerrix.github.io/deno-tutorial/`。 36 | * 线上网站在 js.org 上部署成功:[deno-tutorial.js.org]( https://deno-tutorial.js.org)。 37 | 38 | ## 20200609 39 | 40 | > 遇到问题不要慌,放好心态,逐步排查,然后搜重点,实在不行社区里问问题。 41 | 42 | * 合并 (#4)[https://github.com/hylerrix/deno-tutorial/pull/4] PR。 43 | * 三小时尝试构建 pagic,解决了如下安装时的问题: 44 | * 报错 `error: Uncaught Http: error sending request for url (https://raw.githubusercontent.com/pillarjs/path-to-regexp/v6.1.0/src/index.ts): error trying to connect: tcp connect error: Connection refused (os error 61)`:给 `/etc/hosts` 文件增加 `199.232.68.133 raw.githubusercontent.com` 即可。 45 | * 报错 `TS2345 [ERROR]: Argument of type '{ type: string; }' is not assignable to parameter of type 'string'.`:升级 Deno 版本到 v1.0.5 即可。 46 | 47 | ## 20200513~20200531 48 | 49 | * 值 Deno v1.0 发布之际开源本电子书。 50 | * 这段时间创作了两篇文章并授权翻译了三篇文章。 -------------------------------------------------------------------------------- /demos/scattered/official-examples/tests/echo_server_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | import { assertStrictEq, assertNotEquals } from "../../testing/asserts.ts"; 3 | import { BufReader, ReadLineResult } from "../../io/bufio.ts"; 4 | 5 | Deno.test("[examples/echo_server]", async () => { 6 | const encoder = new TextEncoder(); 7 | const decoder = new TextDecoder(); 8 | const process = Deno.run({ 9 | cmd: [Deno.execPath(), "run", "--allow-net", "echo_server.ts"], 10 | cwd: "examples", 11 | stdout: "piped", 12 | }); 13 | 14 | let conn: Deno.Conn | undefined; 15 | try { 16 | const processReader = new BufReader(process.stdout!); 17 | const message = await processReader.readLine(); 18 | 19 | assertNotEquals(message, null); 20 | assertStrictEq( 21 | decoder.decode((message as ReadLineResult).line).trim(), 22 | "Listening on 0.0.0.0:8080" 23 | ); 24 | 25 | conn = await Deno.connect({ hostname: "127.0.0.1", port: 8080 }); 26 | const connReader = new BufReader(conn); 27 | 28 | await conn.write(encoder.encode("Hello echo_server\n")); 29 | const result = await connReader.readLine(); 30 | 31 | assertNotEquals(result, null); 32 | 33 | const actualResponse = decoder 34 | .decode((result as ReadLineResult).line) 35 | .trim(); 36 | const expectedResponse = "Hello echo_server"; 37 | 38 | assertStrictEq(actualResponse, expectedResponse); 39 | } finally { 40 | conn?.close(); 41 | process.stdout!.close(); 42 | process.close(); 43 | } 44 | }); 45 | -------------------------------------------------------------------------------- /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ 3 | "README.md" 4 | ], 5 | "imageSize": 100, 6 | "commit": false, 7 | "contributors": [ 8 | { 9 | "login": "hylerrix", 10 | "name": "hylerrix", 11 | "avatar_url": "https://avatars1.githubusercontent.com/u/19285461?v=4", 12 | "profile": "https://github.com/hylerrix", 13 | "contributions": [ 14 | "ideas" 15 | ] 16 | }, 17 | { 18 | "login": "imcoddy", 19 | "name": "imcoddy", 20 | "avatar_url": "https://avatars0.githubusercontent.com/u/622780?v=4", 21 | "profile": "https://www.twitter.com/imcoddy", 22 | "contributions": [ 23 | "doc" 24 | ] 25 | }, 26 | { 27 | "login": "xcatliu", 28 | "name": "xcatliu", 29 | "avatar_url": "https://avatars0.githubusercontent.com/u/5453359?v=4", 30 | "profile": "http://xcatliu.com/", 31 | "contributions": [ 32 | "infra" 33 | ] 34 | }, 35 | { 36 | "login": "justjavac", 37 | "name": "迷渡", 38 | "avatar_url": "https://avatars1.githubusercontent.com/u/359395?v=4", 39 | "profile": "https://twitter.com/justjavac", 40 | "contributions": [ 41 | "infra" 42 | ] 43 | }, 44 | { 45 | "login": "AlvinMi", 46 | "name": "YuHui", 47 | "avatar_url": "https://avatars3.githubusercontent.com/u/21032217?v=4", 48 | "profile": "https://github.com/AlvinMi", 49 | "contributions": [ 50 | "doc" 51 | ] 52 | } 53 | ], 54 | "contributorsPerLine": 7, 55 | "projectName": "deno-tutorial", 56 | "projectOwner": "hylerrix", 57 | "repoType": "github", 58 | "repoHost": "https://github.com", 59 | "skipCi": true, 60 | "commitConvention": "none" 61 | } 62 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/README.md: -------------------------------------------------------------------------------- 1 | # Deno example programs 2 | 3 | This module contains small scripts that demonstrate use of Deno and its standard 4 | module. 5 | 6 | You can run these examples using just their URL or install the example as an 7 | executable script which references the URL. (Think of installing as creating a 8 | bookmark to a program.) 9 | 10 | ### A TCP echo server 11 | 12 | ```shell 13 | deno run --allow-net https://deno.land/std/examples/echo_server.ts 14 | ``` 15 | 16 | Or 17 | 18 | ```shell 19 | deno install --allow-net https://deno.land/std/examples/echo_server.ts 20 | ``` 21 | 22 | ### cat - print file to standard output 23 | 24 | ```shell 25 | deno install --allow-read -n deno_cat https://deno.land/std/examples/cat.ts 26 | deno_cat file.txt 27 | ``` 28 | 29 | ### catj - print flattened JSON to standard output 30 | 31 | A very useful command by Soheil Rashidi ported to Deno. 32 | 33 | ```shell 34 | deno install --allow-read https://deno.land/std/examples/catj.ts 35 | catj example.json 36 | catj file1.json file2.json 37 | echo example.json | catj - 38 | ``` 39 | 40 | ### curl - print the contents of a url to standard output 41 | 42 | ```shell 43 | deno run --allow-net=deno.land https://deno.land/std/examples/curl.ts https://deno.land/ 44 | ``` 45 | 46 | ### gist - easily create and upload Gists 47 | 48 | ``` 49 | export GIST_TOKEN=ABC # Generate at https://github.com/settings/tokens 50 | deno install --allow-net --allow-env https://deno.land/std/examples/gist.ts 51 | gist --title "Example gist 1" script.ts 52 | gist --t "Example gist 2" script2.ts 53 | ``` 54 | 55 | ### chat - WebSocket chat server and browser client 56 | 57 | ```shell 58 | deno run --allow-net --allow-read https://deno.land/std/examples/chat/server.ts 59 | ``` 60 | 61 | Open http://localhost:8080 on the browser. 62 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/tests/xeval_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | import { xeval } from "../xeval.ts"; 3 | import { stringsReader } from "../../io/util.ts"; 4 | import { decode, encode } from "../../encoding/utf8.ts"; 5 | import { 6 | assertEquals, 7 | assertStrContains, 8 | assert, 9 | } from "../../testing/asserts.ts"; 10 | const { execPath, run } = Deno; 11 | 12 | Deno.test("xevalSuccess", async function (): Promise { 13 | const chunks: string[] = []; 14 | await xeval(stringsReader("a\nb\nc"), ($): number => chunks.push($)); 15 | assertEquals(chunks, ["a", "b", "c"]); 16 | }); 17 | 18 | Deno.test("xevalDelimiter", async function (): Promise { 19 | const chunks: string[] = []; 20 | await xeval(stringsReader("!MADMADAMADAM!"), ($): number => chunks.push($), { 21 | delimiter: "MADAM", 22 | }); 23 | assertEquals(chunks, ["!MAD", "ADAM!"]); 24 | }); 25 | 26 | const xevalPath = "examples/xeval.ts"; 27 | 28 | Deno.test({ 29 | name: "xevalCliReplvar", 30 | fn: async function (): Promise { 31 | const p = run({ 32 | cmd: [execPath(), "run", xevalPath, "--replvar=abc", "console.log(abc)"], 33 | stdin: "piped", 34 | stdout: "piped", 35 | stderr: "null", 36 | }); 37 | assert(p.stdin != null); 38 | await p.stdin.write(encode("hello")); 39 | p.stdin.close(); 40 | assertEquals(await p.status(), { code: 0, success: true }); 41 | assertEquals(decode(await p.output()).trimEnd(), "hello"); 42 | p.close(); 43 | }, 44 | }); 45 | 46 | Deno.test("xevalCliSyntaxError", async function (): Promise { 47 | const p = run({ 48 | cmd: [execPath(), "run", xevalPath, "("], 49 | stdin: "null", 50 | stdout: "piped", 51 | stderr: "piped", 52 | }); 53 | assertEquals(await p.status(), { code: 1, success: false }); 54 | assertEquals(decode(await p.output()), ""); 55 | assertStrContains(decode(await p.stderrOutput()), "Uncaught SyntaxError"); 56 | p.close(); 57 | }); 58 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/gist.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno --allow-net --allow-env 2 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 3 | // A program to post files to gist.github.com. Use the following to install it: 4 | // deno install -f --allow-env --allow-read --allow-net=api.github.com https://deno.land/std/examples/gist.ts 5 | import { parse } from "../flags/mod.ts"; 6 | 7 | function pathBase(p: string): string { 8 | const parts = p.split("/"); 9 | return parts[parts.length - 1]; 10 | } 11 | 12 | const token = Deno.env.get("GIST_TOKEN"); 13 | if (!token) { 14 | console.error("GIST_TOKEN environmental variable not set."); 15 | console.error("Get a token here: https://github.com/settings/tokens"); 16 | Deno.exit(1); 17 | } 18 | 19 | const parsedArgs = parse(Deno.args); 20 | 21 | if (parsedArgs._.length === 0) { 22 | console.error( 23 | "Usage: gist.ts --allow-env --allow-net [-t|--title Example] some_file " + 24 | "[next_file]" 25 | ); 26 | Deno.exit(1); 27 | } 28 | 29 | const files: Record = {}; 30 | for (const filename of parsedArgs._) { 31 | const base = pathBase(filename as string); 32 | const content = await Deno.readFile(filename as string); 33 | const contentStr = new TextDecoder().decode(content); 34 | files[base] = { content: contentStr }; 35 | } 36 | 37 | const content = { 38 | description: parsedArgs.title || parsedArgs.t || "Example", 39 | public: false, 40 | files: files, 41 | }; 42 | const body = JSON.stringify(content); 43 | 44 | const res = await fetch("https://api.github.com/gists", { 45 | method: "POST", 46 | headers: [ 47 | ["Content-Type", "application/json"], 48 | ["User-Agent", "Deno-Gist"], 49 | ["Authorization", `token ${token}`], 50 | ], 51 | body, 52 | }); 53 | 54 | if (res.ok) { 55 | const resObj = await res.json(); 56 | console.log("Success"); 57 | console.log(resObj["html_url"]); 58 | } else { 59 | const err = await res.text(); 60 | console.error("Failure to POST", err); 61 | } 62 | -------------------------------------------------------------------------------- /.github/workflows/gh-pages.yml: -------------------------------------------------------------------------------- 1 | name: gh-pages 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build-and-deploy: 7 | runs-on: ubuntu-18.04 8 | steps: 9 | - uses: actions/checkout@v2 10 | 11 | - name: Build 12 | env: 13 | DENO_INSTALL: /home/runner/.deno 14 | run: | 15 | curl -fsSL https://deno.land/x/install/install.sh | sh 16 | export PATH="$DENO_INSTALL/bin:$PATH" 17 | deno --version 18 | deno upgrade --version 1.6.3 19 | deno install --unstable --allow-env --allow-read --allow-write --allow-net --allow-run -n pagic https://deno.land/x/pagic@v1.1.1/mod.ts 20 | pagic build 21 | 22 | - name: Deploy 23 | if: github.ref == 'refs/heads/main' && github.event_name == 'push' 24 | env: 25 | GA_ID: UA-169223577-1 26 | uses: peaceiris/actions-gh-pages@v3 27 | with: 28 | github_token: ${{ secrets.GITHUB_TOKEN }} 29 | publish_dir: ./dist 30 | cname: deno-tutorial.js.org 31 | 32 | build-and-deploy-cn: 33 | runs-on: ubuntu-18.04 34 | steps: 35 | - uses: actions/checkout@v2 36 | 37 | - name: Build CN 38 | if: github.ref == 'refs/heads/master' && github.event_name == 'push' 39 | env: 40 | DENO_INSTALL: /home/runner/.deno 41 | run: | 42 | curl -fsSL https://deno.land/x/install/install.sh | sh 43 | export PATH="$DENO_INSTALL/bin:$PATH" 44 | deno --version 45 | deno upgrade --version 1.6.3 46 | deno install --unstable --allow-env --allow-read --allow-write --allow-net --allow-run -n pagic https://deno.land/x/pagic@v1.1.1/mod.ts 47 | pagic build 48 | 49 | - name: Deploy CN 50 | if: github.ref == 'refs/heads/master' && github.event_name == 'push' 51 | env: 52 | GA_ID: UA-169621310-1 53 | uses: peaceiris/actions-gh-pages@v3 54 | with: 55 | deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} 56 | external_repository: denocn/deno-tutorial 57 | publish_dir: ./dist 58 | cname: tutorial.deno.js.cn 59 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/chat/server_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | import { assert, assertEquals } from "../../testing/asserts.ts"; 3 | import { TextProtoReader } from "../../textproto/mod.ts"; 4 | import { BufReader } from "../../io/bufio.ts"; 5 | import { connectWebSocket, WebSocket } from "../../ws/mod.ts"; 6 | import { delay } from "../../async/delay.ts"; 7 | 8 | const { test } = Deno; 9 | 10 | async function startServer(): Promise { 11 | const server = Deno.run({ 12 | // TODO(lucacasonato): remove unstable once possible 13 | cmd: [ 14 | Deno.execPath(), 15 | "run", 16 | "--allow-net", 17 | "--allow-read", 18 | "--unstable", 19 | "server.ts", 20 | ], 21 | cwd: "examples/chat", 22 | stdout: "piped", 23 | }); 24 | try { 25 | assert(server.stdout != null); 26 | const r = new TextProtoReader(new BufReader(server.stdout)); 27 | const s = await r.readLine(); 28 | assert(s !== null && s.includes("chat server starting")); 29 | } catch (err) { 30 | server.stdout!.close(); 31 | server.close(); 32 | } 33 | 34 | return server; 35 | } 36 | 37 | test({ 38 | name: "[examples/chat] GET / should serve html", 39 | async fn() { 40 | const server = await startServer(); 41 | try { 42 | const resp = await fetch("http://127.0.0.1:8080/"); 43 | assertEquals(resp.status, 200); 44 | assertEquals(resp.headers.get("content-type"), "text/html"); 45 | const html = await resp.text(); 46 | assert(html.includes("ws chat example"), "body is ok"); 47 | } finally { 48 | server.close(); 49 | server.stdout!.close(); 50 | } 51 | await delay(10); 52 | }, 53 | }); 54 | 55 | test({ 56 | name: "[examples/chat] GET /ws should upgrade conn to ws", 57 | async fn() { 58 | const server = await startServer(); 59 | let ws: WebSocket | undefined; 60 | try { 61 | ws = await connectWebSocket("http://127.0.0.1:8080/ws"); 62 | const it = ws[Symbol.asyncIterator](); 63 | 64 | assertEquals((await it.next()).value, "Connected: [1]"); 65 | ws.send("Hello"); 66 | assertEquals((await it.next()).value, "[1]: Hello"); 67 | } finally { 68 | server.close(); 69 | server.stdout!.close(); 70 | ws!.conn.close(); 71 | } 72 | }, 73 | }); 74 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/chat/server.ts: -------------------------------------------------------------------------------- 1 | import { listenAndServe } from "../../http/server.ts"; 2 | import { 3 | acceptWebSocket, 4 | acceptable, 5 | WebSocket, 6 | isWebSocketCloseEvent, 7 | } from "../../ws/mod.ts"; 8 | import { fromFileUrl } from "../../path/mod.ts"; 9 | 10 | const clients = new Map(); 11 | let clientId = 0; 12 | function dispatch(msg: string): void { 13 | for (const client of clients.values()) { 14 | client.send(msg); 15 | } 16 | } 17 | async function wsHandler(ws: WebSocket): Promise { 18 | const id = ++clientId; 19 | clients.set(id, ws); 20 | dispatch(`Connected: [${id}]`); 21 | for await (const msg of ws) { 22 | console.log(`msg:${id}`, msg); 23 | if (typeof msg === "string") { 24 | dispatch(`[${id}]: ${msg}`); 25 | } else if (isWebSocketCloseEvent(msg)) { 26 | clients.delete(id); 27 | dispatch(`Closed: [${id}]`); 28 | break; 29 | } 30 | } 31 | } 32 | 33 | listenAndServe({ port: 8080 }, async (req) => { 34 | if (req.method === "GET" && req.url === "/") { 35 | //Serve with hack 36 | const u = new URL("./index.html", import.meta.url); 37 | if (u.protocol.startsWith("http")) { 38 | // server launched by deno run http(s)://.../server.ts, 39 | fetch(u.href).then(async (resp) => { 40 | const body = new Uint8Array(await resp.arrayBuffer()); 41 | return req.respond({ 42 | status: resp.status, 43 | headers: new Headers({ 44 | "content-type": "text/html", 45 | }), 46 | body, 47 | }); 48 | }); 49 | } else { 50 | // server launched by deno run ./server.ts 51 | const file = await Deno.open(fromFileUrl(u)); 52 | req.respond({ 53 | status: 200, 54 | headers: new Headers({ 55 | "content-type": "text/html", 56 | }), 57 | body: file, 58 | }); 59 | } 60 | } 61 | if (req.method === "GET" && req.url === "/favicon.ico") { 62 | req.respond({ 63 | status: 302, 64 | headers: new Headers({ 65 | location: "https://deno.land/favicon.ico", 66 | }), 67 | }); 68 | } 69 | if (req.method === "GET" && req.url === "/ws") { 70 | if (acceptable(req)) { 71 | acceptWebSocket({ 72 | conn: req.conn, 73 | bufReader: req.r, 74 | bufWriter: req.w, 75 | headers: req.headers, 76 | }).then(wsHandler); 77 | } 78 | } 79 | }); 80 | console.log("chat server starting on :8080...."); 81 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/tests/catj_test.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 | import { assertStrictEq } from "../../testing/asserts.ts"; 3 | 4 | Deno.test("[examples/catj] print an array", async () => { 5 | const decoder = new TextDecoder(); 6 | const process = catj("testdata/catj/array.json"); 7 | try { 8 | const output = await process.output(); 9 | const actual = decoder.decode(output).trim(); 10 | const expected = [ 11 | '.[0] = "string"', 12 | ".[1] = 100", 13 | '.[2].key = "value"', 14 | '.[2].array[0] = "foo"', 15 | '.[2].array[1] = "bar"', 16 | ].join("\n"); 17 | 18 | assertStrictEq(actual, expected); 19 | } finally { 20 | process.stdin!.close(); 21 | process.close(); 22 | } 23 | }); 24 | 25 | Deno.test("[examples/catj] print an object", async () => { 26 | const decoder = new TextDecoder(); 27 | const process = catj("testdata/catj/object.json"); 28 | try { 29 | const output = await process.output(); 30 | const actual = decoder.decode(output).trim(); 31 | const expected = [ 32 | '.string = "foobar"', 33 | ".number = 123", 34 | '.array[0].message = "hello"', 35 | ].join("\n"); 36 | 37 | assertStrictEq(actual, expected); 38 | } finally { 39 | process.stdin!.close(); 40 | process.close(); 41 | } 42 | }); 43 | 44 | Deno.test("[examples/catj] print multiple files", async () => { 45 | const decoder = new TextDecoder(); 46 | const process = catj( 47 | "testdata/catj/simple-object.json", 48 | "testdata/catj/simple-array.json" 49 | ); 50 | try { 51 | const output = await process.output(); 52 | const actual = decoder.decode(output).trim(); 53 | const expected = ['.message = "hello"', ".[0] = 1", ".[1] = 2"].join("\n"); 54 | 55 | assertStrictEq(actual, expected); 56 | } finally { 57 | process.stdin!.close(); 58 | process.close(); 59 | } 60 | }); 61 | 62 | Deno.test("[examples/catj] read from stdin", async () => { 63 | const decoder = new TextDecoder(); 64 | const process = catj("-"); 65 | const input = `{ "foo": "bar" }`; 66 | try { 67 | await process.stdin!.write(new TextEncoder().encode(input)); 68 | process.stdin!.close(); 69 | const output = await process.output(); 70 | const actual = decoder.decode(output).trim(); 71 | 72 | assertStrictEq(actual, '.foo = "bar"'); 73 | } finally { 74 | process.close(); 75 | } 76 | }); 77 | 78 | function catj(...files: string[]): Deno.Process { 79 | return Deno.run({ 80 | cmd: [Deno.execPath(), "run", "--allow-read", "catj.ts", ...files], 81 | cwd: "examples", 82 | stdin: "piped", 83 | stdout: "piped", 84 | env: { NO_COLOR: "true" }, 85 | }); 86 | } 87 | -------------------------------------------------------------------------------- /demos/scattered/official-examples/chat/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ws chat example 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 |
13 |
14 |
    15 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /demos/scattered/the-deno-handbook/app.ts: -------------------------------------------------------------------------------- 1 | import { Application, Router } from "https://deno.land/x/oak/mod.ts"; 2 | 3 | const env = Deno.env.toObject(); 4 | const PORT = env.PORT || 4000; 5 | const HOST = env.HOST || "127.0.0.1"; 6 | 7 | interface Dog { 8 | name: string; 9 | age: number; 10 | } 11 | 12 | let dogs: Array = [ 13 | { 14 | name: "Roger", 15 | age: 8, 16 | }, 17 | { 18 | name: "Syd", 19 | age: 7, 20 | }, 21 | ]; 22 | 23 | export const getDogs = ({ response }: { response: any }) => { 24 | response.body = dogs; 25 | }; 26 | 27 | export const getDog = ({ 28 | params, 29 | response, 30 | }: { 31 | params: { 32 | name: string; 33 | }; 34 | response: any; 35 | }) => { 36 | const dog = dogs.filter((dog) => dog.name === params.name); 37 | if (dog.length) { 38 | response.status = 200; 39 | response.body = dog[0]; 40 | return; 41 | } 42 | 43 | response.status = 400; 44 | response.body = { msg: `Cannot find dog ${params.name}` }; 45 | }; 46 | 47 | export const addDog = async ({ 48 | request, 49 | response, 50 | }: { 51 | request: any; 52 | response: any; 53 | }) => { 54 | const body = await request.body(); 55 | const { name, age }: { name: string; age: number } = body.value; 56 | dogs.push({ 57 | name: name, 58 | age: age, 59 | }); 60 | 61 | response.body = { msg: "OK" }; 62 | response.status = 200; 63 | }; 64 | 65 | export const updateDog = async ({ 66 | params, 67 | request, 68 | response, 69 | }: { 70 | params: { 71 | name: string; 72 | }; 73 | request: any; 74 | response: any; 75 | }) => { 76 | const temp = dogs.filter((existingDog) => existingDog.name === params.name); 77 | const body = await request.body(); 78 | const { age }: { age: number } = body.value; 79 | 80 | if (temp.length) { 81 | temp[0].age = age; 82 | response.status = 200; 83 | response.body = { msg: "OK" }; 84 | return; 85 | } 86 | 87 | response.status = 400; 88 | response.body = { msg: `Cannot find dog ${params.name}` }; 89 | }; 90 | 91 | export const removeDog = ({ 92 | params, 93 | response, 94 | }: { 95 | params: { 96 | name: string; 97 | }; 98 | response: any; 99 | }) => { 100 | const lengthBefore = dogs.length; 101 | dogs = dogs.filter((dog) => dog.name !== params.name); 102 | 103 | if (dogs.length === lengthBefore) { 104 | response.status = 400; 105 | response.body = { msg: `Cannot find dog ${params.name}` }; 106 | return; 107 | } 108 | 109 | response.body = { msg: "OK" }; 110 | response.status = 200; 111 | }; 112 | 113 | const router = new Router(); 114 | router 115 | .get("/dogs", getDogs) 116 | .get("/dogs/:name", getDog) 117 | .post("/dogs", addDog) 118 | .put("/dogs/:name", updateDog) 119 | .delete("/dogs/:name", removeDog); 120 | 121 | const app = new Application(); 122 | 123 | app.use(router.routes()); 124 | app.use(router.allowedMethods()); 125 | 126 | console.log(`Listening on port ${PORT}...`); 127 | 128 | await app.listen(`${HOST}:${PORT}`); -------------------------------------------------------------------------------- /demos/scattered/official-examples/xeval.ts: -------------------------------------------------------------------------------- 1 | import { parse } from "../flags/mod.ts"; 2 | import { readStringDelim } from "../io/bufio.ts"; 3 | const { args, exit, stdin } = Deno; 4 | type Reader = Deno.Reader; 5 | 6 | /* eslint-disable-next-line max-len */ 7 | // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction. 8 | const AsyncFunction = Object.getPrototypeOf(async function (): Promise {}) 9 | .constructor; 10 | 11 | /* eslint-disable max-len */ 12 | const HELP_MSG = `xeval 13 | 14 | Run a script for each new-line or otherwise delimited chunk of standard input. 15 | 16 | Print all the usernames in /etc/passwd: 17 | cat /etc/passwd | deno run -A https://deno.land/std/examples/xeval.ts "a = $.split(':'); if (a) console.log(a[0])" 18 | 19 | A complicated way to print the current git branch: 20 | git branch | deno run -A https://deno.land/std/examples/xeval.ts -I 'line' "if (line.startsWith('*')) console.log(line.slice(2))" 21 | 22 | Demonstrates breaking the input up by space delimiter instead of by lines: 23 | cat LICENSE | deno run -A https://deno.land/std/examples/xeval.ts -d " " "if ($ === 'MIT') console.log('MIT licensed')", 24 | 25 | USAGE: 26 | deno run -A https://deno.land/std/examples/xeval.ts [OPTIONS] 27 | OPTIONS: 28 | -d, --delim Set delimiter, defaults to newline 29 | -I, --replvar Set variable name to be used in eval, defaults to $ 30 | ARGS: 31 | `; 32 | /* eslint-enable max-len */ 33 | 34 | export type XevalFunc = (v: string) => void; 35 | 36 | export interface XevalOptions { 37 | delimiter?: string; 38 | } 39 | 40 | const DEFAULT_DELIMITER = "\n"; 41 | 42 | export async function xeval( 43 | reader: Reader, 44 | xevalFunc: XevalFunc, 45 | { delimiter = DEFAULT_DELIMITER }: XevalOptions = {} 46 | ): Promise { 47 | for await (const chunk of readStringDelim(reader, delimiter)) { 48 | // Ignore empty chunks. 49 | if (chunk.length > 0) { 50 | await xevalFunc(chunk); 51 | } 52 | } 53 | } 54 | 55 | async function main(): Promise { 56 | const parsedArgs = parse(args, { 57 | boolean: ["help"], 58 | string: ["delim", "replvar"], 59 | alias: { 60 | delim: ["d"], 61 | replvar: ["I"], 62 | help: ["h"], 63 | }, 64 | default: { 65 | delim: DEFAULT_DELIMITER, 66 | replvar: "$", 67 | }, 68 | }); 69 | if (parsedArgs._.length != 1) { 70 | console.error(HELP_MSG); 71 | console.log(parsedArgs._); 72 | exit(1); 73 | } 74 | if (parsedArgs.help) { 75 | return console.log(HELP_MSG); 76 | } 77 | 78 | const delimiter = parsedArgs.delim; 79 | const replVar = parsedArgs.replvar; 80 | const code = parsedArgs._[0]; 81 | 82 | // new AsyncFunction()'s error message for this particular case isn't great. 83 | if (!replVar.match(/^[_$A-z][_$A-z0-9]*$/)) { 84 | console.error(`Bad replvar identifier: "${replVar}"`); 85 | exit(1); 86 | } 87 | 88 | const xEvalFunc = new AsyncFunction(replVar, code); 89 | 90 | await xeval(stdin, xEvalFunc, { delimiter }); 91 | } 92 | 93 | if (import.meta.main) { 94 | main(); 95 | } 96 | -------------------------------------------------------------------------------- /site/index.tsx: -------------------------------------------------------------------------------- 1 | import { React } from '../mod.ts' 2 | 3 | const style = ` 4 | h2 { 5 | font-weight: normal; 6 | } 7 | .main_article { 8 | width: 960px; 9 | max-width: 960px; 10 | padding-bottom: 0; 11 | } 12 | .cards { 13 | display: flex; 14 | justify-content: center; 15 | margin: 3rem -1rem 0 -1rem; 16 | padding-top: 1rem; 17 | border-top: 1px solid var(--color-border); 18 | } 19 | .cards > div { 20 | width: 20rem; 21 | padding: 0 1rem; 22 | } 23 | .cards ul { 24 | color: var(--color-text-muted); 25 | } 26 | .btn { 27 | padding: 0.5rem 1rem; 28 | margin: 0 1rem; 29 | border: 0; 30 | cursor: pointer; 31 | opacity: 0.9; 32 | font-size: 14px; 33 | text-decoration: none; 34 | background-color: var(--color-border); 35 | color: var(--color-text); 36 | } 37 | .btn:hover { 38 | text-decoration: none; 39 | } 40 | .btn-primary { 41 | background-color: var(--color-primary); 42 | color: var(--color-background); 43 | } 44 | .btn:hover { 45 | opacity: 1; 46 | } 47 | @media screen and (max-width: 44rem) { 48 | h2 { 49 | text-align: center; 50 | } 51 | .cards { 52 | flex-direction: column; 53 | } 54 | .cards > div { 55 | width: 100vw; 56 | } 57 | .cards ul { 58 | text-align: center; 59 | padding-left: 0; 60 | list-style: none; 61 | } 62 | pre { 63 | margin-left: -1rem; 64 | margin-right: -1rem; 65 | } 66 | } 67 | ` 68 | 69 | const IndexPage = () => ( 70 | <> 71 |
    72 |