aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/park-editor.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/park-editor.mjs')
-rw-r--r--scripts/park-editor.mjs11
1 files changed, 9 insertions, 2 deletions
diff --git a/scripts/park-editor.mjs b/scripts/park-editor.mjs
index a872008..d0c08da 100644
--- a/scripts/park-editor.mjs
+++ b/scripts/park-editor.mjs
@@ -9,7 +9,7 @@
//
// 注意: ローカル(127.0.0.1)にのみ公開します。追加パッケージは不要です。
import { createServer } from "node:http";
-import { readFile, writeFile } from "node:fs/promises";
+import { readFile, writeFile, rename } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
@@ -103,7 +103,14 @@ const server = createServer(async (req, res) => {
const text = target.dataset.pretty
? `${JSON.stringify(data, null, 2)}\n`
: `${JSON.stringify(data)}\n`;
- await writeFile(target.dataset.path, text, "utf-8");
+ if (text.includes("\uFFFD")) {
+ throw new Error(
+ "文字化け(U+FFFD)が含まれているため保存を中止しました。入力内容を確認してください。",
+ );
+ }
+ const tmp = `${target.dataset.path}.tmp`;
+ await writeFile(tmp, text, "utf-8");
+ await rename(tmp, target.dataset.path);
const count = target.id === "nearbyParks" ? data.features.length : data.length;
console.log(`保存しました: ${target.dataset.label} ${count}件 → ${target.dataset.path}`);