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.
- package/core/init.js +129 -39
- 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
|
|
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
|
-
|
|
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
|
-
|
|
151
|
-
fs.writeFileSync(indexPath, content);
|
|
152
|
-
console.log("ā
Created src/index.css");
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
171
|
+
fs.writeFileSync(indexPath, content);
|
|
155
172
|
|
|
156
|
-
|
|
173
|
+
console.log("ā
src/index.css replaced");
|
|
174
|
+
}
|
|
157
175
|
|
|
158
|
-
|
|
159
|
-
|
|
176
|
+
// -----------------------------
|
|
177
|
+
// āļø TS Config
|
|
178
|
+
// -----------------------------
|
|
179
|
+
function patchTsconfigAlias() {
|
|
180
|
+
const tsconfigPath = "tsconfig.app.json";
|
|
160
181
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
|
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
|
|
212
|
-
} catch (
|
|
213
|
-
console.log("\nā
|
|
214
|
-
console.error(
|
|
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
|
}
|