@cerema/cadriciel 1.4.10 → 1.4.12
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 +0 -0
- package/cli/global/_install.js +106 -0
- package/cli/global/doctor.js +82 -0
- package/cli/global/install.js +138 -90
- package/package.json +2 -1
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
|
+
};
|
package/cli/global/install.js
CHANGED
|
@@ -1,106 +1,154 @@
|
|
|
1
1
|
module.exports = (args) => {
|
|
2
|
-
const
|
|
3
|
-
const
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
console.error(`Docker n'est pas installé.`);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
20
|
+
const isMacOS = os.platform() === 'darwin';
|
|
21
|
+
const isLinux = os.platform() === 'linux';
|
|
22
|
+
const isWindows = os.platform() === 'win32';
|
|
78
23
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
console.error(`Git n'est pas installé.`);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
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:
|
|
30
|
+
description: `Installation des dépendances.`,
|
|
93
31
|
},
|
|
94
32
|
start: () => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
});
|
|
104
152
|
},
|
|
105
153
|
};
|
|
106
154
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cerema/cadriciel",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.12",
|
|
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",
|