Skip to content

Commit db9c46e

Browse files
authored
Merge pull request #47 from drumath2237/feature/#21-giget-download-templates
giget for downloading project template
2 parents 7a9d7c6 + 3493dea commit db9c46e

File tree

3 files changed

+65
-20
lines changed

3 files changed

+65
-20
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@inquirer/prompts": "^5.2.1",
3030
"citty": "^0.1.6",
3131
"consola": "^3.2.3",
32+
"giget": "^1.2.3",
3233
"pkg-types": "^1.1.3"
3334
},
3435
"devDependencies": {

pnpm-lock.yaml

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { cp, mkdir } from "node:fs/promises";
21
import path from "node:path";
3-
import { fileURLToPath } from "node:url";
42
import { runMain as _runMain, defineCommand } from "citty";
53
import { consola } from "consola";
64
import { colorize } from "consola/utils";
5+
import { downloadTemplate } from "giget";
76
import { readPackageJSON, writePackageJSON } from "pkg-types";
87

98
export const runMain = () => _runMain(mainCommand);
@@ -19,37 +18,39 @@ const mainCommand = defineCommand({
1918
};
2019
},
2120
run: async () => {
22-
const projectName = await consola.prompt("Project Name", {
21+
const projectName = await consola.prompt("Project Name?", {
2322
type: "text",
24-
default: "Babylon-App",
25-
placeholder: "Babylon-App",
23+
default: "babylon-app",
24+
placeholder: "babylon-app",
2625
});
2726

28-
const buildTool = await consola.prompt("Build Tools", {
27+
const buildTool = await consola.prompt("Build Tools?", {
2928
type: "select",
3029
options: [{ value: "vite", label: "Vite" }],
3130
});
3231

33-
const language = await consola.prompt("Language", {
32+
const language = await consola.prompt("Language?", {
3433
type: "select",
3534
options: [
3635
{ value: "ts", label: `${colorize("blue", "TypeScript")}` },
3736
{ value: "js", label: `${colorize("yellow", "JavaScript")}` },
3837
],
3938
});
4039

41-
const templateDir = path.resolve(
42-
fileURLToPath(import.meta.url),
43-
"../..",
44-
"templates",
45-
`${buildTool}-${language}`,
46-
);
47-
48-
const workingDir = process.cwd();
49-
const appDir = path.join(workingDir, projectName);
40+
const doInstall = await consola.prompt("Install Dependencies?", {
41+
type: "confirm",
42+
initial: false,
43+
});
5044

51-
await mkdir(appDir);
52-
await cp(templateDir, appDir, { recursive: true });
45+
const githubRepoUrlBase = "gh:drumath2237/create-babylon-app/templates";
46+
const templateName = `${buildTool}-${language}`;
47+
const { dir: appDir } = await downloadTemplate(
48+
`${githubRepoUrlBase}/${templateName}`,
49+
{
50+
dir: projectName,
51+
install: doInstall,
52+
},
53+
);
5354

5455
const packageJson = await readPackageJSON(appDir);
5556
if (packageJson.name) {
@@ -58,7 +59,8 @@ const mainCommand = defineCommand({
5859
await writePackageJSON(jsonPath, packageJson);
5960
}
6061

61-
console.log("\nDone!");
62-
console.log(` cd ${projectName}\n`);
62+
consola.log("\n");
63+
consola.success("Done!✨");
64+
consola.log(` cd ${projectName}`);
6365
},
6466
});

0 commit comments

Comments
 (0)