From d5abf3e67e5b46c90ef2fdb5e9fba17b18b47c9c Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Fri, 14 Apr 2023 16:37:53 -0400 Subject: [PATCH] use commander for each step of the generation process Signed-off-by: Xe Iaso --- book.ts | 147 +++++++++++++++++++++ index.ts | 156 ++++++++++++---------- package-lock.json | 324 +++++++++++++++++++++++++++++++++++++++++++++- package.json | 4 +- tsconfig.json | 5 +- 5 files changed, 562 insertions(+), 74 deletions(-) create mode 100644 book.ts diff --git a/book.ts b/book.ts new file mode 100644 index 0000000..9067257 --- /dev/null +++ b/book.ts @@ -0,0 +1,147 @@ +import * as fs from "node:fs/promises"; +import { OpenAIApi } from "openai"; +import PlotGenerator, { Plot } from "@xeserv/plottoriffic"; + +export interface ChapterListItem { + title: string; + summary: string; +} + +export interface Chapter extends ChapterListItem { + sceneDescriptions: string[]; +} + +export interface Character { + name: string; + symbol: string; + role: string; + desc: string; +} + +export interface Summary { + title: string; + chapterList: ChapterListItem[]; + plotSummary: string; + characters: Character[]; +} + +export const createPlot = async (dirName: string): Promise => { + const pg = new PlotGenerator({ flipGenders: false }); + const plot = pg.generate(); + + await fs.writeFile(`${dirName}/plotto.json`, JSON.stringify(plot)); + + return plot; +}; + +export const createAndParseSummary = async ( + dirName: string, + openai: OpenAIApi, + plot: Plot +): Promise => { + console.log("generating plot summary"); + const promptBase = `Write me the following about the following plot summary for a novel: + +- A two to five word title for the novel starting with "Title: " and followed by two newlines. For example: "Fresh Beginnings" or "Jared's Adventure through Crime". +- A detailed plot summary for the story starting with "Plot Summary: " and followed by two newlines. The plot summary should be on the same line as the prefix. Adapt the story to be about peer to peer networks somehow. +- The string "Chapter Summaries" followed by two newlines. +- A markdown list of detailed chapter summaries in at least 3 sentences and titles for each of the 10 chapters that a novel based on the plot summary would have. Surround each chapter title in quotes and put a dash after the name like this: + +- Chapter name - Chapter summary goes here. More words in the summary go here. +- Second chapter name - Second chapter summary goes here.`; + + const summary = await openai.createChatCompletion({ + model: "gpt-3.5-turbo", + messages: [ + { + role: "user", + content: promptBase + "\n\n" + plot.plot, + }, + ], + }); + + if (!!summary.data.usage) { + const usage = summary.data.usage; + console.log( + `${usage.total_tokens} tokens (${usage.prompt_tokens} prompt, ${usage?.completion_tokens} completion)` + ); + } + + const summaryText = summary.data.choices[0].message?.content; + + await fs.writeFile(`${dirName}/summary.txt`, summaryText as string); + + const titleRegex = /^Title: (.+)$/gm; + const plotSummaryRegex = /^Plot Summary: (.+)$/gm; + const chapterSummaryRegex = /^- (.+) - (.+)$/gm; + + let title = summaryText?.split("\n", 2)[0].split(titleRegex)[1] as string; + + if (title[0] === '"') { + title = title.slice(1, -1); + } + console.log(`title: ${title}`); + + const chapterList: ChapterListItem[] = summaryText + ?.split("\n\n") + .slice(-1)[0] + .split("\n") + .map((line) => { + return line.split(chapterSummaryRegex); + }) + .map((ch) => { + ch.shift(); + ch.pop(); + return { + title: ch[0].slice(1, -1) as string, + summary: ch[1] as string, + } as ChapterListItem; + }) as ChapterListItem[]; + + chapterList.forEach((ch) => console.log(`chapter ${ch.title}: ${ch.summary}`)); + + const plotSummary = summaryText?.split("\n\n", 3)[1].split(plotSummaryRegex)[1] as string; + console.log(`${plotSummary}`); + + const bookInfo: Summary = { + title, + chapterList, + plotSummary, + characters: [], + }; + + for (const ch of plot.cast) { + console.log(ch); + const prompt = `Given the following plot summary and character information, write a two-sentence summary of that character and create plausible character details and an appearance for them. Don't include anything but the summary. Adapt the character's story to be about peer to peer networks somehow. + + Plot summary: ${plotSummary} + Character name: ${ch.name} (${ch.symbol}) + Character role: ${ch.description}`; + + console.log(`getting information for ${ch.name} (${ch.symbol} - ${ch.description})`); + + const chInfo = await openai.createChatCompletion({ + model: "gpt-3.5-turbo", + messages: [ + { + role: "user", + content: prompt, + }, + ], + }); + + const chInfoText = chInfo.data.choices[0].message?.content; + console.log(`${ch.name}: ${chInfoText}`); + + bookInfo.characters.push({ + name: ch.name, + symbol: ch.symbol, + role: ch.description, + desc: chInfoText as string, + }); + } + + await fs.writeFile(`${dirName}/summary.json`, JSON.stringify(bookInfo)); + + return bookInfo; +}; diff --git a/index.ts b/index.ts index a46cf2f..2d98cca 100644 --- a/index.ts +++ b/index.ts @@ -1,89 +1,107 @@ +import { Command } from "commander"; import * as dotenv from "dotenv"; import { Configuration, OpenAIApi } from "openai"; -import PlotGenerator from "@xeserv/plottoriffic"; +import PlotGenerator, { Plot } from "@xeserv/plottoriffic"; import { generateName } from "@kotofurumiya/th-namegen"; import * as fs from "node:fs/promises"; +import { existsSync as fileExists } from "fs"; +import { readPackage } from "read-pkg"; + +import * as book from "./book.js"; dotenv.config(); - -const dirName = `var/${generateName()}`; -await fs.mkdir(dirName, { recursive: true }); -console.log(`dirName: ${dirName}`); - -const pg = new PlotGenerator({ flipGenders: false }); -const plot = pg.generate(); - -await fs.writeFile(`${dirName}/plotto.json`, JSON.stringify(plot)); +const packageInfo = await readPackage(); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); -const promptBase = `Write me the following about the following plot summary for a novel: +const program = new Command(); -- A two to five word title for the novel starting with "Title: " and followed by two newlines. For example: "Fresh Beginnings" or "Jared's Adventure through Crime". -- A detailed plot summary for the story starting with "Plot Summary: " and followed by two newlines. The plot summary should be on the same line as the prefix. -- The string "Chapter Summaries" followed by two newlines. -- A markdown list of detailed chapter summaries in at least 3 sentences and titles for each of the 10 chapters that a novel based on the plot summary would have. Surround each chapter title in quotes and put a dash after the name like this: +program + .name(packageInfo.name) + .description(packageInfo.description as string) + .version(packageInfo.version); -- Chapter name - Chapter summary goes here. More words in the summary go here. -- Second chapter name - Second chapter summary goes here.`; +program + .command("init [dir]") + .description("create a new random folder for a book") + .action(async (dir = `var/${generateName()}`) => { + await fs.mkdir(dir, { recursive: true }); -const summary = await openai.createChatCompletion({ - model: "gpt-3.5-turbo", - messages: [ - { - role: "user", - content: promptBase + "\n\n" + plot.plot, - }, - ], -}); - -if (!!summary.data.usage) { - const usage = summary.data.usage; - console.log( - `${usage.total_tokens} tokens (${usage.prompt_tokens} prompt, ${usage?.completion_tokens} completion)` - ); -} - -const summaryText = summary.data.choices[0].message?.content; - -console.log(summaryText); -await fs.writeFile(`${dirName}/summary.txt`, summaryText as string); - -const titleRegex = /^Title: (.+)$/gm; -const plotSummaryRegex = /^Plot Summary: (.+)$/gm; -const chapterSummaryRegex = /^- (.+) - (.+)$/gm; - -let title = summaryText?.split("\n", 2)[0].split(titleRegex)[1] as string; - -if (title[0] === '"') { - title = title.slice(1, -1); -} - -const chapterList = summaryText - ?.split("\n\n") - .slice(-1)[0] - .split("\n") - .map((line) => { - return line.split(chapterSummaryRegex); - }) - .map((ch) => { - ch.shift(); - ch.pop(); - return { title: ch[0].slice(1, -1), summary: ch[1] }; + console.log(`created folder ${dir}`); }); -const plotSummary = summaryText?.split("\n\n", 3)[1].split(plotSummaryRegex)[1]; +program + .command("genPlotto ") + .description("generate a new book plotto description") + .action(async (dir) => { + if (!fileExists(dir)) { + console.error(`${dir} does not exist, run init?`); + process.exit(1); + } + if (fileExists(`${dir}/plotto.json`)) { + console.error(`plotto data already exists in ${dir}`); + process.exit(1); + } -plot.cast.forEach(async (ch) => {}); + const plot = await book.createPlot(dir); + console.log(`created plot, subject: ${plot.subject}`); + }); -const bookInfo = { - title, - chapterList, - plotSummary, -}; +program + .command("showPlotto ") + .description("show the plotto description for a book directory") + .action(async (dir) => { + if (!fileExists(dir)) { + console.error(`${dir} does not exist, run init?`); + process.exit(1); + } -console.log(bookInfo); -await fs.writeFile(`${dirName}/summary.json`, JSON.stringify(bookInfo)); + const plot: Plot = JSON.parse(await fs.readFile(`${dir}/plotto.json`, "utf8")); + console.log(JSON.stringify(plot, undefined, " ")); + }); + +program + .command("genSummary ") + .description("generate a new summary based on a plotto description") + .action(async (dir) => { + if (!fileExists(dir)) { + console.error(`${dir} does not exist, run init?`); + process.exit(1); + } + if (fileExists(`${dir}/summary.json`)) { + console.error(`plot summary already exists in ${dir}`); + process.exit(1); + } + + const plot: Plot = JSON.parse(await fs.readFile(`${dir}/plotto.json`, "utf8")); + + const summary = await book.createAndParseSummary(dir, openai, plot); + + console.log(`generated book summary`); + }); + +program + .command("showSummary ") + .description("dump high-level details about a plot summary") + .action(async (dir) => { + if (!fileExists(dir)) { + console.error(`${dir} does not exist, run init?`); + process.exit(1); + } + if (!fileExists(`${dir}/summary.json`)) { + console.error(`plot summary does not exist in ${dir}, run genSummary?`); + process.exit(1); + } + + const summary: book.Summary = JSON.parse(await fs.readFile(`${dir}/summary.json`, "utf8")); + + console.log(`title: ${summary.title}\n${summary.plotSummary}\n\ncharacters:`); + summary.characters.forEach((ch) => console.log(`- ${ch.name}: ${ch.role}`)); + console.log("\nchapters:"); + summary.chapterList.forEach(({ title, summary }) => console.log(`- ${title} - ${summary}`)); + }); + +program.parse(); diff --git a/package-lock.json b/package-lock.json index fc2543f..915715b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,8 +11,10 @@ "dependencies": { "@kotofurumiya/th-namegen": "^1.1.3", "@xeserv/plottoriffic": "^2.2.0", + "commander": "^10.0.0", "dotenv": "^16.0.3", - "openai": "^3.2.1" + "openai": "^3.2.1", + "read-pkg": "^8.0.0" }, "devDependencies": { "@types/node": "^18.15.11", @@ -23,6 +25,102 @@ "typescript": "^5.0.4" } }, + "node_modules/@babel/code-frame": { + "version": "7.21.4", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.21.4.tgz", + "integrity": "sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==", + "dependencies": { + "@babel/highlight": "^7.18.6" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-validator-identifier": { + "version": "7.19.1", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz", + "integrity": "sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/highlight": { + "version": "7.18.6", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.18.6.tgz", + "integrity": "sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==", + "dependencies": { + "@babel/helper-validator-identifier": "^7.18.6", + "chalk": "^2.0.0", + "js-tokens": "^4.0.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/highlight/node_modules/ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dependencies": { + "color-convert": "^1.9.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/highlight/node_modules/chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dependencies": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/highlight/node_modules/color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dependencies": { + "color-name": "1.1.3" + } + }, + "node_modules/@babel/highlight/node_modules/color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==" + }, + "node_modules/@babel/highlight/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/@babel/highlight/node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/highlight/node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/@kotofurumiya/th-namegen": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/@kotofurumiya/th-namegen/-/th-namegen-1.1.3.tgz", @@ -34,6 +132,11 @@ "integrity": "sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==", "dev": true }, + "node_modules/@types/normalize-package-data": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz", + "integrity": "sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==" + }, "node_modules/@xeserv/plottoriffic": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@xeserv/plottoriffic/-/plottoriffic-2.2.0.tgz", @@ -393,7 +496,6 @@ "version": "10.0.0", "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.0.tgz", "integrity": "sha512-zS5PnTI22FIRM6ylNW8G4Ap0IEOyk62fhLSD0+uHRT9McRCLGpkVNvao4bjimpK/GShynyQkFFxHhwMcETmduA==", - "dev": true, "engines": { "node": ">=14" } @@ -490,6 +592,14 @@ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "dev": true }, + "node_modules/error-ex": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", + "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "dependencies": { + "is-arrayish": "^0.2.1" + } + }, "node_modules/escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -623,6 +733,11 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -698,6 +813,17 @@ "node": "*" } }, + "node_modules/has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dependencies": { + "function-bind": "^1.1.1" + }, + "engines": { + "node": ">= 0.4.0" + } + }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -716,6 +842,17 @@ "he": "bin/he" } }, + "node_modules/hosted-git-info": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-6.1.1.tgz", + "integrity": "sha512-r0EI+HBMcXadMrugk0GCQ+6BQV39PiWAZVfq7oIckeGiN7sjRGyQxPdft3nQekFTCQbYxLBH+/axZMeH8UX6+w==", + "dependencies": { + "lru-cache": "^7.5.1" + }, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, "node_modules/human-signals": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-4.3.1.tgz", @@ -765,6 +902,11 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, + "node_modules/is-arrayish": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==" + }, "node_modules/is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", @@ -777,6 +919,17 @@ "node": ">=8" } }, + "node_modules/is-core-module": { + "version": "2.12.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.12.0.tgz", + "integrity": "sha512-RECHCBCd/viahWmwj6enj19sKbHfJrddi/6cBDsNTKbNq0f7VeaUkBo60BqzvPqo/W54ChS62Z5qyun7cfOMqQ==", + "dependencies": { + "has": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -855,6 +1008,11 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, + "node_modules/js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" + }, "node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", @@ -867,6 +1025,14 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/json-parse-even-better-errors": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-3.0.0.tgz", + "integrity": "sha512-iZbGHafX/59r39gPwVPRBGw0QQKnA7tte5pSMrhWOW7swGsVvVTjmfyAV9pNqk8YGT7tRCdxRu8uzcgZwoDooA==", + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, "node_modules/lilconfig": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.1.0.tgz", @@ -876,6 +1042,14 @@ "node": ">=10" } }, + "node_modules/lines-and-columns": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-2.0.3.tgz", + "integrity": "sha512-cNOjgCnLB+FnvWWtyRTzmB3POJ+cXxTA81LoW7u8JdmhfXzriropYwpjShnz1QLLWsQwY7nIxoDmcPTwphDK9w==", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + } + }, "node_modules/lint-staged": { "version": "13.2.1", "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-13.2.1.tgz", @@ -1055,6 +1229,14 @@ "node": ">=8" } }, + "node_modules/lru-cache": { + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", + "engines": { + "node": ">=12" + } + }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -1175,6 +1357,20 @@ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" } }, + "node_modules/normalize-package-data": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-5.0.0.tgz", + "integrity": "sha512-h9iPVIfrVZ9wVYQnxFgtw1ugSvGEMOlyPWWtm8BMJhnwyEL/FLbYbTY3V3PpjI/BUK67n9PEWDu6eHzu1fB15Q==", + "dependencies": { + "hosted-git-info": "^6.0.0", + "is-core-module": "^2.8.1", + "semver": "^7.3.5", + "validate-npm-package-license": "^3.0.4" + }, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -1298,6 +1494,35 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/parse-json": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-7.0.0.tgz", + "integrity": "sha512-kP+TQYAzAiVnzOlWOe0diD6L35s9bJh0SCn95PIbZFKrOYuIRQsQkeWEYxzVDuHTt9V9YqvYCJ2Qo4z9wdfZPw==", + "dependencies": { + "@babel/code-frame": "^7.21.4", + "error-ex": "^1.3.2", + "json-parse-even-better-errors": "^3.0.0", + "lines-and-columns": "^2.0.3", + "type-fest": "^3.8.0" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/parse-json/node_modules/type-fest": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-3.8.0.tgz", + "integrity": "sha512-FVNSzGQz9Th+/9R6Lvv7WIAkstylfHN2/JYxkyhhmKFYh9At2DST8t6L6Lref9eYO8PXFTfG9Sg1Agg0K3vq3Q==", + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -1373,6 +1598,34 @@ "safe-buffer": "^5.1.0" } }, + "node_modules/read-pkg": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-8.0.0.tgz", + "integrity": "sha512-Ajb9oSjxXBw0YyOiwtQ2dKbAA/vMnUPnY63XcCk+mXo0BwIdQEMgZLZiMWGttQHcUhUgbK0mH85ethMPKXxziw==", + "dependencies": { + "@types/normalize-package-data": "^2.4.1", + "normalize-package-data": "^5.0.0", + "parse-json": "^7.0.0", + "type-fest": "^3.8.0" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/read-pkg/node_modules/type-fest": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-3.8.0.tgz", + "integrity": "sha512-FVNSzGQz9Th+/9R6Lvv7WIAkstylfHN2/JYxkyhhmKFYh9At2DST8t6L6Lref9eYO8PXFTfG9Sg1Agg0K3vq3Q==", + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", @@ -1471,6 +1724,31 @@ "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-2.4.4.tgz", "integrity": "sha512-9A+PDmgm+2du77B5i0Ip2cxOqqHjgNxnBgglxLcX78A2D6c2rTo61z4jnVABpF4cKeDMDG+cmXXvdnqse2VqMA==" }, + "node_modules/semver": { + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.4.0.tgz", + "integrity": "sha512-RgOxM8Mw+7Zus0+zcLEUn8+JfoLpj/huFTItQy2hsM4khuC1HYRDp0cU482Ewn/Fcy6bCjufD8vAj7voC66KQw==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/semver/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/serialize-javascript": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", @@ -1547,6 +1825,34 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/spdx-correct": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.2.0.tgz", + "integrity": "sha512-kN9dJbvnySHULIluDHy32WHRUu3Og7B9sbY7tsFLctQkIqnMh3hErYgdMjTYuqmcXX+lK5T1lnUt3G7zNswmZA==", + "dependencies": { + "spdx-expression-parse": "^3.0.0", + "spdx-license-ids": "^3.0.0" + } + }, + "node_modules/spdx-exceptions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz", + "integrity": "sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A==" + }, + "node_modules/spdx-expression-parse": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz", + "integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==", + "dependencies": { + "spdx-exceptions": "^2.1.0", + "spdx-license-ids": "^3.0.0" + } + }, + "node_modules/spdx-license-ids": { + "version": "3.0.13", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.13.tgz", + "integrity": "sha512-XkD+zwiqXHikFZm4AX/7JSCXA98U5Db4AFd5XUg/+9UNtnH75+Z9KxtpYiJZx36mUDVOwH83pl7yvCer6ewM3w==" + }, "node_modules/string-argv": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.1.tgz", @@ -1670,6 +1976,15 @@ "node": ">=12.20" } }, + "node_modules/validate-npm-package-license": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", + "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "dependencies": { + "spdx-correct": "^3.0.0", + "spdx-expression-parse": "^3.0.0" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -1723,6 +2038,11 @@ "node": ">=10" } }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/yaml": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.2.1.tgz", diff --git a/package.json b/package.json index d5af919..df3f9e8 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,10 @@ "dependencies": { "@kotofurumiya/th-namegen": "^1.1.3", "@xeserv/plottoriffic": "^2.2.0", + "commander": "^10.0.0", "dotenv": "^16.0.3", - "openai": "^3.2.1" + "openai": "^3.2.1", + "read-pkg": "^8.0.0" }, "lint-staged": { "*.+(js|ts|json)": "prettier --write --ignore-unknown" diff --git a/tsconfig.json b/tsconfig.json index 27b317e..08fd84a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ // https://www.typescriptlang.org/tsconfig#compilerOptions "compilerOptions": { "esModuleInterop": true, - "lib": ["es2020", "dom"], + "lib": ["es2020", "es2022", "dom"], "module": "es2022", "preserveConstEnums": true, "moduleResolution": "node", @@ -10,7 +10,8 @@ "sourceMap": true, "target": "es2022", "types": ["node"], - "outDir": "dist" + "outDir": "dist", + "allowImportingTsExtensions": true }, "exclude": ["node_modules"] }