thecore-auth 0.0.19 → 0.0.20

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,7 +1,7 @@
1
1
  {
2
2
  "name": "thecore-auth",
3
3
  "private": false,
4
- "version": "0.0.19",
4
+ "version": "0.0.20",
5
5
  "type": "module",
6
6
  "main": "dist/thecore-auth.cjs.js",
7
7
  "module": "dist/thecore-auth.esm.js",
@@ -8,6 +8,21 @@ console.log('Sono entrato nello script');
8
8
  const __filename = fileURLToPath(import.meta.url);
9
9
  const __dirname = path.dirname(__filename);
10
10
 
11
+ const findAppRoot = () => {
12
+ let dir = process.cwd();
13
+ while (!fs.existsSync(path.join(dir, "package.json"))) {
14
+ const parentDir = path.dirname(dir);
15
+ if (parentDir === dir) {
16
+ throw new Error("package.json not found in any parent directory.");
17
+ }
18
+ dir = parentDir;
19
+ }
20
+ return dir;
21
+ };
22
+
23
+ const appRoot = findAppRoot();
24
+ const packageJsonPath = path.join(appRoot, "package.json");
25
+
11
26
  const installPeerDependencies = () => {
12
27
  const peerDependencies = {
13
28
  "react-router-dom": "^7.0.0",
@@ -17,29 +32,25 @@ const installPeerDependencies = () => {
17
32
  "jwt-decode": "^3.1.2"
18
33
  };
19
34
 
20
- const packageJsonPath = path.resolve(__dirname, "../../package.json");
21
-
22
35
  if (!fs.existsSync(packageJsonPath)) {
23
36
  console.error("Error: package.json not found");
24
37
  return;
25
38
  }
26
39
 
27
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
28
- const installedDependencies = {
29
- ...packageJson.dependencies,
30
- ...packageJson.devDependencies,
31
- ...packageJson.peerDependencies,
32
- };
33
-
34
40
  Object.keys(peerDependencies).forEach((pkg) => {
35
- const requiredVersion = peerDependencies[pkg];
36
- const installedVersion = installedDependencies[pkg];
37
-
38
- if (!installedVersion) {
39
- console.log(`Peer dependency "${pkg}" is missing. Installing...`);
40
- execSync(`npm install ${pkg}@${requiredVersion}`, { stdio: "inherit", cwd: path.resolve(__dirname, "../../") });
41
- } else {
42
- console.log(`Peer dependency "${pkg}" is already installed (version: ${installedVersion}).`);
41
+ try {
42
+ const installedVersion = execSync(`npm list ${pkg} --depth=0 --json`, { cwd: appRoot, encoding: "utf8" });
43
+ const parsedVersion = JSON.parse(installedVersion).dependencies?.[pkg]?.version;
44
+
45
+ if (!parsedVersion) {
46
+ console.log(`📦 Installing ${pkg}@${peerDependencies[pkg]}...`);
47
+ execSync(`npm install ${pkg}@${peerDependencies[pkg]}`, { stdio: "inherit", cwd: appRoot });
48
+ } else {
49
+ console.log(`✅ ${pkg} already installed (version: ${parsedVersion}).`);
50
+ }
51
+ } catch (error) {
52
+ console.log(`📦 Installing ${pkg}@${peerDependencies[pkg]}...`);
53
+ execSync(`npm install ${pkg}@${peerDependencies[pkg]}`, { stdio: "inherit", cwd: appRoot });
43
54
  }
44
55
  });
45
56
  };
@@ -48,25 +59,23 @@ const installTailwind = () => {
48
59
  console.log("Checking if Tailwind CSS is installed...");
49
60
 
50
61
  try {
51
- const packageJsonPath = path.resolve(__dirname, "../../package.json");
52
62
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
53
63
 
54
- if (!packageJson.devDependencies || !packageJson.devDependencies.tailwindcss) {
55
- console.log("Tailwind CSS not found. Installing...");
56
- execSync("npm install -D tailwindcss@3", { stdio: "inherit", cwd: path.resolve(__dirname, "../../") });
57
- execSync("npx tailwindcss init", { stdio: "inherit", cwd: path.resolve(__dirname, "../../") });
58
- console.log("Tailwind CSS installed successfully.");
64
+ if (!packageJson.devDependencies?.tailwindcss) {
65
+ console.log("📦 Installing Tailwind CSS...");
66
+ execSync("npm install -D tailwindcss@3", { stdio: "inherit", cwd: appRoot });
67
+ execSync("npx tailwindcss init", { stdio: "inherit", cwd: appRoot });
68
+ console.log("Tailwind CSS installed.");
59
69
  } else {
60
- console.log("Tailwind CSS is already installed.");
70
+ console.log("Tailwind CSS already installed.");
61
71
  }
62
72
  } catch (error) {
63
- console.error("Error checking or installing Tailwind CSS:", error);
64
- process.exit(1);
73
+ console.error("Error installing Tailwind CSS:", error);
65
74
  }
66
75
  };
67
76
 
68
77
  const modifyTailwindConfig = () => {
69
- const tailwindConfigPath = path.resolve(__dirname, "../../tailwind.config.js");
78
+ const tailwindConfigPath = path.join(appRoot, "tailwind.config.js");
70
79
 
71
80
  if (fs.existsSync(tailwindConfigPath)) {
72
81
  console.log("Modifying tailwind.config.js...");
@@ -93,7 +102,7 @@ const modifyTailwindConfig = () => {
93
102
  };
94
103
 
95
104
  const modifyIndexCss = () => {
96
- const cssPath = path.join(process.cwd(), "src", "index.css");
105
+ const cssPath = path.join(appRoot, "src", "index.css");
97
106
 
98
107
  if (!fs.existsSync(cssPath)) {
99
108
  console.log("index.css not found, creating it...");
@@ -124,4 +133,4 @@ const checkAndInstallDependencies = () => {
124
133
  modifyIndexCss();
125
134
  };
126
135
 
127
- checkAndInstallDependencies();
136
+ checkAndInstallDependencies();