react-apps-ui 1.0.12 → 1.0.14

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 (3) hide show
  1. package/dist/index.js +54 -13
  2. package/package.json +1 -1
  3. package/src/index.ts +62 -13
package/dist/index.js CHANGED
@@ -17,6 +17,32 @@ program
17
17
  .name("react-apps-ui")
18
18
  .description("Add high-quality components to your React Native app")
19
19
  .version("1.0.0");
20
+ // Helper to filter out packages that are already in package.json
21
+ function filterMissingDeps(deps) {
22
+ const packageJsonPath = path_1.default.join(process.cwd(), "package.json");
23
+ if (!fs_1.default.existsSync(packageJsonPath))
24
+ return deps;
25
+ try {
26
+ const pkg = JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf-8"));
27
+ const installed = {
28
+ ...(pkg.dependencies || {}),
29
+ ...(pkg.devDependencies || {}),
30
+ };
31
+ return deps.filter((dep) => {
32
+ let pkgName = dep;
33
+ if (dep.startsWith("@")) {
34
+ pkgName = "@" + dep.slice(1).split("@")[0];
35
+ }
36
+ else {
37
+ pkgName = dep.split("@")[0];
38
+ }
39
+ return !installed[pkgName];
40
+ });
41
+ }
42
+ catch {
43
+ return deps;
44
+ }
45
+ }
20
46
  // --- THE INIT COMMAND ---
21
47
  // 1. Define the foundational architecture for each engine
22
48
  const BASE_DEPS = {
@@ -62,7 +88,7 @@ program
62
88
  const engineKey = response.engine;
63
89
  const setup = BASE_DEPS[engineKey];
64
90
  // 2. USE THE REGISTRY_URL to fetch the correct JSON manifest
65
- const manifestUrl = `${REGISTRY_URL}/${response.engine}.json`;
91
+ const manifestUrl = `${REGISTRY_URL}/${response.engine}.json?t=${Date.now()}`;
66
92
  console.log(chalk_1.default.dim(`\nFetching registry from GitHub...`));
67
93
  try {
68
94
  const res = await fetch(manifestUrl);
@@ -124,18 +150,24 @@ program
124
150
  }
125
151
  }
126
152
  }
127
- // 5. INSTALL FOUNDATIONAL NPM DEPENDENCIES
128
- if (setup.npm.length > 0) {
129
- const depList = setup.npm.join(" ");
130
- console.log(chalk_1.default.blue(`\nšŸ“¦ Installing foundational NPM dependencies: ${depList}...`));
153
+ // 5. INSTALL FOUNDATIONAL NPM DEPENDENCIES (Skipping already installed)
154
+ const missingBaseDeps = filterMissingDeps(setup.npm);
155
+ if (missingBaseDeps.length > 0) {
156
+ const depList = missingBaseDeps.join(" ");
157
+ console.log(chalk_1.default.blue(`\nšŸ“¦ Installing missing foundational NPM dependencies: ${depList}...`));
131
158
  try {
132
- (0, child_process_1.execSync)(`npm install ${depList}`, { stdio: "inherit" });
159
+ (0, child_process_1.execSync)(`npm install ${depList} --legacy-peer-deps`, {
160
+ stdio: "inherit",
161
+ });
133
162
  console.log(chalk_1.default.green("āœ“ Dependencies installed successfully."));
134
163
  }
135
164
  catch (err) {
136
165
  console.log(chalk_1.default.red("āŒ Failed to install dependencies. You may need to install them manually."));
137
166
  }
138
167
  }
168
+ else {
169
+ console.log(chalk_1.default.green("\nāœ“ All foundational NPM dependencies are already installed. Skipping."));
170
+ }
139
171
  console.log(chalk_1.default.blue("\nšŸŽ‰ Initialization complete!"));
140
172
  console.log(chalk_1.default.dim("Wrap your app in the <ThemeProvider> to get started."));
141
173
  }
@@ -159,7 +191,7 @@ program
159
191
  fs_1.default.existsSync(path_1.default.join(process.cwd(), "src/theme/tailwind-preset.js"));
160
192
  const engine = hasTailwind ? "mobile-nativewind" : "mobile-stylesheet";
161
193
  console.log(chalk_1.default.dim(`\nDetected engine: ${engine}`));
162
- const manifestUrl = `${REGISTRY_URL}/${engine}.json`;
194
+ const manifestUrl = `${REGISTRY_URL}/${engine}.json?t=${Date.now()}`;
163
195
  try {
164
196
  // 2. Fetch the massive JSON database
165
197
  const res = await fetch(manifestUrl);
@@ -178,6 +210,9 @@ program
178
210
  compData.registryDependencies.forEach(resolveDependencies);
179
211
  }
