create-aaanh-stack
Version:
Stop repeating myself: Next.js template with Shadcn UI, TypeScript, Tailwind CSS, and T3 Env configuration
73 lines (58 loc) ⢠2.31 kB
JavaScript
const { execSync } = require("child_process");
const path = require("path");
const fs = require("fs");
const projectName = process.argv[2];
if (!projectName) {
console.error("Please specify the project name:");
console.error(" npm create next-shadcn-ts-tw-t3env my-app");
process.exit(1);
}
console.log("\nš Creating your Next.js project...\n");
const templatePath = path.join(__dirname, "..", "template");
const projectPath = path.join(process.cwd(), projectName);
// Create project directory
console.log("š Creating project directory...");
fs.mkdirSync(projectPath, { recursive: true });
// Copy template files
console.log("š Copying template files...");
const copyDir = (src, dest) => {
const entries = fs.readdirSync(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
fs.mkdirSync(destPath, { recursive: true });
copyDir(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
};
copyDir(templatePath, projectPath);
// Update package.json with project name
console.log("š Updating package.json...");
const packageJsonPath = path.join(projectPath, "package.json");
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
packageJson.name = projectName;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
// Handle environment files
console.log("š§ Setting up environment files...");
const envPath = path.join(projectPath, ".env.local");
const envContent = `# Drizzle
DATABASE_URL=""
`;
fs.writeFileSync(envPath, envContent);
console.log("ā
Environment files configured");
console.log(`\n⨠Success! Created ${projectName} at ${projectPath}`);
console.log("\nInside that directory, you can run several commands:");
console.log("\n pnpm dev");
console.log(" Starts the development server.");
console.log("\n pnpm build");
console.log(" Builds the app for production.");
console.log("\n pnpm start");
console.log(" Runs the built app in production mode.");
console.log("\nWe suggest that you begin by typing:");
console.log(`\n cd ${projectName}`);
console.log(" pnpm install");
console.log(" pnpm run dev\n");