@khalisoft/nexcl 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/bin/cli.ts +32 -0
- package/dist/bin/cli.js +27 -0
- package/dist/utils/createProject.js +37 -0
- package/dist/utils/injectCtrl.js +77 -0
- package/package.json +35 -0
- package/tsconfig.json +57 -0
- package/utils/createProject.ts +57 -0
- package/utils/injectCtrl.ts +103 -0
package/bin/cli.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import prompts from "prompts";
|
|
5
|
+
import createProject from "../utils/createProject";
|
|
6
|
+
|
|
7
|
+
const program = new Command();
|
|
8
|
+
|
|
9
|
+
program
|
|
10
|
+
.name("nexcl")
|
|
11
|
+
.description("Next.js CLI with built-in /ctrl admin system")
|
|
12
|
+
.argument("[project-name]")
|
|
13
|
+
.action(async (name: string) => {
|
|
14
|
+
const response = await prompts([
|
|
15
|
+
{
|
|
16
|
+
type: "text",
|
|
17
|
+
name: "projectName",
|
|
18
|
+
message: "Project name:",
|
|
19
|
+
initial: name || "my-app",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
type: "confirm",
|
|
23
|
+
name: "addAdmin",
|
|
24
|
+
message: "Include /ctrl admin panel?",
|
|
25
|
+
initial: true,
|
|
26
|
+
},
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
await createProject(response);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
program.parse();
|
package/dist/bin/cli.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import prompts from "prompts";
|
|
4
|
+
import createProject from "../utils/createProject";
|
|
5
|
+
const program = new Command();
|
|
6
|
+
program
|
|
7
|
+
.name("nexcl")
|
|
8
|
+
.description("Next.js CLI with built-in /ctrl admin system")
|
|
9
|
+
.argument("[project-name]")
|
|
10
|
+
.action(async (name) => {
|
|
11
|
+
const response = await prompts([
|
|
12
|
+
{
|
|
13
|
+
type: "text",
|
|
14
|
+
name: "projectName",
|
|
15
|
+
message: "Project name:",
|
|
16
|
+
initial: name || "my-app",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
type: "confirm",
|
|
20
|
+
name: "addAdmin",
|
|
21
|
+
message: "Include /ctrl admin panel?",
|
|
22
|
+
initial: true,
|
|
23
|
+
},
|
|
24
|
+
]);
|
|
25
|
+
await createProject(response);
|
|
26
|
+
});
|
|
27
|
+
program.parse();
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { execa } from "execa";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import injectCtrl from "./injectCtrl";
|
|
5
|
+
export default async function createProject({ projectName, addAdmin, }) {
|
|
6
|
+
const spinner = ora("Creating Next.js app...").start();
|
|
7
|
+
try {
|
|
8
|
+
// ✅ Create Next.js with TypeScript
|
|
9
|
+
await execa("npx", [
|
|
10
|
+
"create-next-app@latest",
|
|
11
|
+
projectName,
|
|
12
|
+
"--ts",
|
|
13
|
+
"--app",
|
|
14
|
+
"--eslint",
|
|
15
|
+
"--src-dir",
|
|
16
|
+
"--import-alias=@/*",
|
|
17
|
+
"--yes",
|
|
18
|
+
], { stdio: "inherit" });
|
|
19
|
+
spinner.succeed("Next.js app created");
|
|
20
|
+
const target = path.join(process.cwd(), projectName);
|
|
21
|
+
if (addAdmin) {
|
|
22
|
+
await injectCtrl(target);
|
|
23
|
+
}
|
|
24
|
+
const installSpinner = ora("Installing extra dependencies...").start();
|
|
25
|
+
await execa("npm", ["install", "axios", "zustand"], {
|
|
26
|
+
cwd: target,
|
|
27
|
+
stdio: "inherit",
|
|
28
|
+
});
|
|
29
|
+
installSpinner.succeed("Dependencies installed");
|
|
30
|
+
console.log("\n✅ Done!");
|
|
31
|
+
console.log(`cd ${projectName} && npm run dev`);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
spinner.fail("Failed");
|
|
35
|
+
console.error(error);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
export default async function injectCtrl(target) {
|
|
4
|
+
const ctrlPath = path.join(target, "app/ctrl");
|
|
5
|
+
await fs.ensureDir(ctrlPath);
|
|
6
|
+
await fs.ensureDir(path.join(ctrlPath, "pages"));
|
|
7
|
+
await fs.ensureDir(path.join(ctrlPath, "users"));
|
|
8
|
+
await fs.ensureDir(path.join(ctrlPath, "settings"));
|
|
9
|
+
// Layout
|
|
10
|
+
await fs.writeFile(path.join(ctrlPath, "layout.tsx"), `
|
|
11
|
+
import React from "react";
|
|
12
|
+
|
|
13
|
+
export default function CtrlLayout({
|
|
14
|
+
children,
|
|
15
|
+
}: {
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
}) {
|
|
18
|
+
return (
|
|
19
|
+
<div style={{ display: "flex" }}>
|
|
20
|
+
<aside style={{ width: 250, padding: 20 }}>
|
|
21
|
+
<h2>Admin</h2>
|
|
22
|
+
<nav>
|
|
23
|
+
<a href="/ctrl">Dashboard</a><br />
|
|
24
|
+
<a href="/ctrl/pages">Pages</a><br />
|
|
25
|
+
<a href="/ctrl/users">Users</a><br />
|
|
26
|
+
<a href="/ctrl/settings">Settings</a>
|
|
27
|
+
</nav>
|
|
28
|
+
</aside>
|
|
29
|
+
|
|
30
|
+
<main style={{ flex: 1, padding: 20 }}>
|
|
31
|
+
{children}
|
|
32
|
+
</main>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
`);
|
|
37
|
+
// Dashboard
|
|
38
|
+
await fs.writeFile(path.join(ctrlPath, "page.tsx"), `
|
|
39
|
+
export default function Page() {
|
|
40
|
+
return <h1>Admin Dashboard</h1>;
|
|
41
|
+
}
|
|
42
|
+
`);
|
|
43
|
+
// Pages
|
|
44
|
+
await fs.writeFile(path.join(ctrlPath, "pages/page.tsx"), `
|
|
45
|
+
export default function PagesPage() {
|
|
46
|
+
return <div>Pages Management</div>;
|
|
47
|
+
}
|
|
48
|
+
`);
|
|
49
|
+
// Users
|
|
50
|
+
await fs.writeFile(path.join(ctrlPath, "users/page.tsx"), `
|
|
51
|
+
export default function UsersPage() {
|
|
52
|
+
return <div>Users Management</div>;
|
|
53
|
+
}
|
|
54
|
+
`);
|
|
55
|
+
// Settings
|
|
56
|
+
await fs.writeFile(path.join(ctrlPath, "settings/page.tsx"), `
|
|
57
|
+
export default function SettingsPage() {
|
|
58
|
+
return <div>Settings</div>;
|
|
59
|
+
}
|
|
60
|
+
`);
|
|
61
|
+
// Middleware
|
|
62
|
+
await fs.writeFile(path.join(target, "src/middleware.ts"), `
|
|
63
|
+
import { NextResponse } from "next/server";
|
|
64
|
+
import type { NextRequest } from "next/server";
|
|
65
|
+
|
|
66
|
+
export function middleware(req: NextRequest) {
|
|
67
|
+
if (req.nextUrl.pathname.startsWith("/ctrl")) {
|
|
68
|
+
const isAdmin = true;
|
|
69
|
+
|
|
70
|
+
if (!isAdmin) {
|
|
71
|
+
return NextResponse.redirect(new URL("/", req.url));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
`);
|
|
76
|
+
console.log("✅ /ctrl injected (TypeScript)");
|
|
77
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@khalisoft/nexcl",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "Next.js CLI with built-in admin (/ctrl)",
|
|
6
|
+
"bin": {
|
|
7
|
+
"nexcl": "./dist/bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"dev": "tsx bin/cli.ts"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"nextjs",
|
|
15
|
+
"cli",
|
|
16
|
+
"scaffold"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Devkaahl",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"chalk": "^5.6.2",
|
|
22
|
+
"commander": "^14.0.3",
|
|
23
|
+
"execa": "^9.6.1",
|
|
24
|
+
"fs-extra": "^11.3.4",
|
|
25
|
+
"ora": "^9.3.0",
|
|
26
|
+
"prompts": "^2.4.2"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/fs-extra": "^11.0.4",
|
|
30
|
+
"@types/node": "^25.5.0",
|
|
31
|
+
"@types/prompts": "^2.4.9",
|
|
32
|
+
"tsx": "^4.21.0",
|
|
33
|
+
"typescript": "^5.9.3"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Node",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"skipLibCheck": true
|
|
10
|
+
},
|
|
11
|
+
"include": ["bin", "utils"]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// {
|
|
15
|
+
// // Visit https://aka.ms/tsconfig to read more about this file
|
|
16
|
+
// "compilerOptions": {
|
|
17
|
+
// // File Layout
|
|
18
|
+
// // "rootDir": "./src",
|
|
19
|
+
// // "outDir": "./dist",
|
|
20
|
+
|
|
21
|
+
// // Environment Settings
|
|
22
|
+
// // See also https://aka.ms/tsconfig/module
|
|
23
|
+
// "module": "nodenext",
|
|
24
|
+
// "target": "esnext",
|
|
25
|
+
// "types": [],
|
|
26
|
+
// // For nodejs:
|
|
27
|
+
// // "lib": ["esnext"],
|
|
28
|
+
// // "types": ["node"],
|
|
29
|
+
// // and npm install -D @types/node
|
|
30
|
+
|
|
31
|
+
// // Other Outputs
|
|
32
|
+
// "sourceMap": true,
|
|
33
|
+
// "declaration": true,
|
|
34
|
+
// "declarationMap": true,
|
|
35
|
+
|
|
36
|
+
// // Stricter Typechecking Options
|
|
37
|
+
// "noUncheckedIndexedAccess": true,
|
|
38
|
+
// "exactOptionalPropertyTypes": true,
|
|
39
|
+
|
|
40
|
+
// // Style Options
|
|
41
|
+
// // "noImplicitReturns": true,
|
|
42
|
+
// // "noImplicitOverride": true,
|
|
43
|
+
// // "noUnusedLocals": true,
|
|
44
|
+
// // "noUnusedParameters": true,
|
|
45
|
+
// // "noFallthroughCasesInSwitch": true,
|
|
46
|
+
// // "noPropertyAccessFromIndexSignature": true,
|
|
47
|
+
|
|
48
|
+
// // Recommended Options
|
|
49
|
+
// "strict": true,
|
|
50
|
+
// "jsx": "react-jsx",
|
|
51
|
+
// "verbatimModuleSyntax": true,
|
|
52
|
+
// "isolatedModules": true,
|
|
53
|
+
// "noUncheckedSideEffectImports": true,
|
|
54
|
+
// "moduleDetection": "force",
|
|
55
|
+
// "skipLibCheck": true,
|
|
56
|
+
// }
|
|
57
|
+
// }
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { execa } from "execa";
|
|
2
|
+
import ora from "ora";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import injectCtrl from "./injectCtrl";
|
|
5
|
+
|
|
6
|
+
interface Options {
|
|
7
|
+
projectName: string;
|
|
8
|
+
addAdmin: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default async function createProject({
|
|
12
|
+
projectName,
|
|
13
|
+
addAdmin,
|
|
14
|
+
}: Options) {
|
|
15
|
+
const spinner = ora("Creating Next.js app...").start();
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// ✅ Create Next.js with TypeScript
|
|
19
|
+
await execa(
|
|
20
|
+
"npx",
|
|
21
|
+
[
|
|
22
|
+
"create-next-app@latest",
|
|
23
|
+
projectName,
|
|
24
|
+
"--ts",
|
|
25
|
+
"--app",
|
|
26
|
+
"--eslint",
|
|
27
|
+
"--src-dir",
|
|
28
|
+
"--import-alias=@/*",
|
|
29
|
+
"--yes",
|
|
30
|
+
],
|
|
31
|
+
{ stdio: "inherit" },
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
spinner.succeed("Next.js app created");
|
|
35
|
+
|
|
36
|
+
const target = path.join(process.cwd(), projectName);
|
|
37
|
+
|
|
38
|
+
if (addAdmin) {
|
|
39
|
+
await injectCtrl(target);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const installSpinner = ora("Installing extra dependencies...").start();
|
|
43
|
+
|
|
44
|
+
await execa("npm", ["install", "axios", "zustand"], {
|
|
45
|
+
cwd: target,
|
|
46
|
+
stdio: "inherit",
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
installSpinner.succeed("Dependencies installed");
|
|
50
|
+
|
|
51
|
+
console.log("\n✅ Done!");
|
|
52
|
+
console.log(`cd ${projectName} && npm run dev`);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
spinner.fail("Failed");
|
|
55
|
+
console.error(error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
export default async function injectCtrl(target: string) {
|
|
5
|
+
const ctrlPath = path.join(target, "app/ctrl");
|
|
6
|
+
|
|
7
|
+
await fs.ensureDir(ctrlPath);
|
|
8
|
+
await fs.ensureDir(path.join(ctrlPath, "pages"));
|
|
9
|
+
await fs.ensureDir(path.join(ctrlPath, "users"));
|
|
10
|
+
await fs.ensureDir(path.join(ctrlPath, "settings"));
|
|
11
|
+
|
|
12
|
+
// Layout
|
|
13
|
+
await fs.writeFile(
|
|
14
|
+
path.join(ctrlPath, "layout.tsx"),
|
|
15
|
+
`
|
|
16
|
+
import React from "react";
|
|
17
|
+
|
|
18
|
+
export default function CtrlLayout({
|
|
19
|
+
children,
|
|
20
|
+
}: {
|
|
21
|
+
children: React.ReactNode;
|
|
22
|
+
}) {
|
|
23
|
+
return (
|
|
24
|
+
<div style={{ display: "flex" }}>
|
|
25
|
+
<aside style={{ width: 250, padding: 20 }}>
|
|
26
|
+
<h2>Admin</h2>
|
|
27
|
+
<nav>
|
|
28
|
+
<a href="/ctrl">Dashboard</a><br />
|
|
29
|
+
<a href="/ctrl/pages">Pages</a><br />
|
|
30
|
+
<a href="/ctrl/users">Users</a><br />
|
|
31
|
+
<a href="/ctrl/settings">Settings</a>
|
|
32
|
+
</nav>
|
|
33
|
+
</aside>
|
|
34
|
+
|
|
35
|
+
<main style={{ flex: 1, padding: 20 }}>
|
|
36
|
+
{children}
|
|
37
|
+
</main>
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
`,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Dashboard
|
|
45
|
+
await fs.writeFile(
|
|
46
|
+
path.join(ctrlPath, "page.tsx"),
|
|
47
|
+
`
|
|
48
|
+
export default function Page() {
|
|
49
|
+
return <h1>Admin Dashboard</h1>;
|
|
50
|
+
}
|
|
51
|
+
`,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// Pages
|
|
55
|
+
await fs.writeFile(
|
|
56
|
+
path.join(ctrlPath, "pages/page.tsx"),
|
|
57
|
+
`
|
|
58
|
+
export default function PagesPage() {
|
|
59
|
+
return <div>Pages Management</div>;
|
|
60
|
+
}
|
|
61
|
+
`,
|
|
62
|
+
);
|
|
63
|
+
// Users
|
|
64
|
+
await fs.writeFile(
|
|
65
|
+
path.join(ctrlPath, "users/page.tsx"),
|
|
66
|
+
`
|
|
67
|
+
export default function UsersPage() {
|
|
68
|
+
return <div>Users Management</div>;
|
|
69
|
+
}
|
|
70
|
+
`,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
// Settings
|
|
74
|
+
await fs.writeFile(
|
|
75
|
+
path.join(ctrlPath, "settings/page.tsx"),
|
|
76
|
+
`
|
|
77
|
+
export default function SettingsPage() {
|
|
78
|
+
return <div>Settings</div>;
|
|
79
|
+
}
|
|
80
|
+
`,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
// Middleware
|
|
84
|
+
await fs.writeFile(
|
|
85
|
+
path.join(target, "src/middleware.ts"),
|
|
86
|
+
`
|
|
87
|
+
import { NextResponse } from "next/server";
|
|
88
|
+
import type { NextRequest } from "next/server";
|
|
89
|
+
|
|
90
|
+
export function middleware(req: NextRequest) {
|
|
91
|
+
if (req.nextUrl.pathname.startsWith("/ctrl")) {
|
|
92
|
+
const isAdmin = true;
|
|
93
|
+
|
|
94
|
+
if (!isAdmin) {
|
|
95
|
+
return NextResponse.redirect(new URL("/", req.url));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
`,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
console.log("✅ /ctrl injected (TypeScript)");
|
|
103
|
+
}
|