Guest User

Untitled

a guest
Mar 21st, 2024
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { execSync } = require('child_process');
  2. const fs = require('fs');
  3. const path = require('path');
  4.  
  5. const workspacePath = process.argv[2];
  6. const projectName = process.argv[3];
  7.  
  8. if (!workspacePath || !projectName) {
  9.   console.error('Please provide a workspace path and project name.');
  10.   process.exit(1);
  11. }
  12.  
  13. // Step 1: Creating project in workspace
  14. const projectPath = `${workspacePath}/${projectName}`;
  15. const srcPath = `${projectPath}/src/pages`;
  16. const publicPath = `${projectPath}/public`;
  17. console.log(`Step 1: Creating new Next.js project: ${projectName} in workspace: ${workspacePath}`);
  18.  
  19.  
  20. // Step 2: Create necessary directories recursively
  21. console.log('Step 2:');
  22. [projectPath, srcPath, publicPath].forEach(dir => {
  23.   if (!fs.existsSync(dir)) {
  24.     fs.mkdirSync(dir, { recursive: true });
  25.     console.log(`Created directory: ${dir}`);
  26.   }
  27. });
  28.  
  29. //Navigate to the workspace directory
  30. process.chdir(workspacePath);
  31.  
  32. // Step 3: Initialize a new npm project
  33. execSync('npm init -y');
  34. console.log('Step 3: Initialized new npm project');
  35.  
  36. // Step 4: Install Next.js and React dependencies
  37. execSync('npm install next react react-dom');
  38. console.log('Step 4: Installed Next.js and React dependencies');
  39.  
  40. // Step 5: Install React Three Fiber (R3F)
  41. execSync('npm install @react-three/fiber three @react-three/drei');
  42. console.log('Step 5: Installed React Three Fiber (R3F)');
  43.  
  44. // Step 6: Install Tailwind CSS and its dependencies
  45. execSync('npm install tailwindcss postcss autoprefixer');
  46. console.log('Step 6: Installed Tailwind CSS and its dependencies');
  47.  
  48. // Step 7: Initialize Tailwind CSS
  49. execSync('npx tailwindcss init -p');
  50. console.log('Step 7: Initialized Tailwind CSS');
  51.  
  52. // Step 8: Create necessary configuration files
  53. fs.writeFileSync('postcss.config.js', `module.exports = { plugins: [require('tailwindcss'), require('autoprefixer')], };`);
  54. fs.writeFileSync('tailwind.config.js', `module.exports = { purge: [], darkMode: false, theme: { extend: {}, }, variants: { extend: {}, }, plugins: [], }`);
  55. fs.writeFileSync('next.config.js', `module.exports = {};`);
  56. console.log('Step 8: Created necessary configuration files');
  57.  
  58. // Step 9: Create _app.js file
  59. fs.writeFileSync(path.join(srcPath, '_app.js'), `import './global.css'\n\nfunction MyApp({ Component, pageProps }) {\n  return <Component {...pageProps} />\n}\n\nexport default MyApp`);
  60. console.log('Step 9: Created _app.js file');
  61.  
  62. // Step 10: Create _document.js file
  63. 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`);
  64. console.log('Step 10: Created _document.js file');
  65.  
  66. // Step 11: Create index.js file in pages directory
  67. fs.writeFileSync(path.join(srcPath, 'index.js'), `export default function Home() {\n  return (\n    <div>\n      <h1>Hello, World!</h1>\n    </div>\n  )\n}`);
  68. console.log('Step 11: Created index.js file in pages directory');
  69.  
  70. // Step 12: Create README.md and .gitignore files
  71. process.chdir(projectPath);
  72. fs.writeFileSync('README.md', `# ${projectName}`);
  73. fs.writeFileSync('.gitignore', `node_modules\n.next\n`);
  74. console.log('Step 12: Created README.md and .gitignore files');
  75.  
  76. // Step 13: Start the development server
  77. console.log('Step 13: Starting the development server...');
  78. execSync('npm run dev', { stdio: 'inherit' });
  79.  
  80. console.log(`Project "${projectName}" created successfully!`);
Advertisement
Add Comment
Please, Sign In to add comment