@cerema/cadriciel 1.4.20 → 1.4.22
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/global/doctor.js +26 -17
- package/cli/global/init.js +106 -126
- package/cli/global/install.js +1 -1
- package/cli/global/login.js +1 -0
- package/lib/cadriciel.js +8 -10
- package/lib/message.js +8 -0
- package/lib/util.js +3 -6
- package/package.json +2 -1
- package/bun.lockb +0 -0
package/cli/global/doctor.js
CHANGED
|
@@ -2,6 +2,8 @@ module.exports = (args) => {
|
|
|
2
2
|
const { exec } = require('child_process');
|
|
3
3
|
const Listr = require('listr');
|
|
4
4
|
const chalk = require('chalk-v2');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const platform = os.platform();
|
|
5
7
|
const checkInstallation = (command, postProcess = (output) => output) => {
|
|
6
8
|
return new Promise((resolve, reject) => {
|
|
7
9
|
exec(command, (error, stdout) => {
|
|
@@ -29,23 +31,30 @@ module.exports = (args) => {
|
|
|
29
31
|
console.log(' ');
|
|
30
32
|
console.log(' 🏥 ' + chalk.bold('Pré-requis globaux'));
|
|
31
33
|
console.log(' ');
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
34
|
+
const myTasks = [
|
|
35
|
+
{
|
|
36
|
+
title: 'Homebrew',
|
|
37
|
+
task: () => checkInstallation('brew --version'),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
title: 'Pnpm',
|
|
41
|
+
task: () => checkInstallation('pnpm -v'),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
title: 'Git',
|
|
45
|
+
task: () => checkInstallation('git --version'),
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
title: 'Java',
|
|
49
|
+
task: () => checkInstallation('java --version'),
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
if (platform === 'linux ') myTasks.splice(0, 1);
|
|
53
|
+
|
|
54
|
+
const tasks = new Listr(myTasks, {
|
|
55
|
+
concurrent: true,
|
|
56
|
+
exitOnError: false,
|
|
57
|
+
});
|
|
49
58
|
|
|
50
59
|
const dockerTasks = new Listr(
|
|
51
60
|
[
|
package/cli/global/init.js
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
module.exports = (args) => {
|
|
2
2
|
const { nanoid } = require('nanoid');
|
|
3
3
|
var UID = nanoid();
|
|
4
|
+
const { error } = require('../../lib/message');
|
|
4
5
|
const inquirer = require('inquirer');
|
|
5
6
|
const chalk = require('chalk-v2');
|
|
6
7
|
const path = require('path');
|
|
7
8
|
const AdmZip = require('adm-zip');
|
|
8
9
|
const ora = require('ora');
|
|
9
|
-
const { exec } = require('child_process');
|
|
10
|
+
const { exec: execCallback } = require('child_process');
|
|
11
|
+
const exec = (command) =>
|
|
12
|
+
new Promise((resolve, reject) => {
|
|
13
|
+
execCallback(command, (error, stdout, stderr) => {
|
|
14
|
+
if (error) {
|
|
15
|
+
reject({ error, stderr });
|
|
16
|
+
} else {
|
|
17
|
+
resolve(stdout);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
10
21
|
const os = require('os');
|
|
11
22
|
const recursive = require('recursive-readdir');
|
|
12
23
|
const fs = require('fs');
|
|
@@ -20,6 +31,7 @@ module.exports = (args) => {
|
|
|
20
31
|
getAccount,
|
|
21
32
|
getTemplates,
|
|
22
33
|
} = require('../../lib/util');
|
|
34
|
+
var spinner;
|
|
23
35
|
|
|
24
36
|
const unzipFile = (zipFilePath, outputPath, callback) => {
|
|
25
37
|
const zip = new AdmZip(zipFilePath);
|
|
@@ -28,29 +40,51 @@ module.exports = (args) => {
|
|
|
28
40
|
zip.extractAllTo(outputPath, true);
|
|
29
41
|
callback();
|
|
30
42
|
} catch (err) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
err
|
|
34
|
-
);
|
|
43
|
+
error("Une erreur s'est produite lors de la décompression");
|
|
44
|
+
process.exit(1);
|
|
35
45
|
}
|
|
36
46
|
};
|
|
37
47
|
|
|
48
|
+
const link = (url, name) => {
|
|
49
|
+
if (!name) name = url;
|
|
50
|
+
if (url.includes('localhost')) url = 'http://' + url + '/';
|
|
51
|
+
else url = 'https://' + url + '/';
|
|
52
|
+
return (
|
|
53
|
+
'\u001b[36m\u001b]8;;' +
|
|
54
|
+
url +
|
|
55
|
+
'\u0007' +
|
|
56
|
+
name +
|
|
57
|
+
'\u001b]8;;\u0007\u001b[0m\n'
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
38
61
|
const download = async (name, cb) => {
|
|
39
62
|
const CadricielAPI = require(path.join('..', '..', 'lib', 'cadriciel'));
|
|
40
63
|
const cadriciel = new CadricielAPI();
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
()
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
64
|
+
try {
|
|
65
|
+
await cadriciel.downloadFile(
|
|
66
|
+
'/template?key=' + name + '.zip',
|
|
67
|
+
`${os.tmpdir()}${sep}${name}.zip`
|
|
68
|
+
);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
spinner.stop();
|
|
71
|
+
error('Erreur lors du téléchargement du cadriciel');
|
|
72
|
+
return process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
unzipFile(
|
|
76
|
+
`${os.tmpdir()}${sep}${name}.zip`,
|
|
77
|
+
`${os.tmpdir()}${sep}${UID}`,
|
|
78
|
+
() => {
|
|
79
|
+
DEFAULT_TEMPLATE = name;
|
|
80
|
+
fs.unlink(`${os.tmpdir()}${sep}${name}.zip`, cb);
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
} catch (e) {
|
|
84
|
+
spinner.stop();
|
|
85
|
+
error('Erreur dans le modèle du cadriciel');
|
|
86
|
+
return process.exit(1);
|
|
87
|
+
}
|
|
54
88
|
};
|
|
55
89
|
|
|
56
90
|
const changefs = (o, files, ndx, cb) => {
|
|
@@ -95,7 +129,7 @@ module.exports = (args) => {
|
|
|
95
129
|
});
|
|
96
130
|
};
|
|
97
131
|
|
|
98
|
-
const install_dependencies = (name) => {
|
|
132
|
+
const install_dependencies = async (name) => {
|
|
99
133
|
console.log(' ');
|
|
100
134
|
const spinner = ora('Installation des dépendances').start();
|
|
101
135
|
const projectPath = `${process.cwd()}/${name}`;
|
|
@@ -110,48 +144,40 @@ module.exports = (args) => {
|
|
|
110
144
|
process.chdir(projectPath);
|
|
111
145
|
|
|
112
146
|
// Check if git and pnpm are installed
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
spinner.succeed(
|
|
151
|
-
'🚀 Votre projet a été correctement installé.\n'
|
|
152
|
-
);
|
|
153
|
-
console.log(' ');
|
|
154
|
-
console.log(`
|
|
147
|
+
try {
|
|
148
|
+
await exec('git --version');
|
|
149
|
+
} catch (e) {
|
|
150
|
+
spinner.fail(`git n'est pas installé sur votre système !`);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
await exec('pnpm -v');
|
|
155
|
+
} catch (e) {
|
|
156
|
+
spinner.fail(
|
|
157
|
+
`pnpm n'est pas installé sur votre système ! (https://pnpm.js.org/installation)`
|
|
158
|
+
);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
await exec('pnpm i');
|
|
163
|
+
} catch (errorInstall) {
|
|
164
|
+
spinner.fail(
|
|
165
|
+
`Problème pendant l'installation des dépendances :\n`,
|
|
166
|
+
errorInstall
|
|
167
|
+
);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
await exec(
|
|
172
|
+
'git init && git add --all && git commit -m "first commit [ci skip]" && git checkout -b dev'
|
|
173
|
+
);
|
|
174
|
+
} catch (e) {
|
|
175
|
+
spinner.fail('Erreurs git', errorGit);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
spinner.succeed('🚀 Votre projet a été correctement installé.\n');
|
|
179
|
+
console.log(' ');
|
|
180
|
+
console.log(`
|
|
155
181
|
──────────────────────────────────────────────────────────────
|
|
156
182
|
|
|
157
183
|
Pour lancer l'environnement local de développement :
|
|
@@ -160,77 +186,24 @@ module.exports = (args) => {
|
|
|
160
186
|
|
|
161
187
|
cd ${chalk.green(name)}
|
|
162
188
|
${chalk.cyan('cad start')} .............. 🚀 ${chalk.bold(
|
|
163
|
-
|
|
164
|
-
|
|
189
|
+
"démarre l'environnement de développement"
|
|
190
|
+
)}
|
|
165
191
|
|
|
166
192
|
${chalk.cyan('cad stop')} ............... 🚦 ${chalk.bold(
|
|
167
|
-
|
|
168
|
-
|
|
193
|
+
"arrête l'environnement."
|
|
194
|
+
)}
|
|
169
195
|
|
|
170
|
-
👉
|
|
196
|
+
👉 ${link(
|
|
197
|
+
'https://studio.k8-dev.cerema.fr',
|
|
198
|
+
'studio.k8-dev.cerema.fr'
|
|
199
|
+
)}
|
|
171
200
|
|
|
172
201
|
──────────────────────────────────────────────────────────────`);
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
);
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
// If bun is installed, proceed with the operations
|
|
179
|
-
exec('bun i', (errorInstall) => {
|
|
180
|
-
if (errorInstall) {
|
|
181
|
-
spinner.fail(
|
|
182
|
-
`Problème pendant l'installation des dépendances :\n`,
|
|
183
|
-
errorInstall
|
|
184
|
-
);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
exec(
|
|
189
|
-
'git init && git add --all && git commit -m "first commit [ci skip]" && git checkout -b dev',
|
|
190
|
-
(errorGit) => {
|
|
191
|
-
if (errorGit) {
|
|
192
|
-
spinner.fail('Error occurred during git operations:', errorGit);
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
spinner.succeed('🚀 Votre projet a été correctement installé.\n');
|
|
197
|
-
console.log(' ');
|
|
198
|
-
console.log(
|
|
199
|
-
`
|
|
200
|
-
──────────────────────────────────────────────────────────────
|
|
201
|
-
|
|
202
|
-
Pour lancer l'environnement local de développement :
|
|
203
|
-
|
|
204
|
-
${chalk.magenta(
|
|
205
|
-
' 📦 nécessite docker et docker-compose\n'
|
|
206
|
-
)}
|
|
207
|
-
|
|
208
|
-
cd ${chalk.green(name)}
|
|
209
|
-
${chalk.cyan(
|
|
210
|
-
'cad start'
|
|
211
|
-
)} .............. 🚀 ${chalk.bold(
|
|
212
|
-
"démarre l'environnement de développement"
|
|
213
|
-
)}
|
|
214
|
-
|
|
215
|
-
${chalk.cyan(
|
|
216
|
-
'cad stop'
|
|
217
|
-
)} ............... 🚦 ${chalk.bold(
|
|
218
|
-
"arrête l'environnement."
|
|
219
|
-
)}
|
|
220
|
-
|
|
221
|
-
👉 https://studio.k8-dev.cerema.fr 👈
|
|
222
|
-
|
|
223
|
-
──────────────────────────────────────────────────────────────\n`
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
);
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
});
|
|
202
|
+
console.log(' ');
|
|
230
203
|
};
|
|
231
204
|
|
|
232
205
|
const createProject = async (o) => {
|
|
233
|
-
|
|
206
|
+
spinner = ora('Téléchargement du cadriciel').start();
|
|
234
207
|
const account = await getAccount();
|
|
235
208
|
|
|
236
209
|
return download(o.template.dir, function () {
|
|
@@ -272,7 +245,8 @@ module.exports = (args) => {
|
|
|
272
245
|
|
|
273
246
|
const launch = (response) => {
|
|
274
247
|
response.project = toCamelCase(response.project);
|
|
275
|
-
|
|
248
|
+
if (!response.template) var index = 0;
|
|
249
|
+
else var index = templates.findIndex((p) => p.title == response.template);
|
|
276
250
|
response.template = templates[index];
|
|
277
251
|
|
|
278
252
|
try {
|
|
@@ -291,7 +265,13 @@ module.exports = (args) => {
|
|
|
291
265
|
},
|
|
292
266
|
start: async () => {
|
|
293
267
|
const spinner = ora('Veuillez patienter un instant...').start();
|
|
294
|
-
|
|
268
|
+
try {
|
|
269
|
+
templates = await getTemplates();
|
|
270
|
+
} catch (e) {
|
|
271
|
+
spinner.stop();
|
|
272
|
+
error('Mise à jour impossible... Vérifier votre connexion internet');
|
|
273
|
+
return process.exit(1);
|
|
274
|
+
}
|
|
295
275
|
spinner.stop();
|
|
296
276
|
var tpl = [];
|
|
297
277
|
if (!templates) return process.exit(1);
|
package/cli/global/install.js
CHANGED
package/cli/global/login.js
CHANGED
package/lib/cadriciel.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
require('dotenv').config();
|
|
1
2
|
const axios = require('axios');
|
|
2
3
|
const chalk = require('chalk-v2');
|
|
3
4
|
const fs = require('fs');
|
|
4
5
|
const os = require('os');
|
|
5
6
|
const HomeDir = os.homedir() + '/.cadriciel';
|
|
6
|
-
const
|
|
7
|
-
|
|
7
|
+
const { error } = require('./message');
|
|
8
|
+
var baseURL = 'http://localhost:3000/api';
|
|
9
|
+
//var baseURL = 'https://cadriciel.k8-dev.cerema.fr/api';
|
|
8
10
|
|
|
9
11
|
class CadricielAPI {
|
|
10
12
|
constructor(token) {
|
|
@@ -75,14 +77,10 @@ class CadricielAPI {
|
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
async downloadFile(url, savePath) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
fs.writeFileSync(savePath, response.data);
|
|
83
|
-
} catch (error) {
|
|
84
|
-
console.error(chalk.bold.red('Erreur lors du téléchargement du fichier'));
|
|
85
|
-
}
|
|
80
|
+
const response = await this.client.get(url, {
|
|
81
|
+
responseType: 'arraybuffer',
|
|
82
|
+
});
|
|
83
|
+
fs.writeFileSync(savePath, response.data);
|
|
86
84
|
}
|
|
87
85
|
}
|
|
88
86
|
|
package/lib/message.js
ADDED
package/lib/util.js
CHANGED
|
@@ -33,12 +33,9 @@ const getAccountToken = async () => {
|
|
|
33
33
|
const getTemplates = async () => {
|
|
34
34
|
const Cadriciel = require('./cadriciel');
|
|
35
35
|
const cadriciel = new Cadriciel();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} catch (e) {
|
|
40
|
-
log.error("Vous n'êtes pas authentifié.");
|
|
41
|
-
}
|
|
36
|
+
|
|
37
|
+
const o = await cadriciel.get('/update');
|
|
38
|
+
return o;
|
|
42
39
|
};
|
|
43
40
|
const wipeDirectory = (directoryPath) => {
|
|
44
41
|
if (fs.existsSync(directoryPath)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cerema/cadriciel",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.22",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"npm": ">=8.0.0",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"boxen": "5.1.2",
|
|
16
16
|
"chalk-v2": "^1.0.2",
|
|
17
17
|
"commander": "^10.0.0",
|
|
18
|
+
"dotenv": "^16.3.1",
|
|
18
19
|
"express": "^4.18.2",
|
|
19
20
|
"figlet": "^1.5.2",
|
|
20
21
|
"inquirer": "8.2.5",
|
package/bun.lockb
DELETED
|
Binary file
|