@iksdev/shard-cli 0.1.35 → 0.1.37

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 (2) hide show
  1. package/bin/shard.js +69 -0
  2. package/package.json +1 -1
package/bin/shard.js CHANGED
@@ -15,6 +15,58 @@ const CONFIG_PATH = path.join(CONFIG_DIR, 'config.json');
15
15
  const STATE_FILE = '.shard-sync-state.json';
16
16
  const DEFAULT_SERVER = 'https://shard-0ow4.onrender.com';
17
17
  const IGNORED_DIRS = new Set(['.git', 'node_modules']);
18
+ // ─── Vérification de mise à jour npm ─────────────────────────────────────────
19
+ async function checkForUpdate() {
20
+ return new Promise((resolve) => {
21
+ const https = require('https');
22
+ const pkgName = require('./package.json').name;
23
+ const currentVersion = require('./package.json').version;
24
+
25
+ const req = https.get(
26
+ `https://registry.npmjs.org/${pkgName}/latest`,
27
+ { headers: { Accept: 'application/json' }, timeout: 3000 },
28
+ (res) => {
29
+ let data = '';
30
+ res.on('data', (c) => (data += c));
31
+ res.on('end', () => {
32
+ try {
33
+ const latest = JSON.parse(data).version;
34
+ resolve(latest && latest !== currentVersion ? latest : null);
35
+ } catch { resolve(null); }
36
+ });
37
+ }
38
+ );
39
+ req.on('error', () => resolve(null));
40
+ req.on('timeout', () => { req.destroy(); resolve(null); });
41
+ });
42
+ }
43
+
44
+ async function promptUpdate(latestVersion) {
45
+ const pkgName = require('./package.json').name;
46
+ return new Promise((resolve) => {
47
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
48
+ const msg = `\n⚠️ Nouvelle version disponible : v${latestVersion}\n Lance cette commande pour mettre à jour :\n\n npm i -g ${pkgName}@latest\n\n→ Mettre à jour maintenant ? (y/n) : `;
49
+ rl.question(msg, (answer) => {
50
+ rl.close();
51
+ resolve(answer.trim().toLowerCase() === 'y');
52
+ });
53
+ });
54
+ }
55
+
56
+ async function runUpdate(latestVersion) {
57
+ const { execSync } = require('child_process');
58
+ const pkgName = require('./package.json').name;
59
+ console.log(`\n⏳ Mise à jour en cours...`);
60
+ try {
61
+ execSync(`npm i -g ${pkgName}@latest`, { stdio: 'inherit' });
62
+ console.log(`\n✅ Mis à jour vers v${latestVersion} ! Relance ta commande.`);
63
+ } catch {
64
+ console.error(`\n❌ Échec de la mise à jour. Lance manuellement :\n npm i -g ${pkgName}@latest`);
65
+ }
66
+ process.exit(0);
67
+ }
68
+
69
+
18
70
 
19
71
  function printHelp() {
20
72
  console.log(`
@@ -1058,6 +1110,23 @@ async function syncFolder(positionals, flags) {
1058
1110
  async function main() {
1059
1111
  const { command, positionals, flags } = parseArgs(process.argv.slice(2));
1060
1112
 
1113
+ // Vérifie la mise à jour à chaque commande (sauf --help)
1114
+ if (command && command !== 'help' && command !== '--help' && command !== '-h') {
1115
+ const latestVersion = await checkForUpdate();
1116
+ if (latestVersion) {
1117
+ const config = await readConfig();
1118
+ // Logout automatique si pas à jour
1119
+ await writeConfig({ ...config, token: '' });
1120
+ const wantsUpdate = await promptUpdate(latestVersion);
1121
+ if (wantsUpdate) {
1122
+ await runUpdate(latestVersion);
1123
+ } else {
1124
+ console.log('\n❌ Commande annulée. Mets à jour pour continuer.\n');
1125
+ process.exit(1);
1126
+ }
1127
+ }
1128
+ }
1129
+
1061
1130
  if (!command || command === 'help' || command === '--help' || command === '-h') {
1062
1131
  printHelp();
1063
1132
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iksdev/shard-cli",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "description": "CLI pour synchroniser un dossier local avec Shard",
5
5
  "bin": {
6
6
  "shard": "bin/shard.js"