@cerema/cadriciel 1.5.7 β†’ 1.5.9

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.
@@ -104,15 +104,12 @@ Host cadriciel
104
104
  bar1.start(100, 0);
105
105
  progress(bar1, response, async () => {
106
106
  console.log(' ');
107
- console.log(response);
107
+
108
108
  const step1 = ora('πŸ“₯ TΓ©lΓ©chargement du projet en cours...').start();
109
109
  try {
110
- console.log('o');
111
110
  await updatePK();
112
- console.log('o');
111
+
113
112
  try {
114
- console.log('git clone ' + response.prj.uri);
115
- console.log('git clone ' + response.prj.uri);
116
113
  const git = await execPromise('git clone ' + response.prj.uri, {
117
114
  cwd: process.cwd(),
118
115
  });
@@ -170,7 +167,10 @@ Host cadriciel
170
167
 
171
168
  πŸ’» ${chalk.bold('Pour manager votre projet :')}
172
169
 
173
- πŸ‘‰ ${link('studio.cerema.dev', 'studio.cerema.dev')}
170
+ πŸ‘‰ ${link(
171
+ global.CACHE_URI.studio.split('://')[1],
172
+ global.CACHE_URI.studio.split('://')[1]
173
+ )}
174
174
 
175
175
  ──────────────────────────────────────────────────────────────`);
176
176
  console.log(' ');
@@ -16,7 +16,7 @@ module.exports = (args) => {
16
16
  const app = express();
17
17
  const REALM = 'CeremaApps';
18
18
 
19
- const KEYCLOAK_SERVER = 'https://orion.cerema.fr';
19
+ const KEYCLOAK_SERVER = global.CACHE_URI.orion;
20
20
  const PORT = 14211;
21
21
  const CLIENT_ID = 'cadriciel_login';
22
22
 
package/cli.js CHANGED
@@ -8,11 +8,14 @@ const { spawn } = require('child_process'); // For executing shell commands.
8
8
  const os = require('os'); // Operating system-related utilities.
9
9
  const userHomeDir = os.homedir(); // Fetching the user's home directory.
10
10
  const boxen = require('boxen'); // For creating boxes in the console.
11
+ const axios = require('axios'); // For making HTTP requests.
11
12
 
12
13
  // Locating the '.cadriciel' directory starting from the current working directory.
13
14
  const CADRICIEL_PATH = findCadricielDir(process.cwd());
14
15
  const CADRICIEL_COMMAND = 'cad';
15
- global.CADRICIEL_URI = 'https://cadriciel.cerema.dev/api';
16
+ const CADRICIEL_PERMALINK =
17
+ 'https://gist.githubusercontent.com/zucatti/08b37516b23c08028a2b07694f0329b6/raw/cadriciel-url.json';
18
+ global.CADRICIEL_URI = '';
16
19
  //global.CADRICIEL_URI = 'http://localhost:3000/api';
17
20
 
18
21
  // Initialize command storage objects.
@@ -21,6 +24,55 @@ var CADRICIEL_COMMANDS = {};
21
24
 
22
25
  // Path for version checking file.
23
26
  const VERSION_CHECK_FILE = path.join(userHomeDir, '.cadriciel_last_check.json');
27
+ const CACHE_FILE_PATH = path.join(userHomeDir, '.cadriciel_cache.json');
28
+ global.CACHE_URI = {};
29
+
30
+ // Function to check internet connection
31
+ const checkInternetConnection = async () => {
32
+ try {
33
+ await axios.get('https://www.google.com');
34
+ return true;
35
+ } catch {
36
+ return false;
37
+ }
38
+ };
39
+
40
+ // Function to fetch data from permalink URL
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
+ }
51
+ };
52
+
53
+ // Function to get cached data
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;
61
+ };
62
+
63
+ // Function to check if the cache file is up-to-date
64
+ const isCacheUpToDate = () => {
65
+ if (!fs.existsSync(CACHE_FILE_PATH)) {
66
+ return false;
67
+ }
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
73
+
74
+ return fileModifiedDate >= today;
75
+ };
24
76
 
25
77
  // Function to decide whether a version check is needed.
26
78
  const shouldCheckVersion = async () => {
@@ -447,53 +499,63 @@ const parseCommand = (args) => {
447
499
  else ExecCommand(path.replace(/ /g, '/'), arguments);
448
500
  };
449
501
 
450
- // Main function.
451
- checkVersion()
452
- .then((version) => {
453
- const current_version = require(__dirname + '/package.json').version;
454
- if (version === null) {
455
- version = current_version;
456
- }
457
- if (current_version != version) {
458
- const message =
459
- 'Une nouvelle version (' +
460
- version +
461
- ') a Γ©tΓ© dΓ©tectΓ©e. Veuillez mettre Γ  jour.\n' +
462
- chalk.white.bold('npm i -g @cerema/cadriciel@' + version);
463
-
464
- // Options pour le cadre
465
- const boxenOptions = {
466
- padding: 1,
467
- margin: 1,
468
- borderColor: 'yellow',
469
- borderStyle: 'double',
470
- };
471
-
472
- // Mise en forme du message avec Chalk
473
- const styledMessage = chalk.yellow(message);
474
-
475
- // CrΓ©ation de l'encadrΓ© avec Boxen
476
- const framedMessage = boxen(styledMessage, boxenOptions);
477
-
478
- console.log(framedMessage);
479
- loadGlobalCommands();
480
- process.argv.shift();
481
- process.argv.shift();
482
- if (process.argv.length <= 0) return displayBanner();
483
- processCommands(process.argv);
484
- } else {
485
- loadGlobalCommands();
486
- process.argv.shift();
487
- process.argv.shift();
488
- if (process.argv.length <= 0) return displayBanner();
489
- processCommands(process.argv);
502
+ const checkCachePermaLink = async () => {
503
+ if (!isCacheUpToDate()) {
504
+ const isConnected = await checkInternetConnection();
505
+ if (isConnected) {
506
+ await fetchData();
490
507
  }
491
- })
492
- .catch((error) => {
493
- console.log(error);
494
- /*loadGlobalCommands();
508
+ }
509
+
510
+ const cachedData = getCachedData();
511
+ if (cachedData) {
512
+ global.CADRICIEL_URI = cachedData.api + '/api';
513
+ }
514
+ };
515
+
516
+ // Main function.
517
+ const main = async () => {
518
+ await checkCachePermaLink();
519
+
520
+ let version = await checkVersion();
521
+ const current_version = require(__dirname + '/package.json').version;
522
+ if (version === null) {
523
+ version = current_version;
524
+ }
525
+ if (current_version != version) {
526
+ const message =
527
+ 'Une nouvelle version (' +
528
+ version +
529
+ ') a Γ©tΓ© dΓ©tectΓ©e. Veuillez mettre Γ  jour.\n' +
530
+ chalk.white.bold('npm i -g @cerema/cadriciel@' + version);
531
+
532
+ // Options pour le cadre
533
+ const boxenOptions = {
534
+ padding: 1,
535
+ margin: 1,
536
+ borderColor: 'yellow',
537
+ borderStyle: 'double',
538
+ };
539
+
540
+ // Mise en forme du message avec Chalk
541
+ const styledMessage = chalk.yellow(message);
542
+
543
+ // CrΓ©ation de l'encadrΓ© avec Boxen
544
+ const framedMessage = boxen(styledMessage, boxenOptions);
545
+
546
+ console.log(framedMessage);
547
+ loadGlobalCommands();
495
548
  process.argv.shift();
496
549
  process.argv.shift();
497
- if (process.argv.length <= 2) return displayBanner();
498
- processCommands(process.argv.splice(2));*/
499
- });
550
+ if (process.argv.length <= 0) return displayBanner();
551
+ processCommands(process.argv);
552
+ } else {
553
+ loadGlobalCommands();
554
+ process.argv.shift();
555
+ process.argv.shift();
556
+ if (process.argv.length <= 0) return displayBanner();
557
+ processCommands(process.argv);
558
+ }
559
+ };
560
+
561
+ main();
package/lib/cadriciel.js CHANGED
@@ -7,6 +7,7 @@ const HomeDir = os.homedir() + '/.cadriciel';
7
7
  const { error } = require('./message');
8
8
  const https = require('https');
9
9
  var baseURL = global.CADRICIEL_URI;
10
+
10
11
  class CadricielAPI {
11
12
  constructor(token) {
12
13
  const httpsAgent = new https.Agent({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cerema/cadriciel",
3
- "version": "1.5.7",
3
+ "version": "1.5.9",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "npm": ">=8.0.0",