@cerema/cadriciel 1.4.17 → 1.4.18

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/cli.js +44 -3
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -22,7 +22,31 @@ try {
22
22
  fs.unlinkSync(`${userHomeDir}/.cadriciel/account.json`);
23
23
  } catch (e) {}
24
24
 
25
+ const VERSION_CHECK_FILE = path.join(userHomeDir, '.cadriciel_last_check.json');
26
+
27
+ const shouldCheckVersion = async () => {
28
+ try {
29
+ const data = fs.readFileSync(VERSION_CHECK_FILE, 'utf8');
30
+ const lastCheck = JSON.parse(data);
31
+ const lastCheckDate = new Date(lastCheck.date);
32
+ const diff = Date.now() - lastCheckDate.getTime();
33
+ const twelveHours = 12 * 60 * 60 * 1000;
34
+
35
+ return diff > twelveHours;
36
+ } catch (e) {
37
+ return true;
38
+ }
39
+ };
40
+
41
+ const updateLastCheckDate = () => {
42
+ const data = JSON.stringify({ date: new Date() });
43
+ fs.writeFileSync(VERSION_CHECK_FILE, data, 'utf8');
44
+ };
45
+
25
46
  const checkVersion = async () => {
47
+ if (!(await shouldCheckVersion())) {
48
+ return Promise.resolve(null); // Aucune version à vérifier, renvoie null
49
+ }
26
50
  return new Promise((resolve, reject) => {
27
51
  const packageName = '@cerema/cadriciel';
28
52
  const child = spawn('npm', ['view', packageName, 'version'], {
@@ -35,12 +59,27 @@ const checkVersion = async () => {
35
59
  version += data.toString();
36
60
  });
37
61
 
62
+ child.stderr.on('data', (data) => {
63
+ console.error(`err: ${data}`);
64
+ });
65
+
66
+ child.on('error', (error) => {
67
+ console.error(`Erreur lors de l'exécution de npm view: ${error.message}`);
68
+ reject(error);
69
+ });
70
+
38
71
  child.on('close', (code) => {
39
72
  if (code !== 0) {
40
- return;
73
+ console.error(
74
+ `Le processus npm view s'est terminé avec le code ${code}`
75
+ );
76
+ return reject(
77
+ new Error('Erreur lors de la récupération de la version')
78
+ );
41
79
  }
42
80
 
43
81
  version = version.trim();
82
+ updateLastCheckDate();
44
83
  resolve(version);
45
84
  });
46
85
  });
@@ -258,13 +297,15 @@ const processCommands = (args) => {
258
297
  checkVersion()
259
298
  .then((version) => {
260
299
  const current_version = require(__dirname + '/package.json').version;
261
-
300
+ if (version === null) {
301
+ version = current_version;
302
+ }
262
303
  if (current_version != version) {
263
304
  const message =
264
305
  'Une nouvelle version (' +
265
306
  version +
266
307
  ') a été détectée. Veuillez mettre à jour.\n' +
267
- chalk.white.bold('npm i -g @cerema/cadriciel');
308
+ chalk.white.bold('npm i -g @cerema/cadriciel@' + version);
268
309
 
269
310
  // Options pour le cadre
270
311
  const boxenOptions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cerema/cadriciel",
3
- "version": "1.4.17",
3
+ "version": "1.4.18",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "npm": ">=8.0.0",