feat(create): download templates with giget

Made-with: Cursor
This commit is contained in:
zuiidea
2026-04-14 22:32:16 +08:00
parent 26b002e80a
commit 6031d691ea
+24
View File
@@ -0,0 +1,24 @@
import os from "node:os";
import path from "node:path";
import { randomUUID } from "node:crypto";
import { downloadTemplate } from "giget";
import { CliError } from "./errors.js";
export async function downloadExampleToTemp(
gigetSource: string
): Promise<string> {
const dir = path.join(os.tmpdir(), `create-antd-admin-${randomUUID()}`);
try {
const { dir: outDir } = await downloadTemplate(gigetSource, {
dir,
forceClean: true,
});
return outDir;
} catch (e) {
const msg = e instanceof Error ? e.message : String(e);
throw new CliError(
`Failed to download template.\nSource: ${gigetSource}\n${msg}`,
"DOWNLOAD_FAILED"
);
}
}