From ebaa260f2c08079101c040a0587a78f662973d29 Mon Sep 17 00:00:00 2001 From: Hiroki Miyaji <40714517+hiroki0525@users.noreply.github.com> Date: Wed, 8 Nov 2023 21:20:28 +0900 Subject: [PATCH] add init script (#46) --- packages/ui/.gitignore | 1 + packages/ui/init.ts | 21 +++++++++++++++++++ packages/ui/package.json | 5 +++-- packages/ui/src/index.ts | 1 + packages/ui/src/notion.ts | 2 +- .../generateDandoriMiroCards.ts | 0 .../generateDandoriNotionPages.ts | 2 +- packages/ui/{scripts => templates}/mock.ts | 0 8 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 packages/ui/.gitignore create mode 100644 packages/ui/init.ts rename packages/ui/{scripts => templates}/generateDandoriMiroCards.ts (100%) rename packages/ui/{scripts => templates}/generateDandoriNotionPages.ts (87%) rename packages/ui/{scripts => templates}/mock.ts (100%) diff --git a/packages/ui/.gitignore b/packages/ui/.gitignore new file mode 100644 index 0000000..528dc4e --- /dev/null +++ b/packages/ui/.gitignore @@ -0,0 +1 @@ +scripts \ No newline at end of file diff --git a/packages/ui/init.ts b/packages/ui/init.ts new file mode 100644 index 0000000..cb4c9f9 --- /dev/null +++ b/packages/ui/init.ts @@ -0,0 +1,21 @@ +#!/usr/bin/env node + +import { copyFile, mkdir, readdir, rm } from "fs/promises"; + +const scriptsDir = "./scripts"; +const templatesDir = "./templates"; + +try { + await rm(scriptsDir, { recursive: true }); +} catch { + // no such file or directory error +} +await mkdir(scriptsDir); +const templateFiles = await readdir(templatesDir); +await Promise.all( + templateFiles.map(async (templateFile) => { + const templateFilePath = `${templatesDir}/${templateFile}`; + const scriptFilePath = `${scriptsDir}/${templateFile}`; + await copyFile(templateFilePath, scriptFilePath); + }), +); diff --git a/packages/ui/package.json b/packages/ui/package.json index 2c301a0..2f19a9a 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -19,8 +19,9 @@ "type": "module", "scripts": { "build": "tsup --config ../../tsup.config.ts", - "dev:miro": "tsx ./scripts/generateDandoriMiroCards.ts", - "dev:notion": "tsx ./scripts/generateDandoriNotionPages.ts", + "init": "tsx init.ts", + "dev:miro": "tsx script/generateDandoriMiroCards.ts", + "dev:notion": "tsx script/generateDandoriNotionPages.ts", "test": "vitest run" }, "keywords": [], diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts index 00347bd..97c12c1 100644 --- a/packages/ui/src/index.ts +++ b/packages/ui/src/index.ts @@ -1 +1,2 @@ export * from "./miro"; +export * from "./notion"; diff --git a/packages/ui/src/notion.ts b/packages/ui/src/notion.ts index f0e6f95..feb2e51 100644 --- a/packages/ui/src/notion.ts +++ b/packages/ui/src/notion.ts @@ -85,7 +85,7 @@ const createPageParams = ( }; }; -export default async function generateDandoriNotionPages( +export async function generateDandoriNotionPages( tasks: DandoriTask[], options: GenerateDandoriNotionDatabaseItemsOptions, ): Promise { diff --git a/packages/ui/scripts/generateDandoriMiroCards.ts b/packages/ui/templates/generateDandoriMiroCards.ts similarity index 100% rename from packages/ui/scripts/generateDandoriMiroCards.ts rename to packages/ui/templates/generateDandoriMiroCards.ts diff --git a/packages/ui/scripts/generateDandoriNotionPages.ts b/packages/ui/templates/generateDandoriNotionPages.ts similarity index 87% rename from packages/ui/scripts/generateDandoriNotionPages.ts rename to packages/ui/templates/generateDandoriNotionPages.ts index bcceac5..3e27ae9 100644 --- a/packages/ui/scripts/generateDandoriNotionPages.ts +++ b/packages/ui/templates/generateDandoriNotionPages.ts @@ -1,6 +1,6 @@ import { loadEnvFile } from "@dandori/libs"; import { tasks } from "./mock"; -import generateDandoriNotionPages from "../src/notion"; +import { generateDandoriNotionPages } from "@dandori/ui"; // set environment variables like access token loadEnvFile(); diff --git a/packages/ui/scripts/mock.ts b/packages/ui/templates/mock.ts similarity index 100% rename from packages/ui/scripts/mock.ts rename to packages/ui/templates/mock.ts