@cerema/cadriciel 1.4.1 → 1.4.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.
@@ -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(
@@ -1,35 +1,107 @@
1
1
  module.exports = (args) => {
2
- const { execSync } = require('child_process');
2
+ const chalk = require('chalk-v2');
3
+ const ora = require('ora');
4
+ const os = require('os');
5
+ const fs = require('fs');
6
+ const { spawn } = require('child_process');
7
+ const HOSTS_PATH = '/etc/hosts';
8
+ const MAPPING_ENTRY = '127.0.0.1 keycloak';
3
9
 
4
- const getCommandOutput = (command) => {
10
+ function addMapping() {
5
11
  try {
6
- const output = execSync(command, { encoding: 'utf-8' });
7
- return output.trim(); // Remove new line and trailing space
8
- } catch (error) {
9
- // If there's an error (like the command not found), we'll assume it's not installed
10
- return 'Not installed';
12
+ const hostsContent = fs.readFileSync(HOSTS_PATH, 'utf8');
13
+ if (!hostsContent.includes(MAPPING_ENTRY)) {
14
+ fs.appendFileSync(HOSTS_PATH, os.EOL + MAPPING_ENTRY);
15
+ }
16
+ } catch (e) {
17
+ console.error(
18
+ chalk.red.bold(
19
+ "\nVous devez lancer la commande en tant qu'administrateur.\n"
20
+ )
21
+ );
22
+ return process.exit(0);
11
23
  }
24
+ }
25
+
26
+ const checkIfCommandExists = (command, callback) => {
27
+ const proc = spawn('which', [command]);
28
+
29
+ let found = false;
30
+ proc.stdout.on('data', (data) => {
31
+ if (data.toString().trim() !== '') {
32
+ found = true;
33
+ }
34
+ });
35
+
36
+ proc.on('close', (code) => {
37
+ callback(found);
38
+ });
12
39
  };
13
40
 
14
- const getSoftwareVersions = () => {
15
- const softwareChecks = {
16
- Homebrew: 'brew -v',
17
- Git: 'git --version',
18
- Docker: 'docker --version',
19
- Java: 'java -version 2>&1 | head -n 1', // Java version gets printed to stderr
20
- Maven: 'mvn -v | head -n 1',
21
- //Liquibase: 'liquibase --version',
22
- Nodejs: 'node --version',
23
- };
24
-
25
- const versions = {};
26
-
27
- for (const [software, command] of Object.entries(softwareChecks)) {
28
- versions[software] = getCommandOutput(command);
41
+ const installDockerImages = (images, ndx) => {
42
+ if (!ndx) {
43
+ ndx = 0;
44
+ console.log('\n💻 ' + chalk.bold('Installation des dépendances...\n'));
29
45
  }
46
+ if (!images[ndx]) return console.log('\n👍 Installation terminée.');
47
+ const image = images[ndx];
48
+
49
+ const response = ora(`Téléchargement de l'image: ${image}`).start();
50
+ const dockerPull = spawn('docker', ['pull', image]);
51
+
52
+ dockerPull.stdout.on('data', (data) => {
53
+ //console.log(data.toString().trim());
54
+ });
30
55
 
31
- return versions;
56
+ dockerPull.stderr.on('data', (data) => {
57
+ response.fail(chalk.red('Le service Docker ne répond pas.'));
58
+ return process.exit(1);
59
+ });
60
+
61
+ dockerPull.on('close', (code) => {
62
+ if (code !== 0) {
63
+ response.fail(`Error pulling image ${image}`);
64
+ } else {
65
+ response.succeed(`Image ${image} OK.`);
66
+ installDockerImages(images, ndx + 1);
67
+ }
68
+ });
32
69
  };
33
70
 
34
- //console.log(getSoftwareVersions());
71
+ const setupEnvironment = (images) => {
72
+ checkIfCommandExists('docker', (dockerExists) => {
73
+ if (!dockerExists) {
74
+ console.error(`Docker n'est pas installé.`);
75
+ return;
76
+ }
77
+
78
+ checkIfCommandExists('git', (gitExists) => {
79
+ if (!gitExists) {
80
+ console.error(`Git n'est pas installé.`);
81
+ return;
82
+ }
83
+
84
+ installDockerImages(images);
85
+ });
86
+ });
87
+ };
88
+ return {
89
+ info: {
90
+ title: 'install',
91
+ description:
92
+ 'Installation des dépendances (La première fois uniquement).)',
93
+ },
94
+ start: () => {
95
+ addMapping();
96
+ const dockerImagesToInstall = [
97
+ 'postgres:15',
98
+ 'cerema/cadriciel:1.0.0',
99
+ 'dpage/pgadmin4',
100
+ 'inbucket/inbucket:latest',
101
+ 'quay.io/keycloak/keycloak:legacy',
102
+ 'liquibase/liquibase',
103
+ ];
104
+ setupEnvironment(dockerImagesToInstall);
105
+ },
106
+ };
35
107
  };
@@ -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
@@ -129,9 +129,19 @@ const displayBanner = () => {
129
129
  log.error('Something went wrong...');
130
130
  return;
131
131
  }
132
+ try {
133
+ let info = require(CADRICIEL_PATH + '/version.json');
134
+ version_cadriciel =
135
+ ` - ${chalk.green('Cadriciel v')} ` +
136
+ chalk.green.bold(info.version) +
137
+ chalk.green(' (' + info.name + ')');
138
+ } catch (e) {
139
+ version_cadriciel = '';
140
+ }
132
141
  console.log(
133
142
  chalk.cyan(data) +
134
- chalk.bold('\n CLI v' + require('./package.json').version)
143
+ chalk.bold('\n CLI v ' + require('./package.json').version) +
144
+ version_cadriciel
135
145
  );
136
146
  console.log(' ');
137
147
  console.log(
@@ -144,6 +154,7 @@ const displayBanner = () => {
144
154
  console.log(' ');
145
155
  display(CADRICIEL_GLOBAL_COMMANDS);
146
156
  console.log(' ');
157
+
147
158
  console.log(chalk.bold(' Commandes du projet :'));
148
159
  if (!CADRICIEL_PATH) {
149
160
  console.log(`\n Vous n'êtes pas à l'intérieur d'un projet. `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cerema/cadriciel",
3
- "version": "1.4.1",
3
+ "version": "1.4.4",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "npm": ">=8.0.0",
package/_install.js DELETED
@@ -1,107 +0,0 @@
1
- module.exports = (args) => {
2
- const chalk = require('chalk-v2');
3
- const ora = require('ora');
4
- const os = require('os');
5
- const fs = require('fs');
6
- const { spawn } = require('child_process');
7
- const HOSTS_PATH = '/etc/hosts';
8
- const MAPPING_ENTRY = '127.0.0.1 keycloak';
9
-
10
- function addMapping() {
11
- try {
12
- const hostsContent = fs.readFileSync(HOSTS_PATH, 'utf8');
13
- if (!hostsContent.includes(MAPPING_ENTRY)) {
14
- fs.appendFileSync(HOSTS_PATH, os.EOL + MAPPING_ENTRY);
15
- }
16
- } catch (e) {
17
- console.error(
18
- chalk.red.bold(
19
- "\nVous devez lancer la commande en tant qu'administrateur.\n"
20
- )
21
- );
22
- return process.exit(0);
23
- }
24
- }
25
-
26
- const checkIfCommandExists = (command, callback) => {
27
- const proc = spawn('which', [command]);
28
-
29
- let found = false;
30
- proc.stdout.on('data', (data) => {
31
- if (data.toString().trim() !== '') {
32
- found = true;
33
- }
34
- });
35
-
36
- proc.on('close', (code) => {
37
- callback(found);
38
- });
39
- };
40
-
41
- const installDockerImages = (images, ndx) => {
42
- if (!ndx) {
43
- ndx = 0;
44
- console.log('\n💻 ' + chalk.bold('Installation des dépendances...\n'));
45
- }
46
- if (!images[ndx]) return console.log('\n👍 Installation terminée.');
47
- const image = images[ndx];
48
-
49
- const response = ora(`Téléchargement de l'image: ${image}`).start();
50
- const dockerPull = spawn('docker', ['pull', image]);
51
-
52
- dockerPull.stdout.on('data', (data) => {
53
- //console.log(data.toString().trim());
54
- });
55
-
56
- dockerPull.stderr.on('data', (data) => {
57
- response.fail(chalk.red('Le service Docker ne répond pas.'));
58
- return process.exit(1);
59
- });
60
-
61
- dockerPull.on('close', (code) => {
62
- if (code !== 0) {
63
- response.fail(`Error pulling image ${image}`);
64
- } else {
65
- response.succeed(`Image ${image} OK.`);
66
- installDockerImages(images, ndx + 1);
67
- }
68
- });
69
- };
70
-
71
- const setupEnvironment = (images) => {
72
- checkIfCommandExists('docker', (dockerExists) => {
73
- if (!dockerExists) {
74
- console.error(`Docker n'est pas installé.`);
75
- return;
76
- }
77
-
78
- checkIfCommandExists('git', (gitExists) => {
79
- if (!gitExists) {
80
- console.error(`Git n'est pas installé.`);
81
- return;
82
- }
83
-
84
- installDockerImages(images);
85
- });
86
- });
87
- };
88
- return {
89
- info: {
90
- title: 'install',
91
- description:
92
- 'Installation des dépendances (La première fois uniquement).)',
93
- },
94
- start: () => {
95
- addMapping();
96
- const dockerImagesToInstall = [
97
- 'postgres:15',
98
- 'cerema/cadriciel:1.0.0',
99
- 'dpage/pgadmin4',
100
- 'inbucket/inbucket:latest',
101
- 'quay.io/keycloak/keycloak:legacy',
102
- 'liquibase/liquibase',
103
- ];
104
- setupEnvironment(dockerImagesToInstall);
105
- },
106
- };
107
- };