180
212
  };
213
+ // Force the CLI to always check base dependencies
214
+ const setup = BASE_DEPS[engine];
215
+ setup.registry.forEach(resolveDependencies);
181
216
  // Run the resolver for every component the user typed in the terminal
182
217
  components.forEach(resolveDependencies);
183
218
  // We don't need to reinstall the theme if it was pulled as a dependency
@@ -211,7 +246,7 @@ program
211
246
  }
212
247
  }
213
248
  }
214
- // 5. INSTALL NPM DEPENDENCIES
249
+ // 5. INSTALL NPM DEPENDENCIES (Skipping already installed)
215
250
  const depsToInstall = new Set();
216
251
  // Collect all dependencies from the components we just added
217
252
  for (const compName of componentsToAdd) {
@@ -220,18 +255,24 @@ program
220
255
  compData.dependencies.forEach((dep) => depsToInstall.add(dep));
221
256
  }
222
257
  }
223
- if (depsToInstall.size > 0) {
224
- const depList = Array.from(depsToInstall).join(" ");
225
- console.log(chalk_1.default.blue(`\nšŸ“¦ Installing NPM dependencies: ${depList}...`));
258
+ // Filter out anything already installed in user's package.json
259
+ const missingDeps = filterMissingDeps(Array.from(depsToInstall));
260
+ if (missingDeps.length > 0) {
261
+ const depList = missingDeps.join(" ");
262
+ console.log(chalk_1.default.blue(`\nšŸ“¦ Installing missing NPM dependencies: ${depList}...`));
226
263
  try {
227
- // This runs 'npm install' directly in the user's terminal
228
- (0, child_process_1.execSync)(`npm install ${depList}`, { stdio: "inherit" });
264
+ (0, child_process_1.execSync)(`npm install ${depList} --legacy-peer-deps`, {
265
+ stdio: "inherit",
266
+ });
229
267
  console.log(chalk_1.default.green("āœ“ Dependencies installed successfully."));
230
268
  }
231
269
  catch (err) {
232
270
  console.log(chalk_1.default.red("āŒ Failed to install dependencies. You may need to install them manually."));
233
271
  }
234
272
  }
273
+ else if (depsToInstall.size > 0) {
274
+ console.log(chalk_1.default.green("\nāœ“ Required NPM dependencies are already installed. Skipping."));
275
+ }
235
276
  console.log(chalk_1.default.blue("\nšŸŽ‰ Components installed successfully!"));
236
277
  }
237
278
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-apps-ui",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "A universal, Shadcn-inspired UI component CLI for Web, React Native, and Expo.",
5
5
  "author": "Anand Vyas",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -17,6 +17,32 @@ program
17
17
  .description("Add high-quality components to your React Native app")
18
18
  .version("1.0.0");
19
19
 
20
+ // Helper to filter out packages that are already in package.json
21
+ function filterMissingDeps(deps: string[]): string[] {
22
+ const packageJsonPath = path.join(process.cwd(), "package.json");
23
+ if (!fs.existsSync(packageJsonPath)) return deps;
24
+
25
+ try {
26
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
27
+ const installed = {
28
+ ...(pkg.dependencies || {}),
29
+ ...(pkg.devDependencies || {}),
30
+ };
31
+
32
+ return deps.filter((dep) => {
33
+ let pkgName = dep;
34
+ if (dep.startsWith("@")) {
35
+ pkgName = "@" + dep.slice(1).split("@")[0];
36
+ } else {
37
+ pkgName = dep.split("@")[0];
38
+ }
39
+ return !installed[pkgName];
40
+ });
41
+ } catch {
42
+ return deps;
43
+ }
44
+ }
45
+
20
46
  // --- THE INIT COMMAND ---
21
47
 
22
48
  // 1. Define the foundational architecture for each engine
@@ -68,7 +94,7 @@ program
68
94
  const setup = BASE_DEPS[engineKey];
69
95
 
70
96
  // 2. USE THE REGISTRY_URL to fetch the correct JSON manifest
71
- const manifestUrl = `${REGISTRY_URL}/${response.engine}.json`;
97
+ const manifestUrl = `${REGISTRY_URL}/${response.engine}.json?t=${Date.now()}`;
72
98
  console.log(chalk.dim(`\nFetching registry from GitHub...`));
73
99
 
