From 51753f01dd3989da28a3c5933978f2e129ba6149 Mon Sep 17 00:00:00 2001 From: Andre Wiggins Date: Fri, 3 Jan 2025 18:26:03 -0600 Subject: [PATCH] Update to new website structure --- src/config.ts | 3 ++- src/normalizers.ts | 12 ++++++++++++ src/repos/website.ts | 7 ++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/config.ts b/src/config.ts index e3a79e4..2da0df2 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,6 +1,7 @@ import fs from "fs/promises"; import os from "os"; import path from "path"; +import { formatJSON } from "./normalizers.js"; const homePath = os.homedir(); @@ -43,6 +44,6 @@ export const loadConfig = async (): Promise => { export const saveConfig = async (config: Config): Promise => { await ensureConfigDir(); - const json = JSON.stringify(config, null, 4); + const json = await formatJSON(config); await fs.writeFile(CONFIG_PATH, json); }; diff --git a/src/normalizers.ts b/src/normalizers.ts index 3887d60..9ffadbf 100644 --- a/src/normalizers.ts +++ b/src/normalizers.ts @@ -1,3 +1,4 @@ +import prettier from "prettier"; import slugify from "./slugify-import-shim.js"; export const makeEventId = (eventName) => { if (typeof eventName === "undefined") { @@ -81,3 +82,14 @@ export const handleTalkTopics = ( } return talkTopics.split(", "); }; + +export function formatJSON(data: any): Promise { + return prettier.format(JSON.stringify(data) + "\n", { + parser: "json", + // This is the config from the seattlejs.com repo + useTabs: false, + singleQuote: true, + semi: false, + arrowParens: "avoid", + }); +} diff --git a/src/repos/website.ts b/src/repos/website.ts index 91d4a78..f6907ca 100644 --- a/src/repos/website.ts +++ b/src/repos/website.ts @@ -7,8 +7,8 @@ import { WebsiteTalk, } from "./website-types.js"; -const IMAGE_BASE = "public"; -const JSON_BASE = "app/data"; +const IMAGE_BASE = "src"; +const JSON_BASE = "src/data"; const IMAGE_DIRS = { speakers: path.join(IMAGE_BASE, "images/speakers"), @@ -101,13 +101,14 @@ export const exportImages = async (imageObjects, type, projectPath) => { export const exportData = async (jsData, type, projectPath) => { console.log("exporting", JSON_FILES[type]); - const json = JSON.stringify(jsData, null, 4); + const json = await formatJSON(jsData); const fullPath = path.join(projectPath, JSON_FILES[type]); await fs.writeFile(fullPath, json); }; import Fs from "fs"; import Https from "https"; +import { formatJSON } from "../normalizers.js"; /** * Download a file from the given `url` into the `targetFile`.