create-three-demo
Version:
Unofficial Vite + Three.js template with convenience helpers and examples
50 lines (41 loc) ⢠1.46 kB
JavaScript
import fs from "fs-extra";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { execSync } from "node:child_process";
import prompts from "prompts";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
async function main() {
const targetDir = process.argv[2] || "my-sketchbook";
const templateDir = path.join(__dirname, "template");
console.log(`\nš¦ Copying template into ${targetDir}...`);
await fs.copy(templateDir, targetDir);
process.chdir(targetDir);
// Ask if user wants to initialize a git repo
const { shouldInitGit } = await prompts({
type: "confirm",
name: "shouldInitGit",
message: "Initialize a new git repository?",
initial: true,
});
if (shouldInitGit) {
try {
execSync("git init", { stdio: "ignore" });
execSync("git branch -M main", { stdio: "ignore" });
execSync("git add .", { stdio: "ignore" });
execSync('git commit -m "Initial commit from create-three-sketchbook"', {
stdio: "ignore",
});
console.log("ā
Git repository initialized.");
} catch (err) {
console.warn("ā ļø Failed to initialize git repo:", err.message);
}
} else {
console.log("Skipping git init.");
}
console.log("\nš Done! Next steps:");
console.log(` cd ${targetDir}`);
console.log(" pnpm install # or npm install");
console.log(" pnpm dev # start the dev server");
}
main();