@cerema/cadriciel 1.1.5 → 1.2.0
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/cadriciel/build.js +8 -0
- package/cli/cadriciel/dev.js +8 -0
- package/cli/cadriciel/gen.js +34 -0
- package/cli/cadriciel/logs.js +8 -0
- package/cli/cadriciel/project.js +14 -0
- package/cli/cadriciel/reset.js +8 -0
- package/cli/cadriciel/restart.js +8 -0
- package/cli/cadriciel/rm.js +34 -0
- package/cli/cadriciel/start.js +8 -0
- package/cli/cadriciel/stop.js +8 -0
- package/{cmd → cli/global}/init.js +48 -57
- package/cli/global/install.js +86 -0
- package/{cmd → cli/global}/login.js +18 -19
- package/cli/global/logout.js +22 -0
- package/cli/global/update.js +27 -0
- package/cli.js +168 -21
- package/package.json +3 -2
- package/cmd/install.js +0 -83
- package/cmd/logout.js +0 -22
- package/cmd/update.js +0 -26
- package/etc/gitignore.txt +0 -136
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module.exports = (args) => {
|
|
2
|
+
return {
|
|
3
|
+
info: {
|
|
4
|
+
title: 'gen',
|
|
5
|
+
description: `Génération automatique des éléments clés pour votre projet`,
|
|
6
|
+
sub: [
|
|
7
|
+
{
|
|
8
|
+
title: 'api',
|
|
9
|
+
description: `Génération des API`,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
title: 'component',
|
|
13
|
+
description: `Génération de composant angular`,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
title: 'db',
|
|
17
|
+
description: `Gestion de base de données`,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
title: 'page',
|
|
21
|
+
description: `Génération de pages angular`,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
title: 'project',
|
|
25
|
+
description: `Gestion de projet`,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
title: 'service',
|
|
29
|
+
description: `Génération de services angular`,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module.exports = (args) => {
|
|
2
|
+
return {
|
|
3
|
+
info: {
|
|
4
|
+
title: 'rm',
|
|
5
|
+
description: `Suppression automatique des éléments clés pour votre projet`,
|
|
6
|
+
sub: [
|
|
7
|
+
{
|
|
8
|
+
title: 'api',
|
|
9
|
+
description: `Suppression d'une API`,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
title: 'component',
|
|
13
|
+
description: `Suppression de composant angular`,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
title: 'db',
|
|
17
|
+
description: `Suppression de base de données`,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
title: 'page',
|
|
21
|
+
description: `Suppression de pages angular`,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
title: 'project',
|
|
25
|
+
description: `Suppression de projet`,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
title: 'service',
|
|
29
|
+
description: `Suppression de services angular`,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module.exports =
|
|
1
|
+
module.exports = (args) => {
|
|
2
2
|
var UID = require('shortid').generate();
|
|
3
3
|
const inquirer = require('inquirer');
|
|
4
4
|
const chalk = require('chalk-v2');
|
|
@@ -14,8 +14,8 @@ module.exports = function (program) {
|
|
|
14
14
|
capitalizeFirstLetter,
|
|
15
15
|
getAccount,
|
|
16
16
|
getTemplates,
|
|
17
|
-
} = require('
|
|
18
|
-
const { S3 } = require('
|
|
17
|
+
} = require('../../lib/util');
|
|
18
|
+
const { S3 } = require('../../lib/s3');
|
|
19
19
|
|
|
20
20
|
const unzipFile = (zipFilePath, outputPath, callback) => {
|
|
21
21
|
const zip = new AdmZip(zipFilePath);
|
|
@@ -100,14 +100,6 @@ module.exports = function (program) {
|
|
|
100
100
|
process.cwd() + '/' + o.project + '/.project',
|
|
101
101
|
JSON.stringify(o)
|
|
102
102
|
);
|
|
103
|
-
const gitIgnore = fs.readFileSync(
|
|
104
|
-
__dirname + '/../etc/gitignore.txt',
|
|
105
|
-
'utf-8'
|
|
106
|
-
);
|
|
107
|
-
fs.writeFileSync(
|
|
108
|
-
process.cwd() + '/' + o.project + '/.gitignore',
|
|
109
|
-
gitIgnore
|
|
110
|
-
);
|
|
111
103
|
spinner.succeed(`projet ${o.project} crée avec succès.`);
|
|
112
104
|
console.log(' ');
|
|
113
105
|
console.log(
|
|
@@ -141,53 +133,52 @@ module.exports = function (program) {
|
|
|
141
133
|
});
|
|
142
134
|
});
|
|
143
135
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
136
|
+
return {
|
|
137
|
+
info: {
|
|
138
|
+
title: 'completion',
|
|
139
|
+
description: `Démarrage d'un projet Cadriciel`,
|
|
140
|
+
},
|
|
141
|
+
start: async () => {
|
|
142
|
+
const templates = await getTemplates();
|
|
143
|
+
var tpl = [];
|
|
144
|
+
for (let i = 0; i < templates.length; i++) tpl.push(templates[i].title);
|
|
145
|
+
console.log(
|
|
146
|
+
'\n😃 ' + chalk.bold('Tout grand projet commence par un nom !\n')
|
|
147
|
+
);
|
|
148
|
+
const questions = [
|
|
149
|
+
{
|
|
150
|
+
type: 'input',
|
|
151
|
+
name: 'project',
|
|
152
|
+
message: 'Nom du projet',
|
|
153
|
+
validate: (value) => {
|
|
154
|
+
if (value === '') return false;
|
|
155
|
+
else return true;
|
|
156
|
+
},
|
|
160
157
|
},
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
} catch (e) {}
|
|
158
|
+
{
|
|
159
|
+
type: 'list',
|
|
160
|
+
name: 'template',
|
|
161
|
+
message: 'Choisissez le modèle de cadriciel',
|
|
162
|
+
choices: tpl,
|
|
163
|
+
},
|
|
164
|
+
];
|
|
165
|
+
inquirer
|
|
166
|
+
.prompt(questions)
|
|
167
|
+
.then((response) => {
|
|
168
|
+
response.project = response.project.replace(/[^a-zA-Z0-9]/g, '');
|
|
169
|
+
var index = templates.findIndex((p) => p.title == response.template);
|
|
170
|
+
response.template = templates[index];
|
|
171
|
+
try {
|
|
172
|
+
var stat = fs.statSync(process.cwd() + '/' + response.project);
|
|
173
|
+
return log.error('Ce projet existe déjà !');
|
|
174
|
+
} catch (e) {}
|
|
179
175
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
176
|
+
OUTPUT_DIRECTORY = `${process.cwd()}`;
|
|
177
|
+
createProject(response);
|
|
178
|
+
})
|
|
179
|
+
.catch((error) => {
|
|
180
|
+
log.error(error);
|
|
181
|
+
});
|
|
182
|
+
},
|
|
186
183
|
};
|
|
187
|
-
|
|
188
|
-
/** command line init */
|
|
189
|
-
program
|
|
190
|
-
.command('init')
|
|
191
|
-
.description("Démarrage d'un projet Cadriciel")
|
|
192
|
-
.action(init);
|
|
193
184
|
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
module.exports = (args) => {
|
|
2
|
+
const chalk = require('chalk-v2');
|
|
3
|
+
const ora = require('ora');
|
|
4
|
+
const { spawn } = require('child_process');
|
|
5
|
+
|
|
6
|
+
const checkIfCommandExists = (command, callback) => {
|
|
7
|
+
const proc = spawn('which', [command]);
|
|
8
|
+
|
|
9
|
+
let found = false;
|
|
10
|
+
proc.stdout.on('data', (data) => {
|
|
11
|
+
if (data.toString().trim() !== '') {
|
|
12
|
+
found = true;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
proc.on('close', (code) => {
|
|
17
|
+
callback(found);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const installDockerImages = (images, ndx) => {
|
|
22
|
+
if (!ndx) {
|
|
23
|
+
ndx = 0;
|
|
24
|
+
console.log('\n💻 ' + chalk.bold('Installation des dépendances...\n'));
|
|
25
|
+
}
|
|
26
|
+
if (!images[ndx]) return console.log('\n👍 Installation terminée.');
|
|
27
|
+
const image = images[ndx];
|
|
28
|
+
|
|
29
|
+
const response = ora(`Téléchargement de l'image: ${image}`).start();
|
|
30
|
+
const dockerPull = spawn('docker', ['pull', image]);
|
|
31
|
+
|
|
32
|
+
dockerPull.stdout.on('data', (data) => {
|
|
33
|
+
//console.log(data.toString().trim());
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
dockerPull.stderr.on('data', (data) => {
|
|
37
|
+
response.fail(chalk.red('Le service Docker ne répond pas.'));
|
|
38
|
+
return process.exit(1);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
dockerPull.on('close', (code) => {
|
|
42
|
+
if (code !== 0) {
|
|
43
|
+
response.fail(`Error pulling image ${image}`);
|
|
44
|
+
} else {
|
|
45
|
+
response.succeed(`Image ${image} OK.`);
|
|
46
|
+
installDockerImages(images, ndx + 1);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const setupEnvironment = (images) => {
|
|
52
|
+
checkIfCommandExists('docker', (dockerExists) => {
|
|
53
|
+
if (!dockerExists) {
|
|
54
|
+
console.error(`Docker n'est pas installé.`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
checkIfCommandExists('git', (gitExists) => {
|
|
59
|
+
if (!gitExists) {
|
|
60
|
+
console.error(`Git n'est pas installé.`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
installDockerImages(images);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
info: {
|
|
70
|
+
title: 'install',
|
|
71
|
+
label: 'beta',
|
|
72
|
+
description: 'Installation des dépendances',
|
|
73
|
+
},
|
|
74
|
+
start: () => {
|
|
75
|
+
const dockerImagesToInstall = [
|
|
76
|
+
'postgres:15',
|
|
77
|
+
'cerema/cadriciel:1.0.0',
|
|
78
|
+
'dpage/pgadmin4',
|
|
79
|
+
'inbucket/inbucket:latest',
|
|
80
|
+
'quay.io/keycloak/keycloak:legacy',
|
|
81
|
+
'liquibase/liquibase',
|
|
82
|
+
];
|
|
83
|
+
setupEnvironment(dockerImagesToInstall);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
module.exports =
|
|
1
|
+
module.exports = (args) => {
|
|
2
2
|
const os = require('os');
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const userHomeDir = os.homedir();
|
|
5
5
|
const inquirer = require('inquirer');
|
|
6
6
|
|
|
7
7
|
const log = require('log-beautify');
|
|
8
|
-
const { makeAccount } = require('
|
|
9
|
-
const { S3 } = require('
|
|
8
|
+
const { makeAccount } = require('../../lib/util');
|
|
9
|
+
const { S3 } = require('../../lib/s3');
|
|
10
10
|
|
|
11
11
|
const createLogin = () => {
|
|
12
12
|
inquirer
|
|
@@ -37,21 +37,20 @@ module.exports = function (program) {
|
|
|
37
37
|
throw error;
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
return {
|
|
41
|
+
info: {
|
|
42
|
+
title: 'login',
|
|
43
|
+
description: 'Authentification du cadriciel',
|
|
44
|
+
},
|
|
45
|
+
start: () => {
|
|
46
|
+
fs.readFile(
|
|
47
|
+
`${userHomeDir}/.cadriciel/account.json`,
|
|
48
|
+
'utf-8',
|
|
49
|
+
function (e, r) {
|
|
50
|
+
if (e) return createLogin();
|
|
51
|
+
log.warning('Vous êtes déjà authentifié.');
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
},
|
|
50
55
|
};
|
|
51
|
-
|
|
52
|
-
/** command line init */
|
|
53
|
-
program
|
|
54
|
-
.command('login')
|
|
55
|
-
.description('Authentification du cadriciel')
|
|
56
|
-
.action(login);
|
|
57
56
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module.exports = (args) => {
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const userHomeDir = os.homedir();
|
|
5
|
+
const log = require('log-beautify');
|
|
6
|
+
return {
|
|
7
|
+
info: {
|
|
8
|
+
title: 'logout',
|
|
9
|
+
description: 'Déconnexion de votre compte',
|
|
10
|
+
},
|
|
11
|
+
start: () => {
|
|
12
|
+
fs.unlink(`${userHomeDir}/.cadriciel/account.json`, function (e) {
|
|
13
|
+
if (e) return log.error("Vous n'êtes pas authentifié.");
|
|
14
|
+
fs.unlink(`${userHomeDir}/.cadriciel/template.json`, function (e) {
|
|
15
|
+
fs.rmdir(`${userHomeDir}/.cadriciel`, function (e) {
|
|
16
|
+
log.success('Vous avez bien été déconnecté.');
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module.exports = (args) => {
|
|
2
|
+
const log = require('log-beautify');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const { S3 } = require('../../lib/s3');
|
|
6
|
+
return {
|
|
7
|
+
info: {
|
|
8
|
+
title: 'update',
|
|
9
|
+
description: 'Mise à jour du cadriciel',
|
|
10
|
+
},
|
|
11
|
+
start: async () => {
|
|
12
|
+
console.log('- Mise à jour du cadriciel');
|
|
13
|
+
/** update json */
|
|
14
|
+
const s3 = await S3();
|
|
15
|
+
s3.get('cadriciel-templates', 'template.json', function (e) {
|
|
16
|
+
fs.rename(
|
|
17
|
+
os.tmpdir() + '/template.json',
|
|
18
|
+
os.homedir() + '/.cadriciel/template.json',
|
|
19
|
+
function (e) {
|
|
20
|
+
if (e) return log.error('Mise à jour impossible');
|
|
21
|
+
log.success('OK');
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
};
|
package/cli.js
CHANGED
|
@@ -1,31 +1,178 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { Command } = require('commander');
|
|
4
1
|
const figlet = require('figlet');
|
|
5
2
|
const chalk = require('chalk-v2');
|
|
6
3
|
const fs = require('fs');
|
|
7
4
|
const log = require('log-beautify');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { exec } = require('child_process');
|
|
7
|
+
|
|
8
|
+
const CADRICIEL_PATH = findCadricielDir(process.cwd());
|
|
9
|
+
const CADRICIEL_COMMAND =
|
|
10
|
+
process.argv[1].split('/')[process.argv[1].split('/').length - 1];
|
|
11
|
+
|
|
12
|
+
var CADRICIEL_GLOBAL_COMMANDS = {};
|
|
13
|
+
var CADRICIEL_COMMANDS = {};
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Recherche récursivement le répertoire '.cadriciel' à partir du chemin donné, en remontant vers les répertoires parents.
|
|
17
|
+
* @param {string} startPath - Le chemin de départ pour la recherche.
|
|
18
|
+
* @returns {string|null} Le chemin du répertoire '.cadriciel' trouvé, ou null si non trouvé.
|
|
19
|
+
*/
|
|
20
|
+
function findCadricielDir(startPath) {
|
|
21
|
+
let currentPath = startPath;
|
|
14
22
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
while (currentPath !== path.parse(currentPath).root) {
|
|
24
|
+
const potentialPath = path.join(currentPath, '.cadriciel/bin');
|
|
25
|
+
if (
|
|
26
|
+
fs.existsSync(potentialPath) &&
|
|
27
|
+
fs.statSync(potentialPath).isDirectory()
|
|
28
|
+
) {
|
|
29
|
+
return potentialPath;
|
|
30
|
+
}
|
|
31
|
+
currentPath = path.dirname(currentPath); // Monter vers le répertoire parent.
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return null;
|
|
19
35
|
}
|
|
20
36
|
|
|
21
|
-
|
|
37
|
+
const loadGlobalCommands = () => {
|
|
38
|
+
let dir = fs.readdirSync(__dirname + '/cli/global');
|
|
39
|
+
for (let i = 0; i < dir.length; i++) {
|
|
40
|
+
CADRICIEL_GLOBAL_COMMANDS[dir[i].split('.')[0]] = require(__dirname +
|
|
41
|
+
'/cli/global/' +
|
|
42
|
+
dir[i])();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const loadCadricielCommands = () => {
|
|
47
|
+
let dir = fs.readdirSync(__dirname + '/cli/cadriciel');
|
|
48
|
+
for (let i = 0; i < dir.length; i++) {
|
|
49
|
+
CADRICIEL_COMMANDS[dir[i].split('.')[0]] = require(__dirname +
|
|
50
|
+
'/cli/cadriciel/' +
|
|
51
|
+
dir[i])();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const label = (caption) => {
|
|
56
|
+
if (caption === 'experimental') return chalk.red(' (' + caption + ') ');
|
|
57
|
+
if (caption === 'beta') return chalk.magenta(' (' + caption + ') ');
|
|
58
|
+
if (caption === 'ai')
|
|
59
|
+
return chalk.yellow(' (' + caption.toUpperCase() + ') ');
|
|
60
|
+
return '';
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const formatDescription = (description, maxLength) => {
|
|
64
|
+
if (description.length <= maxLength) return description;
|
|
65
|
+
|
|
66
|
+
const breakPoint = description.lastIndexOf(' ', maxLength);
|
|
67
|
+
const firstPart = description.substring(0, breakPoint);
|
|
68
|
+
const secondPart = description.substring(breakPoint + 1).trim();
|
|
22
69
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
70
|
+
return firstPart + '\n ' + secondPart;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const display = (commands) => {
|
|
74
|
+
const maxWidth = 30;
|
|
75
|
+
const maxDescriptionLength = 50;
|
|
76
|
+
|
|
77
|
+
for (let el in commands) {
|
|
78
|
+
let title = el;
|
|
79
|
+
|
|
80
|
+
if (commands[el].info) {
|
|
81
|
+
let description = commands[el].info.description;
|
|
82
|
+
if (commands[el].info.sub) {
|
|
83
|
+
title += ' <subcommand>';
|
|
84
|
+
const sc = [];
|
|
85
|
+
for (let i = 0; i < commands[el].info.sub.length; i++) {
|
|
86
|
+
sc.push(commands[el].info.sub[i].title);
|
|
87
|
+
}
|
|
88
|
+
description +=
|
|
89
|
+
chalk.grey(' (subcommands: ') +
|
|
90
|
+
chalk.cyan(sc.join(', ')) +
|
|
91
|
+
chalk.grey(')');
|
|
92
|
+
}
|
|
93
|
+
const dots = '.'.repeat(maxWidth - title.length);
|
|
94
|
+
|
|
95
|
+
const formattedDesc = formatDescription(
|
|
96
|
+
description,
|
|
97
|
+
maxDescriptionLength
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
console.log(
|
|
101
|
+
' ' +
|
|
102
|
+
chalk.cyanBright(title) +
|
|
103
|
+
' ' +
|
|
104
|
+
chalk.grey(dots) +
|
|
105
|
+
' ' +
|
|
106
|
+
label(commands[el].info.label) +
|
|
107
|
+
' ' +
|
|
108
|
+
chalk.white(formattedDesc)
|
|
109
|
+
);
|
|
110
|
+
}
|
|
28
111
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const displayBanner = () => {
|
|
115
|
+
figlet('Cadriciel', function (err, data) {
|
|
116
|
+
if (err) {
|
|
117
|
+
console.log(err);
|
|
118
|
+
log.error('Something went wrong...');
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
console.log(
|
|
122
|
+
chalk.cyan(data) +
|
|
123
|
+
chalk.bold('\n CLI v' + require('./package.json').version)
|
|
124
|
+
);
|
|
125
|
+
console.log(' ');
|
|
126
|
+
console.log(
|
|
127
|
+
`${chalk.bold(' Usage :')} ${chalk.cyanBright(
|
|
128
|
+
CADRICIEL_COMMAND + ' <commande>'
|
|
129
|
+
)} ${chalk.cyan('[<args>]')}`
|
|
130
|
+
);
|
|
131
|
+
console.log(' ');
|
|
132
|
+
console.log(chalk.bold(' Commandes globales :'));
|
|
133
|
+
console.log(' ');
|
|
134
|
+
display(CADRICIEL_GLOBAL_COMMANDS);
|
|
135
|
+
console.log(' ');
|
|
136
|
+
console.log(chalk.bold(' Commandes du projet :'));
|
|
137
|
+
if (!CADRICIEL_PATH) {
|
|
138
|
+
console.log(`\n Vous n'êtes pas à l'intérieur d'un projet. `);
|
|
139
|
+
console.log(' ');
|
|
140
|
+
} else {
|
|
141
|
+
console.log(' ');
|
|
142
|
+
display(CADRICIEL_COMMANDS);
|
|
143
|
+
console.log(' ');
|
|
144
|
+
}
|
|
145
|
+
console.log();
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const processCommands = (args) => {
|
|
150
|
+
const command = args[0];
|
|
151
|
+
if (!CADRICIEL_COMMANDS[command]) {
|
|
152
|
+
if (!CADRICIEL_GLOBAL_COMMANDS[command]) {
|
|
153
|
+
log.error('Commande inconnue : ' + command);
|
|
154
|
+
return displayBanner();
|
|
155
|
+
}
|
|
156
|
+
CADRICIEL_GLOBAL_COMMANDS[command].start(args);
|
|
157
|
+
} else {
|
|
158
|
+
const cmd = `node ${CADRICIEL_PATH}/${command} ${args.splice(1).join(' ')}`;
|
|
159
|
+
exec(cmd, (error, stdout, stderr) => {
|
|
160
|
+
if (error) {
|
|
161
|
+
console.error(`Erreur d'exécution de la commande: ${error.message}`);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (stderr) {
|
|
165
|
+
console.error(`Erreur: ${stderr}`);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
console.log(stdout);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
loadGlobalCommands();
|
|
174
|
+
loadCadricielCommands();
|
|
175
|
+
|
|
176
|
+
if (process.argv.length <= 2) return displayBanner();
|
|
177
|
+
|
|
178
|
+
processCommands(process.argv.splice(2));
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cerema/cadriciel",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"npm": ">=8.0.0",
|
|
7
7
|
"node": ">=16.0.0",
|
|
8
8
|
"bin": {
|
|
9
|
-
"cadriciel": "./cli.js"
|
|
9
|
+
"cadriciel": "./cli.js",
|
|
10
|
+
"cad": "./cli.js"
|
|
10
11
|
},
|
|
11
12
|
"dependencies": {
|
|
12
13
|
"adm-zip": "^0.5.10",
|
package/cmd/install.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
module.exports = function (program) {
|
|
2
|
-
const chalk = require('chalk-v2');
|
|
3
|
-
const ora = require('ora');
|
|
4
|
-
const { spawn } = require('child_process');
|
|
5
|
-
const init = async (str, options) => {
|
|
6
|
-
const checkIfCommandExists = (command, callback) => {
|
|
7
|
-
const proc = spawn('which', [command]);
|
|
8
|
-
|
|
9
|
-
let found = false;
|
|
10
|
-
proc.stdout.on('data', (data) => {
|
|
11
|
-
if (data.toString().trim() !== '') {
|
|
12
|
-
found = true;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
proc.on('close', (code) => {
|
|
17
|
-
callback(found);
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const installDockerImages = (images, ndx) => {
|
|
22
|
-
if (!ndx) {
|
|
23
|
-
ndx = 0;
|
|
24
|
-
console.log('\n💻 ' + chalk.bold('Installation des dépendances...\n'));
|
|
25
|
-
}
|
|
26
|
-
if (!images[ndx]) return console.log('\n👍 Installation terminée.');
|
|
27
|
-
const image = images[ndx];
|
|
28
|
-
|
|
29
|
-
const response = ora(`Téléchargement de l'image: ${image}`).start();
|
|
30
|
-
const dockerPull = spawn('docker', ['pull', image]);
|
|
31
|
-
|
|
32
|
-
dockerPull.stdout.on('data', (data) => {
|
|
33
|
-
//console.log(data.toString().trim());
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
dockerPull.stderr.on('data', (data) => {
|
|
37
|
-
response.fail(chalk.red('Le service Docker ne répond pas.'));
|
|
38
|
-
return process.exit(1);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
dockerPull.on('close', (code) => {
|
|
42
|
-
if (code !== 0) {
|
|
43
|
-
response.fail(`Error pulling image ${image}`);
|
|
44
|
-
} else {
|
|
45
|
-
response.succeed(`Image ${image} OK.`);
|
|
46
|
-
installDockerImages(images, ndx + 1);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const setupEnvironment = (images) => {
|
|
52
|
-
checkIfCommandExists('docker', (dockerExists) => {
|
|
53
|
-
if (!dockerExists) {
|
|
54
|
-
console.error(`Docker n'est pas installé.`);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
checkIfCommandExists('git', (gitExists) => {
|
|
59
|
-
if (!gitExists) {
|
|
60
|
-
console.error(`Git n'est pas installé.`);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
installDockerImages(images);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
const dockerImagesToInstall = [
|
|
69
|
-
'postgres:15',
|
|
70
|
-
'cerema/cadriciel:1.0.0',
|
|
71
|
-
'dpage/pgadmin4',
|
|
72
|
-
'inbucket/inbucket:latest',
|
|
73
|
-
'quay.io/keycloak/keycloak:legacy',
|
|
74
|
-
'liquibase/liquibase',
|
|
75
|
-
];
|
|
76
|
-
setupEnvironment(dockerImagesToInstall);
|
|
77
|
-
};
|
|
78
|
-
/** command line init */
|
|
79
|
-
program
|
|
80
|
-
.command('install')
|
|
81
|
-
.description('Installation des dépendances')
|
|
82
|
-
.action(init);
|
|
83
|
-
};
|
package/cmd/logout.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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/update.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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('cadriciel-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/etc/gitignore.txt
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
node_modules
|
|
2
|
-
etc
|
|
3
|
-
.env
|
|
4
|
-
docker
|
|
5
|
-
.angular
|
|
6
|
-
|
|
7
|
-
# Logs
|
|
8
|
-
logs
|
|
9
|
-
*.log
|
|
10
|
-
npm-debug.log*
|
|
11
|
-
yarn-debug.log*
|
|
12
|
-
yarn-error.log*
|
|
13
|
-
lerna-debug.log*
|
|
14
|
-
.pnpm-debug.log*
|
|
15
|
-
|
|
16
|
-
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
17
|
-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
18
|
-
|
|
19
|
-
# Runtime data
|
|
20
|
-
pids
|
|
21
|
-
*.pid
|
|
22
|
-
*.seed
|
|
23
|
-
*.pid.lock
|
|
24
|
-
|
|
25
|
-
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
26
|
-
lib-cov
|
|
27
|
-
|
|
28
|
-
# Coverage directory used by tools like istanbul
|
|
29
|
-
coverage
|
|
30
|
-
*.lcov
|
|
31
|
-
|
|
32
|
-
# nyc test coverage
|
|
33
|
-
.nyc_output
|
|
34
|
-
|
|
35
|
-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
36
|
-
.grunt
|
|
37
|
-
|
|
38
|
-
# Bower dependency directory (https://bower.io/)
|
|
39
|
-
bower_components
|
|
40
|
-
|
|
41
|
-
# node-waf configuration
|
|
42
|
-
.lock-wscript
|
|
43
|
-
|
|
44
|
-
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
45
|
-
build/Release
|
|
46
|
-
|
|
47
|
-
# Dependency directories
|
|
48
|
-
node_modules/
|
|
49
|
-
jspm_packages/
|
|
50
|
-
|
|
51
|
-
# Snowpack dependency directory (https://snowpack.dev/)
|
|
52
|
-
web_modules/
|
|
53
|
-
|
|
54
|
-
# TypeScript cache
|
|
55
|
-
*.tsbuildinfo
|
|
56
|
-
|
|
57
|
-
# Optional npm cache directory
|
|
58
|
-
.npm
|
|
59
|
-
|
|
60
|
-
# Optional eslint cache
|
|
61
|
-
.eslintcache
|
|
62
|
-
|
|
63
|
-
# Optional stylelint cache
|
|
64
|
-
.stylelintcache
|
|
65
|
-
|
|
66
|
-
# Microbundle cache
|
|
67
|
-
.rpt2_cache/
|
|
68
|
-
.rts2_cache_cjs/
|
|
69
|
-
.rts2_cache_es/
|
|
70
|
-
.rts2_cache_umd/
|
|
71
|
-
|
|
72
|
-
# Optional REPL history
|
|
73
|
-
.node_repl_history
|
|
74
|
-
|
|
75
|
-
# Output of 'npm pack'
|
|
76
|
-
*.tgz
|
|
77
|
-
|
|
78
|
-
# Yarn Integrity file
|
|
79
|
-
.yarn-integrity
|
|
80
|
-
|
|
81
|
-
# dotenv environment variable files
|
|
82
|
-
.env
|
|
83
|
-
.env.development.local
|
|
84
|
-
.env.test.local
|
|
85
|
-
.env.production.local
|
|
86
|
-
.env.local
|
|
87
|
-
|
|
88
|
-
# parcel-bundler cache (https://parceljs.org/)
|
|
89
|
-
.cache
|
|
90
|
-
.parcel-cache
|
|
91
|
-
|
|
92
|
-
# Next.js build output
|
|
93
|
-
.next
|
|
94
|
-
out
|
|
95
|
-
|
|
96
|
-
# Nuxt.js build / generate output
|
|
97
|
-
.nuxt
|
|
98
|
-
dist
|
|
99
|
-
|
|
100
|
-
# Gatsby files
|
|
101
|
-
.cache/
|
|
102
|
-
# Comment in the public line in if your project uses Gatsby and not Next.js
|
|
103
|
-
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
104
|
-
# public
|
|
105
|
-
|
|
106
|
-
# vuepress build output
|
|
107
|
-
.vuepress/dist
|
|
108
|
-
|
|
109
|
-
# vuepress v2.x temp and cache directory
|
|
110
|
-
.temp
|
|
111
|
-
.cache
|
|
112
|
-
|
|
113
|
-
# Docusaurus cache and generated files
|
|
114
|
-
.docusaurus
|
|
115
|
-
|
|
116
|
-
# Serverless directories
|
|
117
|
-
.serverless/
|
|
118
|
-
|
|
119
|
-
# FuseBox cache
|
|
120
|
-
.fusebox/
|
|
121
|
-
|
|
122
|
-
# DynamoDB Local files
|
|
123
|
-
.dynamodb/
|
|
124
|
-
|
|
125
|
-
# TernJS port file
|
|
126
|
-
.tern-port
|
|
127
|
-
|
|
128
|
-
# Stores VSCode versions used for testing VSCode extensions
|
|
129
|
-
.vscode-test
|
|
130
|
-
|
|
131
|
-
# yarn v2
|
|
132
|
-
.yarn/cache
|
|
133
|
-
.yarn/unplugged
|
|
134
|
-
.yarn/build-state.yml
|
|
135
|
-
.yarn/install-state.gz
|
|
136
|
-
.pnp.*
|