@cerema/cadriciel 1.6.2-beta → 1.6.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/cli.js CHANGED
@@ -14,7 +14,7 @@ const axios = require('axios'); // For making HTTP requests.
14
14
  const CADRICIEL_PATH = findCadricielDir(process.cwd());
15
15
  const CADRICIEL_COMMAND = 'cad';
16
16
  const CADRICIEL_PERMALINK =
17
- 'https://gist.githubusercontent.com/zucatti/08b37516b23c08028a2b07694f0329b6/raw/cadriciel-url.json';
17
+ 'https://gist.githubusercontent.com/zucatti/08b37516b23c08028a2b07694f0329b6/raw/cadriciel-url.json';
18
18
  global.CADRICIEL_URI = '';
19
19
  //global.CADRICIEL_URI = 'http://localhost:3000/api';
20
20
 
@@ -29,113 +29,113 @@ global.CACHE_URI = {};
29
29
 
30
30
  // Function to check internet connection
31
31
  const checkInternetConnection = async () => {
32
- try {
33
- await axios.get('https://www.google.com');
34
- return true;
35
- } catch {
36
- return false;
37
- }
32
+ try {
33
+ await axios.get('https://www.google.com');
34
+ return true;
35
+ } catch {
36
+ return false;
37
+ }
38
38
  };
39
39
 
40
40
  // Function to fetch data from permalink URL
41
41
  const fetchData = async () => {
42
- try {
43
- const response = await axios.get(CADRICIEL_PERMALINK);
44
- const data = response.data;
45
- // Save data to cache file
46
- fs.writeFileSync(CACHE_FILE_PATH, JSON.stringify(data, null, 2));
47
- console.log('Data fetched and cached successfully.');
48
- } catch (error) {
49
- console.error('Error fetching data:', error.message);
50
- }
42
+ try {
43
+ const response = await axios.get(CADRICIEL_PERMALINK);
44
+ const data = response.data;
45
+ // Save data to cache file
46
+ fs.writeFileSync(CACHE_FILE_PATH, JSON.stringify(data, null, 2));
47
+ console.log('Data fetched and cached successfully.');
48
+ } catch (error) {
49
+ console.error('Error fetching data:', error.message);
50
+ }
51
51
  };
52
52
 
53
53
  // Function to get cached data
54
54
  const getCachedData = () => {
55
- if (fs.existsSync(CACHE_FILE_PATH)) {
56
- const data = fs.readFileSync(CACHE_FILE_PATH, 'utf-8');
57
- global.CACHE_URI = JSON.parse(data);
58
- return JSON.parse(data);
59
- }
60
- return null;
55
+ if (fs.existsSync(CACHE_FILE_PATH)) {
56
+ const data = fs.readFileSync(CACHE_FILE_PATH, 'utf-8');
57
+ global.CACHE_URI = JSON.parse(data);
58
+ return JSON.parse(data);
59
+ }
60
+ return null;
61
61
  };
62
62
 
63
63
  // Function to check if the cache file is up-to-date
64
64
  const isCacheUpToDate = () => {
65
- if (!fs.existsSync(CACHE_FILE_PATH)) {
66
- return false;
67
- }
65
+ if (!fs.existsSync(CACHE_FILE_PATH)) {
66
+ return false;
67
+ }
68
68
 
69
- const stats = fs.statSync(CACHE_FILE_PATH);
70
- const fileModifiedDate = new Date(stats.mtime);
71
- const today = new Date();
72
- today.setHours(0, 0, 0, 0); // Set to start of the day
69
+ const stats = fs.statSync(CACHE_FILE_PATH);
70
+ const fileModifiedDate = new Date(stats.mtime);
71
+ const today = new Date();
72
+ today.setHours(0, 0, 0, 0); // Set to start of the day
73
73
 
74
- return fileModifiedDate >= today;
74
+ return fileModifiedDate >= today;
75
75
  };
76
76
 
77
77
  // Function to decide whether a version check is needed.
