@cerema/cadriciel 1.4.13 → 1.4.15

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.
@@ -29,40 +29,37 @@ module.exports = (args) => {
29
29
  console.log(' ');
30
30
  console.log(' 🏥 ' + chalk.bold('Pré-requis globaux'));
31
31
  console.log(' ');
32
- const tasks = new Listr([
33
- {
34
- title: 'Homebrew',
35
- task: () => checkInstallation('brew --version'),
36
- },
37
- {
38
- title: 'Git',
39
- task: () => checkInstallation('git --version'),
40
- },
41
- {
42
- title: 'Java',
43
- task: () => checkInstallation('java --version'),
44
- },
45
- {
46
- title: 'Maven',
47
- task: () => checkInstallation('mvn -v'),
48
- },
49
- {
50
- title: 'Liquibase',
51
- task: () =>
52
- checkInstallation('liquibase --version', extractLiquibaseVersion),
53
- },
54
- ]);
32
+ const tasks = new Listr(
33
+ [
34
+ {
35
+ title: 'Homebrew',
36
+ task: () => checkInstallation('brew --version'),
37
+ },
38
+ {
39
+ title: 'Git',
40
+ task: () => checkInstallation('git --version'),
41
+ },
42
+ {
43
+ title: 'Java',
44
+ task: () => checkInstallation('java --version'),
45
+ },
46
+ ],
47
+ { concurrent: true, exitOnError: false }
48
+ );
55
49
 
56
- const dockerTasks = new Listr([
57
- {
58
- title: 'Docker',
59
- task: () => checkInstallation('docker ps'),
60
- },
61
- {
62
- title: 'Docker Compose',
63
- task: () => checkInstallation('docker-compose --version'),
64
- },
65
- ]);
50
+ const dockerTasks = new Listr(
51
+ [
52
+ {
53
+ title: 'Docker',
54
+ task: () => checkInstallation('docker ps'),
55
+ },
56
+ {
57
+ title: 'Docker Compose',
58
+ task: () => checkInstallation('docker-compose --version'),
59
+ },
60
+ ],
61
+ { concurrent: true, exitOnError: false }
62
+ );
66
63
 
67
64
  tasks
68
65
  .run()
@@ -252,6 +252,7 @@ module.exports = (args) => {
252
252
  });
253
253
  });
254
254
  };
255
+
255
256
  return {
256
257
  info: {
257
258
  title: 'completion',
@@ -1,154 +1,107 @@
1
1
  module.exports = (args) => {
2
- const { exec } = require('child_process');
3
- const Listr = require('listr');
2
+ const chalk = require('chalk-v2');
3
+ const ora = require('ora');
4
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';
5
9
 
6
- const executeCommand = (command) => {
7
- return new Promise((resolve, reject) => {
8
- exec(command, (error, stdout, stderr) => {
9
- if (error) {
10
- console.error(stderr);
11
- reject(error);
12
- } else {
13
- console.log(stdout);
14
- resolve(stdout);
15
- }
16
- });
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], { shell: true });
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);
17
38
  });
18
39
  };
19
40
 
20
- const isMacOS = os.platform() === 'darwin';
21
- const isLinux = os.platform() === 'linux';
22
- const isWindows = os.platform() === 'win32';
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], { shell: true });
51
+
52
+ dockerPull.stdout.on('data', (data) => {
53
+ //console.log(data.toString().trim());
54
+ });
55
+
56
+ dockerPull.stderr.on('data', (data) => {
57
+ console.log(data);
58
+ response.fail(chalk.red('Le service Docker ne répond pas.'));
59
+ return process.exit(1);
60
+ });
23
61
 
24
- const installWithChocolatey = (packageName) => {
25
- return executeCommand(`choco install ${packageName} -y`);
62
+ dockerPull.on('close', (code) => {
63
+ if (code !== 0) {
64
+ response.fail(`Error pulling image ${image}`);
65
+ } else {
66
+ response.succeed(`Image ${image} OK.`);
67
+ installDockerImages(images, ndx + 1);
68
+ }
69
+ });
70
+ };
71
+
72
+ const setupEnvironment = (images) => {
73
+ checkIfCommandExists('docker', (dockerExists) => {
74
+ if (!dockerExists) {
75
+ console.error(`Docker n'est pas installé.`);
76
+ return;
77
+ }
78
+
79
+ checkIfCommandExists('git', (gitExists) => {
80
+ if (!gitExists) {
81
+ console.error(`Git n'est pas installé.`);
82
+ return;
83
+ }
84
+
85
+ installDockerImages(images);
86
+ });
87
+ });
26
88
  };
