sparesdev 0.0.6 → 0.0.7

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 (2) hide show
  1. package/core/init.js +75 -15
  2. package/package.json +1 -1
package/core/init.js CHANGED
@@ -1,6 +1,61 @@
1
1
  import fs from "fs";
2
2
  import { execSync } from "child_process";
3
3
 
4
+ function getMissingDependencies() {
5
+ try {
6
+ const pkg = JSON.parse(fs.readFileSync("package.json", "utf-8"));
7
+
8
+ const installed = {
9
+ ...pkg.dependencies,
10
+ ...pkg.devDependencies
11
+ };
12
+
13
+ const required = [
14
+ "react",
15
+ "react-dom",
16
+ "react-router-dom",
17
+ "clsx",
18
+ "tailwind-merge",
19
+ "class-variance-authority"
20
+ ];
21
+
22
+ return required.filter(dep => !installed?.[dep]);
23
+ } catch {
24
+ return required;
25
+ }
26
+ }
27
+
28
+ function patchViteConfig() {
29
+ const viteConfigPath = "vite.config.ts";
30
+
31
+ if (!fs.existsSync(viteConfigPath)) {
32
+ console.log("⚠️ vite.config.ts not found, skipping patch");
33
+ return;
34
+ }
35
+
36
+ let content = fs.readFileSync(viteConfigPath, "utf-8");
37
+
38
+ // add import if missing
39
+ if (!content.includes("@tailwindcss/vite")) {
40
+ content = content.replace(
41
+ /import react from ['"]@vitejs\/plugin-react['"]/,
42
+ `import react from '@vitejs/plugin-react'\nimport tailwindcss from '@tailwindcss/vite'`
43
+ );
44
+ }
45
+
46
+ // add plugin if missing
47
+ if (!content.includes("tailwindcss()")) {
48
+ content = content.replace(
49
+ /plugins:\s*\[([^\]]*)\]/,
50
+ "plugins: [$1, tailwindcss()]"
51
+ );
52
+ }
53
+
54
+ fs.writeFileSync(viteConfigPath, content);
55
+
56
+ console.log("✅ vite.config.ts updated with Tailwind");
57
+ }
58
+
4
59
  export async function init() {
5
60
  const config = {
6
61
  language: "typescript",
@@ -17,27 +72,32 @@ export async function init() {
17
72
 
18
73
  console.log("\n✅ Initialized SparesDev\n");
19
74
 
75
+ const missingDeps = getMissingDependencies();
76
+
20
77
  try {
21
- console.log("📦 Installing required dependencies...\n");
78
+ if (missingDeps.length) {
79
+ console.log(
80
+ `📦 Installing dependencies: ${missingDeps.join(", ")}\n`
81
+ );
82
+
83
+ execSync(`npm install ${missingDeps.join(" ")}`, {
84
+ stdio: "inherit"
85
+ });
86
+ } else {
87
+ console.log("✅ Core dependencies already installed\n");
88
+ }
89
+
90
+ console.log("🎨 Installing Tailwind CSS...\n");
22
91
 
23
92
  execSync(
24
- "npm install react react-dom react-router-dom clsx tailwind-merge class-variance-authority",
93
+ "npm install -D tailwindcss @tailwindcss/vite",
25
94
  { stdio: "inherit" }
26
95
  );
27
96
 
28
- console.log("\n✅ Dependencies installed successfully\n");
97
+ patchViteConfig();
98
+
99
+ console.log("\n✅ Setup completed successfully\n");
29
100
  } catch {
30
- console.log("\n❌ Dependency installation failed");
31
- console.log(`
32
- Run manually:
33
- npm install react react-dom react-router-dom clsx tailwind-merge class-variance-authority
34
- `);
101
+ console.log("\n❌ Installation failed");
35
102
  }
36
-
37
- console.log(`
38
- ⚠️ Tailwind v4 Required
39
-
40
- - Create src/index.css
41
- - Create src/tokens.css
42
- `);
43
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sparesdev",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "bin": {