create-next-mui 0.1.0 → 0.1.2

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/README.md +7 -1
  2. package/package.json +1 -1
  3. package/src/index.js +90 -27
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ <img width="1420" height="308" alt="CREATE-NEXT-MUI-BANNER" src="https://github.com/user-attachments/assets/11e72fc8-6b6d-40c4-97a1-c05f7b943e02" />
2
+
1
3
  # create-next-mui 🚀
2
4
 
3
5
  [![npm version](https://img.shields.io/npm/v/create-next-mui?style=flat&logo=npm&color=CB3837)](https://www.npmjs.com/package/create-next-mui)
@@ -15,6 +17,10 @@ Stop wasting time wiring up Emotion caches, Next.js App Router layout configs, o
15
17
  You don't need to install anything globally. Just run the following command in your terminal:
16
18
 
17
19
  ```bash
20
+ npx create-next-mui my-next-mui-app
21
+
22
+ # or use prompts
23
+
18
24
  npx create-next-mui
19
25
 
20
26
  # or
@@ -22,7 +28,7 @@ npx create-next-mui
22
28
  npm init next-mui
23
29
  ```
24
30
 
25
- The interactive prompt engine (powered by `@clack/prompts`) will guide you through naming your project and selecting your preferred flavor.
31
+ Passing a project name creates that folder and uses the same name in the generated project metadata. If you omit the name, the interactive prompt engine (powered by `@clack/prompts`) will guide you through naming your project and selecting your preferred flavor.
26
32
 
27
33
  ---
28
34
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-next-mui",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "spin up your nextjs project with mui setup",
5
5
  "keywords": [
6
6
  "nextjs",
package/src/index.js CHANGED
@@ -10,41 +10,102 @@ import { fileURLToPath } from "node:url";
10
10
  const __filename = fileURLToPath(import.meta.url);
11
11
  const __dirname = path.dirname(__filename);
12
12
 
13
+ const args = process.argv.slice(2);
14
+ const positionalArgs = args.filter(
15
+ (arg) => !["--yes", "-y", "--js"].includes(arg),
16
+ );
17
+
18
+ const PROJECT_NAME = positionalArgs[0];
19
+ const hasInitialProjectName = PROJECT_NAME !== undefined;
20
+
21
+ const hasYesFlag = args.includes("--yes") || args.includes("-y");
22
+ const hasJsFlag = args.includes("--js");
23
+
24
+ const DEFAULT_LANGUAGE = hasJsFlag ? "js" : "ts";
25
+
26
+ function validateProjectName(value) {
27
+ if (value.length === 0) return "Project name is required!";
28
+
29
+ if (value !== "." && value.match(/[^a-zA-Z0-9-_]/g)) {
30
+ return "Keep it URL safe or use '.' for the current folder";
31
+ }
32
+ }
33
+
34
+ function getPackageName(projectName, targetProjectDir) {
35
+ const rawName =
36
+ projectName === "." ? path.basename(targetProjectDir) : projectName;
37
+
38
+ return rawName.toLowerCase();
39
+ }
40
+
41
+ async function updateProjectName(targetProjectDir, packageName) {
42
+ const files = ["package.json", "package-lock.json"];
43
+
44
+ await Promise.all(
45
+ files.map(async (file) => {
46
+ const filePath = path.join(targetProjectDir, file);
47
+
48
+ try {
49
+ const content = await fs.readFile(filePath, "utf8");
50
+ const json = JSON.parse(content);
51
+
52
+ json.name = packageName;
53
+
54
+ if (json.packages?.[""]?.name) {
55
+ json.packages[""].name = packageName;
56
+ }
57
+
58
+ await fs.writeFile(filePath, `${JSON.stringify(json, null, 2)}\n`);
59
+ } catch (error) {
60
+ if (error.code === "ENOENT") return;
61
+
62
+ throw error;
63
+ }
64
+ }),
65
+ );
66
+ }
67
+
13
68
  async function main() {
14
69
  console.clear();
15
70
  p.intro(color.bgBlue(color.white(" create-next-mui ")));
16
71
 
72
+ const projectNameError = hasInitialProjectName
73
+ ? validateProjectName(PROJECT_NAME)
74
+ : undefined;
75
+
76
+ if (projectNameError) {
77
+ p.cancel(projectNameError);
78
+ process.exit(1);
79
+ }
80
+
17
81
  const project = await p.group(
18
82
  {
19
83
  name: () =>
20
- p.text({
21
- message: "What is your project name?",
22
- placeholder: "my-next-mui-app (or '.' for current directory)",
23
- validate(value) {
24
- if (value.length === 0) return "Project name is required!";
25
-
26
- // ✅ Allow exactly "." otherwise apply your safe character regex
27
- if (value !== "." && value.match(/[^a-zA-Z0-9-_]/g)) {
28
- return "Keep it URL safe or use '.' for the current folder";
29
- }
30
- },
31
- }),
84
+ hasInitialProjectName
85
+ ? Promise.resolve(PROJECT_NAME)
86
+ : p.text({
87
+ message: "What is your project name?",
88
+ placeholder: "my-next-mui-app (or '.' for current directory)",
89
+ validate: validateProjectName,
90
+ }),
32
91
  language: () =>
33
- p.select({
34
- message: "Choose your language flavor:",
35
- options: [
36
- {
37
- value: "ts",
38
- label: "TypeScript (Recommended)",
39
- hint: "Strict typings, clean architecture",
40
- },
41
- {
42
- value: "js",
43
- label: "JavaScript",
44
- hint: "Vanilla JS configuration",
45
- },
46
- ],
47
- }),
92
+ hasYesFlag
93
+ ? Promise.resolve(DEFAULT_LANGUAGE)
94
+ : p.select({
95
+ message: "Choose your language flavor:",
96
+ options: [
97
+ {
98
+ value: "ts",
99
+ label: "TypeScript (Recommended)",
100
+ hint: "Strict typings, clean architecture",
101
+ },
102
+ {
103
+ value: "js",
104
+ label: "JavaScript",
105
+ hint: "Vanilla JS configuration",
106
+ },
107
+ ],
108
+ }),
48
109
  },
49
110
  {
50
111
  onCancel: () => {
@@ -61,6 +122,7 @@ async function main() {
61
122
 
62
123
  // Define destination paths (where the user is running the command)
63
124
  const targetProjectDir = path.resolve(process.cwd(), project.name);
125
+ const packageName = getPackageName(project.name, targetProjectDir);
64
126
 
65
127
  // If targeting current directory, make sure it's clean
66
128
  if (project.name === ".") {
@@ -97,6 +159,7 @@ async function main() {
97
159
  );
98
160
  },
99
161
  });
162
+ await updateProjectName(targetProjectDir, packageName);
100
163
 
101
164
  s.stop(color.green("Workspace scaffolded successfully!"));
102
165
  } catch (error) {