thecore-auth 0.0.1 → 0.0.3

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.1",
4
+ "version": "0.0.3",
5
5
  "type": "module",
6
6
  "main": "dist/thecore-auth.cjs.js",
7
7
  "module": "dist/thecore-auth.esm.js",
@@ -16,7 +16,7 @@
16
16
  "build": "vite build",
17
17
  "lint": "eslint .",
18
18
  "preview": "vite preview",
19
- "postinstall": "node ./scripts/check-peer-dependencies.js"
19
+ "install": "node ./scripts/check-peer-dependencies.js"
20
20
  },
21
21
  "dependencies": {
22
22
  "axios": "^1.7.9",
@@ -52,6 +52,7 @@
52
52
  },
53
53
  "files": [
54
54
  "dist",
55
+ "scripts",
55
56
  "README.md"
56
57
  ],
57
58
  "repository": {
@@ -0,0 +1,138 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { execSync } from 'child_process';
4
+
5
+ const installPeerDependencies = () => {
6
+ const peerDependencies = {
7
+ react: "^18.0.0",
8
+ "react-dom": "^18.0.0",
9
+ "react-router-dom": "^7.0.0",
10
+ axios: "^1.0.0",
11
+ tailwindcss: "^3.0.0",
12
+ "react-icons": "^5.4.0",
13
+ "jwt-decode": "^3.1.2"
14
+ };
15
+
16
+ const packageJsonPath = path.resolve("package.json");
17
+
18
+ if (!fs.existsSync(packageJsonPath)) {
19
+ console.error("Error: package.json not found");
20
+ return;
21
+ }
22
+
23
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
24
+ const installedDependencies = {
25
+ ...packageJson.dependencies,
26
+ ...packageJson.devDependencies,
27
+ ...packageJson.peerDependencies,
28
+ };
29
+
30
+ Object.keys(peerDependencies).forEach((pkg) => {
31
+ const requiredVersion = peerDependencies[pkg];
32
+ const installedVersion = installedDependencies[pkg];
33
+
34
+ if (!installedVersion) {
35
+ console.log(`Peer dependency "${pkg}" is missing. Installing...`);
36
+ execSync(`npm install ${pkg}@${requiredVersion}`, { stdio: "inherit" });
37
+ } else {
38
+ console.log(`Peer dependency "${pkg}" is already installed (version: ${installedVersion}).`);
39
+ }
40
+ });
41
+ };
42
+
43
+ const installTailwind = () => {
44
+ console.log("Checking if Tailwind CSS is installed...");
45
+
46
+ try {
47
+ // Verifica se tailwindcss è già presente nelle dipendenze
48
+ const packageJsonPath = path.resolve("package.json");
49
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
50
+
51
+ if (!packageJson.devDependencies || !packageJson.devDependencies.tailwindcss) {
52
+ console.log("Tailwind CSS not found. Installing...");
53
+
54
+ // Esegui i comandi per installare tailwindcss
55
+ execSync("npm install -D tailwindcss@3", { stdio: "inherit" });
56
+
57
+ // Esegui npx per generare tailwind.config.js
58
+ execSync("npx tailwindcss init", { stdio: "inherit" });
59
+
60
+ console.log("Tailwind CSS installed successfully.");
61
+ } else {
62
+ console.log("Tailwind CSS is already installed.");
63
+ }
64
+ } catch (error) {
65
+ console.error("Error checking or installing Tailwind CSS:", error);
66
+ process.exit(1);
67
+ }
68
+ };
69
+
70
+ const modifyTailwindConfig = () => {
71
+ const tailwindConfigPath = path.resolve("tailwind.config.js");
72
+
73
+ // Verifica se il file tailwind.config.js esiste
74
+ if (fs.existsSync(tailwindConfigPath)) {
75
+ console.log("Modifying tailwind.config.js...");
76
+
77
+ // Leggi il contenuto del file
78
+ const configContent = fs.readFileSync(tailwindConfigPath, "utf8");
79
+
80
+ // Aggiungi la configurazione content (assicurati che non esista già)
81
+ if (!configContent.includes("content:")) {
82
+ const updatedConfigContent = configContent.replace(
83
+ `module.exports = {
84
+ content: [
85
+ "./src/**/*.{js,jsx,ts,tsx}",
86
+ "./public/index.html",
87
+ ],
88
+ theme: {
89
+ extend: {},
90
+ },
91
+ plugins: [],
92
+ };`
93
+ );
94
+ fs.writeFileSync(tailwindConfigPath, updatedConfigContent);
95
+ console.log("Added content path to tailwind.config.js.");
96
+ } else {
97
+ console.log("content path already present in tailwind.config.js.");
98
+ }
99
+ } else {
100
+ console.error("tailwind.config.js not found");
101
+ }
102
+ };
103
+
104
+ const modifyIndexCss = () => {
105
+ const cssPath = path.resolve("src/index.css");
106
+
107
+ // Verifica se il file index.css esiste
108
+ if (fs.existsSync(cssPath)) {
109
+ console.log("Adding Tailwind directives to the beginning of index.css...");
110
+
111
+ // Leggi il contenuto del file CSS
112
+ const cssContent = fs.readFileSync(cssPath, "utf8");
113
+
114
+ // Direttive di Tailwind da aggiungere
115
+ const tailwindDirectives = `@tailwind base;\n@tailwind components;\n@tailwind utilities;\n`;
116
+
117
+ // Aggiungi le direttive all'inizio del file se non sono già presenti
118
+ if (!cssContent.includes("@tailwind base;")) {
119
+ const updatedCssContent = tailwindDirectives + cssContent;
120
+ fs.writeFileSync(cssPath, updatedCssContent);
121
+ console.log("Tailwind directives added to index.css.");
122
+ } else {
123
+ console.log("Tailwind directives already present in index.css.");
124
+ }
125
+ } else {
126
+ console.error("index.css not found");
127
+ }
128
+ };
129
+
130
+ const checkAndInstallDependencies = () => {
131
+ installPeerDependencies();
132
+ installTailwind();
133
+ modifyTailwindConfig();
134
+ modifyIndexCss();
135
+ };
136
+
137
+ // Esegui tutto
138
+ checkAndInstallDependencies();