@cerema/cadriciel 1.4.9 → 1.4.11

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
@@ -0,0 +1,106 @@
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
+ 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
+ };
@@ -0,0 +1,82 @@
1
+ module.exports = (args) => {
2
+ const { exec } = require('child_process');
3
+ const Listr = require('listr');
4
+ const chalk = require('chalk-v2');
5
+ const checkInstallation = (command, postProcess = (output) => output) => {
6
+ return new Promise((resolve, reject) => {
7
+ exec(command, (error, stdout) => {
8
+ if (error) {
9
+ reject(new Error('Not installed'));
10
+ } else {
11
+ resolve(postProcess(stdout.trim()));
12
+ }
13
+ });
14
+ });
15
+ };
16
+
17
+ const extractLiquibaseVersion = (output) => {
18
+ const versionLine = output
19
+ .split('\n')
20
+ .find((line) => line.startsWith('Liquibase Version:'));
21
+ return versionLine ? versionLine.trim() : 'Version not found';
22
+ };
23
+ return {
24
+ info: {
25
+ title: 'doctor',
26
+ description: `Affichage des pré-requis du cadriciel.`,
27
+ },
28
+ start: () => {
29
+ console.log(' ');
30
+ console.log(' 🏥 ' + chalk.bold('Pré-requis globaux'));
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
+ ]);
55
+
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
+ ]);
66
+
67
+ tasks
68
+ .run()
69
+ .then(() => {
70
+ console.log(' ');
71
+ console.log(
72
+ ' 📦 ' +
73
+ chalk.bold('Pré-requis Docker') +
74
+ ' (si vous utilisez docker)'
75
+ );
76
+ console.log(' ');
77
+ dockerTasks.run().catch((err) => {});
78
+ })
79
+ .catch((err) => {});
80
+ },
81
+ };
82
+ };
@@ -1,108 +1,150 @@
1
1
  module.exports = (args) => {
2
- const chalk = require('chalk-v2');
3
- const ora = require('ora');
2
+ const { exec } = require('child_process');
3
+ const Listr = require('listr');
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';
9
5
 
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
- 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
- }
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
+ });
69
17
  });
70
18
  };
71
19
 
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
- }
20
+ const isMacOS = os.platform() === 'darwin';
21
+ const isLinux = os.platform() === 'linux';
22
+ const isWindows = os.platform() === 'win32';
84
23
 
85
- installDockerImages(images);
86
- });
87
- });
24
+ const installWithChocolatey = (packageName) => {
25
+ return executeCommand(`choco install ${packageName} -y`);
88
26
  };
