create-next-mui 0.1.0 → 0.1.1

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 +63 -12
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.1",
4
4
  "description": "spin up your nextjs project with mui setup",
5
5
  "keywords": [
6
6
  "nextjs",
package/src/index.js CHANGED
@@ -10,25 +10,74 @@ import { fileURLToPath } from "node:url";
10
10
  const __filename = fileURLToPath(import.meta.url);
11
11
  const __dirname = path.dirname(__filename);
12
12
 
13
+ const initialProjectName = process.argv[2];
14
+ const hasInitialProjectName = typeof initialProjectName === "string";
15
+
16
+ function validateProjectName(value) {
17
+ if (value.length === 0) return "Project name is required!";
18
+
19
+ if (value !== "." && value.match(/[^a-zA-Z0-9-_]/g)) {
20
+ return "Keep it URL safe or use '.' for the current folder";
21
+ }
22
+ }
23
+
24
+ function getPackageName(projectName, targetProjectDir) {
25
+ const rawName =
26
+ projectName === "." ? path.basename(targetProjectDir) : projectName;
27
+
28
+ return rawName.toLowerCase();
29
+ }
30
+
31
+ async function updateProjectName(targetProjectDir, packageName) {
32
+ const files = ["package.json", "package-lock.json"];
33
+
34
+ await Promise.all(
35
+ files.map(async (file) => {
36
+ const filePath = path.join(targetProjectDir, file);
37
+
38
+ try {
39
+ const content = await fs.readFile(filePath, "utf8");
40
+ const json = JSON.parse(content);
41
+
42
+ json.name = packageName;
43
+
44
+ if (json.packages?.[""]?.name) {
45
+ json.packages[""].name = packageName;
46
+ }
47
+
48
+ await fs.writeFile(filePath, `${JSON.stringify(json, null, 2)}\n`);
49
+ } catch (error) {
50
+ if (error.code === "ENOENT") return;
51
+
52
+ throw error;
53
+ }
54
+ }),
55
+ );
56
+ }
57
+
13
58
  async function main() {
14
59
  console.clear();
15
60
  p.intro(color.bgBlue(color.white(" create-next-mui ")));
16
61
 
62
+ const projectNameError = hasInitialProjectName
63
+ ? validateProjectName(initialProjectName)
64
+ : undefined;
65
+
66
+ if (projectNameError) {
67
+ p.cancel(projectNameError);
68
+ process.exit(1);
69
+ }
70
+
17
71
  const project = await p.group(
18
72
  {
19
73
  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
- }),
74
+ hasInitialProjectName
75
+ ? Promise.resolve(initialProjectName)
76
+ : p.text({
77
+ message: "What is your project name?",
78
+ placeholder: "my-next-mui-app (or '.' for current directory)",
79
+ validate: validateProjectName,
80
+ }),
32
81
  language: () =>
33
82
  p.select({
34
83
  message: "Choose your language flavor:",
@@ -61,6 +110,7 @@ async function main() {
61
110
 
62
111
  // Define destination paths (where the user is running the command)
63
112
  const targetProjectDir = path.resolve(process.cwd(), project.name);
113
+ const packageName = getPackageName(project.name, targetProjectDir);
64
114
 
65
115
  // If targeting current directory, make sure it's clean
66
116
  if (project.name === ".") {
@@ -97,6 +147,7 @@ async function main() {
97
147
  );
98
148
  },
99
149
  });
150
+ await updateProjectName(targetProjectDir, packageName);
100
151
 
101
152
  s.stop(color.green("Workspace scaffolded successfully!"));
102
153
  } catch (error) {