@cerema/cadriciel 1.4.2 → 1.4.5

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/bun.lockb CHANGED
Binary file
@@ -13,6 +13,7 @@ module.exports = (args) => {
13
13
  const log = require('log-beautify');
14
14
  const isBinary = require('isbinaryfile').isBinaryFile;
15
15
  const userHomeDir = os.homedir();
16
+ var sep = path.sep;
16
17
  const {
17
18
  capitalizeFirstLetter,
18
19
  getAccount,
@@ -34,17 +35,21 @@ module.exports = (args) => {
34
35
  };
35
36
 
36
37
  const download = async (name, cb) => {
37
- const CadricielAPI = require('../../lib/cadriciel');
38
+ const CadricielAPI = require(path.join('..', '..', 'lib', 'cadriciel'));
38
39
  const cadriciel = new CadricielAPI();
39
40
  await cadriciel.downloadFile(
40
41
  '/template?key=' + name + '.zip',
41
- `${os.tmpdir()}/${name}.zip`
42
+ `${os.tmpdir()}${sep}${name}.zip`
42
43
  );
43
44
 
44
- unzipFile(`${os.tmpdir()}/${name}.zip`, `${os.tmpdir()}/${UID}`, () => {
45
- DEFAULT_TEMPLATE = name;
46
- fs.unlink(`${os.tmpdir()}/${name}.zip`, cb);
47
- });
45
+ unzipFile(
46
+ `${os.tmpdir()}${sep}${name}.zip`,
47
+ `${os.tmpdir()}${sep}${UID}`,
48
+ () => {
49
+ DEFAULT_TEMPLATE = name;
50
+ fs.unlink(`${os.tmpdir()}${sep}${name}.zip`, cb);
51
+ }
52
+ );
48
53
  };
49
54
 
50
55
  const changefs = (o, files, ndx, cb) => {
@@ -68,8 +73,8 @@ module.exports = (args) => {
68
73
  text = text.replace(/§§pgadmin_password§§/g, o.pgadmin_password);
69
74
  var output =
70
75
  OUTPUT_DIRECTORY +
71
- '/' +
72
- input.split(UID + '/')[1].replace(/§§project§§/g, o.project);
76
+ sep +
77
+ input.split(UID + sep)[1].replace(/§§project§§/g, o.project);
73
78
  var dir = require('path').dirname(output);
74
79
  fs.mkdirSync(dir, { recursive: true });
75
80
  fs.writeFileSync(output, text);
@@ -79,8 +84,8 @@ module.exports = (args) => {
79
84
  return changefs(o, files, ndx + 1, cb);
80
85
  var output =
81
86
  OUTPUT_DIRECTORY +
82
- '/' +
83
- input.split(UID + '/')[1].replace(/§§project§§/g, o.project);
87
+ sep +
88
+ input.split(UID + sep)[1].replace(/§§project§§/g, o.project);
84
89
  var dir = require('path').dirname(output);
85
90
  fs.mkdirSync(dir, { recursive: true });
86
91
  fs.copyFileSync(input, output);
@@ -144,8 +149,9 @@ module.exports = (args) => {
144
149
  spinner.succeed(
145
150
  '🚀 Votre projet a été correctement installé.\n'
146
151
  );
147
- console.log(
148
- `\n──────────────────────────────────────────────────────────────
152
+ console.log(' ');
153
+ console.log(`
154
+ ──────────────────────────────────────────────────────────────
149
155
 
150
156
  Pour lancer l'environnement local de développement :
151
157
 
@@ -153,17 +159,17 @@ module.exports = (args) => {
153
159
 
154
160
  cd ${chalk.green(name)}
155
161
  ${chalk.cyan('cad start')} .............. 🚀 ${chalk.bold(
156
- "démarre l'environnement local de développement"
157
- )}
162
+ "démarre l'environnement de développement"
163
+ )}
158
164
 
159
165
  ${chalk.cyan('cad stop')} ............... 🚦 ${chalk.bold(
160
- "arrête l'environnement."
161
- )}
166
+ "arrête l'environnement."
167
+ )}
162
168
 
163
- 👉 https://cadriciel.k8-dev.cerema.fr/api 👈
169
+ 👉 https://cadriciel.k8-dev.cerema.fr/api 👈);
164
170
 
165
- ──────────────────────────────────────────────────────────────\n`
166
- );
171
+ ──────────────────────────────────────────────────────────────`);
172
+ console.log(' ');
167
173
  }
168
174
  );
169
175
  });
