@mikemajara/notion-cms
Version:
A TypeScript library for using Notion as a headless CMS
3 lines • 2.03 kB
JavaScript
import {h,a as a$1}from'./chunk-AJFR4JNV.mjs';import {Command}from'commander';import*as r from'path';import*as a from'fs';import*as l from'readline';var n=new Command;function d(){return l.createInterface({input:process.stdin,output:process.stdout})}async function f(e){let t=d();return new Promise(o=>{t.question(`File already exists: ${e}
Do you want to overwrite it? (y/N): `,s=>{t.close(),o(s.toLowerCase()==="y");});})}n.name("notion-cms").description("CLI for generating TypeScript types from Notion databases");n.command("generate").description("Generate TypeScript types from a Notion database").option("-d, --database <id>","Notion database ID (for single database)").option("--databases <ids>","Multiple Notion database IDs separated by commas").option("-o, --output <path>","Output path","./notion").requiredOption("-t, --token <token>","Notion API token").option("-f, --force","Force overwrite existing files without asking",false).action(async e=>{try{!e.database&&!e.databases&&(console.error("Error: Either --database or --databases must be provided"),process.exit(1)),e.database&&e.databases&&(console.error("Error: Cannot use both --database and --databases options"),process.exit(1));let t=r.resolve(process.cwd(),e.output),o=e.databases?e.databases.split(",").map(s=>s.trim()):[e.database];if(console.log(`Generating types for ${o.length===1?"database":"databases"}: ${o.join(", ")}`),console.log(`Output path: ${t}`),a.existsSync(t)||a.mkdirSync(t,{recursive:!0}),o.length>1)await h(o,t,e.token,e.force);else {let s=r.join(t,"notion-types.ts");a.existsSync(s)&&!e.force?await f(s)?(a.unlinkSync(s),console.log("Overwriting existing notion-types.ts file.")):console.log("Keeping existing notion-types.ts file."):a.existsSync(s)&&e.force&&(a.unlinkSync(s),console.log("Force overwriting existing notion-types.ts file.")),await a$1(o[0],t,e.token,e.force);}console.log("Types generated successfully!");}catch(t){console.error("Error generating types:",t),process.exit(1);}});n.parse(process.argv);