74
100
  try {
@@ -184,16 +210,20 @@ program
184
210
  }
185
211
  }
186
212
 
187
- // 5. INSTALL FOUNDATIONAL NPM DEPENDENCIES
188
- if (setup.npm.length > 0) {
189
- const depList = setup.npm.join(" ");
213
+ // 5. INSTALL FOUNDATIONAL NPM DEPENDENCIES (Skipping already installed)
214
+ const missingBaseDeps = filterMissingDeps(setup.npm);
215
+
216
+ if (missingBaseDeps.length > 0) {
217
+ const depList = missingBaseDeps.join(" ");
190
218
  console.log(
191
219
  chalk.blue(
192
- `\nšŸ“¦ Installing foundational NPM dependencies: ${depList}...`,
220
+ `\nšŸ“¦ Installing missing foundational NPM dependencies: ${depList}...`,
193
221
  ),
194
222
  );
195
223
  try {
196
- execSync(`npm install ${depList}`, { stdio: "inherit" });
224
+ execSync(`npm install ${depList} --legacy-peer-deps`, {
225
+ stdio: "inherit",
226
+ });
197
227
  console.log(
198
228
  chalk.green("āœ“ Dependencies installed successfully."),
199
229
  );
@@ -204,6 +234,12 @@ program
204
234
  ),
205
235
  );
206
236
  }
237
+ } else {
238
+ console.log(
239
+ chalk.green(
240
+ "\nāœ“ All foundational NPM dependencies are already installed. Skipping.",
241
+ ),
242
+ );
207
243
  }
208
244
 
209
245
  console.log(chalk.blue("\nšŸŽ‰ Initialization complete!"));
@@ -245,7 +281,7 @@ program
245
281
  const engine = hasTailwind ? "mobile-nativewind" : "mobile-stylesheet";
246
282
 
247
283
  console.log(chalk.dim(`\nDetected engine: ${engine}`));
248
- const manifestUrl = `${REGISTRY_URL}/${engine}.json`;
284
+ const manifestUrl = `${REGISTRY_URL}/${engine}.json?t=${Date.now()}`;
249
285
 
250
286
  try {
251
287
  // 2. Fetch the massive JSON database
@@ -268,6 +304,10 @@ program
268
304
  }
269
305
  };
270
306
 
307
+ // Force the CLI to always check base dependencies
308
+ const setup = BASE_DEPS[engine];
309
+ setup.registry.forEach(resolveDependencies);
310
+
271
311
  // Run the resolver for every component the user typed in the terminal
272
312
  components.forEach(resolveDependencies);
273
313
 
@@ -331,7 +371,7 @@ program
331
371
  }
332
372
  }
333
373
 
334
- // 5. INSTALL NPM DEPENDENCIES
374
+ // 5. INSTALL NPM DEPENDENCIES (Skipping already installed)
335
375
  const depsToInstall = new Set<string>();
336
376
 
337
377
  // Collect all dependencies from the components we just added
@@ -344,16 +384,19 @@ program
344
384
  }
345
385
  }
346
386
 
347
- if (depsToInstall.size > 0) {
348
- const depList = Array.from(depsToInstall).join(" ");
387
+ // Filter out anything already installed in user's package.json
388
+ const missingDeps = filterMissingDeps(Array.from(depsToInstall));
389
+ if (missingDeps.length > 0) {
390
+ const depList = missingDeps.join(" ");
349
391
  console.log(
350
392
  chalk.blue(
351
- `\nšŸ“¦ Installing NPM dependencies: ${depList}...`,
393
+ `\nšŸ“¦ Installing missing NPM dependencies: ${depList}...`,
352
394
  ),
353
395
  );
354
396
  try {
355
- // This runs 'npm install' directly in the user's terminal
356
- execSync(`npm install ${depList}`, { stdio: "inherit" });
397
+ execSync(`npm install ${depList} --legacy-peer-deps`, {
398
+ stdio: "inherit",
399
+ });
357
400
  console.log(
358
401
  chalk.green("āœ“ Dependencies installed successfully."),
359
402
  );
@@ -364,6 +407,12 @@ program
364
407
  ),
365
408
  );
366
409
  }
410
+ } else if (depsToInstall.size > 0) {
411
+ console.log(
412
+ chalk.green(
413
+ "\nāœ“ Required NPM dependencies are already installed. Skipping.",
414
+ ),
415
+ );
367
416
  }
368
417
 
369
418
  console.log(chalk.blue("\nšŸŽ‰ Components installed successfully!"));