Skip to content

Commit d2da8d8

Browse files
authored
Merge pull request #7 from blu3mo/fix/read-env-by-deno
環境変数の取得方法を修正
2 parents eeb38c8 + e34904b commit d2da8d8

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: deno run --allow-net=scrapbox.io --allow-read=./ index.ts
1+
web: deno run --allow-net=scrapbox.io --allow-read=./ --allow-env index.ts

index.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { config } from "https://deno.land/x/dotenv@v2.0.0/mod.ts";
1+
import "https://deno.land/x/dotenv/load.ts";
22

33
interface Page {
44
title: string;
@@ -69,20 +69,24 @@ async function importJSON(
6969
);
7070
}
7171

72-
const env = config();
73-
const sid = env["SID"];
74-
const exportingProjectName = env["SOURCE_PROJECT_NAME"]; //インポート元(本来はprivateプロジェクト)
75-
const importingProjectName = env["DESTINATION_PROJECT_NAME"]; //インポート先(publicプロジェクト)
7672

77-
console.log(`Exporting a json file from "/${exportingProjectName}"...`);
78-
const pages = await exportJSON(exportingProjectName, sid);
79-
console.log("exported: ", pages);
80-
const importPages = pages.filter(({ lines }) =>
81-
lines.some((line) => line.includes("[public.icon]"))
82-
);
83-
if (importPages.length > 0) {
84-
console.log(`Importing the page data to "/${importingProjectName}"...`);
85-
await importJSON(importingProjectName, sid, importPages);
73+
const sid = Deno.env.get("SID");
74+
const exportingProjectName = Deno.env.get("SOURCE_PROJECT_NAME"); //インポート元(本来はprivateプロジェクト)
75+
const importingProjectName = Deno.env.get("DESTINATION_PROJECT_NAME"); //インポート先(publicプロジェクト)
76+
77+
if (sid !== undefined && exportingProjectName !== undefined && importingProjectName !== undefined) {
78+
console.log(`Exporting a json file from "/${exportingProjectName}"...`);
79+
const pages = await exportJSON(exportingProjectName, sid);
80+
console.log("exported: ", pages);
81+
const importPages = pages.filter(({ lines }) =>
82+
lines.some((line) => line.includes("[public.icon]"))
83+
);
84+
if (importPages.length > 0) {
85+
console.log(`Importing the page data to "/${importingProjectName}"...`);
86+
await importJSON(importingProjectName, sid, importPages);
87+
} else {
88+
console.log("No page to be imported found.");
89+
}
8690
} else {
87-
console.log("No page to be imported found.");
91+
console.log("Environmental variables lacking")
8892
}

0 commit comments

Comments
 (0)