export const getArguments = () => { const args = process.argv; const command = args[0]; const scriptPath = args[1]; const workspacePath = args[2]; const filePath = args[3]; let frontMatter = args[4]; // Parse the frontmatter if (frontMatter.startsWith(`"`) || frontMatter.startsWith(`'`)) { frontMatter = frontMatter.slice(1); } if (frontMatter.endsWith(`"`) || frontMatter.endsWith(`'`)) { frontMatter = frontMatter.slice(0, -1); } try { frontMatter = typeof frontMatter === "string" ? JSON.parse(frontMatter) : frontMatter; } catch (e) { // Failed parsing JSON } // Get all arguments after the file path const answerArgs = args.slice(5); let promptResponse: string | undefined; const answers = answerArgs.reduce((acc, curr) => { const [key, value] = curr.split("="); if (key === "promptResponse") { promptResponse = value; } else { acc[key] = value; } return acc; }, {} as { [key: string]: string }); return { command, scriptPath, workspacePath, filePath, frontMatter, answers: Object.keys(answers).length > 0 ? answers : undefined, promptResponse, }; };