next-generate-cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/index.js +143 -0
  3. package/package.json +28 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Suraj Pathak (github: surajpathakcs)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/index.js ADDED
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env node
2
+ const { Command } = require('commander');
3
+
4
+ const program = new Command();
5
+
6
+ program
7
+ .name('next-gen')
8
+ .description('Minimal CLI for Next.js scaffolding')
9
+ .version('0.1.0');
10
+
11
+ program
12
+ .command('page <name>')
13
+ .description('Generate a Next.js page')
14
+ .action((name) => {
15
+ generatePage(name);
16
+ });
17
+
18
+ program
19
+ .command('component <name>')
20
+ .description('Generate a React component')
21
+ .action((name) => {
22
+ generateComponent(name)
23
+ });
24
+
25
+ program
26
+ .command('api <name>')
27
+ .description('Generate a Next.js API route')
28
+ .action((name) => {
29
+ generateApiRoute(name);
30
+ });
31
+
32
+ program.parse(process.argv);
33
+
34
+ // Detect which router is being used
35
+ function detectRouter() {
36
+ const fs = require('fs');
37
+ const path = require('path');
38
+
39
+ const appDir = path.join(process.cwd(), 'src/app');
40
+ const pagesDir = path.join(process.cwd(), 'src/pages');
41
+
42
+ if (fs.existsSync(appDir)) {
43
+ return 'app';
44
+ } else if (fs.existsSync(pagesDir)) {
45
+ return 'pages';
46
+ }
47
+ // Default to app router if neither exists
48
+ return 'app';
49
+ }
50
+
51
+ function generatePage(name) {
52
+ const fs = require('fs');
53
+ const path = require('path');
54
+ const router = detectRouter();
55
+
56
+ // Determine path based on router type
57
+ let pageDir, page;
58
+ if (router === 'app') {
59
+ pageDir = path.join(process.cwd(), 'src/app', name);
60
+ page = path.join(pageDir, 'page.jsx');
61
+ } else {
62
+ pageDir = path.join(process.cwd(), 'src/pages');
63
+ page = path.join(pageDir, `${name}.jsx`);
64
+ }
65
+
66
+ // Create directory and file
67
+ if (!fs.existsSync(pageDir)) {
68
+ fs.mkdirSync(pageDir, { recursive: true });
69
+ }
70
+
71
+ const pageContent =
72
+ `export default function ${capitalize(name)}Page() {
73
+ return (
74
+ <div>
75
+ <h1>${capitalize(name)} Page</h1>
76
+ </div>
77
+ );
78
+ }`;
79
+
80
+ fs.writeFileSync(page, pageContent);
81
+ console.log(`Created page at ${page} (${router === 'app' ? 'App' : 'Pages'} Router)`);
82
+ }
83
+
84
+ function generateComponent(name) {
85
+ const fs = require('fs');
86
+ const path = require('path');
87
+
88
+ const componentsDir = path.join(process.cwd(), 'src/components');
89
+ if (!fs.existsSync(componentsDir)) {
90
+ fs.mkdirSync(componentsDir, { recursive: true });
91
+ }
92
+ const component = path.join(componentsDir, `${name}.jsx`);
93
+ const componentContent =
94
+ `import React from 'react';
95
+ const ${capitalize(name)} = () => {
96
+ return (
97
+ <div>
98
+ <h2>${capitalize(name)} Component</h2>
99
+ </div>
100
+ );
101
+ }
102
+ export default ${capitalize(name)};`;
103
+
104
+ fs.writeFileSync(component, componentContent);
105
+ console.log(`Created component at ${component}`);
106
+ }
107
+
108
+ function generateApiRoute(name) {
109
+ const fs = require('fs');
110
+ const path = require('path');
111
+ const router = detectRouter();
112
+
113
+ // Determine path and content based on router type
114
+ let apiDir, apiRoute, apiContent;
115
+ if (router === 'app') {
116
+ apiDir = path.join(process.cwd(), 'src/app/api', name);
117
+ apiRoute = path.join(apiDir, 'route.js');
118
+ apiContent =
119
+ `export async function GET(request) {
120
+ return Response.json({ message: 'Hello from ${name} API route' });
121
+ }`;
122
+ } else {
123
+ apiDir = path.join(process.cwd(), 'src/pages/api');
124
+ apiRoute = path.join(apiDir, `${name}.js`);
125
+ apiContent =
126
+ `export default function handler(req, res) {
127
+ res.status(200).json({ message: 'Hello from ${name} API route' });
128
+ }`;
129
+ }
130
+
131
+ // Create directory and file
132
+ if (!fs.existsSync(apiDir)) {
133
+ fs.mkdirSync(apiDir, { recursive: true });
134
+ }
135
+
136
+ fs.writeFileSync(apiRoute, apiContent);
137
+ console.log(`Created API route at ${apiRoute} (${router === 'app' ? 'App' : 'Pages'} Router)`);
138
+ }
139
+
140
+ // Helper function
141
+ function capitalize(str) {
142
+ return str.charAt(0).toUpperCase() + str.slice(1);
143
+ };
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "next-generate-cli",
3
+ "version": "1.0.0",
4
+ "description": "Minimal CLI tool to generate Next.js projects with customizable options.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "bin": {
10
+ "next-gen": "./index.js"
11
+ },
12
+ "keywords": [
13
+ "nextjs",
14
+ "cli",
15
+ "generator",
16
+ "template",
17
+ "project-generator",
18
+ "next-gen",
19
+ "boilerplate",
20
+ "scaffolding"
21
+ ],
22
+ "author": "Suraj Pathak",
23
+ "license": "MIT",
24
+ "type": "commonjs",
25
+ "dependencies": {
26
+ "commander": "^14.0.2"
27
+ }
28
+ }