@cerema/cadriciel 1.4.12 → 1.4.14

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,46 @@ 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
+ title: 'Maven',
48
+ task: () => checkInstallation('mvn -v'),
49
+ },
50
+ {
51
+ title: 'Liquibase',
52
+ task: () =>
53
+ checkInstallation('liquibase --version', extractLiquibaseVersion),
54
+ },
55
+ ],
56
+ { concurrent: true, exitOnError: false }
57
+ );
55
58
 
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
- ]);
59
+ const dockerTasks = new Listr(
60
+ [
61
+ {
62
+ title: 'Docker',
63
+ task: () => checkInstallation('docker ps'),
64
+ },
65
+ {
66
+ title: 'Docker Compose',
67
+ task: () => checkInstallation('docker-compose --version'),
68
+ },
69
+ ],
70
+ { concurrent: true, exitOnError: false }
71
+ );
66
72
 
67
73
  tasks
68
74
  .run()
@@ -1,154 +1,105 @@
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);
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
+ }
17
69
  });
18
70
  };
19
71
 
20
- const isMacOS = os.platform() === 'darwin';
21
- const isLinux = os.platform() === 'linux';
22
- const isWindows = os.platform() === 'win32';
72
+ const setupEnvironment = (images) => {
73
+ checkIfCommandExists('docker', (dockerExists) => {
74
+ if (!dockerExists) {
75
+ console.error(`Docker n'est pas installé.`);
76
+ return;
77
+ }
23
78
 
24
- const installWithChocolatey = (packageName) => {
25
- return executeCommand(`choco install ${packageName} -y`);
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
  };
27
89
  return {
28
90
  info: {
29
91
  title: 'install',
30
- description: `Installation des dépendances.`,
92
+ description: 'Installation des dépendances (La première fois uniquement)',
31
93
  },
32
94
  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
- });
95
+ addMapping();
96
+ const dockerImagesToInstall = [
97
+ 'postgis/postgis',
98
+ 'dpage/pgadmin4',
99
+ 'inbucket/inbucket:latest',
100
+ 'quay.io/keycloak/keycloak:legacy',
101
+ ];
102
+ setupEnvironment(dockerImagesToInstall);
152
103
  },
153
104
  };
154
105
  };
package/cli.js CHANGED
@@ -25,7 +25,9 @@ try {
25
25
  const checkVersion = async () => {
26
26
  return new Promise((resolve, reject) => {
27
27
  const packageName = '@cerema/cadriciel';
28
- const child = spawn('npm', ['view', packageName, 'version']);
28
+ const child = spawn('npm', ['view', packageName, 'version'], {
29
+ shell: true,
30
+ });
29
31
 
30
32
  let version = '';
31
33
 
@@ -245,6 +247,7 @@ const processCommands = (args) => {
245
247
 
246
248
  const child = spawn(cmd, fullArgs, {
247
249
  stdio: 'inherit',
250
+ shell: true,
248
251
  });
249
252
 
250
253
  child.on('close', (code) => {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cerema/cadriciel",
3
- "version": "1.4.12",
3
+ "version": "1.4.14",
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]);
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
- };