89
+
27
90
  return {
28
91
  info: {
29
92
  title: 'install',
30
- description: `Installation des dépendances.`,
93
+ label: 'docker',
94
+ description: 'Installation des images Docker',
31
95
  },
32
96
  start: () => {
33
- const tasksDocker = new Listr([
34
- {
35
- title: 'Docker',
36
- task: () => executeCommand('brew install rancher-desktop'),
37
- enabled: () => isMacOS || isLinux,
38
- skip: () =>
39
- executeCommand('docker ps').then(() => 'Docker est déjà installé.'),
40
- },
41
- {
42
- title: 'Docker',
43
- enabled: () => isWindows,
44
- task: () => installWithChocolatey('rancher-desktop'),
45
- skip: () =>
46
- executeCommand('docker ps').then(() => 'Docker est déjà installé.'),
47
- },
48
- ]);
49
- const tasks = new Listr([
50
- {
51
- title: 'Install Homebrew',
52
- enabled: () => isMacOS || isLinux,
53
- task: () =>
54
- executeCommand(
55
- '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
56
- ),
57
- skip: () =>
58
- executeCommand('brew --version').then(
59
- () => 'Homebrew est déjà installé.'
60
- ),
61
- },
62
- {
63
- title: 'Install Git',
64
- enabled: () => isMacOS || isLinux,
65
- task: () => executeCommand('brew install git'),
66
- skip: () =>
67
- executeCommand('git --version').then(
68
- () => 'Git est déjà installé.'
69
- ),
70
- },
71
- {
72
- title: 'Install Java (OpenJDK 17)',
73
- enabled: () => isMacOS || isLinux,
74
- task: () => executeCommand('brew install openjdk@17'),
75
- skip: () =>
76
- executeCommand('java -version').then(
77
- () => 'Java (OpenJDK 17) est déjà installé.'
78
- ),
79
- },
80
- {
81
- title: 'Install Maven',
82
- enabled: () => isMacOS || isLinux,
83
- task: () => executeCommand('brew install maven'),
84
- skip: () =>
85
- executeCommand('mvn -v').then(() => 'Maven est déjà installé.'),
86
- },
87
- {
88
- title: 'Install Liquibase',
89
- enabled: () => isMacOS || isLinux,
90
- task: () => executeCommand('brew install liquibase'),
91
- skip: () =>
92
- executeCommand('liquibase --version').then(
93
- () => 'Liquibase est déjà installé.'
94
- ),
95
- },
96
- {
97
- title: 'Install Chocolatey (Windows)',
98
- enabled: () => isWindows,
99
- task: () =>
100
- executeCommand(
101
- `@"%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\\chocolatey\\bin"`
102
- ),
103
- skip: () =>
104
- executeCommand('choco -v').then(
105
- () => 'Chocolatey est déjà installé.'
106
- ),
107
- },
108
- {
109
- title: 'Install Git (Windows)',
110
- enabled: () => isWindows,
111
- task: () => installWithChocolatey('git'),
112
- skip: () =>
113
- executeCommand('git --version').then(
114
- () => 'Git est déjà installé.'
115
- ),
116
- },
117
- {
118
- title: 'Install Java (OpenJDK 17) (Windows)',
119
- enabled: () => isWindows,
120
- task: () => installWithChocolatey('openjdk17'),
121
- skip: () =>
122
- executeCommand('java -version').then(
123
- () => 'Java (OpenJDK 17) est déjà installé.'
124
- ),
125
- },
126
- {
127
- title: 'Install Maven (Windows)',
128
- enabled: () => isWindows,
129
- task: () => installWithChocolatey('maven'),
130
- skip: () =>
131
- executeCommand('mvn -v').then(() => 'Maven est déjà installé.'),
132
- },
133
- {
134
- title: 'Install Liquibase (Windows)',
135
- enabled: () => isWindows,
136
- task: () => installWithChocolatey('liquibase'),
137
- skip: () =>
138
- executeCommand('liquibase --version').then(
139
- () => 'Liquibase est déjà installé.'
140
- ),
141
- },
142
- ]);
143
-
144
- tasks
145
- .run()
146
- .then(() => {
147
- tasksDocker.run().catch((err) => {});
148
- })
149
- .catch((err) => {
150
- console.error(err);
151
- });
97
+ addMapping();
98
+ const dockerImagesToInstall = [
99
+ 'postgis/postgis',
100
+ 'dpage/pgadmin4',
101
+ 'inbucket/inbucket:latest',
102
+ 'quay.io/keycloak/keycloak:legacy',
103
+ ];
104
+ setupEnvironment(dockerImagesToInstall);
152
105
  },
153
106
  };
