@cerema/cadriciel 0.5.1 → 0.5.2
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.js +114 -14
- package/package.json +7 -4
package/cli.js
CHANGED
|
@@ -3,14 +3,18 @@
|
|
|
3
3
|
const { Command } = require('commander');
|
|
4
4
|
const figlet = require('figlet');
|
|
5
5
|
const chalk = require('chalk-v2');
|
|
6
|
+
const shelljs = require('shelljs');
|
|
6
7
|
const recursive = require('recursive-readdir');
|
|
7
8
|
const fs = require('fs');
|
|
8
9
|
const isBinary = require('isbinaryfile').isBinaryFile;
|
|
9
10
|
const prompts = require('prompts');
|
|
10
11
|
const axios = require('axios');
|
|
11
12
|
const unzipper = require('unzipper');
|
|
12
|
-
const
|
|
13
|
+
const ora = require('ora');
|
|
14
|
+
const log = require('log-beautify');
|
|
13
15
|
const URI = 'https://f000.backblazeb2.com/file/cerema/template.zip';
|
|
16
|
+
const { spawn } = require('child_process');
|
|
17
|
+
const terminalLink = require('terminal-link');
|
|
14
18
|
|
|
15
19
|
const download = (uri, output, cb) => {
|
|
16
20
|
axios({
|
|
@@ -19,7 +23,7 @@ const download = (uri, output, cb) => {
|
|
|
19
23
|
responseType: 'stream',
|
|
20
24
|
}).then(function (response) {
|
|
21
25
|
return response.data.pipe(
|
|
22
|
-
fs.createWriteStream(output).on('close', function () {
|
|
26
|
+
fs.createWriteStream(__dirname + '/' + output).on('close', function () {
|
|
23
27
|
fs.createReadStream(__dirname + '/' + output).pipe(
|
|
24
28
|
unzipper.Extract({ path: __dirname }).on('close', function () {
|
|
25
29
|
fs.unlinkSync(__dirname + '/' + output);
|
|
@@ -38,6 +42,10 @@ const questions = [
|
|
|
38
42
|
type: 'text',
|
|
39
43
|
name: 'project',
|
|
40
44
|
message: 'Nom du projet',
|
|
45
|
+
validate: (value) => {
|
|
46
|
+
if (value === '') return false;
|
|
47
|
+
else return true;
|
|
48
|
+
},
|
|
41
49
|
},
|
|
42
50
|
{
|
|
43
51
|
type: 'number',
|
|
@@ -51,17 +59,29 @@ const questions = [
|
|
|
51
59
|
initial: 8888,
|
|
52
60
|
message: 'Spécifiez le port de PgAdmin',
|
|
53
61
|
},
|
|
62
|
+
{
|
|
63
|
+
type: 'number',
|
|
64
|
+
name: 'inbucket_port',
|
|
65
|
+
initial: 8889,
|
|
66
|
+
message: 'Spécifiez le port de FakeSMTP',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: 'number',
|
|
70
|
+
name: 'keycloak_port',
|
|
71
|
+
initial: 8890,
|
|
72
|
+
message: 'Spécifiez le port de Keycloak',
|
|
73
|
+
},
|
|
54
74
|
{
|
|
55
75
|
type: 'text',
|
|
56
76
|
name: 'pgadmin_email',
|
|
57
77
|
initial: 'admin@cerema.fr',
|
|
58
|
-
message: 'Login
|
|
78
|
+
message: 'Login',
|
|
59
79
|
},
|
|
60
80
|
{
|
|
61
81
|
type: 'text',
|
|
62
82
|
name: 'pgadmin_password',
|
|
63
83
|
initial: 'CeremaRulez!',
|
|
64
|
-
message: 'Mot de passe
|
|
84
|
+
message: 'Mot de passe',
|
|
65
85
|
},
|
|
66
86
|
];
|
|
67
87
|
|
|
@@ -69,6 +89,31 @@ function capitalizeFirstLetter(string) {
|
|
|
69
89
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
70
90
|
}
|
|
71
91
|
|
|
92
|
+
function info() {
|
|
93
|
+
var text = fs.readFileSync(process.cwd() + '/.project', 'utf-8');
|
|
94
|
+
var p = JSON.parse(text);
|
|
95
|
+
//console.log(p);
|
|
96
|
+
console.log('---');
|
|
97
|
+
console.log('Serveur PGAdmin');
|
|
98
|
+
var link = terminalLink(
|
|
99
|
+
'http://127.0.0.1:' + p.pgadmin_port,
|
|
100
|
+
'http://127.0.0.1:' + p.pgadmin_port
|
|
101
|
+
);
|
|
102
|
+
console.log(link);
|
|
103
|
+
console.log('\nServeur FakeSMTP');
|
|
104
|
+
link = terminalLink(
|
|
105
|
+
'http://127.0.0.1:' + p.inbucket_port,
|
|
106
|
+
'http://127.0.0.1:' + p.inbucket_port
|
|
107
|
+
);
|
|
108
|
+
console.log(link);
|
|
109
|
+
console.log('\nServeur KeyCloak (ORION)');
|
|
110
|
+
link = terminalLink(
|
|
111
|
+
'http://127.0.0.1:' + p.keycloak_port,
|
|
112
|
+
'http://127.0.0.1:' + p.keycloak_port
|
|
113
|
+
);
|
|
114
|
+
console.log(link);
|
|
115
|
+
}
|
|
116
|
+
|
|
72
117
|
function changefs(o, files, ndx, cb) {
|
|
73
118
|
if (!files[ndx]) return cb();
|
|
74
119
|
var input = files[ndx];
|
|
@@ -81,6 +126,8 @@ function changefs(o, files, ndx, cb) {
|
|
|
81
126
|
text = text.replace(/{{projectUpper}}/g, o.name.toUpperCase());
|
|
82
127
|
text = text.replace(/{{projectID}}/g, capitalizeFirstLetter(o.name));
|
|
83
128
|
text = text.replace(/{{pg_port}}/g, o.pg_port);
|
|
129
|
+
text = text.replace(/{{inbucket_port}}/g, o.inbucket_port);
|
|
130
|
+
text = text.replace(/{{keycloak_port}}/g, o.keycloak_port);
|
|
84
131
|
text = text.replace(/{{pgadmin_port}}/g, o.pgadmin_port);
|
|
85
132
|
text = text.replace(/{{pgadmin_email}}/g, o.pgadmin_email);
|
|
86
133
|
text = text.replace(/{{pgadmin_password}}/g, o.pgadmin_password);
|
|
@@ -108,12 +155,20 @@ function changefs(o, files, ndx, cb) {
|
|
|
108
155
|
}
|
|
109
156
|
|
|
110
157
|
function createProject(o) {
|
|
158
|
+
var spinner = ora('Téléchargement du cadriciel').start();
|
|
111
159
|
return download(URI, 'template.zip', function () {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
160
|
+
spinner.succeed();
|
|
161
|
+
spinner = ora('Création du projet ' + o.name).start();
|
|
162
|
+
recursive(__dirname + '/template', async function (err, files) {
|
|
163
|
+
changefs(o, files, 0, function () {
|
|
164
|
+
fs.rmSync(__dirname + '/template', { recursive: true, force: true });
|
|
165
|
+
fs.writeFileSync(
|
|
166
|
+
process.cwd() + '/' + o.name + '/.project',
|
|
167
|
+
JSON.stringify(o)
|
|
168
|
+
);
|
|
169
|
+
spinner.succeed(`projet ${o.name} crée avec succès.`);
|
|
170
|
+
console.log('\n🚀 Happy coding !\n');
|
|
171
|
+
});
|
|
117
172
|
});
|
|
118
173
|
});
|
|
119
174
|
}
|
|
@@ -131,26 +186,71 @@ program
|
|
|
131
186
|
//.option('-s, --separator <char>', 'separator character', ',')
|
|
132
187
|
.action((str, options) => {
|
|
133
188
|
if (!str) throw `Vous devez nommer le projet`;
|
|
134
|
-
//var prj = str.replace(/[^a-zA-Z0-9]/g, '');
|
|
135
189
|
(async () => {
|
|
136
190
|
const response = await prompts(questions);
|
|
137
|
-
|
|
191
|
+
try {
|
|
192
|
+
var stat = fs.statSync(process.cwd() + '/' + response.project);
|
|
193
|
+
return log.error('Ce projet existe déjà !');
|
|
194
|
+
} catch (e) {}
|
|
138
195
|
var o = {
|
|
139
196
|
name: response.project.replace(/[^a-zA-Z0-9]/g, ''),
|
|
140
197
|
pg_port: response.pgport,
|
|
141
198
|
pgadmin_port: response.pgadmin,
|
|
142
199
|
pgadmin_email: response.pgadmin_email,
|
|
143
200
|
pgadmin_password: response.pgadmin_password,
|
|
201
|
+
inbucket_port: response.inbucket_port,
|
|
202
|
+
keycloak_port: response.keycloak_port,
|
|
144
203
|
};
|
|
145
204
|
OUTPUT_DIRECTORY = process.cwd() + '/' + o.name;
|
|
146
205
|
createProject(o);
|
|
147
206
|
})();
|
|
148
207
|
});
|
|
149
|
-
|
|
208
|
+
program
|
|
209
|
+
.command('start')
|
|
210
|
+
.description('Démarrage des services pour un développement local')
|
|
211
|
+
//.argument('<string>', 'Nom du projet')
|
|
212
|
+
//.option('--first', 'display just the first substring')
|
|
213
|
+
//.option('-s, --separator <char>', 'separator character', ',')
|
|
214
|
+
.action((str, options) => {
|
|
215
|
+
spawn(
|
|
216
|
+
'docker-compose',
|
|
217
|
+
['-f', process.cwd() + '/docker/docker-compose.yml', 'up', '-d'],
|
|
218
|
+
{
|
|
219
|
+
stdio: 'inherit',
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
info();
|
|
223
|
+
});
|
|
224
|
+
program
|
|
225
|
+
.command('stop')
|
|
226
|
+
.description('Arrête les services')
|
|
227
|
+
//.argument('<string>', 'Nom du projet')
|
|
228
|
+
//.option('--first', 'display just the first substring')
|
|
229
|
+
//.option('-s, --separator <char>', 'separator character', ',')
|
|
230
|
+
.action((str, options) => {
|
|
231
|
+
console.log(chalk.white('Arrêter les services du Cadriciel'));
|
|
232
|
+
spawn(
|
|
233
|
+
'docker-compose',
|
|
234
|
+
['-f', process.cwd() + '/docker/docker-compose.yml', 'down'],
|
|
235
|
+
{
|
|
236
|
+
stdio: 'inherit',
|
|
237
|
+
}
|
|
238
|
+
);
|
|
239
|
+
log.success('OK');
|
|
240
|
+
});
|
|
241
|
+
program
|
|
242
|
+
.command('info')
|
|
243
|
+
.description('Affichage des informations des services')
|
|
244
|
+
//.argument('<string>', 'Nom du projet')
|
|
245
|
+
//.option('--first', 'display just the first substring')
|
|
246
|
+
//.option('-s, --separator <char>', 'separator character', ',')
|
|
247
|
+
.action((str, options) => {
|
|
248
|
+
info();
|
|
249
|
+
});
|
|
150
250
|
figlet('Cadriciel', function (err, data) {
|
|
151
251
|
if (err) {
|
|
152
|
-
console.log(
|
|
153
|
-
|
|
252
|
+
console.log(err);
|
|
253
|
+
log.error('Something went wrong...');
|
|
154
254
|
return;
|
|
155
255
|
}
|
|
156
256
|
console.log(chalk.cyan(data));
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cerema/cadriciel",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"npm": ">=8.0.0",
|
|
7
|
+
"node": ">=16.0.0",
|
|
6
8
|
"bin": {
|
|
7
9
|
"cadriciel": "./cli.js"
|
|
8
10
|
},
|
|
@@ -10,14 +12,15 @@
|
|
|
10
12
|
"axios": "^1.2.3",
|
|
11
13
|
"chalk-v2": "^1.0.2",
|
|
12
14
|
"commander": "^10.0.0",
|
|
13
|
-
"cp-file": "^10.0.0",
|
|
14
15
|
"figlet": "^1.5.2",
|
|
15
|
-
"file-download": "^0.1.2",
|
|
16
|
-
"fs-extra": "^11.1.0",
|
|
17
16
|
"handlebars": "^4.7.7",
|
|
18
17
|
"isbinaryfile": "^5.0.0",
|
|
18
|
+
"log-beautify": "^1.2.0",
|
|
19
|
+
"ora": "^5.4.1",
|
|
19
20
|
"prompts": "^2.4.2",
|
|
20
21
|
"recursive-readdir": "^2.2.3",
|
|
22
|
+
"shelljs": "^0.8.5",
|
|
23
|
+
"terminal-link": "2.1.1",
|
|
21
24
|
"unzipper": "^0.10.11"
|
|
22
25
|
}
|
|
23
26
|
}
|