@cerema/cadriciel 0.5.2 → 0.5.4
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 +11 -237
- package/cmd/init.js +143 -0
- package/cmd/login.js +56 -0
- package/cmd/logout.js +22 -0
- package/cmd/start.js +15 -0
- package/cmd/stop.js +16 -0
- package/cmd/update.js +26 -0
- package/lib/s3.js +30 -0
- package/lib/util.js +41 -0
- package/package.json +4 -5
package/cli.js
CHANGED
|
@@ -3,250 +3,24 @@
|
|
|
3
3
|
const { Command } = require('commander');
|
|
4
4
|
const figlet = require('figlet');
|
|
5
5
|
const chalk = require('chalk-v2');
|
|
6
|
-
const shelljs = require('shelljs');
|
|
7
|
-
const recursive = require('recursive-readdir');
|
|
8
6
|
const fs = require('fs');
|
|
9
|
-
const isBinary = require('isbinaryfile').isBinaryFile;
|
|
10
|
-
const prompts = require('prompts');
|
|
11
|
-
const axios = require('axios');
|
|
12
|
-
const unzipper = require('unzipper');
|
|
13
|
-
const ora = require('ora');
|
|
14
|
-
const log = require('log-beautify');
|
|
15
|
-
const URI = 'https://f000.backblazeb2.com/file/cerema/template.zip';
|
|
16
|
-
const { spawn } = require('child_process');
|
|
17
|
-
const terminalLink = require('terminal-link');
|
|
18
|
-
|
|
19
|
-
const download = (uri, output, cb) => {
|
|
20
|
-
axios({
|
|
21
|
-
method: 'get',
|
|
22
|
-
url: uri,
|
|
23
|
-
responseType: 'stream',
|
|
24
|
-
}).then(function (response) {
|
|
25
|
-
return response.data.pipe(
|
|
26
|
-
fs.createWriteStream(__dirname + '/' + output).on('close', function () {
|
|
27
|
-
fs.createReadStream(__dirname + '/' + output).pipe(
|
|
28
|
-
unzipper.Extract({ path: __dirname }).on('close', function () {
|
|
29
|
-
fs.unlinkSync(__dirname + '/' + output);
|
|
30
|
-
cb();
|
|
31
|
-
})
|
|
32
|
-
);
|
|
33
|
-
})
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
var OUTPUT_DIRECTORY = '';
|
|
39
|
-
|
|
40
|
-
const questions = [
|
|
41
|
-
{
|
|
42
|
-
type: 'text',
|
|
43
|
-
name: 'project',
|
|
44
|
-
message: 'Nom du projet',
|
|
45
|
-
validate: (value) => {
|
|
46
|
-
if (value === '') return false;
|
|
47
|
-
else return true;
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
type: 'number',
|
|
52
|
-
name: 'pgport',
|
|
53
|
-
initial: 5433,
|
|
54
|
-
message: 'Spécifiez le port de PostGres',
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
type: 'number',
|
|
58
|
-
name: 'pgadmin',
|
|
59
|
-
initial: 8888,
|
|
60
|
-
message: 'Spécifiez le port de PgAdmin',
|
|
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
|
-
},
|
|
74
|
-
{
|
|
75
|
-
type: 'text',
|
|
76
|
-
name: 'pgadmin_email',
|
|
77
|
-
initial: 'admin@cerema.fr',
|
|
78
|
-
message: 'Login',
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
type: 'text',
|
|
82
|
-
name: 'pgadmin_password',
|
|
83
|
-
initial: 'CeremaRulez!',
|
|
84
|
-
message: 'Mot de passe',
|
|
85
|
-
},
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
function capitalizeFirstLetter(string) {
|
|
89
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
90
|
-
}
|
|
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
|
-
|
|
117
|
-
function changefs(o, files, ndx, cb) {
|
|
118
|
-
if (!files[ndx]) return cb();
|
|
119
|
-
var input = files[ndx];
|
|
120
|
-
var data = fs.readFileSync(input);
|
|
121
|
-
var stat = fs.lstatSync(input);
|
|
122
|
-
isBinary(data, stat.size).then((result) => {
|
|
123
|
-
if (result === false) {
|
|
124
|
-
var text = fs.readFileSync(input, 'utf-8');
|
|
125
|
-
text = text.replace(/{{project}}/g, o.name);
|
|
126
|
-
text = text.replace(/{{projectUpper}}/g, o.name.toUpperCase());
|
|
127
|
-
text = text.replace(/{{projectID}}/g, capitalizeFirstLetter(o.name));
|
|
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);
|
|
131
|
-
text = text.replace(/{{pgadmin_port}}/g, o.pgadmin_port);
|
|
132
|
-
text = text.replace(/{{pgadmin_email}}/g, o.pgadmin_email);
|
|
133
|
-
text = text.replace(/{{pgadmin_password}}/g, o.pgadmin_password);
|
|
134
|
-
var output =
|
|
135
|
-
OUTPUT_DIRECTORY +
|
|
136
|
-
'/' +
|
|
137
|
-
input.split('template/')[1].replace(/{{project}}/g, o.name);
|
|
138
|
-
var dir = require('path').dirname(output);
|
|
139
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
140
|
-
fs.writeFileSync(output, text);
|
|
141
|
-
changefs(o, files, ndx + 1, cb);
|
|
142
|
-
} else {
|
|
143
|
-
if (input.indexOf('.DS_Store') > -1)
|
|
144
|
-
return changefs(o, files, ndx + 1, cb);
|
|
145
|
-
var output =
|
|
146
|
-
OUTPUT_DIRECTORY +
|
|
147
|
-
'/' +
|
|
148
|
-
input.split('template/')[1].replace(/{{project}}/g, o.name);
|
|
149
|
-
var dir = require('path').dirname(output);
|
|
150
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
151
|
-
fs.copyFileSync(input, output);
|
|
152
|
-
changefs(o, files, ndx + 1, cb);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
7
|
|
|
157
|
-
|
|
158
|
-
var spinner = ora('Téléchargement du cadriciel').start();
|
|
159
|
-
return download(URI, 'template.zip', function () {
|
|
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
|
-
});
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
}
|
|
8
|
+
const log = require('log-beautify');
|
|
175
9
|
|
|
176
10
|
const program = new Command();
|
|
177
11
|
program
|
|
178
12
|
.name('cadriciel')
|
|
179
|
-
.description('CLI du Cadriciel')
|
|
13
|
+
.description('CLI du Cadriciel\ncopyright 2023 CEREMA')
|
|
180
14
|
.version(require(__dirname + '/package.json').version);
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const response = await prompts(questions);
|
|
191
|
-
try {
|
|
192
|
-
var stat = fs.statSync(process.cwd() + '/' + response.project);
|
|
193
|
-
return log.error('Ce projet existe déjà !');
|
|
194
|
-
} catch (e) {}
|
|
195
|
-
var o = {
|
|
196
|
-
name: response.project.replace(/[^a-zA-Z0-9]/g, ''),
|
|
197
|
-
pg_port: response.pgport,
|
|
198
|
-
pgadmin_port: response.pgadmin,
|
|
199
|
-
pgadmin_email: response.pgadmin_email,
|
|
200
|
-
pgadmin_password: response.pgadmin_password,
|
|
201
|
-
inbucket_port: response.inbucket_port,
|
|
202
|
-
keycloak_port: response.keycloak_port,
|
|
203
|
-
};
|
|
204
|
-
OUTPUT_DIRECTORY = process.cwd() + '/' + o.name;
|
|
205
|
-
createProject(o);
|
|
206
|
-
})();
|
|
207
|
-
});
|
|
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
|
-
});
|
|
15
|
+
|
|
16
|
+
/** loading all command lines */
|
|
17
|
+
let dir = fs.readdirSync(__dirname + '/cmd');
|
|
18
|
+
for (let i = 0; i < dir.length; i++) {
|
|
19
|
+
require(__dirname + '/cmd/' + dir[i])(program);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** starting up */
|
|
23
|
+
|
|
250
24
|
figlet('Cadriciel', function (err, data) {
|
|
251
25
|
if (err) {
|
|
252
26
|
console.log(err);
|
package/cmd/init.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
module.exports = function (program) {
|
|
2
|
+
var UID = require('shortid').generate();
|
|
3
|
+
const inquirer = require('inquirer');
|
|
4
|
+
const ora = require('ora');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const unzipper = require('unzipper');
|
|
7
|
+
const recursive = require('recursive-readdir');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const log = require('log-beautify');
|
|
10
|
+
const util = require('util');
|
|
11
|
+
const isBinary = require('isbinaryfile').isBinaryFile;
|
|
12
|
+
const {
|
|
13
|
+
capitalizeFirstLetter,
|
|
14
|
+
getAccount,
|
|
15
|
+
getTemplates,
|
|
16
|
+
} = require('../lib/util');
|
|
17
|
+
const { S3 } = require('../lib/s3');
|
|
18
|
+
|
|
19
|
+
const download = async (name, cb) => {
|
|
20
|
+
var client = await S3();
|
|
21
|
+
client.get('templates', `${name}.zip`, function () {
|
|
22
|
+
fs.createReadStream(`${os.tmpdir()}/${name}.zip`).pipe(
|
|
23
|
+
unzipper
|
|
24
|
+
.Extract({ path: os.tmpdir() + '/' + UID })
|
|
25
|
+
.on('close', function () {
|
|
26
|
+
DEFAULT_TEMPLATE = name;
|
|
27
|
+
fs.unlink(`${os.tmpdir()}/${name}.zip`, cb);
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const changefs = (o, files, ndx, cb) => {
|
|
34
|
+
if (!files[ndx]) return cb();
|
|
35
|
+
|
|
36
|
+
var input = files[ndx];
|
|
37
|
+
var data = fs.readFileSync(input);
|
|
38
|
+
var stat = fs.lstatSync(input);
|
|
39
|
+
isBinary(data, stat.size).then((result) => {
|
|
40
|
+
if (result === false) {
|
|
41
|
+
var text = fs.readFileSync(input, 'utf-8');
|
|
42
|
+
text = text.replace(/§§project§§/g, o.project);
|
|
43
|
+
text = text.replace(/§§projectUpper§§/g, o.project.toUpperCase());
|
|
44
|
+
text = text.replace(/§§projectID§§/g, capitalizeFirstLetter(o.project));
|
|
45
|
+
text = text.replace(/§§pg_port§§/g, o.pg_port);
|
|
46
|
+
text = text.replace(/§§inbucket_port§§/g, o.inbucket_port);
|
|
47
|
+
text = text.replace(/§§keycloak_port§§/g, o.keycloak_port);
|
|
48
|
+
text = text.replace(/§§pgadmin_port§§/g, o.pgadmin_port);
|
|
49
|
+
text = text.replace(/§§pgadmin_email§§/g, o.pgadmin_email);
|
|
50
|
+
text = text.replace(/§§pgadmin_password§§/g, o.pgadmin_password);
|
|
51
|
+
var output =
|
|
52
|
+
OUTPUT_DIRECTORY +
|
|
53
|
+
'/' +
|
|
54
|
+
input.split(UID + '/')[1].replace(/§§project§§/g, o.project);
|
|
55
|
+
var dir = require('path').dirname(output);
|
|
56
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
57
|
+
fs.writeFileSync(output, text);
|
|
58
|
+
changefs(o, files, ndx + 1, cb);
|
|
59
|
+
} else {
|
|
60
|
+
if (input.indexOf('.DS_Store') > -1)
|
|
61
|
+
return changefs(o, files, ndx + 1, cb);
|
|
62
|
+
var output =
|
|
63
|
+
OUTPUT_DIRECTORY +
|
|
64
|
+
'/' +
|
|
65
|
+
input.split(UID + '/')[1].replace(/§§project§§/g, o.project);
|
|
66
|
+
var dir = require('path').dirname(output);
|
|
67
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
68
|
+
fs.copyFileSync(input, output);
|
|
69
|
+
changefs(o, files, ndx + 1, cb);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const createProject = async (o) => {
|
|
75
|
+
const account = await getAccount();
|
|
76
|
+
var spinner = ora('Téléchargement du cadriciel').start();
|
|
77
|
+
return download(o.template.dir, function () {
|
|
78
|
+
spinner.succeed();
|
|
79
|
+
spinner = ora('Création du projet ' + o.project).start();
|
|
80
|
+
recursive(`${os.tmpdir()}/${UID}`, async function (err, files) {
|
|
81
|
+
spinner.succeed();
|
|
82
|
+
changefs(o, files, 0, function () {
|
|
83
|
+
fs.rmSync(os.tmpdir() + '/' + UID, {
|
|
84
|
+
recursive: true,
|
|
85
|
+
force: true,
|
|
86
|
+
});
|
|
87
|
+
fs.writeFileSync(
|
|
88
|
+
process.cwd() + '/' + o.project + '/.project',
|
|
89
|
+
JSON.stringify(o)
|
|
90
|
+
);
|
|
91
|
+
spinner.succeed(`projet ${o.project} crée avec succès.`);
|
|
92
|
+
console.log('\n🚀 Happy coding !\n');
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const init = async (str, options) => {
|
|
99
|
+
const templates = await getTemplates();
|
|
100
|
+
var tpl = [];
|
|
101
|
+
for (let i = 0; i < templates.length; i++) tpl.push(templates[i].title);
|
|
102
|
+
const questions = [
|
|
103
|
+
{
|
|
104
|
+
type: 'input',
|
|
105
|
+
name: 'project',
|
|
106
|
+
message: 'Nom du projet',
|
|
107
|
+
validate: (value) => {
|
|
108
|
+
if (value === '') return false;
|
|
109
|
+
else return true;
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
type: 'list',
|
|
114
|
+
name: 'template',
|
|
115
|
+
message: 'Choisissez le modèle de cadriciel',
|
|
116
|
+
choices: tpl,
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
inquirer
|
|
120
|
+
.prompt(questions)
|
|
121
|
+
.then((response) => {
|
|
122
|
+
response.project = response.project.replace(/[^a-zA-Z0-9]/g, '');
|
|
123
|
+
var index = templates.findIndex((p) => p.title == response.template);
|
|
124
|
+
response.template = templates[index];
|
|
125
|
+
try {
|
|
126
|
+
var stat = fs.statSync(process.cwd() + '/' + response.project);
|
|
127
|
+
return log.error('Ce projet existe déjà !');
|
|
128
|
+
} catch (e) {}
|
|
129
|
+
|
|
130
|
+
OUTPUT_DIRECTORY = `${process.cwd()}`;
|
|
131
|
+
createProject(response);
|
|
132
|
+
})
|
|
133
|
+
.catch((error) => {
|
|
134
|
+
log.error(error);
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** command line init */
|
|
139
|
+
program
|
|
140
|
+
.command('init')
|
|
141
|
+
.description("Démarrage d'un projet Cadriciel")
|
|
142
|
+
.action(init);
|
|
143
|
+
};
|
package/cmd/login.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module.exports = function (program) {
|
|
2
|
+
const os = require('os');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const userHomeDir = os.homedir();
|
|
5
|
+
const inquirer = require('inquirer');
|
|
6
|
+
|
|
7
|
+
const log = require('log-beautify');
|
|
8
|
+
const { makeAccount } = require('../lib/util');
|
|
9
|
+
const { S3 } = require('../lib/s3');
|
|
10
|
+
|
|
11
|
+
const createLogin = () => {
|
|
12
|
+
inquirer
|
|
13
|
+
.prompt([
|
|
14
|
+
{
|
|
15
|
+
type: 'input',
|
|
16
|
+
name: 'accessKey',
|
|
17
|
+
message: 'Login',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
type: 'password',
|
|
21
|
+
name: 'secretKey',
|
|
22
|
+
message: 'Mot de passe',
|
|
23
|
+
},
|
|
24
|
+
])
|
|
25
|
+
.then(async (answers) => {
|
|
26
|
+
var client = await S3(answers);
|
|
27
|
+
client.get('templates', 'template.json', function (e, r) {
|
|
28
|
+
if (e) return log.error('Votre login ou mot de passe incorrecte');
|
|
29
|
+
makeAccount(JSON.stringify(answers), function (e) {
|
|
30
|
+
if (e) return log.error('Impossible de créer votre compte.');
|
|
31
|
+
log.success('Votre compte a été crée avec succès.');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
})
|
|
35
|
+
.catch((error) => {
|
|
36
|
+
throw error;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const login = (str, options) => {
|
|
41
|
+
fs.readFile(
|
|
42
|
+
`${userHomeDir}/.cadriciel/account.json`,
|
|
43
|
+
'utf-8',
|
|
44
|
+
function (e, r) {
|
|
45
|
+
if (e) return createLogin();
|
|
46
|
+
log.warning('Vous êtes déjà authentifié.');
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** command line init */
|
|
52
|
+
program
|
|
53
|
+
.command('login')
|
|
54
|
+
.description('Authentification du cadriciel')
|
|
55
|
+
.action(login);
|
|
56
|
+
};
|
package/cmd/logout.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module.exports = function (program) {
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const userHomeDir = os.homedir();
|
|
5
|
+
const log = require('log-beautify');
|
|
6
|
+
const logout = (str, options) => {
|
|
7
|
+
fs.unlink(`${userHomeDir}/.cadriciel/account.json`, function (e) {
|
|
8
|
+
if (e) return log.error("Vous n'êtes pas authentifié.");
|
|
9
|
+
fs.unlink(`${userHomeDir}/.cadriciel/template.json`, function (e) {
|
|
10
|
+
fs.rmdir(`${userHomeDir}/.cadriciel`, function (e) {
|
|
11
|
+
log.success('Vous avez bien été déconnecté.');
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** command line init */
|
|
18
|
+
program
|
|
19
|
+
.command('logout')
|
|
20
|
+
.description('Déconnexion de votre compte')
|
|
21
|
+
.action(logout);
|
|
22
|
+
};
|
package/cmd/start.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module.exports = function (program) {
|
|
2
|
+
program
|
|
3
|
+
.command('start')
|
|
4
|
+
.description('Démarrage des services pour un développement local')
|
|
5
|
+
.action((str, options) => {
|
|
6
|
+
spawn(
|
|
7
|
+
'docker-compose',
|
|
8
|
+
['-f', process.cwd() + '/docker/docker-compose.yml', 'up', '-d'],
|
|
9
|
+
{
|
|
10
|
+
stdio: 'inherit',
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
info();
|
|
14
|
+
});
|
|
15
|
+
};
|
package/cmd/stop.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module.exports = function (program) {
|
|
2
|
+
program
|
|
3
|
+
.command('stop')
|
|
4
|
+
.description('Arrête les services')
|
|
5
|
+
.action((str, options) => {
|
|
6
|
+
console.log(chalk.white('Arrêter les services du Cadriciel'));
|
|
7
|
+
spawn(
|
|
8
|
+
'docker-compose',
|
|
9
|
+
['-f', process.cwd() + '/docker/docker-compose.yml', 'down'],
|
|
10
|
+
{
|
|
11
|
+
stdio: 'inherit',
|
|
12
|
+
}
|
|
13
|
+
);
|
|
14
|
+
log.success('OK');
|
|
15
|
+
});
|
|
16
|
+
};
|
package/cmd/update.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module.exports = function (program) {
|
|
2
|
+
const log = require('log-beautify');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const { S3 } = require('../lib/s3');
|
|
6
|
+
const update = async () => {
|
|
7
|
+
console.log('- Mise à jour du cadriciel');
|
|
8
|
+
/** update json */
|
|
9
|
+
const s3 = await S3();
|
|
10
|
+
s3.get('templates', 'template.json', function (e) {
|
|
11
|
+
fs.rename(
|
|
12
|
+
os.tmpdir() + '/template.json',
|
|
13
|
+
os.homedir() + '/.cadriciel/template.json',
|
|
14
|
+
function (e) {
|
|
15
|
+
if (e) return log.error('Mise à jour impossible');
|
|
16
|
+
log.success('OK');
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
/** command line init */
|
|
22
|
+
program
|
|
23
|
+
.command('update')
|
|
24
|
+
.description("Démarrage d'un projet Cadriciel")
|
|
25
|
+
.action(update);
|
|
26
|
+
};
|
package/lib/s3.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const os = require('os');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const util = require('util');
|
|
4
|
+
const log = require('log-beautify');
|
|
5
|
+
const userHomeDir = os.homedir();
|
|
6
|
+
const S3_URI = 's3.siipro.fr';
|
|
7
|
+
const Minio = require('minio');
|
|
8
|
+
|
|
9
|
+
const readFile = util.promisify(fs.readFile);
|
|
10
|
+
|
|
11
|
+
const S3 = async function (current_login) {
|
|
12
|
+
const login = async (current_login) => {
|
|
13
|
+
if (current_login) {
|
|
14
|
+
current_login.port = 443;
|
|
15
|
+
current_login.endPoint = S3_URI;
|
|
16
|
+
current_login.useSSL = true;
|
|
17
|
+
return new Minio.Client(current_login);
|
|
18
|
+
}
|
|
19
|
+
const r = await readFile(`${userHomeDir}/.cadriciel/account.json`, 'utf-8');
|
|
20
|
+
if (r) return new Minio.Client(JSON.parse(r));
|
|
21
|
+
};
|
|
22
|
+
var client = await login(current_login);
|
|
23
|
+
return {
|
|
24
|
+
get(bucket, filename, cb) {
|
|
25
|
+
client.fGetObject(bucket, filename, `${os.tmpdir()}/${filename}`, cb);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.S3 = S3;
|
package/lib/util.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const os = require('os');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const util = require('util');
|
|
4
|
+
const userHomeDir = os.homedir();
|
|
5
|
+
const log = require('log-beautify');
|
|
6
|
+
const readFile = util.promisify(fs.readFile);
|
|
7
|
+
const capitalizeFirstLetter = (string) => {
|
|
8
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
9
|
+
};
|
|
10
|
+
const getAccount = async () => {
|
|
11
|
+
try {
|
|
12
|
+
var txt = await readFile(`${userHomeDir}/.cadriciel/account.json`);
|
|
13
|
+
return JSON.parse(txt);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
log.error("Vous n'êtes pas authentifié.");
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const getTemplates = async () => {
|
|
19
|
+
try {
|
|
20
|
+
var txt = await readFile(`${userHomeDir}/.cadriciel/template.json`);
|
|
21
|
+
return JSON.parse(txt);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
log.error("Vous n'êtes pas authentifié.");
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const makeAccount = (o, cb) => {
|
|
27
|
+
fs.mkdir(userHomeDir + '/.cadriciel', function (e) {
|
|
28
|
+
fs.readFile(`${os.tmpdir()}/template.json`, 'utf-8', function (e, r) {
|
|
29
|
+
if (e) throw e;
|
|
30
|
+
fs.writeFile(userHomeDir + '/.cadriciel/template.json', r, function (e) {
|
|
31
|
+
if (e) throw e;
|
|
32
|
+
fs.writeFile(userHomeDir + '/.cadriciel/account.json', o, cb);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.getAccount = getAccount;
|
|
39
|
+
exports.makeAccount = makeAccount;
|
|
40
|
+
exports.getTemplates = getTemplates;
|
|
41
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cerema/cadriciel",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"npm": ">=8.0.0",
|
|
@@ -9,17 +9,16 @@
|
|
|
9
9
|
"cadriciel": "./cli.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"axios": "^1.2.3",
|
|
13
12
|
"chalk-v2": "^1.0.2",
|
|
14
13
|
"commander": "^10.0.0",
|
|
15
14
|
"figlet": "^1.5.2",
|
|
16
|
-
"
|
|
15
|
+
"inquirer": "8.2.5",
|
|
17
16
|
"isbinaryfile": "^5.0.0",
|
|
18
17
|
"log-beautify": "^1.2.0",
|
|
18
|
+
"minio": "^7.0.32",
|
|
19
19
|
"ora": "^5.4.1",
|
|
20
|
-
"prompts": "^2.4.2",
|
|
21
20
|
"recursive-readdir": "^2.2.3",
|
|
22
|
-
"
|
|
21
|
+
"shortid": "^2.2.16",
|
|
23
22
|
"terminal-link": "2.1.1",
|
|
24
23
|
"unzipper": "^0.10.11"
|
|
25
24
|
}
|