78
78
  const shouldCheckVersion = async () => {
79
- try {
80
- const data = fs.readFileSync(VERSION_CHECK_FILE, 'utf8');
81
- const lastCheck = JSON.parse(data);
82
- const lastCheckDate = new Date(lastCheck.date);
83
- const diff = Date.now() - lastCheckDate.getTime();
84
- const twelveHours = 12 * 60 * 60 * 1000;
85
-
86
- return diff > twelveHours;
87
- } catch (e) {
88
- return true;
89
- }
79
+ try {
80
+ const data = fs.readFileSync(VERSION_CHECK_FILE, 'utf8');
81
+ const lastCheck = JSON.parse(data);
82
+ const lastCheckDate = new Date(lastCheck.date);
83
+ const diff = Date.now() - lastCheckDate.getTime();
84
+ const twelveHours = 12 * 60 * 60 * 1000;
85
+
86
+ return diff > twelveHours;
87
+ } catch (e) {
88
+ return true;
89
+ }
90
90
  };
91
91
 
92
92
  // Function to update the date of the last version check.
93
93
  const updateLastCheckDate = () => {
94
- const data = JSON.stringify({ date: new Date() });
95
- fs.writeFileSync(VERSION_CHECK_FILE, data, 'utf8');
94
+ const data = JSON.stringify({ date: new Date() });
95
+ fs.writeFileSync(VERSION_CHECK_FILE, data, 'utf8');
96
96
  };
97
97
 
98
98
  // Function to check the current version of the package.
