@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.
- package/cli/global/doctor.js +30 -33
- package/cli/global/init.js +1 -0
- package/cli/global/install.js +91 -138
- package/cli/global/login.js +1 -0
- package/cli.js +2 -1
- package/lib/cadriciel.js +6 -0
- package/package.json +1 -1
- package/cli/global/_install.js +0 -106
package/cli/global/doctor.js
CHANGED
|
@@ -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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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()
|
package/cli/global/init.js
CHANGED
package/cli/global/install.js
CHANGED
|
@@ -1,154 +1,107 @@
|
|
|
1
1
|
module.exports = (args) => {
|
|
2
|
-
const
|
|
3
|
-
const
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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
|
-
|
|
93
|
+
label: 'docker',
|
|
94
|
+
description: 'Installation des images Docker',
|
|
31
95
|
},
|
|
32
96
|
start: () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
};
|
package/cli/global/login.js
CHANGED
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
|
|
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
package/cli/global/_install.js
DELETED
|
@@ -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
|
-
};
|