@cerema/cadriciel 1.4.0 → 1.4.1
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/_install.js +107 -0
- package/bun.lockb +0 -0
- package/cli/global/doc.js +1 -2
- package/cli/global/init.js +78 -22
- package/cli/global/install.js +24 -96
- package/package.json +1 -1
package/_install.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
response.fail(chalk.red('Le service Docker ne répond pas.'));
|
|
58
|
+
return process.exit(1);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
dockerPull.on('close', (code) => {
|
|
62
|
+
if (code !== 0) {
|
|
63
|
+
response.fail(`Error pulling image ${image}`);
|
|
64
|
+
} else {
|
|
65
|
+
response.succeed(`Image ${image} OK.`);
|
|
66
|
+
installDockerImages(images, ndx + 1);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const setupEnvironment = (images) => {
|
|
72
|
+
checkIfCommandExists('docker', (dockerExists) => {
|
|
73
|
+
if (!dockerExists) {
|
|
74
|
+
console.error(`Docker n'est pas installé.`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
checkIfCommandExists('git', (gitExists) => {
|
|
79
|
+
if (!gitExists) {
|
|
80
|
+
console.error(`Git n'est pas installé.`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
installDockerImages(images);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
info: {
|
|
90
|
+
title: 'install',
|
|
91
|
+
description:
|
|
92
|
+
'Installation des dépendances (La première fois uniquement).)',
|
|
93
|
+
},
|
|
94
|
+
start: () => {
|
|
95
|
+
addMapping();
|
|
96
|
+
const dockerImagesToInstall = [
|
|
97
|
+
'postgres:15',
|
|
98
|
+
'cerema/cadriciel:1.0.0',
|
|
99
|
+
'dpage/pgadmin4',
|
|
100
|
+
'inbucket/inbucket:latest',
|
|
101
|
+
'quay.io/keycloak/keycloak:legacy',
|
|
102
|
+
'liquibase/liquibase',
|
|
103
|
+
];
|
|
104
|
+
setupEnvironment(dockerImagesToInstall);
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
};
|
package/bun.lockb
ADDED
|
Binary file
|
package/cli/global/doc.js
CHANGED
|
@@ -6,8 +6,7 @@ module.exports = (args) => {
|
|
|
6
6
|
description: `Documentation du cadriciel`,
|
|
7
7
|
},
|
|
8
8
|
start: async () => {
|
|
9
|
-
var url =
|
|
10
|
-
'https://omneedia.notion.site/omneedia/Cadriciel-Springboot-c54392db030347e7b3579ea383752347';
|
|
9
|
+
var url = 'https://docs.k8-dev.cerema.fr/';
|
|
11
10
|
var start =
|
|
12
11
|
process.platform == 'darwin'
|
|
13
12
|
? 'open'
|
package/cli/global/init.js
CHANGED
|
@@ -110,16 +110,66 @@ module.exports = (args) => {
|
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
exec('
|
|
114
|
-
if (errorPnpm)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
113
|
+
exec('bun -v', (errorPnpm) => {
|
|
114
|
+
if (errorPnpm)
|
|
115
|
+
return exec('pnpm -v', (errorPnpm) => {
|
|
116
|
+
if (errorPnpm) {
|
|
117
|
+
spinner.fail(
|
|
118
|
+
`pnpm n'est pas installé sur votre système ! (https://pnpm.js.org/installation)`
|
|
119
|
+
);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
120
122
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
// If git and pnpm are installed, proceed with the operations
|
|
124
|
+
exec('pnpm i', (errorInstall) => {
|
|
125
|
+
if (errorInstall) {
|
|
126
|
+
spinner.fail(
|
|
127
|
+
`Problème pendant l'installation des dépendances :\n`,
|
|
128
|
+
errorInstall
|
|
129
|
+
);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
exec(
|
|
134
|
+
'git init && git add --all && git commit -m "first commit" && git checkout -b dev',
|
|
135
|
+
(errorGit) => {
|
|
136
|
+
if (errorGit) {
|
|
137
|
+
spinner.fail(
|
|
138
|
+
'Error occurred during git operations:',
|
|
139
|
+
errorGit
|
|
140
|
+
);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
spinner.succeed(
|
|
145
|
+
'🚀 Votre projet a été correctement installé.\n'
|
|
146
|
+
);
|
|
147
|
+
console.log(
|
|
148
|
+
`\n──────────────────────────────────────────────────────────────
|
|
149
|
+
|
|
150
|
+
Pour lancer l'environnement local de développement :
|
|
151
|
+
|
|
152
|
+
${chalk.magenta(' 📦 nécessite docker et docker-compose\n')}
|
|
153
|
+
|
|
154
|
+
cd ${chalk.green(name)}
|
|
155
|
+
${chalk.cyan('cad start')} .............. 🚀 ${chalk.bold(
|
|
156
|
+
"démarre l'environnement local de développement"
|
|
157
|
+
)}
|
|
158
|
+
|
|
159
|
+
${chalk.cyan('cad stop')} ............... 🚦 ${chalk.bold(
|
|
160
|
+
"arrête l'environnement."
|
|
161
|
+
)}
|
|
162
|
+
|
|
163
|
+
👉 https://cadriciel.k8-dev.cerema.fr/api 👈
|
|
164
|
+
|
|
165
|
+
──────────────────────────────────────────────────────────────\n`
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
// If bun is installed, proceed with the operations
|
|
172
|
+
exec('bun i', (errorInstall) => {
|
|
123
173
|
if (errorInstall) {
|
|
124
174
|
spinner.fail(
|
|
125
175
|
`Problème pendant l'installation des dépendances :\n`,
|
|
@@ -139,23 +189,29 @@ module.exports = (args) => {
|
|
|
139
189
|
spinner.succeed('🚀 Votre projet a été correctement installé.\n');
|
|
140
190
|
console.log(
|
|
141
191
|
`\n──────────────────────────────────────────────────────────────
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
192
|
+
|
|
193
|
+
Pour lancer l'environnement local de développement :
|
|
194
|
+
|
|
195
|
+
${chalk.magenta(
|
|
196
|
+
' 📦 nécessite docker et docker-compose\n'
|
|
197
|
+
)}
|
|
198
|
+
|
|
199
|
+
cd ${chalk.green(name)}
|
|
200
|
+
${chalk.cyan(
|
|
201
|
+
'cad start'
|
|
202
|
+
)} .............. 🚀 ${chalk.bold(
|
|
149
203
|
"démarre l'environnement local de développement"
|
|
150
204
|
)}
|
|
151
|
-
|
|
152
|
-
|
|
205
|
+
|
|
206
|
+
${chalk.cyan(
|
|
207
|
+
'cad stop'
|
|
208
|
+
)} ............... 🚦 ${chalk.bold(
|
|
153
209
|
"arrête l'environnement."
|
|
154
210
|
)}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
──────────────────────────────────────────────────────────────\n`
|
|
211
|
+
|
|
212
|
+
👉 https://cadriciel.k8-dev.cerema.fr/api 👈
|
|
213
|
+
|
|
214
|
+
──────────────────────────────────────────────────────────────\n`
|
|
159
215
|
);
|
|
160
216
|
}
|
|
161
217
|
);
|
package/cli/global/install.js
CHANGED
|
@@ -1,107 +1,35 @@
|
|
|
1
1
|
module.exports = (args) => {
|
|
2
|
-
const
|
|
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';
|
|
2
|
+
const { execSync } = require('child_process');
|
|
9
3
|
|
|
10
|
-
|
|
4
|
+
const getCommandOutput = (command) => {
|
|
11
5
|
try {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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);
|
|
6
|
+
const output = execSync(command, { encoding: 'utf-8' });
|
|
7
|
+
return output.trim(); // Remove new line and trailing space
|
|
8
|
+
} catch (error) {
|
|
9
|
+
// If there's an error (like the command not found), we'll assume it's not installed
|
|
10
|
+
return 'Not installed';
|
|
23
11
|
}
|
|
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
12
|
};
|
|
40
13
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
14
|
+
const getSoftwareVersions = () => {
|
|
15
|
+
const softwareChecks = {
|
|
16
|
+
Homebrew: 'brew -v',
|
|
17
|
+
Git: 'git --version',
|
|
18
|
+
Docker: 'docker --version',
|
|
19
|
+
Java: 'java -version 2>&1 | head -n 1', // Java version gets printed to stderr
|
|
20
|
+
Maven: 'mvn -v | head -n 1',
|
|
21
|
+
//Liquibase: 'liquibase --version',
|
|
22
|
+
Nodejs: 'node --version',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const versions = {};
|
|
26
|
+
|
|
27
|
+
for (const [software, command] of Object.entries(softwareChecks)) {
|
|
28
|
+
versions[software] = getCommandOutput(command);
|
|
45
29
|
}
|
|
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
30
|
|
|
56
|
-
|
|
57
|
-
response.fail(chalk.red('Le service Docker ne répond pas.'));
|
|
58
|
-
return process.exit(1);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
dockerPull.on('close', (code) => {
|
|
62
|
-
if (code !== 0) {
|
|
63
|
-
response.fail(`Error pulling image ${image}`);
|
|
64
|
-
} else {
|
|
65
|
-
response.succeed(`Image ${image} OK.`);
|
|
66
|
-
installDockerImages(images, ndx + 1);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
31
|
+
return versions;
|
|
69
32
|
};
|
|
70
33
|
|
|
71
|
-
|
|
72
|
-
checkIfCommandExists('docker', (dockerExists) => {
|
|
73
|
-
if (!dockerExists) {
|
|
74
|
-
console.error(`Docker n'est pas installé.`);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
checkIfCommandExists('git', (gitExists) => {
|
|
79
|
-
if (!gitExists) {
|
|
80
|
-
console.error(`Git n'est pas installé.`);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
installDockerImages(images);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
return {
|
|
89
|
-
info: {
|
|
90
|
-
title: 'install',
|
|
91
|
-
description:
|
|
92
|
-
'Installation des dépendances (La première fois uniquement).)',
|
|
93
|
-
},
|
|
94
|
-
start: () => {
|
|
95
|
-
addMapping();
|
|
96
|
-
const dockerImagesToInstall = [
|
|
97
|
-
'postgres:15',
|
|
98
|
-
'cerema/cadriciel:1.0.0',
|
|
99
|
-
'dpage/pgadmin4',
|
|
100
|
-
'inbucket/inbucket:latest',
|
|
101
|
-
'quay.io/keycloak/keycloak:legacy',
|
|
102
|
-
'liquibase/liquibase',
|
|
103
|
-
];
|
|
104
|
-
setupEnvironment(dockerImagesToInstall);
|
|
105
|
-
},
|
|
106
|
-
};
|
|
34
|
+
//console.log(getSoftwareVersions());
|
|
107
35
|
};
|