@cerema/cadriciel 1.4.16 → 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.
- package/cli/global/login.js +0 -3
- package/cli.js +44 -3
- package/lib/cadriciel.js +0 -7
- package/package.json +1 -1
package/cli/global/login.js
CHANGED
|
@@ -96,7 +96,6 @@ module.exports = (args) => {
|
|
|
96
96
|
try {
|
|
97
97
|
var response = await cadriciel.get('/login');
|
|
98
98
|
} catch (e) {
|
|
99
|
-
console.log(e);
|
|
100
99
|
console.log(' ');
|
|
101
100
|
console.log(
|
|
102
101
|
chalk.red(' [AUTH]') +
|
|
@@ -114,7 +113,6 @@ module.exports = (args) => {
|
|
|
114
113
|
response.token,
|
|
115
114
|
async (err) => {
|
|
116
115
|
if (err) {
|
|
117
|
-
console.log(err);
|
|
118
116
|
return res
|
|
119
117
|
.status(500)
|
|
120
118
|
.send("Erreur lors de l'écriture du token.");
|
|
@@ -136,7 +134,6 @@ module.exports = (args) => {
|
|
|
136
134
|
);
|
|
137
135
|
})
|
|
138
136
|
.catch((error) => {
|
|
139
|
-
console.log(error);
|
|
140
137
|
res
|
|
141
138
|
.status(500)
|
|
142
139
|
.send("Erreur lors de l'échange du code d'autorisaton.");
|
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
|
-
|
|
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/lib/cadriciel.js
CHANGED
|
@@ -13,7 +13,6 @@ class CadricielAPI {
|
|
|
13
13
|
token = fs.readFileSync(HomeDir + '/account', 'utf-8');
|
|
14
14
|
token = token.replace(/\n/g, '');
|
|
15
15
|
} catch (e) {
|
|
16
|
-
console.log(e);
|
|
17
16
|
console.log(
|
|
18
17
|
chalk.bold(' [AUTH] ') +
|
|
19
18
|
chalk.red(
|
|
@@ -29,17 +28,11 @@ class CadricielAPI {
|
|
|
29
28
|
timeout: 10000,
|
|
30
29
|
headers: { Authorization: 'Bearer ' + token },
|
|
31
30
|
});
|
|
32
|
-
console.log({
|
|
33
|
-
baseURL: baseURL,
|
|
34
|
-
timeout: 10000,
|
|
35
|
-
headers: { Authorization: 'Bearer ' + token },
|
|
36
|
-
});
|
|
37
31
|
}
|
|
38
32
|
|
|
39
33
|
async get(url, params = {}) {
|
|
40
34
|
try {
|
|
41
35
|
const response = await this.client.get(url, { params });
|
|
42
|
-
console.log(response);
|
|
43
36
|
return response.data;
|
|
44
37
|
} catch (error) {
|
|
45
38
|
throw error;
|