Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { execSync } = require('child_process');
- const fs = require('fs');
- const path = require('path');
- const workspacePath = process.argv[2];
- const projectName = process.argv[3];
- if (!workspacePath || !projectName) {
- console.error('Please provide a workspace path and project name.');
- process.exit(1);
- }
- // Step 1: Creating project in workspace
- const projectPath = `${workspacePath}/${projectName}`;
- const srcPath = `${projectPath}/src/pages`;
- const publicPath = `${projectPath}/public`;
- console.log(`Step 1: Creating new Next.js project: ${projectName} in workspace: ${workspacePath}`);
- // Step 2: Create necessary directories recursively
- console.log('Step 2:');
- [projectPath, srcPath, publicPath].forEach(dir => {
- if (!fs.existsSync(dir)) {
- fs.mkdirSync(dir, { recursive: true });
- console.log(`Created directory: ${dir}`);
- }
- });
- //Navigate to the workspace directory
- process.chdir(workspacePath);
- // Step 3: Initialize a new npm project
- execSync('npm init -y');
- console.log('Step 3: Initialized new npm project');
- // Step 4: Install Next.js and React dependencies
- execSync('npm install next react react-dom');
- console.log('Step 4: Installed Next.js and React dependencies');
- // Step 5: Install React Three Fiber (R3F)
- execSync('npm install @react-three/fiber three @react-three/drei');
- console.log('Step 5: Installed React Three Fiber (R3F)');
- // Step 6: Install Tailwind CSS and its dependencies
- execSync('npm install tailwindcss postcss autoprefixer');
- console.log('Step 6: Installed Tailwind CSS and its dependencies');
- // Step 7: Initialize Tailwind CSS
- execSync('npx tailwindcss init -p');
- console.log('Step 7: Initialized Tailwind CSS');
- // Step 8: Create necessary configuration files
- fs.writeFileSync('postcss.config.js', `module.exports = { plugins: [require('tailwindcss'), require('autoprefixer')], };`);
- fs.writeFileSync('tailwind.config.js', `module.exports = { purge: [], darkMode: false, theme: { extend: {}, }, variants: { extend: {}, }, plugins: [], }`);
- fs.writeFileSync('next.config.js', `module.exports = {};`);
- console.log('Step 8: Created necessary configuration files');
- // Step 9: Create _app.js file
- fs.writeFileSync(path.join(srcPath, '_app.js'), `import './global.css'\n\nfunction MyApp({ Component, pageProps }) {\n return <Component {...pageProps} />\n}\n\nexport default MyApp`);
- console.log('Step 9: Created _app.js file');
- // Step 10: Create _document.js file
- fs.writeFileSync(path.join(srcPath, '_document.js'), `import Document, { Html, Head, Main, NextScript } from 'next/document'\n\nclass MyDocument extends Document {\n render() {\n return (\n <Html>\n <Head />\n <body>\n <Main />\n <NextScript />\n </body>\n </Html>\n )\n }\n}\n\nexport default MyDocument`);
- console.log('Step 10: Created _document.js file');
- // Step 11: Create index.js file in pages directory
- fs.writeFileSync(path.join(srcPath, 'index.js'), `export default function Home() {\n return (\n <div>\n <h1>Hello, World!</h1>\n </div>\n )\n}`);
- console.log('Step 11: Created index.js file in pages directory');
- // Step 12: Create README.md and .gitignore files
- process.chdir(projectPath);
- fs.writeFileSync('README.md', `# ${projectName}`);
- fs.writeFileSync('.gitignore', `node_modules\n.next\n`);
- console.log('Step 12: Created README.md and .gitignore files');
- // Step 13: Start the development server
- console.log('Step 13: Starting the development server...');
- execSync('npm run dev', { stdio: 'inherit' });
- console.log(`Project "${projectName}" created successfully!`);
Advertisement
Add Comment
Please, Sign In to add comment