99
99
  const checkVersion = async () => {
100
- if (!(await shouldCheckVersion())) {
101
- return Promise.resolve(null); // Aucune version à vérifier, renvoie null
102
- }
103
- return new Promise((resolve, reject) => {
104
- const packageName = '@cerema/cadriciel';
105
- const child = spawn('npm', ['view', packageName, 'version'], {
106
- shell: true,
107
- });
108
-
109
- let version = '';
110
-
111
- child.stdout.on('data', (data) => {
112
- version += data.toString();
113
- });
114
-
115
- child.stderr.on('data', (data) => {
116
- console.error(`err: ${data}`);
117
- });
118
-
119
- child.on('error', (error) => {
120
- console.error(`Erreur lors de l'exécution de npm view: ${error.message}`);
121
- reject(error);
122
- });
123
-
124
- child.on('close', (code) => {
125
- if (code !== 0) {
126
- console.error(
127
- `Le processus npm view s'est terminé avec le code ${code}`
128
- );
129
- return reject(
130
- new Error('Erreur lors de la récupération de la version')
131
- );
132
- }
133
-
134
- version = version.trim();
135
- updateLastCheckDate();
136
- resolve(version);
100
+ if (!(await shouldCheckVersion())) {
101
+ return Promise.resolve(null); // Aucune version à vérifier, renvoie null
102
+ }
103
+ return new Promise((resolve, reject) => {
104
+ const packageName = '@cerema/cadriciel';
105
+ const child = spawn(`npm view ${packageName} version`, {
106
+ shell: true,
107
+ });
108
+
109
+ let version = '';
110
+
111
+ child.stdout.on('data', (data) => {
112
+ version += data.toString();
113
+ });
114
+
115
+ child.stderr.on('data', (data) => {
116
+ console.error(`err: ${data}`);
117
+ });
118
+
119
+ child.on('error', (error) => {
120
+ console.error(`Erreur lors de l'exécution de npm view: ${error.message}`);
121
+ reject(error);
122
+ });
123
+
124
+ child.on('close', (code) => {
125
+ if (code !== 0) {
126
+ console.error(
127
+ `Le processus npm view s'est terminé avec le code ${code}`
128
+ );
129
+ return reject(
130
+ new Error('Erreur lors de la récupération de la version')
131
+ );
132
+ }
133
+
134
+ version = version.trim();
135
+ updateLastCheckDate();
136
+ resolve(version);
137
+ });
137
138
  });
138
- });
139
139
  };
140
140
 
141
141
  /**
@@ -144,229 +144,229 @@ const checkVersion = async () => {
144
144
  * @returns {string|null} Path of the found directory or null.
145
145
  */
146
146
  function findCadricielDir(startPath) {
147
- let currentPath = startPath;
148
-
149
- while (currentPath !== path.parse(currentPath).root) {
150
- const potentialPath = path.join(currentPath, '.cadriciel/cli');
151
- if (
152
- fs.existsSync(potentialPath) &&
153
- fs.statSync(potentialPath).isDirectory()
154
- ) {
155
- return potentialPath;
147
+ let currentPath = startPath;
148
+
149
+ while (currentPath !== path.parse(currentPath).root) {
150
+ const potentialPath = path.join(currentPath, '.cadriciel/cli');
151
+ if (
152
+ fs.existsSync(potentialPath) &&
153
+ fs.statSync(potentialPath).isDirectory()
154
+ ) {
155
+ return potentialPath;
156
+ }
157
+ currentPath = path.dirname(currentPath); // Monter vers le répertoire parent.
156
158
  }
157
- currentPath = path.dirname(currentPath); // Monter vers le répertoire parent.
158
- }
159
159
 
160
- return null;
160
+ return null;
161
161
  }
162
162
 
163
163
  // Function to load global commands.
164
164
  const loadGlobalCommands = () => {
165
- let args = process.argv;
166
- //args.shift();
167
- let dir = fs.readdirSync(__dirname + '/cli/global');
168
- for (let i = 0; i < dir.length; i++) {
169
- if (dir[i].indexOf('.js') > -1)
170
- CADRICIEL_GLOBAL_COMMANDS[dir[i].split('.')[0]] = require(__dirname +
171
- '/cli/global/' +
172
- dir[i])(args);
173
- }
165
+ let args = process.argv;
166
+ //args.shift();
167
+ let dir = fs.readdirSync(__dirname + '/cli/global');
168
+ for (let i = 0; i < dir.length; i++) {
169
+ if (dir[i].indexOf('.js') > -1)
170
+ CADRICIEL_GLOBAL_COMMANDS[dir[i].split('.')[0]] = require(__dirname +
171
+ '/cli/global/' +
172
+ dir[i])(args);
173
+ }
174
174
  };
175
175
 
176
176
  // Function to load project specific commands.
177
177
  const loadCadricielCommands = (path) => {
178
- try {
179
- const cli = require(path + 'cli');
180
- for (let el in cli) {
181
- if (cli[el].description) {
182
- let subs = [];
183
- for (let s in cli[el]) {
184
- if (s !== 'description') subs.push({ title: s });
185
- }
186
- let description = '';
187
- if (cli[el].description.indexOf(']') > -1) {
188
- description = cli[el].description.split('] ')[1];
189
- let lbl = cli[el].description
190
- .split('] ')[0]
191
- .replace('[', '')
192
- .replace(']', '');
193
- CADRICIEL_COMMANDS[el] = {
194
- info: {
195
- title: el,
196
- description: description,
197
- label: lbl.toLowerCase(),
198
- sub: subs,
199
- },
200
- };
201
- } else {
202
- description = cli[el].description;
203
- CADRICIEL_COMMANDS[el] = {
204
- info: {
205
- title: el,
206
- description: cli[el].description,
207
- sub: subs,
208
- },
209
- };
210
- }
211
- } else {
212
- let description = '';
213
- if (cli[el].indexOf(']') > -1) {
214
- description = cli[el].split('] ')[1];
215
- let lbl = cli[el].split('] ')[0].replace('[', '').replace(']', '');
216
- CADRICIEL_COMMANDS[el] = {
217
- info: {
218
- title: el,
219
- description: description,
220
- label: lbl.toLowerCase(),
221
- },
222
- };
223
- } else {
224
- description = cli[el];
225
- CADRICIEL_COMMANDS[el] = {
226
- info: {
227
- title: el,
228
- description: description,
229
- },
230
- };
178
+ try {
179
+ const cli = require(path + 'cli');
180
+ for (let el in cli) {
181
+ if (cli[el].description) {
182
+ let subs = [];
183
+ for (let s in cli[el]) {
184
+ if (s !== 'description') subs.push({ title: s });
185
+ }
186
+ let description = '';
187
+ if (cli[el].description.indexOf(']') > -1) {
188
+ description = cli[el].description.split('] ')[1];
189
+ let lbl = cli[el].description
190
+ .split('] ')[0]
191
+ .replace('[', '')
192
+ .replace(']', '');
193
+ CADRICIEL_COMMANDS[el] = {
194
+ info: {
195
+ title: el,
196
+ description: description,
197
+ label: lbl.toLowerCase(),
198
+ sub: subs,
199
+ },
200
+ };
201
+ } else {
202
+ description = cli[el].description;
203
+ CADRICIEL_COMMANDS[el] = {
204
+ info: {
205
+ title: el,
206
+ description: cli[el].description,
207
+ sub: subs,
208
+ },
209
+ };
210
+ }
211
+ } else {
212
+ let description = '';
213
+ if (cli[el].indexOf(']') > -1) {
214
+ description = cli[el].split('] ')[1];
215
+ let lbl = cli[el].split('] ')[0].replace('[', '').replace(']', '');
216
+ CADRICIEL_COMMANDS[el] = {
217
+ info: {
218
+ title: el,
219
+ description: description,
220
+ label: lbl.toLowerCase(),
221
+ },
222
+ };
223
+ } else {
224
+ description = cli[el];
225
+ CADRICIEL_COMMANDS[el] = {
226
+ info: {
227
+ title: el,
228
+ description: description,
229
+ },
230
+ };
231
+ }
232
+ }
231
233
  }
232
- }
233
- }
234
- } catch (e) {}
234
+ } catch (e) { }
235
235
  };
236
236
 
237
237
  // Function to format command labels with chalk for color coding.
238
238
  const label = (caption) => {
239
- if (caption === 'experimental') return chalk.red(' (' + caption + ') ');
240
- if (caption === 'alpha') return chalk.cyan(' (' + caption + ') ');
241
- if (caption === 'beta') return chalk.magenta(' (' + caption + ') ');
242
- if (caption === 'docker') return chalk.green(' (' + caption + ') ');
243
- if (caption === 'ai')
244
- return chalk.yellow(' (' + caption.toUpperCase() + ') ');
245
- return '';
239
+ if (caption === 'experimental') return chalk.red(' (' + caption + ') ');
240
+ if (caption === 'alpha') return chalk.cyan(' (' + caption + ') ');
241
+ if (caption === 'beta') return chalk.magenta(' (' + caption + ') ');
242
+ if (caption === 'docker') return chalk.green(' (' + caption + ') ');
243
+ if (caption === 'ai')
244
+ return chalk.yellow(' (' + caption.toUpperCase() + ') ');
245
+ return '';
246
246
  };
247
247
 
248
248
  // Function to format command descriptions.
249
249
  const formatDescription = (description, maxLength) => {
250
- if (description.length <= maxLength) return description;
250
+ if (description.length <= maxLength) return description;
251
251
 
252
- const breakPoint = description.lastIndexOf(' ', maxLength);
253
- const firstPart = description.substring(0, breakPoint);
254
- const secondPart = description.substring(breakPoint + 1).trim();
252
+ const breakPoint = description.lastIndexOf(' ', maxLength);
253
+ const firstPart = description.substring(0, breakPoint);
254
+ const secondPart = description.substring(breakPoint + 1).trim();
255
255
 
256
- return firstPart + '\n ' + secondPart;
256
+ return firstPart + '\n ' + secondPart;
257
257
  };
258
258
 
259
259
  // Function to display commands.
260
260
  const display = (commands) => {
261
- const maxWidth = 30;
262
- const maxDescriptionLength = 50;
263
-
264
- for (let el in commands) {
265
- let title = el;
266
- if (commands[el].info.title != '---') {
267
- if (commands[el].info) {
268
- let description = commands[el].info.description;
269
- if (commands[el].info.sub) {
270
- title += ' <subcommand>';
271
- const sc = [];
272
- for (let i = 0; i < commands[el].info.sub.length; i++) {
273
- sc.push(commands[el].info.sub[i].title);
274
- }
275
- description += chalk.white(' ');
276
- description += chalk.grey(' (subcommands: ');
277
- description += chalk.cyan(sc.join(', '));
278
- description += chalk.grey(')');
261
+ const maxWidth = 30;
262
+ const maxDescriptionLength = 50;
263
+
264
+ for (let el in commands) {
265
+ let title = el;
266
+ if (commands[el].info.title != '---') {
267
+ if (commands[el].info) {
268
+ let description = commands[el].info.description;
269
+ if (commands[el].info.sub) {
270
+ title += ' <subcommand>';
271
+ const sc = [];
272
+ for (let i = 0; i < commands[el].info.sub.length; i++) {
273
+ sc.push(commands[el].info.sub[i].title);
274
+ }
275
+ description += chalk.white(' ');
276
+ description += chalk.grey(' (subcommands: ');
277
+ description += chalk.cyan(sc.join(', '));
278
+ description += chalk.grey(')');
279
+ }
280
+ const dots = '.'.repeat(maxWidth - title.length);
281
+
282
+ const formattedDesc = formatDescription(
283
+ description,
284
+ maxDescriptionLength
285
+ );
286
+
287
+ console.log(
288
+ ' ' +
289
+ chalk.cyanBright(title) +
290
+ ' ' +
291
+ chalk.grey(dots) +
292
+ ' ' +
293
+ label(commands[el].info.label) +
294
+ ' ' +
295
+ chalk.white(formattedDesc)
296
+ );
297
+ }
279
298
  }
280
- const dots = '.'.repeat(maxWidth - title.length);
281
-
282
- const formattedDesc = formatDescription(
283
- description,
284
- maxDescriptionLength
285
- );
286
-
287
- console.log(
288
- ' ' +
289
- chalk.cyanBright(title) +
290
- ' ' +
291
- chalk.grey(dots) +
292
- ' ' +
293
- label(commands[el].info.label) +
294
- ' ' +
295
- chalk.white(formattedDesc)
296
- );
297
- }
298
299
  }
299
- }
300
300
  };
301
301
 
302
302
  // Function to display the banner and the list of commands.
303
303
  const displayBanner = () => {
304
- figlet('Cadriciel', function (err, data) {
305
- if (err) {
306
- console.log(err);
307
- log.error('Something went wrong...');
308
- return;
309
- }
310
- try {
311
- let info = require(CADRICIEL_PATH + '/../version.json');
312
- version_cadriciel =
313
- ` - ${chalk.green('Cadriciel v')} ` +
314
- chalk.green.bold(info.version) +
315
- chalk.green(' (' + info.name + ')');
316
- } catch (e) {
317
- version_cadriciel = '';
318
- }
319
- console.log(
320
- chalk.cyan(data) +
321
- chalk.bold('\n CLI v' + require('./package.json').version) +
322
- version_cadriciel
323
- );
324
- console.log(' ');
325
- console.log(
326
- `${chalk.bold(' Usage :')} ${chalk.cyanBright(
327
- CADRICIEL_COMMAND + ' <commande>'
328
- )} ${chalk.cyan('[<args>]')}`
329
- );
330
- console.log(' ');
331
- console.log(chalk.bold(' Commandes globales :'));
332
- console.log(' ');
333
- display(CADRICIEL_GLOBAL_COMMANDS);
334
- console.log(' ');
335
-
336
- console.log(chalk.bold(' Commandes du projet :'));
337
- if (!CADRICIEL_PATH) {
338
- console.log(`\n Vous n'êtes pas à l'intérieur d'un projet. `);
339
- console.log(' ');
340
- } else {
341
- loadCadricielCommands(CADRICIEL_PATH + '/../');
342
- console.log(' ');
343
- display(CADRICIEL_COMMANDS);
344
- console.log(' ');
345
- }
346
- console.log(' ');
347
- });
304
+ figlet('Cadriciel', function (err, data) {
305
+ if (err) {
306
+ console.log(err);
307
+ log.error('Something went wrong...');
308
+ return;
309
+ }
310
+ try {
311
+ let info = require(CADRICIEL_PATH + '/../version.json');
312
+ version_cadriciel =
313
+ ` - ${chalk.green('Cadriciel v')} ` +
314
+ chalk.green.bold(info.version) +
315
+ chalk.green(' (' + info.name + ')');
316
+ } catch (e) {
317
+ version_cadriciel = '';
318
+ }
319
+ console.log(
320
+ chalk.cyan(data) +
321
+ chalk.bold('\n CLI v' + require('./package.json').version) +
322
+ version_cadriciel
323
+ );
324
+ console.log(' ');
325
+ console.log(
326
+ `${chalk.bold(' Usage :')} ${chalk.cyanBright(
327
+ CADRICIEL_COMMAND + ' <commande>'
328
+ )} ${chalk.cyan('[<args>]')}`
329
+ );
330
+ console.log(' ');
331
+ console.log(chalk.bold(' Commandes globales :'));
332
+ console.log(' ');
333
+ display(CADRICIEL_GLOBAL_COMMANDS);
334
+ console.log(' ');
335
+
336
+ console.log(chalk.bold(' Commandes du projet :'));
337
+ if (!CADRICIEL_PATH) {
338
+ console.log(`\n Vous n'êtes pas à l'intérieur d'un projet. `);
339
+ console.log(' ');
340
+ } else {
341
+ loadCadricielCommands(CADRICIEL_PATH + '/../');
342
+ console.log(' ');
343
+ display(CADRICIEL_COMMANDS);
344
+ console.log(' ');
345
+ }
346
+ console.log(' ');
347
+ });
348
348
  };
349
349
 
350
350
  // Function to process entered commands.
351
351
  const processCommands = (args) => {
352
- const command = args[0];
353
- const maxWidth = 30;
354
- const maxDescriptionLength = 50;
355
-
356
- loadCadricielCommands(CADRICIEL_PATH + '/../');
357
-
358
- if (CADRICIEL_GLOBAL_COMMANDS[command]) {
359
- CADRICIEL_GLOBAL_COMMANDS[command].start(args);
360
- } else {
361
- if (CADRICIEL_COMMANDS[command]) {
362
- console.log(' ');
363
- const dir = args.join('/');
364
- return parseCommand(args);
352
+ const command = args[0];
353
+ const maxWidth = 30;
354
+ const maxDescriptionLength = 50;
355
+
356
+ loadCadricielCommands(CADRICIEL_PATH + '/../');
357
+
358
+ if (CADRICIEL_GLOBAL_COMMANDS[command]) {
359
+ CADRICIEL_GLOBAL_COMMANDS[command].start(args);
365
360
  } else {
366
- log.error('Commande inconnue : ' + command);
367
- return displayBanner();
361
+ if (CADRICIEL_COMMANDS[command]) {
362
+ console.log(' ');
363
+ const dir = args.join('/');
364
+ return parseCommand(args);
365
+ } else {
366
+ log.error('Commande inconnue : ' + command);
367
+ return displayBanner();
368
+ }
368
369
  }
369
- }
370
370
  };
371
371
 
372
372
  /**
@@ -378,187 +378,187 @@ const processCommands = (args) => {
378
378
  * @param {object} cli - The command line interface object.
379
379
  */
380
380
  const displaySub = (path, title, description, cli) => {
381
- CADRICIEL_COMMANDS = {};
382
- delete cli.description;
383
- for (let el in cli) {
384
- if (cli[el].description) {
385
- let subs = [];
386
- for (let s in cli[el]) {
387
- if (s !== 'description') subs.push({ title: s });
388
- }
389
- let description = '';
390
- if (cli[el].description.indexOf(']') > -1) {
391
- description = cli[el].description.split('] ')[1];
392
- let lbl = cli[el].description
393
- .split('] ')[0]
394
- .replace('[', '')
395
- .replace(']', '');
396
- CADRICIEL_COMMANDS[el] = {
397
- info: {
398
- title: el,
399
- description: description,
400
- label: lbl.toLowerCase(),
401
- sub: subs,
402
- },
403
- };
404
- } else {
405
- description = cli[el].description;
406
- CADRICIEL_COMMANDS[el] = {
407
- info: {
408
- title: el,
409
- description: cli[el].description,
410
- sub: subs,
411
- },
412
- };
413
- }
414
- } else {
415
- let description = '';
416
- if (cli[el].indexOf(']') > -1) {
417
- description = cli[el].split('] ')[1];
418
- let lbl = cli[el].split('] ')[0].replace('[', '').replace(']', '');
419
- CADRICIEL_COMMANDS[el] = {
420
- info: {
421
- title: el,
422
- description: description,
423
- label: lbl.toLowerCase(),
424
- },
425
- };
426
- } else {
427
- CADRICIEL_COMMANDS[el] = {
428
- info: {
429
- title: el,
430
- description: cli[el],
431
- },
432
- };
433
- }
434
- }
435
- }
436
- figlet('Cadriciel', function (err, data) {
437
- if (err) {
438
- console.log(err);
439
- log.error('Something went wrong...');
440
- return;
441
- }
442
- try {
443
- let info = require(CADRICIEL_PATH + '/../version.json');
444
- version_cadriciel =
445
- ` - ${chalk.green('Cadriciel v')} ` +
446
- chalk.green.bold(info.version) +
447
- chalk.green(' (' + info.name + ')');
448
- } catch (e) {
449
- version_cadriciel = '';
381
+ CADRICIEL_COMMANDS = {};
382
+ delete cli.description;
383
+ for (let el in cli) {
384
+ if (cli[el].description) {
385
+ let subs = [];
386
+ for (let s in cli[el]) {
387
+ if (s !== 'description') subs.push({ title: s });
388
+ }
389
+ let description = '';
390
+ if (cli[el].description.indexOf(']') > -1) {
391
+ description = cli[el].description.split('] ')[1];
392
+ let lbl = cli[el].description
393
+ .split('] ')[0]
394
+ .replace('[', '')
395
+ .replace(']', '');
396
+ CADRICIEL_COMMANDS[el] = {
397
+ info: {
398
+ title: el,
399
+ description: description,
400
+ label: lbl.toLowerCase(),
401
+ sub: subs,
402
+ },
403
+ };
404
+ } else {
405
+ description = cli[el].description;
406
+ CADRICIEL_COMMANDS[el] = {
407
+ info: {
408
+ title: el,
409
+ description: cli[el].description,
410
+ sub: subs,
411
+ },
412
+ };
413
+ }
414
+ } else {
415
+ let description = '';
416
+ if (cli[el].indexOf(']') > -1) {
417
+ description = cli[el].split('] ')[1];
418
+ let lbl = cli[el].split('] ')[0].replace('[', '').replace(']', '');
419
+ CADRICIEL_COMMANDS[el] = {
420
+ info: {
421
+ title: el,
422
+ description: description,
423
+ label: lbl.toLowerCase(),
424
+ },
425
+ };
426
+ } else {
427
+ CADRICIEL_COMMANDS[el] = {
428
+ info: {
429
+ title: el,
430
+ description: cli[el],
431
+ },
432
+ };
433
+ }
434
+ }
450
435
  }
451
- console.log(
452
- chalk.cyan(data) +
453
- chalk.bold('\n CLI v' + require('./package.json').version) +
454
- version_cadriciel
455
- );
456
- console.log(' ');
457
- console.log(' ' + chalk.bold(description));
458
- console.log(' ');
459
- console.log(
460
- `${chalk.bold(' Usage :')} ${chalk.cyanBright(
461
- CADRICIEL_COMMAND + path + ' <commande>'
462
- )} ${chalk.cyan('[<args>]')}`
463
- );
464
- console.log(' ');
465
- display(CADRICIEL_COMMANDS);
466
- console.log(' ');
467
- });
436
+ figlet('Cadriciel', function (err, data) {
437
+ if (err) {
438
+ console.log(err);
439
+ log.error('Something went wrong...');
440
+ return;
441
+ }
442
+ try {
443
+ let info = require(CADRICIEL_PATH + '/../version.json');
444
+ version_cadriciel =
445
+ ` - ${chalk.green('Cadriciel v')} ` +
446
+ chalk.green.bold(info.version) +
447
+ chalk.green(' (' + info.name + ')');
448
+ } catch (e) {
449
+ version_cadriciel = '';
450
+ }
451
+ console.log(
452
+ chalk.cyan(data) +
453
+ chalk.bold('\n CLI v' + require('./package.json').version) +
454
+ version_cadriciel
455
+ );
456
+ console.log(' ');
457
+ console.log(' ' + chalk.bold(description));
458
+ console.log(' ');
459
+ console.log(
460
+ `${chalk.bold(' Usage :')} ${chalk.cyanBright(
461
+ CADRICIEL_COMMAND + path + ' <commande>'
462
+ )} ${chalk.cyan('[<args>]')}`
463
+ );
464
+ console.log(' ');
465
+ display(CADRICIEL_COMMANDS);
466
+ console.log(' ');
467
+ });
468
468
  };
469
469
 
470
470
  // Function to execute commands.
471
471
  const ExecCommand = (p, args) => {
472
- const unit = require(CADRICIEL_PATH + p);
473
- const params = {
474
- dir: {
475
- home: `${userHomeDir}/.cadriciel`,
476
- cadriciel: path.normalize(CADRICIEL_PATH + '/..'),
477
- root: path.normalize(CADRICIEL_PATH + '/../..'),
478
- },
479
- };
480
- unit(args, params);
472
+ const unit = require(CADRICIEL_PATH + p);
473
+ const params = {
474
+ dir: {
475
+ home: `${userHomeDir}/.cadriciel`,
476
+ cadriciel: path.normalize(CADRICIEL_PATH + '/..'),
477
+ root: path.normalize(CADRICIEL_PATH + '/../..'),
478
+ },
479
+ };
480
+ unit(args, params);
481
481
  };
482
482
 
483
483
  // Function to parse commands.
484
484
  const parseCommand = (args) => {
485
- const cli = require(CADRICIEL_PATH + '/../cli');
486
- let cmd = cli;
487
- let arguments = [];
488
- let title = '';
489
- let path = '';
490
- for (let i = 0; i < args.length; i++) {
491
- if (!cmd[args[i]]) arguments.push(args[i]);
492
- else {
493
- cmd = cmd[args[i]];
494
- title = args[i];
495
- path += ' ' + title;
485
+ const cli = require(CADRICIEL_PATH + '/../cli');
486
+ let cmd = cli;
487
+ let arguments = [];
488
+ let title = '';
489
+ let path = '';
490
+ for (let i = 0; i < args.length; i++) {
491
+ if (!cmd[args[i]]) arguments.push(args[i]);
492
+ else {
493
+ cmd = cmd[args[i]];
494
+ title = args[i];
495
+ path += ' ' + title;
496
+ }
496
497
  }
497
- }
498
- if (cmd.description) displaySub(path, title, cmd.description, cmd);
499
- else ExecCommand(path.replace(/ /g, '/'), arguments);
498
+ if (cmd.description) displaySub(path, title, cmd.description, cmd);
499
+ else ExecCommand(path.replace(/ /g, '/'), arguments);
500
500
  };
501
501
 
502
502
  const checkCachePermaLink = async () => {
503
- if (!isCacheUpToDate()) {
504
- const isConnected = await checkInternetConnection();
505
- if (isConnected) {
506
- await fetchData();
503
+ if (!isCacheUpToDate()) {
504
+ const isConnected = await checkInternetConnection();
505
+ if (isConnected) {
506
+ await fetchData();
507
+ }
507
508
  }
508
- }
509
509
 
510
- const cachedData = getCachedData();
511
- if (cachedData) {
512
- global.CADRICIEL_URI = cachedData.api + '/api';
513
- }
510
+ const cachedData = getCachedData();
511
+ if (cachedData) {
512
+ global.CADRICIEL_URI = cachedData.api + '/api';
513
+ }
514
514
  };
515
515
 
516
516
  // Main function.
517
517
  const main = async () => {
518
- let version = await checkVersion();
519
- /*
520
- await checkCachePermaLink();
521
-
522
- let version = await checkVersion();
523
- const current_version = require(__dirname + '/package.json').version;
524
- if (version === null) {
525
- version = current_version;
526
- }
527
- if (current_version != version) {
528
- const message =
529
- 'Une nouvelle version (' +
530
- version +
531
- ') a été détectée. Veuillez mettre à jour.\n' +
532
- chalk.white.bold('npm i -g @cerema/cadriciel@' + version);
533
-
534
- // Options pour le cadre
535
- const boxenOptions = {
536
- padding: 1,
537
- margin: 1,
538
- borderColor: 'yellow',
539
- borderStyle: 'double',
540
- };
541
-
542
- // Mise en forme du message avec Chalk
543
- const styledMessage = chalk.yellow(message);
544
-
545
- // Création de l'encadré avec Boxen
546
- const framedMessage = boxen(styledMessage, boxenOptions);
547
-
548
- console.log(framedMessage);
518
+ let version = await checkVersion();
519
+ /*
520
+ await checkCachePermaLink();
521
+
522
+ let version = await checkVersion();
523
+ const current_version = require(__dirname + '/package.json').version;
524
+ if (version === null) {
525
+ version = current_version;
526
+ }
527
+ if (current_version != version) {
528
+ const message =
529
+ 'Une nouvelle version (' +
530
+ version +
531
+ ') a été détectée. Veuillez mettre à jour.\n' +
532
+ chalk.white.bold('npm i -g @cerema/cadriciel@' + version);
533
+
534
+ // Options pour le cadre
535
+ const boxenOptions = {
536
+ padding: 1,
537
+ margin: 1,
538
+ borderColor: 'yellow',
539
+ borderStyle: 'double',
540
+ };
541
+
542
+ // Mise en forme du message avec Chalk
543
+ const styledMessage = chalk.yellow(message);
544
+
545
+ // Création de l'encadré avec Boxen
546
+ const framedMessage = boxen(styledMessage, boxenOptions);
547
+
548
+ console.log(framedMessage);
549
+ loadGlobalCommands();
550
+ process.argv.shift();
551
+ process.argv.shift();
552
+ if (process.argv.length <= 0) return displayBanner();
553
+ processCommands(process.argv);
554
+ } else {
555
+ */
549
556
  loadGlobalCommands();
550
557
  process.argv.shift();
551
558
  process.argv.shift();
552
559
  if (process.argv.length <= 0) return displayBanner();
553
560
  processCommands(process.argv);
554
- } else {
555
- */
556
- loadGlobalCommands();
557
- process.argv.shift();
558
- process.argv.shift();
559
- if (process.argv.length <= 0) return displayBanner();
560
- processCommands(process.argv);
561
- //}
561
+ //}
562
562
  };
563
563
 
564
564
  main();