create-man-next-app
Version:
Create a modern Next.js 15 app with TypeScript, Tailwind, ShadCN, and more
88 lines (68 loc) ⢠2.74 kB
JavaScript
const { execSync } = require("child_process");
const path = require("path");
// Get arguments passed to the create command
const args = process.argv.slice(2);
// Run the script with npx to avoid installation issues
try {
// Clone the repository directly using git
console.log("\nš Creating Next.js app...\n");
const projectName = args[0] || "my-next-app";
const projectPath = path.resolve(process.cwd(), projectName);
// Create the project directory
execSync(`mkdir -p ${projectName}`);
// Clone the repository into the project directory
execSync(
`git clone --depth=1 https://github.com/Muhsin-42/man-next-app.git ${projectName}`,
{ stdio: "inherit" }
);
// Clean up the git history
execSync(`cd ${projectName} && rm -rf .git`, { stdio: "inherit" });
// Initialize a new git repository
execSync(
`cd ${projectName} && git init && git add . && git commit -m "Initial commit from create-man-next-app"`,
{
stdio: "inherit",
env: {
...process.env,
GIT_AUTHOR_NAME: "Create Man Next App",
GIT_AUTHOR_EMAIL: "noreply@example.com",
},
}
);
// Install dependencies
console.log("\nš¦ Installing dependencies...\n");
// Determine package manager
let packageManager = "npm";
if (args.includes("--use-yarn")) packageManager = "yarn";
else if (args.includes("--use-pnpm")) packageManager = "pnpm";
else if (args.includes("--use-bun")) packageManager = "bun";
try {
execSync(`cd ${projectName} && ${packageManager} install`, {
stdio: "inherit",
});
} catch (error) {
console.error(
`\nā Failed to install dependencies with ${packageManager}.`
);
console.error("You can try installing them manually.");
}
console.log(`
ā
Successfully created a Next.js app at ${projectPath}
Inside that directory, you can run several commands:
${packageManager === "yarn" ? "yarn" : packageManager === "pnpm" ? "pnpm" : packageManager === "bun" ? "bun" : "npm run"} dev
Starts the development server.
${packageManager === "yarn" ? "yarn" : packageManager === "pnpm" ? "pnpm" : packageManager === "bun" ? "bun" : "npm run"} build
Builds the app for production.
${packageManager === "yarn" ? "yarn" : packageManager === "pnpm" ? "pnpm" : packageManager === "bun" ? "bun" : "npm run"} start
Runs the built app in production mode.
We suggest that you begin by typing:
cd ${projectName}
${packageManager === "yarn" ? "yarn" : packageManager === "pnpm" ? "pnpm" : packageManager === "bun" ? "bun" : "npm run"} dev
Happy hacking! ā„
`);
} catch (error) {
console.error("\nā Failed to create Next.js app");
console.error(error.message);
process.exit(1);
}