@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/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 +426 -428
- 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
|
@@ -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
|
-
|
|
17
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
if (!fs.existsSync(CACHE_FILE_PATH)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
98
|
-
|
|
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
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
160
|
+
return null;
|
|
164
161
|
}
|
|
165
162
|
|
|
166
163
|
// Function to load global commands.
|
|
167
164
|
const loadGlobalCommands = () => {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
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
|
-
|
|
231
|
-
|
|
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
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
|
|
250
|
+
if (description.length <= maxLength) return description;
|
|
254
251
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
252
|
+
const breakPoint = description.lastIndexOf(' ', maxLength);
|
|
253
|
+
const firstPart = description.substring(0, breakPoint);
|
|
254
|
+
const secondPart = description.substring(breakPoint + 1).trim();
|
|
258
255
|
|
|
259
|
-
|
|
256
|
+
return firstPart + '\n ' + secondPart;
|
|
260
257
|
};
|
|
261
258
|
|
|
262
259
|
// Function to display commands.
|
|
263
260
|
const display = (commands) => {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
|
|
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
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
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
|
-
|
|
370
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
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
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
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
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
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
|
-
|
|
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
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
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
|
-
|
|
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
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
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();
|