{"version":3,"file":"init.mjs","names":[],"sources":["../../src/commands/init.ts"],"sourcesContent":["import { readFile, writeFile } from \"node:fs/promises\";\nimport { cwd } from \"node:process\";\nimport { pathToFileURL } from \"node:url\";\nimport { x } from \"tinyexec\";\nimport type { CommandContext } from \"../context.ts\";\n\nexport async function init(ctx: CommandContext) {\n\tconst [_name = \".\"] = ctx.args;\n\tconst cwdUrl = pathToFileURL(`${cwd()}/`);\n\tconst name =\n\t\t_name === \".\" ? new URL(\"../\", cwdUrl).pathname.split(\"/\").filter(Boolean).pop()! : _name;\n\tconst dest = new URL(\"./.temp/\", cwdUrl);\n\tfor await (const line of x(\"pnpx\", [\"giget@latest\", \"gh:bombshell-dev/template\", name])) {\n\t\tconsole.log(line);\n\t}\n\n\tconst promises: Promise<void>[] = [];\n\tfor (const file of [\"package.json\", \"README.md\"]) {\n\t\tpromises.push(\n\t\t\tpostprocess(new URL(file, dest), (contents) => {\n\t\t\t\treturn contents.replaceAll(\"$name\", name);\n\t\t\t}),\n\t\t);\n\t}\n\tawait Promise.all(promises);\n}\n\nasync function postprocess(\n\tfile: URL,\n\ttransform: (contents: string) => string | undefined | Promise<string | undefined>,\n) {\n\tconst contents = await readFile(file, { encoding: \"utf8\" });\n\tconst result = await transform(contents);\n\tif (!result) return;\n\tawait writeFile(file, result, { encoding: \"utf8\" });\n}\n"],"mappings":";;;;;;AAMA,eAAsB,KAAK,KAAqB;CAC/C,MAAM,CAAC,QAAQ,OAAO,IAAI;CAC1B,MAAM,SAAS,cAAc,GAAG,KAAK,CAAC,GAAG;CACzC,MAAM,OACL,UAAU,MAAM,IAAI,IAAI,OAAO,OAAO,CAAC,SAAS,MAAM,IAAI,CAAC,OAAO,QAAQ,CAAC,KAAK,GAAI;CACrF,MAAM,OAAO,IAAI,IAAI,YAAY,OAAO;AACxC,YAAW,MAAM,QAAQ,EAAE,QAAQ;EAAC;EAAgB;EAA6B;EAAK,CAAC,CACtF,SAAQ,IAAI,KAAK;CAGlB,MAAM,WAA4B,EAAE;AACpC,MAAK,MAAM,QAAQ,CAAC,gBAAgB,YAAY,CAC/C,UAAS,KACR,YAAY,IAAI,IAAI,MAAM,KAAK,GAAG,aAAa;AAC9C,SAAO,SAAS,WAAW,SAAS,KAAK;GACxC,CACF;AAEF,OAAM,QAAQ,IAAI,SAAS;;AAG5B,eAAe,YACd,MACA,WACC;CAED,MAAM,SAAS,MAAM,UADJ,MAAM,SAAS,MAAM,EAAE,UAAU,QAAQ,CAAC,CACnB;AACxC,KAAI,CAAC,OAAQ;AACb,OAAM,UAAU,MAAM,QAAQ,EAAE,UAAU,QAAQ,CAAC"}