@cerema/cadriciel 1.4.21 → 1.4.23
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 +89 -128
- package/cli/global/login.js +1 -0
- package/cli.js +1 -2
- 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,10 +40,8 @@ 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
|
|
|
@@ -51,19 +61,30 @@ module.exports = (args) => {
|
|
|
51
61
|
const download = async (name, cb) => {
|
|
52
62
|
const CadricielAPI = require(path.join('..', '..', 'lib', 'cadriciel'));
|
|
53
63
|
const cadriciel = new CadricielAPI();
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
()
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
+
}
|
|
67
88
|
};
|
|
68
89
|
|
|
69
90
|
const changefs = (o, files, ndx, cb) => {
|
|
@@ -108,7 +129,7 @@ module.exports = (args) => {
|
|
|
108
129
|
});
|
|
109
130
|
};
|
|
110
131
|
|
|
111
|
-
const install_dependencies = (name) => {
|
|
132
|
+
const install_dependencies = async (name) => {
|
|
112
133
|
console.log(' ');
|
|
113
134
|
const spinner = ora('Installation des dépendances').start();
|
|
114
135
|
const projectPath = `${process.cwd()}/${name}`;
|
|
@@ -123,48 +144,40 @@ module.exports = (args) => {
|
|
|
123
144
|
process.chdir(projectPath);
|
|
124
145
|
|
|
125
146
|
// Check if git and pnpm are installed
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
spinner.succeed(
|
|
164
|
-
'🚀 Votre projet a été correctement installé.\n'
|
|
165
|
-
);
|
|
166
|
-
console.log(' ');
|
|
167
|
-
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(`
|
|
168
181
|
──────────────────────────────────────────────────────────────
|
|
169
182
|
|
|
170
183
|
Pour lancer l'environnement local de développement :
|
|
@@ -173,12 +186,12 @@ module.exports = (args) => {
|
|
|
173
186
|
|
|
174
187
|
cd ${chalk.green(name)}
|
|
175
188
|
${chalk.cyan('cad start')} .............. 🚀 ${chalk.bold(
|
|
176
|
-
|
|
177
|
-
|
|
189
|
+
"démarre l'environnement de développement"
|
|
190
|
+
)}
|
|
178
191
|
|
|
179
192
|
${chalk.cyan('cad stop')} ............... 🚦 ${chalk.bold(
|
|
180
|
-
|
|
181
|
-
|
|
193
|
+
"arrête l'environnement."
|
|
194
|
+
)}
|
|
182
195
|
|
|
183
196
|
👉 ${link(
|
|
184
197
|
'https://studio.k8-dev.cerema.fr',
|
|
@@ -186,70 +199,11 @@ module.exports = (args) => {
|
|
|
186
199
|
)}
|
|
187
200
|
|
|
188
201
|
──────────────────────────────────────────────────────────────`);
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
// If bun is installed, proceed with the operations
|
|
195
|
-
exec('bun i', (errorInstall) => {
|
|
196
|
-
if (errorInstall) {
|
|
197
|
-
spinner.fail(
|
|
198
|
-
`Problème pendant l'installation des dépendances :\n`,
|
|
199
|
-
errorInstall
|
|
200
|
-
);
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
exec(
|
|
205
|
-
'git init && git add --all && git commit -m "first commit [ci skip]" && git checkout -b dev',
|
|
206
|
-
(errorGit) => {
|
|
207
|
-
if (errorGit) {
|
|
208
|
-
spinner.fail('Error occurred during git operations:', errorGit);
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
spinner.succeed('🚀 Votre projet a été correctement installé.\n');
|
|
213
|
-
console.log(' ');
|
|
214
|
-
console.log(
|
|
215
|
-
`
|
|
216
|
-
──────────────────────────────────────────────────────────────
|
|
217
|
-
|
|
218
|
-
Pour lancer l'environnement local de développement :
|
|
219
|
-
|
|
220
|
-
${chalk.magenta(
|
|
221
|
-
' 📦 nécessite docker et docker-compose\n'
|
|
222
|
-
)}
|
|
223
|
-
|
|
224
|
-
cd ${chalk.green(name)}
|
|
225
|
-
${chalk.cyan(
|
|
226
|
-
'cad start'
|
|
227
|
-
)} .............. 🚀 ${chalk.bold(
|
|
228
|
-
"démarre l'environnement de développement"
|
|
229
|
-
)}
|
|
230
|
-
|
|
231
|
-
${chalk.cyan(
|
|
232
|
-
'cad stop'
|
|
233
|
-
)} ............... 🚦 ${chalk.bold(
|
|
234
|
-
"arrête l'environnement."
|
|
235
|
-
)}
|
|
236
|
-
|
|
237
|
-
👉 ${link(
|
|
238
|
-
'studio.k8-dev.cerema.fr',
|
|
239
|
-
'studio.k8-dev.cerema.fr'
|
|
240
|
-
)}
|
|
241
|
-
|
|
242
|
-
──────────────────────────────────────────────────────────────\n`
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
);
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
});
|
|
202
|
+
console.log(' ');
|
|
249
203
|
};
|
|
250
204
|
|
|
251
205
|
const createProject = async (o) => {
|
|
252
|
-
|
|
206
|
+
spinner = ora('Téléchargement du cadriciel').start();
|
|
253
207
|
const account = await getAccount();
|
|
254
208
|
|
|
255
209
|
return download(o.template.dir, function () {
|
|
@@ -291,7 +245,8 @@ module.exports = (args) => {
|
|
|
291
245
|
|
|
292
246
|
const launch = (response) => {
|
|
293
247
|
response.project = toCamelCase(response.project);
|
|
294
|
-
|
|
248
|
+
if (!response.template) var index = 0;
|
|
249
|
+
else var index = templates.findIndex((p) => p.title == response.template);
|
|
295
250
|
response.template = templates[index];
|
|
296
251
|
|
|
297
252
|
try {
|
|
@@ -310,7 +265,13 @@ module.exports = (args) => {
|
|
|
310
265
|
},
|
|
311
266
|
start: async () => {
|
|
312
267
|
const spinner = ora('Veuillez patienter un instant...').start();
|
|
313
|
-
|
|
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
|
+
}
|
|
314
275
|
spinner.stop();
|
|
315
276
|
var tpl = [];
|
|
316
277
|
if (!templates) return process.exit(1);
|
package/cli/global/login.js
CHANGED
package/cli.js
CHANGED
|
@@ -10,8 +10,7 @@ const userHomeDir = os.homedir();
|
|
|
10
10
|
const boxen = require('boxen');
|
|
11
11
|
|
|
12
12
|
const CADRICIEL_PATH = findCadricielDir(process.cwd());
|
|
13
|
-
const CADRICIEL_COMMAND =
|
|
14
|
-
process.argv[1].split('/')[process.argv[1].split('/').length - 1];
|
|
13
|
+
const CADRICIEL_COMMAND = 'cad';
|
|
15
14
|
global.CADRICIEL_URI = 'https://cadriciel.k8-dev.cerema.fr/api';
|
|
16
15
|
|
|
17
16
|
var CADRICIEL_GLOBAL_COMMANDS = {};
|
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.23",
|
|
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
|