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