@lystech/core 1.0.3 → 3.0.4
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/README.md +1 -1
- package/bin/README.md +126 -126
- package/bin/attach.cjs +277 -277
- package/bin/check-pwa.cjs +276 -276
- package/bin/setup-github-action.cjs +209 -209
- package/dist/lystech-core-provider.es.js +1 -1
- package/dist/lystech-core-provider.umd.js +1 -1
- package/package.json +73 -73
package/bin/attach.cjs
CHANGED
|
@@ -1,277 +1,277 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Script pour attacher un projet au système de mise à jour automatique
|
|
5
|
-
*
|
|
6
|
-
* Usage: npx lystechcorenpmpackage attach
|
|
7
|
-
*
|
|
8
|
-
* Ce script:
|
|
9
|
-
* 1. Détecte le repo GitHub actuel
|
|
10
|
-
* 2. Génère la configuration pour consumers.json
|
|
11
|
-
* 3. Guide l'utilisateur pour compléter le setup
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const fs = require("fs");
|
|
15
|
-
const path = require("path");
|
|
16
|
-
const { execSync } = require("child_process");
|
|
17
|
-
|
|
18
|
-
// Couleurs console
|
|
19
|
-
const colors = {
|
|
20
|
-
reset: "\x1b[0m",
|
|
21
|
-
bright: "\x1b[1m",
|
|
22
|
-
green: "\x1b[32m",
|
|
23
|
-
yellow: "\x1b[33m",
|
|
24
|
-
blue: "\x1b[34m",
|
|
25
|
-
cyan: "\x1b[36m",
|
|
26
|
-
red: "\x1b[31m",
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
function log(message, color = colors.reset) {
|
|
30
|
-
console.log(`${color}${message}${colors.reset}`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function header(message) {
|
|
34
|
-
console.log("");
|
|
35
|
-
log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`, colors.cyan);
|
|
36
|
-
log(` ${message}`, colors.bright + colors.cyan);
|
|
37
|
-
log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`, colors.cyan);
|
|
38
|
-
console.log("");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function success(message) {
|
|
42
|
-
log(`✅ ${message}`, colors.green);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function warning(message) {
|
|
46
|
-
log(`⚠️ ${message}`, colors.yellow);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function error(message) {
|
|
50
|
-
log(`❌ ${message}`, colors.red);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function info(message) {
|
|
54
|
-
log(`ℹ️ ${message}`, colors.blue);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Détecte les informations Git du repo actuel
|
|
59
|
-
*/
|
|
60
|
-
function detectGitInfo() {
|
|
61
|
-
try {
|
|
62
|
-
// Vérifier si on est dans un repo git
|
|
63
|
-
execSync("git rev-parse --git-dir", { stdio: "ignore" });
|
|
64
|
-
|
|
65
|
-
// Récupérer l'URL remote
|
|
66
|
-
const remoteUrl = execSync("git config --get remote.origin.url", {
|
|
67
|
-
encoding: "utf8",
|
|
68
|
-
}).trim();
|
|
69
|
-
|
|
70
|
-
// Parser l'URL GitHub
|
|
71
|
-
const match = remoteUrl.match(/github\.com[:/]([^/]+)\/([^/\.]+)/);
|
|
72
|
-
if (!match) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const [, owner, repo] = match;
|
|
77
|
-
|
|
78
|
-
// Récupérer la branche par défaut
|
|
79
|
-
let defaultBranch = "master";
|
|
80
|
-
try {
|
|
81
|
-
defaultBranch = execSync(
|
|
82
|
-
"git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'",
|
|
83
|
-
{ encoding: "utf8", shell: "bash" },
|
|
84
|
-
).trim();
|
|
85
|
-
} catch {
|
|
86
|
-
// Essayer une autre méthode
|
|
87
|
-
try {
|
|
88
|
-
defaultBranch =
|
|
89
|
-
execSync("git branch -r", { encoding: "utf8" })
|
|
90
|
-
.split("\n")
|
|
91
|
-
.find((b) => b.includes("HEAD"))
|
|
92
|
-
?.split("->")[1]
|
|
93
|
-
?.trim()
|
|
94
|
-
?.replace("origin/", "") || "master";
|
|
95
|
-
} catch {
|
|
96
|
-
// Garder master par défaut
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return { owner, repo, branch: defaultBranch };
|
|
101
|
-
} catch {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Lit le package.json du projet
|
|
108
|
-
*/
|
|
109
|
-
function readPackageJson() {
|
|
110
|
-
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
111
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Génère la configuration pour consumers.json
|
|
119
|
-
*/
|
|
120
|
-
function generateConsumerConfig(gitInfo, packageJson) {
|
|
121
|
-
const scripts = packageJson?.scripts || {};
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
owner: gitInfo.owner,
|
|
125
|
-
repo: gitInfo.repo,
|
|
126
|
-
branch: gitInfo.branch,
|
|
127
|
-
enabled: true,
|
|
128
|
-
buildScript: scripts.build ? "build" : "",
|
|
129
|
-
deployScript: scripts.deploy ? "deploy" : "",
|
|
130
|
-
deployTarget: scripts.deploy?.includes("firebase")
|
|
131
|
-
? "firebase"
|
|
132
|
-
: scripts.deploy?.includes("vercel")
|
|
133
|
-
? "vercel"
|
|
134
|
-
: "custom",
|
|
135
|
-
notes: packageJson?.description || `Projet ${gitInfo.repo}`,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Affiche les instructions pour compléter le setup
|
|
141
|
-
*/
|
|
142
|
-
function printInstructions(config) {
|
|
143
|
-
header("📋 Configuration générée");
|
|
144
|
-
|
|
145
|
-
log(
|
|
146
|
-
"Ajoutez cette entrée au fichier consumers.json du package:",
|
|
147
|
-
colors.bright,
|
|
148
|
-
);
|
|
149
|
-
console.log("");
|
|
150
|
-
console.log(JSON.stringify(config, null, 2));
|
|
151
|
-
console.log("");
|
|
152
|
-
|
|
153
|
-
header("🚀 Prochaines étapes");
|
|
154
|
-
|
|
155
|
-
log("Pour activer la mise à jour automatique:", colors.bright);
|
|
156
|
-
console.log("");
|
|
157
|
-
|
|
158
|
-
log(
|
|
159
|
-
"1️⃣ Créer une Pull Request sur le repo lystechcorenpmpackage:",
|
|
160
|
-
colors.cyan,
|
|
161
|
-
);
|
|
162
|
-
console.log(" - Ouvrir: https://github.com/eracine4/lystechcorenpmpackage");
|
|
163
|
-
console.log(" - Éditer: consumers.json");
|
|
164
|
-
console.log(" - Ajouter la configuration ci-dessus");
|
|
165
|
-
console.log("");
|
|
166
|
-
|
|
167
|
-
log("2️⃣ Configurer le token GitHub (dans le repo du package):", colors.cyan);
|
|
168
|
-
console.log(" Si ce n'est pas déjà fait:");
|
|
169
|
-
console.log(" a) Créer un Personal Access Token:");
|
|
170
|
-
console.log(
|
|
171
|
-
" https://github.com/settings/tokens/new?scopes=repo&description=Lystech%20Auto%20Update",
|
|
172
|
-
);
|
|
173
|
-
console.log(" b) Ajouter le secret CONSUMER_UPDATE_TOKEN:");
|
|
174
|
-
console.log(
|
|
175
|
-
" https://github.com/eracine4/lystechcorenpmpackage/settings/secrets/actions",
|
|
176
|
-
);
|
|
177
|
-
console.log("");
|
|
178
|
-
|
|
179
|
-
if (config.deployScript) {
|
|
180
|
-
log(
|
|
181
|
-
`3️⃣ Configurer les secrets de déploiement (${config.deployTarget}):`,
|
|
182
|
-
colors.cyan,
|
|
183
|
-
);
|
|
184
|
-
console.log(
|
|
185
|
-
` Dans votre repo: https://github.com/${config.owner}/${config.repo}/settings/secrets/actions`,
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
if (config.deployTarget === "firebase") {
|
|
189
|
-
console.log(" - FIREBASE_TOKEN (requis pour npm run deploy)");
|
|
190
|
-
} else if (config.deployTarget === "vercel") {
|
|
191
|
-
console.log(" - VERCEL_TOKEN");
|
|
192
|
-
}
|
|
193
|
-
console.log("");
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
log(
|
|
197
|
-
"✅ Une fois la PR mergée, vos updates seront automatiques!",
|
|
198
|
-
colors.green,
|
|
199
|
-
);
|
|
200
|
-
console.log("");
|
|
201
|
-
info(
|
|
202
|
-
"Le package mettra à jour ce projet automatiquement à chaque publication.",
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Crée un fichier de référence local
|
|
208
|
-
*/
|
|
209
|
-
function createLocalReference(config) {
|
|
210
|
-
const refPath = path.join(process.cwd(), ".lystech-auto-update.json");
|
|
211
|
-
fs.writeFileSync(refPath, JSON.stringify(config, null, 2));
|
|
212
|
-
success(`Configuration sauvegardée dans: .lystech-auto-update.json`);
|
|
213
|
-
warning(
|
|
214
|
-
"Ajoutez ce fichier au .gitignore si vous ne voulez pas le committer",
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Main
|
|
220
|
-
*/
|
|
221
|
-
function main() {
|
|
222
|
-
header("🔗 Lystech Auto-Update - Attachement");
|
|
223
|
-
|
|
224
|
-
// Détecter le repo
|
|
225
|
-
const gitInfo = detectGitInfo();
|
|
226
|
-
if (!gitInfo) {
|
|
227
|
-
error("Impossible de détecter les informations Git");
|
|
228
|
-
console.log("Assurez-vous d'être dans un repo GitHub cloné");
|
|
229
|
-
process.exit(1);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
success(
|
|
233
|
-
`Repo détecté: ${gitInfo.owner}/${gitInfo.repo} (branche: ${gitInfo.branch})`,
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
// Lire package.json
|
|
237
|
-
const packageJson = readPackageJson();
|
|
238
|
-
if (!packageJson) {
|
|
239
|
-
error("package.json introuvable");
|
|
240
|
-
process.exit(1);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
success(`Projet: ${packageJson.name || gitInfo.repo}`);
|
|
244
|
-
|
|
245
|
-
// Vérifier si le package est installé
|
|
246
|
-
const hasPackage =
|
|
247
|
-
packageJson.dependencies?.lystechcorenpmpackage ||
|
|
248
|
-
packageJson.devDependencies?.lystechcorenpmpackage;
|
|
249
|
-
|
|
250
|
-
if (!hasPackage) {
|
|
251
|
-
warning("lystechcorenpmpackage n'est pas dans les dépendances");
|
|
252
|
-
console.log("Installez-le d'abord: npm install lystechcorenpmpackage");
|
|
253
|
-
console.log("");
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Générer la config
|
|
257
|
-
const config = generateConsumerConfig(gitInfo, packageJson);
|
|
258
|
-
|
|
259
|
-
// Sauvegarder localement
|
|
260
|
-
createLocalReference(config);
|
|
261
|
-
|
|
262
|
-
// Afficher les instructions
|
|
263
|
-
printInstructions(config);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// Point d'entrée
|
|
267
|
-
if (require.main === module) {
|
|
268
|
-
try {
|
|
269
|
-
main();
|
|
270
|
-
} catch (err) {
|
|
271
|
-
error(`Erreur: ${err.message}`);
|
|
272
|
-
console.error(err);
|
|
273
|
-
process.exit(1);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
module.exports = { detectGitInfo, generateConsumerConfig };
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Script pour attacher un projet au système de mise à jour automatique
|
|
5
|
+
*
|
|
6
|
+
* Usage: npx lystechcorenpmpackage attach
|
|
7
|
+
*
|
|
8
|
+
* Ce script:
|
|
9
|
+
* 1. Détecte le repo GitHub actuel
|
|
10
|
+
* 2. Génère la configuration pour consumers.json
|
|
11
|
+
* 3. Guide l'utilisateur pour compléter le setup
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const fs = require("fs");
|
|
15
|
+
const path = require("path");
|
|
16
|
+
const { execSync } = require("child_process");
|
|
17
|
+
|
|
18
|
+
// Couleurs console
|
|
19
|
+
const colors = {
|
|
20
|
+
reset: "\x1b[0m",
|
|
21
|
+
bright: "\x1b[1m",
|
|
22
|
+
green: "\x1b[32m",
|
|
23
|
+
yellow: "\x1b[33m",
|
|
24
|
+
blue: "\x1b[34m",
|
|
25
|
+
cyan: "\x1b[36m",
|
|
26
|
+
red: "\x1b[31m",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function log(message, color = colors.reset) {
|
|
30
|
+
console.log(`${color}${message}${colors.reset}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function header(message) {
|
|
34
|
+
console.log("");
|
|
35
|
+
log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`, colors.cyan);
|
|
36
|
+
log(` ${message}`, colors.bright + colors.cyan);
|
|
37
|
+
log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`, colors.cyan);
|
|
38
|
+
console.log("");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function success(message) {
|
|
42
|
+
log(`✅ ${message}`, colors.green);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function warning(message) {
|
|
46
|
+
log(`⚠️ ${message}`, colors.yellow);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function error(message) {
|
|
50
|
+
log(`❌ ${message}`, colors.red);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function info(message) {
|
|
54
|
+
log(`ℹ️ ${message}`, colors.blue);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Détecte les informations Git du repo actuel
|
|
59
|
+
*/
|
|
60
|
+
function detectGitInfo() {
|
|
61
|
+
try {
|
|
62
|
+
// Vérifier si on est dans un repo git
|
|
63
|
+
execSync("git rev-parse --git-dir", { stdio: "ignore" });
|
|
64
|
+
|
|
65
|
+
// Récupérer l'URL remote
|
|
66
|
+
const remoteUrl = execSync("git config --get remote.origin.url", {
|
|
67
|
+
encoding: "utf8",
|
|
68
|
+
}).trim();
|
|
69
|
+
|
|
70
|
+
// Parser l'URL GitHub
|
|
71
|
+
const match = remoteUrl.match(/github\.com[:/]([^/]+)\/([^/\.]+)/);
|
|
72
|
+
if (!match) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const [, owner, repo] = match;
|
|
77
|
+
|
|
78
|
+
// Récupérer la branche par défaut
|
|
79
|
+
let defaultBranch = "master";
|
|
80
|
+
try {
|
|
81
|
+
defaultBranch = execSync(
|
|
82
|
+
"git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'",
|
|
83
|
+
{ encoding: "utf8", shell: "bash" },
|
|
84
|
+
).trim();
|
|
85
|
+
} catch {
|
|
86
|
+
// Essayer une autre méthode
|
|
87
|
+
try {
|
|
88
|
+
defaultBranch =
|
|
89
|
+
execSync("git branch -r", { encoding: "utf8" })
|
|
90
|
+
.split("\n")
|
|
91
|
+
.find((b) => b.includes("HEAD"))
|
|
92
|
+
?.split("->")[1]
|
|
93
|
+
?.trim()
|
|
94
|
+
?.replace("origin/", "") || "master";
|
|
95
|
+
} catch {
|
|
96
|
+
// Garder master par défaut
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return { owner, repo, branch: defaultBranch };
|
|
101
|
+
} catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Lit le package.json du projet
|
|
108
|
+
*/
|
|
109
|
+
function readPackageJson() {
|
|
110
|
+
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
111
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Génère la configuration pour consumers.json
|
|
119
|
+
*/
|
|
120
|
+
function generateConsumerConfig(gitInfo, packageJson) {
|
|
121
|
+
const scripts = packageJson?.scripts || {};
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
owner: gitInfo.owner,
|
|
125
|
+
repo: gitInfo.repo,
|
|
126
|
+
branch: gitInfo.branch,
|
|
127
|
+
enabled: true,
|
|
128
|
+
buildScript: scripts.build ? "build" : "",
|
|
129
|
+
deployScript: scripts.deploy ? "deploy" : "",
|
|
130
|
+
deployTarget: scripts.deploy?.includes("firebase")
|
|
131
|
+
? "firebase"
|
|
132
|
+
: scripts.deploy?.includes("vercel")
|
|
133
|
+
? "vercel"
|
|
134
|
+
: "custom",
|
|
135
|
+
notes: packageJson?.description || `Projet ${gitInfo.repo}`,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Affiche les instructions pour compléter le setup
|
|
141
|
+
*/
|
|
142
|
+
function printInstructions(config) {
|
|
143
|
+
header("📋 Configuration générée");
|
|
144
|
+
|
|
145
|
+
log(
|
|
146
|
+
"Ajoutez cette entrée au fichier consumers.json du package:",
|
|
147
|
+
colors.bright,
|
|
148
|
+
);
|
|
149
|
+
console.log("");
|
|
150
|
+
console.log(JSON.stringify(config, null, 2));
|
|
151
|
+
console.log("");
|
|
152
|
+
|
|
153
|
+
header("🚀 Prochaines étapes");
|
|
154
|
+
|
|
155
|
+
log("Pour activer la mise à jour automatique:", colors.bright);
|
|
156
|
+
console.log("");
|
|
157
|
+
|
|
158
|
+
log(
|
|
159
|
+
"1️⃣ Créer une Pull Request sur le repo lystechcorenpmpackage:",
|
|
160
|
+
colors.cyan,
|
|
161
|
+
);
|
|
162
|
+
console.log(" - Ouvrir: https://github.com/eracine4/lystechcorenpmpackage");
|
|
163
|
+
console.log(" - Éditer: consumers.json");
|
|
164
|
+
console.log(" - Ajouter la configuration ci-dessus");
|
|
165
|
+
console.log("");
|
|
166
|
+
|
|
167
|
+
log("2️⃣ Configurer le token GitHub (dans le repo du package):", colors.cyan);
|
|
168
|
+
console.log(" Si ce n'est pas déjà fait:");
|
|
169
|
+
console.log(" a) Créer un Personal Access Token:");
|
|
170
|
+
console.log(
|
|
171
|
+
" https://github.com/settings/tokens/new?scopes=repo&description=Lystech%20Auto%20Update",
|
|
172
|
+
);
|
|
173
|
+
console.log(" b) Ajouter le secret CONSUMER_UPDATE_TOKEN:");
|
|
174
|
+
console.log(
|
|
175
|
+
" https://github.com/eracine4/lystechcorenpmpackage/settings/secrets/actions",
|
|
176
|
+
);
|
|
177
|
+
console.log("");
|
|
178
|
+
|
|
179
|
+
if (config.deployScript) {
|
|
180
|
+
log(
|
|
181
|
+
`3️⃣ Configurer les secrets de déploiement (${config.deployTarget}):`,
|
|
182
|
+
colors.cyan,
|
|
183
|
+
);
|
|
184
|
+
console.log(
|
|
185
|
+
` Dans votre repo: https://github.com/${config.owner}/${config.repo}/settings/secrets/actions`,
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
if (config.deployTarget === "firebase") {
|
|
189
|
+
console.log(" - FIREBASE_TOKEN (requis pour npm run deploy)");
|
|
190
|
+
} else if (config.deployTarget === "vercel") {
|
|
191
|
+
console.log(" - VERCEL_TOKEN");
|
|
192
|
+
}
|
|
193
|
+
console.log("");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
log(
|
|
197
|
+
"✅ Une fois la PR mergée, vos updates seront automatiques!",
|
|
198
|
+
colors.green,
|
|
199
|
+
);
|
|
200
|
+
console.log("");
|
|
201
|
+
info(
|
|
202
|
+
"Le package mettra à jour ce projet automatiquement à chaque publication.",
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Crée un fichier de référence local
|
|
208
|
+
*/
|
|
209
|
+
function createLocalReference(config) {
|
|
210
|
+
const refPath = path.join(process.cwd(), ".lystech-auto-update.json");
|
|
211
|
+
fs.writeFileSync(refPath, JSON.stringify(config, null, 2));
|
|
212
|
+
success(`Configuration sauvegardée dans: .lystech-auto-update.json`);
|
|
213
|
+
warning(
|
|
214
|
+
"Ajoutez ce fichier au .gitignore si vous ne voulez pas le committer",
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Main
|
|
220
|
+
*/
|
|
221
|
+
function main() {
|
|
222
|
+
header("🔗 Lystech Auto-Update - Attachement");
|
|
223
|
+
|
|
224
|
+
// Détecter le repo
|
|
225
|
+
const gitInfo = detectGitInfo();
|
|
226
|
+
if (!gitInfo) {
|
|
227
|
+
error("Impossible de détecter les informations Git");
|
|
228
|
+
console.log("Assurez-vous d'être dans un repo GitHub cloné");
|
|
229
|
+
process.exit(1);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
success(
|
|
233
|
+
`Repo détecté: ${gitInfo.owner}/${gitInfo.repo} (branche: ${gitInfo.branch})`,
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
// Lire package.json
|
|
237
|
+
const packageJson = readPackageJson();
|
|
238
|
+
if (!packageJson) {
|
|
239
|
+
error("package.json introuvable");
|
|
240
|
+
process.exit(1);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
success(`Projet: ${packageJson.name || gitInfo.repo}`);
|
|
244
|
+
|
|
245
|
+
// Vérifier si le package est installé
|
|
246
|
+
const hasPackage =
|
|
247
|
+
packageJson.dependencies?.lystechcorenpmpackage ||
|
|
248
|
+
packageJson.devDependencies?.lystechcorenpmpackage;
|
|
249
|
+
|
|
250
|
+
if (!hasPackage) {
|
|
251
|
+
warning("lystechcorenpmpackage n'est pas dans les dépendances");
|
|
252
|
+
console.log("Installez-le d'abord: npm install lystechcorenpmpackage");
|
|
253
|
+
console.log("");
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Générer la config
|
|
257
|
+
const config = generateConsumerConfig(gitInfo, packageJson);
|
|
258
|
+
|
|
259
|
+
// Sauvegarder localement
|
|
260
|
+
createLocalReference(config);
|
|
261
|
+
|
|
262
|
+
// Afficher les instructions
|
|
263
|
+
printInstructions(config);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Point d'entrée
|
|
267
|
+
if (require.main === module) {
|
|
268
|
+
try {
|
|
269
|
+
main();
|
|
270
|
+
} catch (err) {
|
|
271
|
+
error(`Erreur: ${err.message}`);
|
|
272
|
+
console.error(err);
|
|
273
|
+
process.exit(1);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
module.exports = { detectGitInfo, generateConsumerConfig };
|