nextgenie-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.
- package/README.md +102 -0
- package/package.json +18 -0
- package/src/index.ts +107 -0
- package/tsconfig.json +28 -0
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# NextGenie 🧞♂️
|
|
2
|
+
|
|
3
|
+
A magical CLI tool to quickly generate Next.js app directory pages and layouts.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g nextgenie
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- 🚀 Quickly generate Next.js pages and layouts
|
|
14
|
+
- 📁 Create nested page structures with a single command
|
|
15
|
+
- 🎯 Automatic layout.tsx generation
|
|
16
|
+
- ⚡️ Simple and intuitive syntax
|
|
17
|
+
- 🔥 Built with TypeScript for reliability
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Creating Simple Pages
|
|
22
|
+
|
|
23
|
+
Create single or multiple pages directly in your app directory:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
nextgenie create about contact
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
This will generate:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
app/
|
|
33
|
+
├─ about/
|
|
34
|
+
│ ├─ page.tsx
|
|
35
|
+
│ └─ layout.tsx
|
|
36
|
+
└─ contact/
|
|
37
|
+
├─ page.tsx
|
|
38
|
+
└─ layout.tsx
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Creating Nested Pages
|
|
42
|
+
|
|
43
|
+
Create pages inside a specific folder using the `in` keyword:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
nextgenie create profile settings in dashboard
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This will generate:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
app/
|
|
53
|
+
└─ dashboard/
|
|
54
|
+
├─ layout.tsx
|
|
55
|
+
├─ profile/
|
|
56
|
+
│ ├─ page.tsx
|
|
57
|
+
│ └─ layout.tsx
|
|
58
|
+
└─ settings/
|
|
59
|
+
├─ page.tsx
|
|
60
|
+
└─ layout.tsx
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Generated Files
|
|
64
|
+
|
|
65
|
+
### page.tsx
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
export default function PageName() {
|
|
69
|
+
return <div>pageName page</div>;
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### layout.tsx
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
export default function LayoutName({
|
|
77
|
+
children,
|
|
78
|
+
}: {
|
|
79
|
+
children: React.ReactNode;
|
|
80
|
+
}) {
|
|
81
|
+
return <div>{children}</div>;
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Requirements
|
|
86
|
+
|
|
87
|
+
- Node.js 16 or higher
|
|
88
|
+
- Next.js 13+ (App Directory)
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
## Author
|
|
93
|
+
|
|
94
|
+
## Contributing
|
|
95
|
+
|
|
96
|
+
Pull requests are welcome! Feel free to contribute to this project.
|
|
97
|
+
|
|
98
|
+
1. Fork the Project
|
|
99
|
+
2. Create your Feature Branch (`git checkout -b feature/amazing-feature`)
|
|
100
|
+
3. Commit your Changes (`git commit -m 'add some amazingfeature'`)
|
|
101
|
+
4. Push to the Branch (`git push origin feature/amazing-feature`)
|
|
102
|
+
5. Open a Pull Request
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nextgenie-cli",
|
|
3
|
+
"module": "src/index.ts",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"devDependencies": {
|
|
7
|
+
"@types/bun": "latest"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"@abidnafi/nextgenie": "src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"typescript": "^5"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"commander": "^13.1.0"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { program } from "commander";
|
|
4
|
+
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
|
|
7
|
+
const appDir = join(process.cwd(), "app");
|
|
8
|
+
|
|
9
|
+
program
|
|
10
|
+
.command("create")
|
|
11
|
+
.argument("<pages...>", "Pages to create, with optional root folder syntax")
|
|
12
|
+
.description("Create Next.js pages with optional root folder")
|
|
13
|
+
.action((args: string[]) => {
|
|
14
|
+
let rootFolder: string | null = null;
|
|
15
|
+
let pages: string[] = [];
|
|
16
|
+
|
|
17
|
+
// Check for "in" keyword instead of arrows
|
|
18
|
+
const separatorIndex = args.findIndex((arg) => arg.toLowerCase() === "in");
|
|
19
|
+
|
|
20
|
+
if (separatorIndex !== -1) {
|
|
21
|
+
// If "in" is present, treat the first argument as the root folder
|
|
22
|
+
if (separatorIndex === 0 || separatorIndex === args.length - 1) {
|
|
23
|
+
console.error(
|
|
24
|
+
"❌ Invalid usage. Correct syntax: nextgenie create page1 page2 in root"
|
|
25
|
+
);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
rootFolder = args[separatorIndex + 1] ?? ""; // Root folder after "in"
|
|
30
|
+
pages = args.slice(0, separatorIndex); // Pages before "in"
|
|
31
|
+
} else {
|
|
32
|
+
pages = args;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (pages.length === 0) {
|
|
36
|
+
console.error("❌ No pages specified!");
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (rootFolder) {
|
|
41
|
+
const rootPath = join(appDir, rootFolder);
|
|
42
|
+
|
|
43
|
+
// Create root folder if it doesn't exist
|
|
44
|
+
if (!existsSync(rootPath)) {
|
|
45
|
+
mkdirSync(rootPath, { recursive: true });
|
|
46
|
+
|
|
47
|
+
// Create layout.tsx for root
|
|
48
|
+
createLayout(rootPath, rootFolder);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Create sub-pages inside the root folder
|
|
52
|
+
pages.forEach((pageName) => {
|
|
53
|
+
const pageSuccess = createPage(join(rootPath, pageName), pageName);
|
|
54
|
+
const layoutSuccess = createLayout(join(rootPath, pageName), pageName);
|
|
55
|
+
if (pageSuccess && layoutSuccess) {
|
|
56
|
+
console.log(`✅ '${pageName}' created in ${rootFolder}!`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
} else {
|
|
60
|
+
// No root folder, create individual pages in app/
|
|
61
|
+
pages.forEach((pageName) => {
|
|
62
|
+
const pagePath = join(appDir, pageName);
|
|
63
|
+
const pageSuccess = createPage(pagePath, pageName);
|
|
64
|
+
const layoutSuccess = createLayout(pagePath, pageName);
|
|
65
|
+
if (pageSuccess && layoutSuccess) {
|
|
66
|
+
console.log(`✅ '${pageName}' created!`);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
program.parse(process.argv);
|
|
73
|
+
|
|
74
|
+
// Function to create a page.tsx
|
|
75
|
+
function createPage(pagePath: string, pageName: string) {
|
|
76
|
+
if (existsSync(pagePath)) {
|
|
77
|
+
console.error(`❌ Page '${pageName}' already exists! Skipping...`);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
mkdirSync(pagePath, { recursive: true });
|
|
82
|
+
|
|
83
|
+
const pageContent = `export default function ${capitalize(pageName)}Page() {
|
|
84
|
+
return <div>${pageName} page</div>;
|
|
85
|
+
}`;
|
|
86
|
+
writeFileSync(join(pagePath, "page.tsx"), pageContent);
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Function to create a layout.tsx
|
|
91
|
+
function createLayout(folderPath: string, folderName: string) {
|
|
92
|
+
const layoutPath = join(folderPath, "layout.tsx");
|
|
93
|
+
if (!existsSync(layoutPath)) {
|
|
94
|
+
const layoutContent = `export default function ${capitalize(
|
|
95
|
+
folderName
|
|
96
|
+
)}Layout({ children }: { children: React.ReactNode }) {
|
|
97
|
+
return <div>{children}</div>;
|
|
98
|
+
}`;
|
|
99
|
+
writeFileSync(layoutPath, layoutContent);
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Capitalize first letter
|
|
105
|
+
function capitalize(str: string): string {
|
|
106
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
107
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Environment setup & latest features
|
|
4
|
+
"lib": ["esnext"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
|
|
11
|
+
// Bundler mode
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"verbatimModuleSyntax": true,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
|
|
17
|
+
// Best practices
|
|
18
|
+
"strict": true,
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true,
|
|
21
|
+
"noUncheckedIndexedAccess": true,
|
|
22
|
+
|
|
23
|
+
// Some stricter flags (disabled by default)
|
|
24
|
+
"noUnusedLocals": false,
|
|
25
|
+
"noUnusedParameters": false,
|
|
26
|
+
"noPropertyAccessFromIndexSignature": false
|
|
27
|
+
}
|
|
28
|
+
}
|