dotenv option (#740)
added dotenv option to read environment variables files --------- Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
@@ -6,23 +6,23 @@ description: |
|
|||||||
|
|
||||||
The `/about` route created on the last page is pretty static. It does not matter
|
The `/about` route created on the last page is pretty static. It does not matter
|
||||||
what query or path parameters are passed to the route, it will always render the
|
what query or path parameters are passed to the route, it will always render the
|
||||||
same page. Let's create a `/:name` that will render a page with a greeting
|
same page. Let's create a `/:name` that will render a page with a greeting that
|
||||||
that contains the name passed in the path.
|
contains the name passed in the path.
|
||||||
|
|
||||||
Before diving in, a quick refresher on "dynamic" routes. Dynamic routes don't
|
Before diving in, a quick refresher on "dynamic" routes. Dynamic routes don't
|
||||||
just match a single static path, but rather a whole bunch of different paths
|
just match a single static path, but rather a whole bunch of different paths
|
||||||
based on a pattern. For example, the `/:name` route will match the paths
|
based on a pattern. For example, the `/:name` route will match the paths `/Luca`
|
||||||
`/Luca` and `/John`, but not `/Luca/John`.
|
and `/John`, but not `/Luca/John`.
|
||||||
|
|
||||||
Fresh supports dynamic routes out of the box through file system routing. To
|
Fresh supports dynamic routes out of the box through file system routing. To
|
||||||
make any path segment dynamic, just put square brackets around that segment in
|
make any path segment dynamic, just put square brackets around that segment in
|
||||||
the file name. For example the `/:name` route maps to the file name
|
the file name. For example the `/:name` route maps to the file name
|
||||||
`routes/[name].tsx`.
|
`routes/[name].tsx`.
|
||||||
|
|
||||||
Just like the static `/about` route, the dynamic `/:name` route will
|
Just like the static `/about` route, the dynamic `/:name` route will render a
|
||||||
render a page. The module must once again expose a component as a default
|
page. The module must once again expose a component as a default export. This
|
||||||
export. This time the component will receive the matched path segment properties
|
time the component will receive the matched path segment properties as arguments
|
||||||
as arguments in its `props` object though.
|
in its `props` object though.
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
// routes/[name].tsx
|
// routes/[name].tsx
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ description: |
|
|||||||
---
|
---
|
||||||
|
|
||||||
The next step after scaffolding out a new project, is to actually start it. To
|
The next step after scaffolding out a new project, is to actually start it. To
|
||||||
do this you can just `deno task start`.
|
do this you can just `deno task start`. Environment variables will be
|
||||||
|
automatically read from `.env`.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ deno task start
|
$ deno task start
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { join, parse, resolve } from "./src/dev/deps.ts";
|
import { join, parse, resolve } from "./src/dev/deps.ts";
|
||||||
import { error } from "./src/dev/error.ts";
|
import { error } from "./src/dev/error.ts";
|
||||||
import { collect, ensureMinDenoVersion, generate } from "./src/dev/mod.ts";
|
import { collect, ensureMinDenoVersion, generate } from "./src/dev/mod.ts";
|
||||||
import { freshImports, twindImports } from "./src/dev/imports.ts";
|
import {
|
||||||
|
dotenvImports,
|
||||||
|
freshImports,
|
||||||
|
twindImports,
|
||||||
|
} from "./src/dev/imports.ts";
|
||||||
|
|
||||||
ensureMinDenoVersion();
|
ensureMinDenoVersion();
|
||||||
|
|
||||||
@@ -84,9 +88,23 @@ if (useVSCode) {
|
|||||||
await Deno.mkdir(join(resolvedDirectory, ".vscode"), { recursive: true });
|
await Deno.mkdir(join(resolvedDirectory, ".vscode"), { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const GITIGNORE = `# dotenv environment variable files
|
||||||
|
.env
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
.env.local
|
||||||
|
`;
|
||||||
|
|
||||||
|
await Deno.writeTextFile(
|
||||||
|
join(resolvedDirectory, ".gitignore"),
|
||||||
|
GITIGNORE,
|
||||||
|
);
|
||||||
|
|
||||||
const importMap = { imports: {} as Record<string, string> };
|
const importMap = { imports: {} as Record<string, string> };
|
||||||
freshImports(importMap.imports);
|
freshImports(importMap.imports);
|
||||||
if (useTwind) twindImports(importMap.imports);
|
if (useTwind) twindImports(importMap.imports);
|
||||||
|
dotenvImports(importMap.imports);
|
||||||
const IMPORT_MAP_JSON = JSON.stringify(importMap, null, 2) + "\n";
|
const IMPORT_MAP_JSON = JSON.stringify(importMap, null, 2) + "\n";
|
||||||
await Deno.writeTextFile(
|
await Deno.writeTextFile(
|
||||||
join(resolvedDirectory, "import_map.json"),
|
join(resolvedDirectory, "import_map.json"),
|
||||||
@@ -250,6 +268,8 @@ let MAIN_TS = `/// <reference no-default-lib="true" />
|
|||||||
/// <reference lib="dom.asynciterable" />
|
/// <reference lib="dom.asynciterable" />
|
||||||
/// <reference lib="deno.ns" />
|
/// <reference lib="deno.ns" />
|
||||||
|
|
||||||
|
import "$std/dotenv/load.ts";
|
||||||
|
|
||||||
import { start } from "$fresh/server.ts";
|
import { start } from "$fresh/server.ts";
|
||||||
import manifest from "./fresh.gen.ts";
|
import manifest from "./fresh.gen.ts";
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ export const RECOMMENDED_PREACT_RTS_VERSION = "5.2.6";
|
|||||||
export const RECOMMENDED_PREACT_SIGNALS_VERSION = "1.1.3";
|
export const RECOMMENDED_PREACT_SIGNALS_VERSION = "1.1.3";
|
||||||
export const RECOMMENDED_PREACT_SIGNALS_CORE_VERSION = "1.2.3";
|
export const RECOMMENDED_PREACT_SIGNALS_CORE_VERSION = "1.2.3";
|
||||||
export const RECOMMENDED_TWIND_VERSION = "0.16.19";
|
export const RECOMMENDED_TWIND_VERSION = "0.16.19";
|
||||||
|
export const RECOMMENDED_STD_VERSION = "0.187.0";
|
||||||
|
|
||||||
export function freshImports(imports: Record<string, string>) {
|
export function freshImports(imports: Record<string, string>) {
|
||||||
imports["$fresh/"] = new URL("../../", import.meta.url).href;
|
imports["$fresh/"] = new URL("../../", import.meta.url).href;
|
||||||
@@ -20,3 +21,7 @@ export function twindImports(imports: Record<string, string>) {
|
|||||||
imports["twind"] = `https://esm.sh/twind@${RECOMMENDED_TWIND_VERSION}`;
|
imports["twind"] = `https://esm.sh/twind@${RECOMMENDED_TWIND_VERSION}`;
|
||||||
imports["twind/"] = `https://esm.sh/twind@${RECOMMENDED_TWIND_VERSION}/`;
|
imports["twind/"] = `https://esm.sh/twind@${RECOMMENDED_TWIND_VERSION}/`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function dotenvImports(imports: Record<string, string>) {
|
||||||
|
imports["$std/"] = `https://deno.land/std@${RECOMMENDED_STD_VERSION}/`;
|
||||||
|
}
|
||||||
|
|||||||
@@ -252,6 +252,7 @@ Deno.test({
|
|||||||
{ "type": "file", "name": "extensions.json" },
|
{ "type": "file", "name": "extensions.json" },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{ "type": "file", "name": ".gitignore" },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user