89
27
  return {
90
28
  info: {
91
29
  title: 'install',
92
- description: 'Installation des dépendances (La première fois uniquement)',
30
+ description: `Installation des dépendances.`,
93
31
  },
94
32
  start: () => {
95
- addMapping();
96
- const dockerImagesToInstall = [
97
- 'postgres:15',
98
- 'cerema/cadriciel:1.1.0',
99
- 'dpage/pgadmin4',
100
- 'inbucket/inbucket:latest',
101
- 'quay.io/keycloak/keycloak:legacy',
102
- 'liquibase/liquibase',
103
- 'cerema/angular',
104
- ];
105
- setupEnvironment(dockerImagesToInstall);
33
+ const tasksDocker = new Listr([
34
+ {
35
+ title: 'Docker',
36
+ task: () => executeCommand('docker ps'),
37
+ skip: () =>
38
+ executeCommand('docker ps').then(
39
+ () => 'Docker is already installed'
40
+ ),
41
+ },
42
+ {
43
+ title: 'Docker Compose',
44
+ skip: () =>
45
+ executeCommand('docker-compose --version').then(
46
+ () => 'Docker Compose is already installed'
47
+ ),
48
+ },
49
+ ]);
50
+ const tasks = new Listr([
51
+ {
52
+ title: 'Install Homebrew',
53
+ enabled: () => isMacOS || isLinux,
54
+ task: () =>
55
+ executeCommand(
56
+ '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
57
+ ),
58
+ skip: () =>
59
+ executeCommand('brew --version').then(
60
+ () => 'Homebrew is already installed'
61
+ ),
62
+ },
63
+ {
64
+ title: 'Install Git',
65
+ enabled: () => isMacOS || isLinux,
66
+ task: () => executeCommand('brew install git'),
67
+ skip: () =>
68
+ executeCommand('git --version').then(
69
+ () => 'Git is already installed'
70
+ ),
71
+ },
72
+ {
73
+ title: 'Install Java (OpenJDK 17)',
74
+ enabled: () => isMacOS || isLinux,
75
+ task: () => executeCommand('brew install openjdk@17'),
76
+ skip: () =>
77
+ executeCommand('java -version').then(
78
+ () => 'Java (OpenJDK 17) is already installed'
79
+ ),
80
+ },
81
+ {
82
+ title: 'Install Maven',
83
+ enabled: () => isMacOS || isLinux,
84
+ task: () => executeCommand('brew install maven'),
85
+ skip: () =>
86
+ executeCommand('mvn -v').then(() => 'Maven is already installed'),
87
+ },
88
+ {
89
+ title: 'Install Liquibase',
90
+ enabled: () => isMacOS || isLinux,
91
+ task: () => executeCommand('brew install liquibase'),
92
+ skip: () =>
93
+ executeCommand('liquibase --version').then(
94
+ () => 'Liquibase is already installed'
95
+ ),
96
+ },
97
+ {
98
+ title: 'Install Chocolatey (Windows)',
99
+ enabled: () => isWindows,
100
+ task: () =>
101
+ executeCommand(
102
+ `@"%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"`
103
+ ),
104
+ skip: () =>
105
+ executeCommand('choco -v').then(
106
+ () => 'Chocolatey is already installed'
107
+ ),
108
+ },
109
+ {
110
+ title: 'Install Git (Windows)',
111
+ enabled: () => isWindows,
112
+ task: () => installWithChocolatey('git'),
113
+ skip: () =>
114
+ executeCommand('git --version').then(
115
+ () => 'Git is already installed'
116
+ ),
117
+ },
118
+ {
119
+ title: 'Install Java (OpenJDK 17) (Windows)',
120
+ enabled: () => isWindows,
121
+ task: () => installWithChocolatey('openjdk17'),
122
+ skip: () =>
123
+ executeCommand('java -version').then(
124
+ () => 'Java (OpenJDK 17) is already installed'
125
+ ),
126
+ },
127
+ {
128
+ title: 'Install Maven (Windows)',
129
+ enabled: () => isWindows,
130
+ task: () => installWithChocolatey('maven'),
131
+ skip: () =>
132
+ executeCommand('mvn -v').then(() => 'Maven is already installed'),
133
+ },
134
+ {
135
+ title: 'Install Liquibase (Windows)',
136
+ enabled: () => isWindows,
137
+ task: () => installWithChocolatey('liquibase'),
138
+ skip: () =>
139
+ executeCommand('liquibase --version').then(
140
+ () => 'Liquibase is already installed'
141
+ ),
142
+ },
143
+ ]);
144
+
145
+ tasks.run().catch((err) => {
146
+ console.error(err);
147
+ });
106
148
  },
107
149
  };
108
150
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cerema/cadriciel",
3
- "version": "1.4.9",
3
+ "version": "1.4.11",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "npm": ">=8.0.0",
@@ -20,6 +20,7 @@
20
20
  "inquirer": "8.2.5",
21
21
  "isbinaryfile": "^5.0.0",
22
22
  "jsonwebtoken": "^9.0.2",
23
+ "listr": "^0.14.3",
23
24
  "log-beautify": "^1.2.0",
24
25
  "nanoid": "^3.3.6",
25
26
  "ora": "^5.4.1",