sparesdev 0.0.6 → 0.0.8
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/core/init.js +189 -16
- package/package.json +1 -1
package/core/init.js
CHANGED
|
@@ -1,6 +1,170 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import { execSync } from "child_process";
|
|
3
3
|
|
|
4
|
+
function getMissingDependencies() {
|
|
5
|
+
const required = [
|
|
6
|
+
"react",
|
|
7
|
+
"react-dom",
|
|
8
|
+
"react-router-dom",
|
|
9
|
+
"clsx",
|
|
10
|
+
"tailwind-merge",
|
|
11
|
+
"class-variance-authority"
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const pkg = JSON.parse(fs.readFileSync("package.json", "utf-8"));
|
|
16
|
+
|
|
17
|
+
const installed = {
|
|
18
|
+
...pkg.dependencies,
|
|
19
|
+
...pkg.devDependencies
|
|
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
|
+
if (!content.includes("@tailwindcss/vite")) {
|
|
39
|
+
content = content.replace(
|
|
40
|
+
/import react from ['"]@vitejs\/plugin-react['"]/,
|
|
41
|
+
`import react from '@vitejs/plugin-react'\nimport tailwindcss from '@tailwindcss/vite'`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!content.includes("tailwindcss()")) {
|
|
46
|
+
content = content.replace(
|
|
47
|
+
/plugins:\s*\[([^\]]*)\]/,
|
|
48
|
+
"plugins: [$1, tailwindcss()]"
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fs.writeFileSync(viteConfigPath, content);
|
|
53
|
+
|
|
54
|
+
console.log("✅ vite.config.ts updated with Tailwind");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function ensureSrcFolder() {
|
|
58
|
+
if (!fs.existsSync("src")) {
|
|
59
|
+
fs.mkdirSync("src", { recursive: true });
|
|
60
|
+
console.log("📁 Created src folder");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function createTokensCss() {
|
|
65
|
+
const tokensPath = "src/tokens.css";
|
|
66
|
+
|
|
67
|
+
if (fs.existsSync(tokensPath)) {
|
|
68
|
+
console.log("ℹ️ tokens.css already exists");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const content = `@theme {
|
|
73
|
+
|
|
74
|
+
/* Screens */
|
|
75
|
+
--breakpoint-sm: 640px;
|
|
76
|
+
--breakpoint-md: 768px;
|
|
77
|
+
--breakpoint-lg: 1024px;
|
|
78
|
+
|
|
79
|
+
/* Fonts */
|
|
80
|
+
--font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
|
|
81
|
+
|
|
82
|
+
/* Text */
|
|
83
|
+
--text-xs: 10px;
|
|
84
|
+
--text-sm: 12px;
|
|
85
|
+
--text-base: 14px;
|
|
86
|
+
--text-lg: 16px;
|
|
87
|
+
--text-xl: 17.5px;
|
|
88
|
+
--text-2xl: 21.88px;
|
|
89
|
+
--text-3xl: 27.34px;
|
|
90
|
+
|
|
91
|
+
/* Colors */
|
|
92
|
+
--color-background: 255 255 255;
|
|
93
|
+
--color-text: 0 0 0;
|
|
94
|
+
|
|
95
|
+
--color-black: #000000;
|
|
96
|
+
--color-white: #FFFFFF;
|
|
97
|
+
--color-neutral-100: #E6E6E6;
|
|
98
|
+
--color-neutral-500: #666666;
|
|
99
|
+
--color-neutral-900: #000000;
|
|
100
|
+
|
|
101
|
+
/* Border Radius */
|
|
102
|
+
--radius-sm: 4px;
|
|
103
|
+
--radius-base: 8px;
|
|
104
|
+
--radius-lg: 12px;
|
|
105
|
+
--radius-xl: 16px;
|
|
106
|
+
--radius-2xl: 24px;
|
|
107
|
+
--radius-full: 9999px;
|
|
108
|
+
|
|
109
|
+
/* Shadows */
|
|
110
|
+
--shadow-sm: 0 1px 3px -1px rgba(0, 0, 0, 0.16);
|
|
111
|
+
--shadow-md: 0 8px 16px -8px rgba(0, 0, 0, 0.16);
|
|
112
|
+
|
|
113
|
+
/* Spacing */
|
|
114
|
+
--spacing-1: 4px;
|
|
115
|
+
--spacing-2: 8px;
|
|
116
|
+
--spacing-4: 16px;
|
|
117
|
+
--spacing-6: 24px;
|
|
118
|
+
--spacing-8: 32px;
|
|
119
|
+
}
|
|
120
|
+
`;
|
|
121
|
+
|
|
122
|
+
fs.writeFileSync(tokensPath, content);
|
|
123
|
+
console.log("✅ Created src/tokens.css");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function createIndexCss() {
|
|
127
|
+
const indexPath = "src/index.css";
|
|
128
|
+
|
|
129
|
+
const content = `@import "tailwindcss";
|
|
130
|
+
@import "./tokens.css";
|
|
131
|
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap');
|
|
132
|
+
|
|
133
|
+
body {
|
|
134
|
+
background: rgb(var(--color-background));
|
|
135
|
+
color: rgb(var(--color-text));
|
|
136
|
+
font-feature-settings: "rlig" 1, "calt" 1;
|
|
137
|
+
font-family: var(--font-sans);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.hide-scrollbar {
|
|
141
|
+
-ms-overflow-style: none;
|
|
142
|
+
scrollbar-width: none;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.hide-scrollbar::-webkit-scrollbar {
|
|
146
|
+
display: none;
|
|
147
|
+
}
|
|
148
|
+
`;
|
|
149
|
+
|
|
150
|
+
if (!fs.existsSync(indexPath)) {
|
|
151
|
+
fs.writeFileSync(indexPath, content);
|
|
152
|
+
console.log("✅ Created src/index.css");
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let existing = fs.readFileSync(indexPath, "utf-8");
|
|
157
|
+
|
|
158
|
+
if (!existing.includes('./tokens.css')) {
|
|
159
|
+
existing = `@import "./tokens.css";\n` + existing;
|
|
160
|
+
|
|
161
|
+
fs.writeFileSync(indexPath, existing);
|
|
162
|
+
console.log("✅ Added tokens.css import to index.css");
|
|
163
|
+
} else {
|
|
164
|
+
console.log("ℹ️ index.css already configured");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
4
168
|
export async function init() {
|
|
5
169
|
const config = {
|
|
6
170
|
language: "typescript",
|
|
@@ -17,27 +181,36 @@ export async function init() {
|
|
|
17
181
|
|
|
18
182
|
console.log("\n✅ Initialized SparesDev\n");
|
|
19
183
|
|
|
184
|
+
const missingDeps = getMissingDependencies();
|
|
185
|
+
|
|
20
186
|
try {
|
|
21
|
-
|
|
187
|
+
if (missingDeps.length) {
|
|
188
|
+
console.log(
|
|
189
|
+
`📦 Installing dependencies: ${missingDeps.join(", ")}\n`
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
execSync(`npm install ${missingDeps.join(" ")}`, {
|
|
193
|
+
stdio: "inherit"
|
|
194
|
+
});
|
|
195
|
+
} else {
|
|
196
|
+
console.log("✅ Core dependencies already installed\n");
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
console.log("🎨 Installing Tailwind CSS...\n");
|
|
22
200
|
|
|
23
201
|
execSync(
|
|
24
|
-
"npm install
|
|
202
|
+
"npm install -D tailwindcss @tailwindcss/vite",
|
|
25
203
|
{ stdio: "inherit" }
|
|
26
204
|
);
|
|
27
205
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Run manually:
|
|
33
|
-
npm install react react-dom react-router-dom clsx tailwind-merge class-variance-authority
|
|
34
|
-
`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
console.log(`
|
|
38
|
-
⚠️ Tailwind v4 Required
|
|
206
|
+
patchViteConfig();
|
|
207
|
+
ensureSrcFolder();
|
|
208
|
+
createTokensCss();
|
|
209
|
+
createIndexCss();
|
|
39
210
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
211
|
+
console.log("\n🎉 SparesDev setup completed successfully\n");
|
|
212
|
+
} catch (error) {
|
|
213
|
+
console.log("\n❌ Installation failed");
|
|
214
|
+
console.error(error.message);
|
|
215
|
+
}
|
|
43
216
|
}
|