@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/assets/docker/.env +27 -0
- package/cli/assets/docker/docker-compose.yml +209 -0
- package/cli/assets/docker/init-db/01-create-keycloak-db.sql +1 -0
- package/cli/assets/docker/init-db/02-cadriciel.sql +3604 -0
- package/cli/global/doctor.js +213 -81
- package/cli/global/init.js +34 -237
- package/cli/global/install.js +99 -20
- package/cli.js +424 -424
- package/package.json +4 -3
- /package/cli/{global → _old}/load.js +0 -0
- /package/cli/{global → _old}/login.js +0 -0
- /package/cli/{global → _old}/logout.js +0 -0
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
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
if (!fs.existsSync(CACHE_FILE_PATH)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
95
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
160
|
+
return null;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
// Function to load global commands.
|
|
164
164
|
const loadGlobalCommands = () => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
250
|
+
if (description.length <= maxLength) return description;
|
|
251
251
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
252
|
+
const breakPoint = description.lastIndexOf(' ', maxLength);
|
|
253
|
+
const firstPart = description.substring(0, breakPoint);
|
|
254
|
+
const secondPart = description.substring(breakPoint + 1).trim();
|
|
255
255
|
|
|
256
|
-
|
|
256
|
+
return firstPart + '\n ' + secondPart;
|
|
257
257
|
};
|
|
258
258
|
|
|
259
259
|
// Function to display commands.
|
|
260
260
|
const display = (commands) => {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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
|
-
|
|
367
|
-
|
|
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
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
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
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
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
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
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
|
-
|
|
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
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
503
|
+
if (!isCacheUpToDate()) {
|
|
504
|
+
const isConnected = await checkInternetConnection();
|
|
505
|
+
if (isConnected) {
|
|
506
|
+
await fetchData();
|
|
507
|
+
}
|
|
507
508
|
}
|
|
508
|
-
}
|
|
509
509
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
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
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
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
|
-
|
|
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();
|