ui-thing 0.0.23 → 0.0.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ui-thing",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "description": "CLI used to add Nuxt 3 components to a project",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "license": "MIT",
42
42
  "dependencies": {
43
- "axios": "^1.6.5",
43
+ "axios": "^1.6.7",
44
44
  "boxen": "^7.1.1",
45
45
  "build": "^0.1.4",
46
46
  "c12": "^1.6.1",
@@ -51,7 +51,7 @@
51
51
  "fs-extra": "^11.2.0",
52
52
  "kleur": "^4.1.5",
53
53
  "lodash": "^4.17.21",
54
- "nypm": "^0.3.4",
54
+ "nypm": "^0.3.6",
55
55
  "ora": "^8.0.1",
56
56
  "prompts": "^2.4.2"
57
57
  },
@@ -61,12 +61,12 @@
61
61
  "@types/figlet": "^1.5.8",
62
62
  "@types/fs-extra": "^11.0.4",
63
63
  "@types/lodash": "^4.14.202",
64
- "@types/node": "^20.11.5",
64
+ "@types/node": "^20.11.10",
65
65
  "@types/prompts": "^2.4.9",
66
- "@vitest/coverage-v8": "^1.2.1",
66
+ "@vitest/coverage-v8": "^1.2.2",
67
67
  "magicast": "^0.3.3",
68
68
  "tsup": "^8.0.1",
69
69
  "typescript": "^5.3.3",
70
- "vitest": "^1.2.1"
70
+ "vitest": "^1.2.2"
71
71
  }
72
72
  }
@@ -257,16 +257,20 @@ export const add = new Command()
257
257
  await updateConfig(cfg.nuxtConfig, "nuxt.config.ts");
258
258
  const foundDeps = _.uniq(found.map((c) => c.deps || []).flat());
259
259
  const foundDevDeps = _.uniq(found.map((c) => c.devDeps || []).flat());
260
- const { confirmInstall } = await prompts({
261
- type: "confirm",
262
- name: "confirmInstall",
263
- message: `Do you want to install the following packages: ${kleur.cyan(
264
- foundDeps.join(", ")
265
- )} ${kleur.cyan(foundDevDeps.join(", "))}`,
266
- initial: true,
267
- });
268
- if (confirmInstall) {
269
- await installPackages(uiConfig.packageManager, foundDeps, foundDevDeps);
260
+
261
+ // check if the foundDeps & foundDevDeps is empty. If they both are, then do not install anything
262
+ if (foundDeps.length !== 0 && foundDevDeps.length !== 0) {
263
+ const { confirmInstall } = await prompts({
264
+ type: "confirm",
265
+ name: "confirmInstall",
266
+ message: `Do you want to install the following packages: ${kleur.cyan(
267
+ foundDeps.join(", ")
268
+ )} ${kleur.cyan(foundDevDeps.join(", "))}`,
269
+ initial: true,
270
+ });
271
+ if (confirmInstall) {
272
+ await installPackages(uiConfig.packageManager, foundDeps, foundDevDeps);
273
+ }
270
274
  }
271
275
 
272
276
  printFancyBoxMessage(
@@ -277,7 +281,10 @@ export const add = new Command()
277
281
  const combinedInstructions = found.map((c) => c.instructions).flat();
278
282
  // remove undefined from the array
279
283
  _.remove(combinedInstructions, (i) => !i);
284
+
285
+ // print the instructions if there are any
280
286
  if (combinedInstructions.length > 0) {
287
+ console.log("");
281
288
  console.log(kleur.bgCyan(" Instructions "));
282
289
  combinedInstructions.forEach((i) => {
283
290
  console.log(`${kleur.cyan("-")} ${i}`);
@@ -1,7 +1,28 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
1
3
  import { execa } from "execa";
2
4
  import _ from "lodash";
3
5
  import ora from "ora";
4
6
 
7
+ function checkPackageJson() {
8
+ const packageJsonPath = path.join(process.cwd(), "package.json");
9
+ let scriptExists = false;
10
+
11
+ // Check if package.json file exists
12
+ if (fs.existsSync(packageJsonPath)) {
13
+ // Read the package.json file
14
+ const packageJsonContent = fs.readFileSync(packageJsonPath, "utf-8");
15
+ const packageJson = JSON.parse(packageJsonContent);
16
+
17
+ // Check if "postinstall" script is defined
18
+ const postinstallScript = packageJson.scripts?.postinstall;
19
+ if (postinstallScript) {
20
+ scriptExists = true;
21
+ }
22
+ }
23
+ return scriptExists;
24
+ }
25
+
5
26
  export const installPackages = async (
6
27
  packageManager: string,
7
28
  deps?: string[] | string,
@@ -22,7 +43,13 @@ export const installPackages = async (
22
43
  if (!_.isUndefined(devDeps) && !_.isEmpty(devDeps)) {
23
44
  await execa(packageManager, [packageManager === "yarn" ? "add" : "install", "-D", ...devDeps]);
24
45
  }
25
- await execa(packageManager, ["run", "postinstall"]);
46
+
47
+ // Check if package.json file exists
48
+ if (checkPackageJson()) {
49
+ // we should check to see if there is a postinstall script and run it
50
+ depsSpinner.text = "Running postinstall script...";
51
+ await execa(packageManager, ["run", "postinstall"]);
52
+ }
26
53
 
27
54
  depsSpinner.succeed("Installed dependencies!");
28
55
  };