154
107
  };
@@ -92,6 +92,7 @@ module.exports = (args) => {
92
92
  try {
93
93
  var response = await cadriciel.get('/login');
94
94
  } catch (e) {
95
+ console.log(e);
95
96
  console.log(' ');
96
97
  console.log(
97
98
  chalk.red(' [AUTH]') +
package/cli.js CHANGED
@@ -91,6 +91,7 @@ const loadCadricielCommands = (path) => {
91
91
  const label = (caption) => {
92
92
  if (caption === 'experimental') return chalk.red(' (' + caption + ') ');
93
93
  if (caption === 'beta') return chalk.magenta(' (' + caption + ') ');
94
+ if (caption === 'docker') return chalk.green(' (' + caption + ') ');
94
95
  if (caption === 'ai')
95
96
  return chalk.yellow(' (' + caption.toUpperCase() + ') ');
96
97
  return '';
@@ -199,7 +200,7 @@ const displayBanner = () => {
199
200
  }
200
201
  console.log(
201
202
  chalk.cyan(data) +
202
- chalk.bold('\n CLI v ' + require('./package.json').version) +
203
+ chalk.bold('\n CLI v' + require('./package.json').version) +
203
204
  version_cadriciel
204
205
  );
205
206
  console.log(' ');
package/lib/cadriciel.js CHANGED
@@ -29,11 +29,17 @@ class CadricielAPI {
29
29
  timeout: 10000,
30
30
  headers: { Authorization: 'Bearer ' + token },
31
31
  });
32
+ console.log({
33
+ baseURL: baseURL,
34
+ timeout: 10000,
35
+ headers: { Authorization: 'Bearer ' + token },
36
+ });
32
37
  }
33
38
 
34
39
  async get(url, params = {}) {
35
40
  try {
36
41
  const response = await this.client.get(url, { params });
42
+ console.log(response);
37
43
  return response.data;
38
44
  } catch (error) {
39
45
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cerema/cadriciel",
3
- "version": "1.4.13",
3
+ "version": "1.4.15",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "npm": ">=8.0.0",
@@ -1,106 +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], { shell: true });
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], { shell: true });
51
-
52
- dockerPull.stdout.on('data', (data) => {
53
- //console.log(data.toString().trim());
54
- });
55
-
56
- dockerPull.stderr.on('data', (data) => {
57
- console.log(data);
58
- response.fail(chalk.red('Le service Docker ne répond pas.'));
59
- return process.exit(1);
60
- });
61
-
62
- dockerPull.on('close', (code) => {
63
- if (code !== 0) {
64
- response.fail(`Error pulling image ${image}`);
65
- } else {
66
- response.succeed(`Image ${image} OK.`);
67
- installDockerImages(images, ndx + 1);
68
- }
69
- });
70
- };
71
-
72
- const setupEnvironment = (images) => {
73
- checkIfCommandExists('docker', (dockerExists) => {
74
- if (!dockerExists) {
75
- console.error(`Docker n'est pas installé.`);
76
- return;
77
- }
78
-
79
- checkIfCommandExists('git', (gitExists) => {
80
- if (!gitExists) {
81
- console.error(`Git n'est pas installé.`);
82
- return;
83
- }
84
-
85
- installDockerImages(images);
86
- });
87
- });
88
- };
89
- return {
90
- info: {
91
- title: 'install',
92
- description: 'Installation des dépendances (La première fois uniquement)',
93
- },
94
- start: () => {
95
- addMapping();
96
- const dockerImagesToInstall = [
97
- 'postgis/postgis',
98
- 'dpage/pgadmin4',
99
- 'inbucket/inbucket:latest',
100
- 'quay.io/keycloak/keycloak:legacy',
101
- 'liquibase/liquibase',
102
- ];
103
- setupEnvironment(dockerImagesToInstall);
104
- },
105
- };
106
- };