Skip to content

Commit

Permalink
feat: add import_map.json to init script (denoland#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreypetri authored Jul 23, 2022
1 parent a7d19f4 commit e3591ef
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,18 @@ blog({
});
```

Beware to use `.tsx` extension to this extent.

## Hosting with Deno Deploy

<TODO>
To deploy the project to the live internet, you can use
[Deno Deploy](https://deno.com/deploy):

1. Push your project to GitHub.
2. [Create a Deno Deploy project](https://dash.deno.com/new).
3. [Link](https://deno.com/deploy/docs/projects#enabling) the Deno Deploy
project to the `main.tsx` file in the root of the created repository.
4. The project will be deployed to a public `$project.deno.dev` subdomain.

## Self hosting

Expand Down
4 changes: 2 additions & 2 deletions blog_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
assert,
assertEquals,
assertStringIncludes,
} from "https://deno.land/std@0.145.0/testing/asserts.ts";
import { fromFileUrl, join } from "https://deno.land/std@0.145.0/path/mod.ts";
} from "https://deno.land/std@0.149.0/testing/asserts.ts";
import { fromFileUrl, join } from "https://deno.land/std@0.149.0/path/mod.ts";

const BLOG_URL = new URL("./testdata/main.js", import.meta.url).href;
const TESTDATA_PATH = fromFileUrl(new URL("./testdata/", import.meta.url));
Expand Down
8 changes: 4 additions & 4 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright 2022 the Deno authors. All rights reserved. MIT license.

export { serveDir } from "https://deno.land/std@0.145.0/http/file_server.ts";
export { walk } from "https://deno.land/std@0.145.0/fs/walk.ts";
export { serveDir } from "https://deno.land/std@0.149.0/http/file_server.ts";
export { walk } from "https://deno.land/std@0.149.0/fs/walk.ts";
export {
dirname,
fromFileUrl,
join,
relative,
} from "https://deno.land/std@0.145.0/path/mod.ts";
} from "https://deno.land/std@0.149.0/path/mod.ts";
export {
type ConnInfo,
serve,
} from "https://deno.land/std@0.145.0/http/mod.ts";
} from "https://deno.land/std@0.149.0/http/mod.ts";

export * as gfm from "https://deno.land/x/[email protected]/mod.ts";
export {
Expand Down
35 changes: 27 additions & 8 deletions init.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2022 the Deno authors. All rights reserved. MIT license.

import { join, resolve } from "https://deno.land/std@0.145.0/path/mod.ts";
import { join, resolve } from "https://deno.land/std@0.149.0/path/mod.ts";

const HELP = `deno_blog
Expand All @@ -19,10 +19,6 @@ Print this message:

const CURRENT_DATE = new Date();
const CURRENT_DATE_STRING = CURRENT_DATE.toISOString().slice(0, 10);
const MAIN_FILE_URL = new URL(
"./blog.tsx",
import.meta.url,
);

const FIRST_POST_CONTENTS = `---
title: Hello world!
Expand All @@ -32,11 +28,17 @@ publish_date: ${CURRENT_DATE_STRING}
This is my first blog post!
`;

const MAIN_CONTENTS = `import blog, { ga, redirects } from "${MAIN_FILE_URL}";
const MAIN_NAME = "main.tsx";
const MAIN_CONTENTS = `/** @jsx h */
import blog, { ga, redirects, h } from "blog";
blog({
title: "My Blog",
description: "This is my new blog.",
// header: <header>Your custom header</header>,
// section: <section>Your custom section</section>,
// footer: <footer>Your custom footer</footer>,
avatar: "https://deno-avatar.deno.dev/avatar/blog.svg",
avatarClass: "rounded-full",
author: "An author",
Expand All @@ -56,10 +58,20 @@ blog({
});
`;

const DENO_JSONC_NAME = "deno.jsonc";
const DENO_JSONC_CONTENTS = `{
"tasks": {
"dev": "deno run --allow-net --allow-read --allow-env --watch main.ts --dev",
"serve": "deno run --allow-net --allow-read --allow-env --no-check main.ts",
},
"importMap": "./import_map.json"
}
`;

const IMPORT_MAP_JSON_NAME = "import_map.json";
const IMPORT_MAP_JSON_CONTENTS = `{
"imports": {
"blog": "https://deno.land/x/[email protected]/blog.tsx"
}
}
`;
Expand Down Expand Up @@ -89,8 +101,15 @@ async function init(directory: string) {
join(directory, "posts/hello_world.md"),
FIRST_POST_CONTENTS,
);
await Deno.writeTextFile(join(directory, "main.ts"), MAIN_CONTENTS);
await Deno.writeTextFile(join(directory, "deno.jsonc"), DENO_JSONC_CONTENTS);
await Deno.writeTextFile(join(directory, MAIN_NAME), MAIN_CONTENTS);
await Deno.writeTextFile(
join(directory, DENO_JSONC_NAME),
DENO_JSONC_CONTENTS,
);
await Deno.writeTextFile(
join(directory, IMPORT_MAP_JSON_NAME),
IMPORT_MAP_JSON_CONTENTS,
);

console.log("Blog initialized, run `deno task dev` to get started.");
}
Expand Down

0 comments on commit e3591ef

Please sign in to comment.