sparesdev 0.0.5 → 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 +85 -7
  2. package/package.json +1 -1
package/core/init.js CHANGED
@@ -1,4 +1,60 @@
1
1
  import fs from "fs";
2
+ import { execSync } from "child_process";
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
+ }
2
58
 
3
59
  export async function init() {
4
60
  const config = {
@@ -10,16 +66,38 @@ export async function init() {
10
66
  };
11
67
 
12
68
  fs.writeFileSync(
13
- "spares.config.json",
69
+ "sparesdev.config.json",
14
70
  JSON.stringify(config, null, 2)
15
71
  );
16
72
 
17
- console.log(`\n✅ Initialized (TypeScript)\n`);
73
+ console.log("\n✅ Initialized SparesDev\n");
74
+
75
+ const missingDeps = getMissingDependencies();
76
+
77
+ try {
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");
91
+
92
+ execSync(
93
+ "npm install -D tailwindcss @tailwindcss/vite",
94
+ { stdio: "inherit" }
95
+ );
18
96
 
19
- console.log(`
20
- ⚠️ Tailwind v4 Required
97
+ patchViteConfig();
21
98
 
22
- - Create src/index.css
23
- - Create src/tokens.css
24
- `);
99
+ console.log("\n✅ Setup completed successfully\n");
100
+ } catch {
101
+ console.log("\n❌ Installation failed");
102
+ }
25
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sparesdev",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "bin": {