sparesdev 0.0.8 → 0.0.9

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 +129 -39
  2. package/package.json +1 -1
package/core/init.js CHANGED
@@ -1,6 +1,9 @@
1
1
  import fs from "fs";
2
2
  import { execSync } from "child_process";
3
3
 
4
+ // -----------------------------
5
+ // šŸ“¦ Dependencies
6
+ // -----------------------------
4
7
  function getMissingDependencies() {
5
8
  const required = [
6
9
  "react",
@@ -25,6 +28,9 @@ function getMissingDependencies() {
25
28
  }
26
29
  }
27
30
 
31
+ // -----------------------------
32
+ // āš™ļø Vite Config
33
+ // -----------------------------
28
34
  function patchViteConfig() {
29
35
  const viteConfigPath = "vite.config.ts";
30
36
 
@@ -35,6 +41,7 @@ function patchViteConfig() {
35
41
 
36
42
  let content = fs.readFileSync(viteConfigPath, "utf-8");
37
43
 
44
+ // Tailwind import
38
45
  if (!content.includes("@tailwindcss/vite")) {
39
46
  content = content.replace(
40
47
  /import react from ['"]@vitejs\/plugin-react['"]/,
@@ -42,6 +49,12 @@ function patchViteConfig() {
42
49
  );
43
50
  }
44
51
 
52
+ // Path import
53
+ if (!content.includes('import path from "path"')) {
54
+ content = `import path from "path"\n` + content;
55
+ }
56
+
57
+ // Tailwind plugin
45
58
  if (!content.includes("tailwindcss()")) {
46
59
  content = content.replace(
47
60
  /plugins:\s*\[([^\]]*)\]/,
@@ -49,11 +62,27 @@ function patchViteConfig() {
49
62
  );
50
63
  }
51
64
 
65
+ // Alias
66
+ if (!content.includes("resolve:")) {
67
+ content = content.replace(
68
+ /export default defineConfig\(\{/,
69
+ `export default defineConfig({
70
+ resolve: {
71
+ alias: {
72
+ "@": path.resolve(__dirname, "./src"),
73
+ },
74
+ },`
75
+ );
76
+ }
77
+
52
78
  fs.writeFileSync(viteConfigPath, content);
53
79
 
54
- console.log("āœ… vite.config.ts updated with Tailwind");
80
+ console.log("āœ… vite.config.ts configured");
55
81
  }
56
82
 
83
+ // -----------------------------
84
+ // šŸ“ Project Structure
85
+ // -----------------------------
57
86
  function ensureSrcFolder() {
58
87
  if (!fs.existsSync("src")) {
59
88
  fs.mkdirSync("src", { recursive: true });
@@ -61,6 +90,9 @@ function ensureSrcFolder() {
61
90
  }
62
91
  }
63
92
 
93
+ // -----------------------------
94
+ // šŸŽØ Tokens
95
+ // -----------------------------
64
96
  function createTokensCss() {
65
97
  const tokensPath = "src/tokens.css";
66
98
 
@@ -85,37 +117,23 @@ function createTokensCss() {
85
117
  --text-base: 14px;
86
118
  --text-lg: 16px;
87
119
  --text-xl: 17.5px;
88
- --text-2xl: 21.88px;
89
- --text-3xl: 27.34px;
90
120
 
91
121
  /* Colors */
92
122
  --color-background: 255 255 255;
93
123
  --color-text: 0 0 0;
94
124
 
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 */
125
+ /* Radius */
102
126
  --radius-sm: 4px;
103
127
  --radius-base: 8px;
104
128
  --radius-lg: 12px;
105
- --radius-xl: 16px;
106
- --radius-2xl: 24px;
107
- --radius-full: 9999px;
108
129
 
109
130
  /* Shadows */
110
131
  --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
132
 
113
133
  /* Spacing */
114
134
  --spacing-1: 4px;
115
135
  --spacing-2: 8px;
116
136
  --spacing-4: 16px;
117
- --spacing-6: 24px;
118
- --spacing-8: 32px;
119
137
  }
120
138
  `;
121
139
 
@@ -123,6 +141,9 @@ function createTokensCss() {
123
141
  console.log("āœ… Created src/tokens.css");
124
142
  }
125
143
 
144
+ // -----------------------------
145
+ // šŸŽÆ Index CSS (overwrite)
146
+ // -----------------------------
126
147
  function createIndexCss() {
127
148
  const indexPath = "src/index.css";
128
149
 
@@ -147,24 +168,93 @@ body {
147
168
  }
148
169
  `;
149
170
 
150
- if (!fs.existsSync(indexPath)) {
151
- fs.writeFileSync(indexPath, content);
152
- console.log("āœ… Created src/index.css");
153
- return;
154
- }
171
+ fs.writeFileSync(indexPath, content);
155
172
 
156
- let existing = fs.readFileSync(indexPath, "utf-8");
173
+ console.log("āœ… src/index.css replaced");
174
+ }
157
175
 
158
- if (!existing.includes('./tokens.css')) {
159
- existing = `@import "./tokens.css";\n` + existing;
176
+ // -----------------------------
177
+ // āš™ļø TS Config
178
+ // -----------------------------
179
+ function patchTsconfigAlias() {
180
+ const tsconfigPath = "tsconfig.app.json";
160
181
 
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
- }
182
+ if (!fs.existsSync(tsconfigPath)) return;
183
+
184
+ const config = JSON.parse(fs.readFileSync(tsconfigPath, "utf-8"));
185
+
186
+ config.compilerOptions = {
187
+ ...config.compilerOptions,
188
+ baseUrl: ".",
189
+ paths: {
190
+ "@/*": ["src/*"]
191
+ }
192
+ };
193
+
194
+ fs.writeFileSync(tsconfigPath, JSON.stringify(config, null, 2));
195
+
196
+ console.log("āœ… tsconfig alias configured");
197
+ }
198
+
199
+ // -----------------------------
200
+ // šŸ” ScrollToTop
201
+ // -----------------------------
202
+ function createScrollToTop() {
203
+ const filePath = "src/ScrollToTop.tsx";
204
+
205
+ const content = `import { useEffect } from "react";
206
+ import { useLocation } from "react-router-dom";
207
+
208
+ function ScrollToTop() {
209
+ const { pathname } = useLocation();
210
+
211
+ useEffect(() => {
212
+ window.scrollTo(0, 0);
213
+ }, [pathname]);
214
+
215
+ return null;
216
+ }
217
+
218
+ export default ScrollToTop;
219
+ `;
220
+
221
+ fs.writeFileSync(filePath, content);
222
+
223
+ console.log("āœ… Created ScrollToTop.tsx");
166
224
  }
167
225
 
226
+ // -----------------------------
227
+ // šŸš€ main.tsx
228
+ // -----------------------------
229
+ function createMainTsx() {
230
+ const filePath = "src/main.tsx";
231
+
232
+ const content = `import { StrictMode } from "react";
233
+ import { createRoot } from "react-dom/client";
234
+ import { BrowserRouter } from "react-router-dom";
235
+
236
+ import "./index.css";
237
+ import App from "./App.tsx";
238
+ import ScrollToTop from "./ScrollToTop.tsx";
239
+
240
+ createRoot(document.getElementById("root")!).render(
241
+ <StrictMode>
242
+ <BrowserRouter>
243
+ <ScrollToTop />
244
+ <App />
245
+ </BrowserRouter>
246
+ </StrictMode>
247
+ );
248
+ `;
249
+
250
+ fs.writeFileSync(filePath, content);
251
+
252
+ console.log("āœ… Replaced src/main.tsx");
253
+ }
254
+
255
+ // -----------------------------
256
+ // 🧠 INIT
257
+ // -----------------------------
168
258
  export async function init() {
169
259
  const config = {
170
260
  language: "typescript",
@@ -185,10 +275,7 @@ export async function init() {
185
275
 
186
276
  try {
187
277
  if (missingDeps.length) {
188
- console.log(
189
- `šŸ“¦ Installing dependencies: ${missingDeps.join(", ")}\n`
190
- );
191
-
278
+ console.log(`šŸ“¦ Installing: ${missingDeps.join(", ")}\n`);
192
279
  execSync(`npm install ${missingDeps.join(" ")}`, {
193
280
  stdio: "inherit"
194
281
  });
@@ -196,21 +283,24 @@ export async function init() {
196
283
  console.log("āœ… Core dependencies already installed\n");
197
284
  }
198
285
 
199
- console.log("šŸŽØ Installing Tailwind CSS...\n");
286
+ console.log("šŸŽØ Installing Tailwind...\n");
200
287
 
201
288
  execSync(
202
289
  "npm install -D tailwindcss @tailwindcss/vite",
203
290
  { stdio: "inherit" }
204
291
  );
205
292
 
206
- patchViteConfig();
207
293
  ensureSrcFolder();
294
+ patchViteConfig();
295
+ patchTsconfigAlias();
208
296
  createTokensCss();
209
297
  createIndexCss();
298
+ createScrollToTop();
299
+ createMainTsx();
210
300
 
211
- console.log("\nšŸŽ‰ SparesDev setup completed successfully\n");
212
- } catch (error) {
213
- console.log("\nāŒ Installation failed");
214
- console.error(error.message);
301
+ console.log("\nšŸŽ‰ SparesDev setup completed\n");
302
+ } catch (err) {
303
+ console.log("\nāŒ Setup failed");
304
+ console.error(err.message);
215
305
  }
216
306
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sparesdev",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "bin": {