@@ -187,8 +193,10 @@ module.exports = (args) => {
187
193
  }
188
194
 
189
195
  spinner.succeed('🚀 Votre projet a été correctement installé.\n');
196
+ console.log(' ');
190
197
  console.log(
191
- `\n──────────────────────────────────────────────────────────────
198
+ `
199
+ ──────────────────────────────────────────────────────────────
192
200
 
193
201
  Pour lancer l'environnement local de développement :
194
202
 
@@ -200,7 +208,7 @@ module.exports = (args) => {
200
208
  ${chalk.cyan(
201
209
  'cad start'
202
210
  )} .............. 🚀 ${chalk.bold(
203
- "démarre l'environnement local de développement"
211
+ "démarre l'environnement de développement"
204
212
  )}
205
213
 
206
214
  ${chalk.cyan(
@@ -54,6 +54,7 @@ module.exports = (args) => {
54
54
  });
55
55
 
56
56
  dockerPull.stderr.on('data', (data) => {
57
+ console.log(data);
57
58
  response.fail(chalk.red('Le service Docker ne répond pas.'));
58
59
  return process.exit(1);
59
60
  });
@@ -94,7 +95,7 @@ module.exports = (args) => {
94
95
  start: () => {
95
96
  addMapping();
96
97
  const dockerImagesToInstall = [
97
- 'postgres:15',
98
+ 'cerema/postgres',
98
99
  'cerema/cadriciel:1.0.0',
99
100
  'dpage/pgadmin4',
100
101
  'inbucket/inbucket:latest',
@@ -53,6 +53,7 @@ module.exports = (args) => {
53
53
  const response = await prompts({
54
54
  type: 'confirm',
55
55
  name: 'code',
56
+ initial: true,
56
57
  message: 'Ouvrir le navigateur et se connecter à ORION',
57
58
  });
58
59
 
@@ -148,17 +149,14 @@ module.exports = (args) => {
148
149
  });
149
150
 
150
151
  // Ouvrez le navigateur vers l'URL d'authentification
151
- switch (process.platform) {
152
- case 'darwin':
153
- exec(`open "${authUrl}"`);
154
- break;
155
- case 'win32':
156
- exec(`start "${authUrl}"`);
157
- break;
158
- default:
159
- exec(`xdg-open "${authUrl}"`);
160
- break;
161
- }
152
+ var start =
153
+ process.platform == 'darwin'
154
+ ? 'open'
155
+ : process.platform == 'win32'
156
+ ? 'start "" '
157
+ : 'xdg-open';
158
+
159
+ require('child_process').exec(start + ' "' + authUrl + '"');
162
160
  });
163
161
  };
164
162
  axios
package/cli.js CHANGED
@@ -7,6 +7,7 @@ const path = require('path');
7
7
  const { spawn } = require('child_process');
8
8
  const os = require('os');
9
9
  const userHomeDir = os.homedir();
10
+ const boxen = require('boxen');
10
11
 
11
12
  const CADRICIEL_PATH = findCadricielDir(process.cwd());
12
13
  const CADRICIEL_COMMAND =
@@ -21,6 +22,28 @@ try {
21
22
  fs.unlinkSync(`${userHomeDir}/.cadriciel/account.json`);
22
23
  } catch (e) {}
23
24
 
25
+ const checkVersion = async () => {
26
+ return new Promise((resolve, reject) => {
27
+ const packageName = '@cerema/cadriciel';
28
+ const child = spawn('npm', ['view', packageName, 'version']);
29
+
30
+ let version = '';
31
+
32
+ child.stdout.on('data', (data) => {
33
+ version += data.toString();
34
+ });
35
+
36
+ child.on('close', (code) => {
37
+ if (code !== 0) {
38
+ return;
39
+ }
40
+
41
+ version = version.trim();
42
+ resolve(version);
43
+ });
44
+ });
45
+ };
46
+
24
47
  /**
25
48
  * Recherche récursivement le répertoire '.cadriciel' à partir du chemin donné, en remontant vers les répertoires parents.
26
49
  * @param {string} startPath - Le chemin de départ pour la recherche.
@@ -129,9 +152,19 @@ const displayBanner = () => {
129
152
  log.error('Something went wrong...');
130
153
  return;
131
154
  }
155
+ try {
156
+ let info = require(CADRICIEL_PATH + '/version.json');
157
+ version_cadriciel =
158
+ ` - ${chalk.green('Cadriciel v')} ` +
159
+ chalk.green.bold(info.version) +
160
+ chalk.green(' (' + info.name + ')');
161
+ } catch (e) {
162
+ version_cadriciel = '';
163
+ }
132
164
  console.log(
133
165
  chalk.cyan(data) +
134
- chalk.bold('\n CLI v' + require('./package.json').version)
166
+ chalk.bold('\n CLI v ' + require('./package.json').version) +
167
+ version_cadriciel
135
168
  );
136
169
  console.log(' ');
137
170
  console.log(
@@ -144,6 +177,7 @@ const displayBanner = () => {
144
177
  console.log(' ');
145
178
  display(CADRICIEL_GLOBAL_COMMANDS);
146
179
  console.log(' ');
180
+
147
181
  console.log(chalk.bold(' Commandes du projet :'));
148
182
  if (!CADRICIEL_PATH) {
149
183
  console.log(`\n Vous n'êtes pas à l'intérieur d'un projet. `);
@@ -180,8 +214,39 @@ const processCommands = (args) => {
180
214
  }
181
215
  };
182
216
 
183
- loadGlobalCommands();
184
-
185
- if (process.argv.length <= 2) return displayBanner();
186
-
187
- processCommands(process.argv.splice(2));
217
+ checkVersion()
218
+ .then((version) => {
219
+ const current_version = require(__dirname + '/package.json').version;
220
+
221
+ if (current_version != version) {
222
+ const message =
223
+ 'Une nouvelle version (' +
224
+ version +
225
+ ') a été détectée. Veuillez mettre à jour.\n' +
226
+ chalk.white.bold('npm i -g @cerema/cadriciel');
227
+
228
+ // Options pour le cadre
229
+ const boxenOptions = {
230
+ padding: 1,
231
+ margin: 1,
232
+ borderColor: 'yellow',
233
+ borderStyle: 'double',
234
+ };
235
+
236
+ // Mise en forme du message avec Chalk
237
+ const styledMessage = chalk.yellow(message);
238
+
239
+ // Création de l'encadré avec Boxen
240
+ const framedMessage = boxen(styledMessage, boxenOptions);
241
+
242
+ console.log(framedMessage);
243
+ loadGlobalCommands();
244
+ processCommands(process.argv.splice(2));
245
+ if (process.argv.length <= 2) return displayBanner();
246
+ }
247
+ })
248
+ .catch((error) => {
249
+ loadGlobalCommands();
250
+ processCommands(process.argv.splice(2));
251
+ if (process.argv.length <= 2) return displayBanner();
252
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cerema/cadriciel",
3
- "version": "1.4.2",
3
+ "version": "1.4.5",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "npm": ">=8.0.0",
@@ -12,6 +12,7 @@
12
12
  "dependencies": {
13
13
  "adm-zip": "^0.5.10",
14
14
  "axios": "^1.5.1",
15
+ "boxen": "5.1.2",
15
16
  "chalk-v2": "^1.0.2",
16
17
  "commander": "^10.0.0",
17
18
  "express": "^4.18.2",