@cerema/cadriciel 1.4.19 β 1.4.20
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/init.js +49 -21
- package/lib/util.js +0 -1
- package/package.json +1 -1
package/cli/global/init.js
CHANGED
|
@@ -14,6 +14,7 @@ module.exports = (args) => {
|
|
|
14
14
|
const isBinary = require('isbinaryfile').isBinaryFile;
|
|
15
15
|
const userHomeDir = os.homedir();
|
|
16
16
|
var sep = path.sep;
|
|
17
|
+
var templates = [];
|
|
17
18
|
const {
|
|
18
19
|
capitalizeFirstLetter,
|
|
19
20
|
getAccount,
|
|
@@ -136,7 +137,7 @@ module.exports = (args) => {
|
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
exec(
|
|
139
|
-
'git init && git add --all && git commit -m "first commit" && git checkout -b dev',
|
|
140
|
+
'git init && git add --all && git commit -m "first commit [ci skip]" && git checkout -b dev',
|
|
140
141
|
(errorGit) => {
|
|
141
142
|
if (errorGit) {
|
|
142
143
|
spinner.fail(
|
|
@@ -166,7 +167,7 @@ module.exports = (args) => {
|
|
|
166
167
|
"arrΓͺte l'environnement."
|
|
167
168
|
)}
|
|
168
169
|
|
|
169
|
-
π https://
|
|
170
|
+
π https://studio.k8-dev.cerema.fr π);
|
|
170
171
|
|
|
171
172
|
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ`);
|
|
172
173
|
console.log(' ');
|
|
@@ -185,7 +186,7 @@ module.exports = (args) => {
|
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
exec(
|
|
188
|
-
'git init && git add --all && git commit -m "first commit" && git checkout -b dev',
|
|
189
|
+
'git init && git add --all && git commit -m "first commit [ci skip]" && git checkout -b dev',
|
|
189
190
|
(errorGit) => {
|
|
190
191
|
if (errorGit) {
|
|
191
192
|
spinner.fail('Error occurred during git operations:', errorGit);
|
|
@@ -217,7 +218,7 @@ module.exports = (args) => {
|
|
|
217
218
|
"arrΓͺte l'environnement."
|
|
218
219
|
)}
|
|
219
220
|
|
|
220
|
-
π https://
|
|
221
|
+
π https://studio.k8-dev.cerema.fr π
|
|
221
222
|
|
|
222
223
|
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n`
|
|
223
224
|
);
|
|
@@ -229,8 +230,8 @@ module.exports = (args) => {
|
|
|
229
230
|
};
|
|
230
231
|
|
|
231
232
|
const createProject = async (o) => {
|
|
232
|
-
const account = await getAccount();
|
|
233
233
|
var spinner = ora('TΓ©lΓ©chargement du cadriciel').start();
|
|
234
|
+
const account = await getAccount();
|
|
234
235
|
|
|
235
236
|
return download(o.template.dir, function () {
|
|
236
237
|
spinner.succeed();
|
|
@@ -253,19 +254,48 @@ module.exports = (args) => {
|
|
|
253
254
|
});
|
|
254
255
|
};
|
|
255
256
|
|
|
257
|
+
const toCamelCase = (str) => {
|
|
258
|
+
return (
|
|
259
|
+
str
|
|
260
|
+
// Remplacez tout caractère non-alphanumérique par un espace
|
|
261
|
+
.replace(/[^a-zA-Z0-9]+/g, ' ')
|
|
262
|
+
// Supprimez les espaces ou autres caractères non alphanumériques au début ou à la fin
|
|
263
|
+
.trim()
|
|
264
|
+
// Convertissez la première lettre de chaque mot en majuscule, sauf pour le premier mot
|
|
265
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) =>
|
|
266
|
+
index === 0 ? word.toLowerCase() : word.toUpperCase()
|
|
267
|
+
)
|
|
268
|
+
// Supprimez les espaces
|
|
269
|
+
.replace(/\s+/g, '')
|
|
270
|
+
);
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const launch = (response) => {
|
|
274
|
+
response.project = toCamelCase(response.project);
|
|
275
|
+
var index = templates.findIndex((p) => p.title == response.template);
|
|
276
|
+
response.template = templates[index];
|
|
277
|
+
|
|
278
|
+
try {
|
|
279
|
+
var stat = fs.statSync(process.cwd() + '/' + response.project);
|
|
280
|
+
return log.error('Ce projet existe dΓ©jΓ !');
|
|
281
|
+
} catch (e) {}
|
|
282
|
+
|
|
283
|
+
OUTPUT_DIRECTORY = `${process.cwd()}`;
|
|
284
|
+
createProject(response);
|
|
285
|
+
};
|
|
286
|
+
|
|
256
287
|
return {
|
|
257
288
|
info: {
|
|
258
289
|
title: 'completion',
|
|
259
290
|
description: `DΓ©marrage d'un projet Cadriciel`,
|
|
260
291
|
},
|
|
261
292
|
start: async () => {
|
|
262
|
-
const
|
|
293
|
+
const spinner = ora('Veuillez patienter un instant...').start();
|
|
294
|
+
templates = await getTemplates();
|
|
295
|
+
spinner.stop();
|
|
263
296
|
var tpl = [];
|
|
264
297
|
if (!templates) return process.exit(1);
|
|
265
298
|
for (let i = 0; i < templates.length; i++) tpl.push(templates[i].title);
|
|
266
|
-
console.log(
|
|
267
|
-
'\nπ ' + chalk.bold('Tout grand projet commence par un nom !\n')
|
|
268
|
-
);
|
|
269
299
|
|
|
270
300
|
const questions = [
|
|
271
301
|
{
|
|
@@ -284,20 +314,18 @@ module.exports = (args) => {
|
|
|
284
314
|
choices: tpl,
|
|
285
315
|
},
|
|
286
316
|
];
|
|
317
|
+
|
|
318
|
+
if (tpl.length == 1) questions.splice(1, 1);
|
|
319
|
+
if (process.argv[1]) {
|
|
320
|
+
if (questions.length == 1)
|
|
321
|
+
return launch({ project: process.argv[1], template: tpl[0] });
|
|
322
|
+
}
|
|
323
|
+
console.log(
|
|
324
|
+
'\nπ ' + chalk.bold('Tout grand projet commence par un nom !\n')
|
|
325
|
+
);
|
|
287
326
|
inquirer
|
|
288
327
|
.prompt(questions)
|
|
289
|
-
.then(
|
|
290
|
-
response.project = response.project.replace(/[^a-zA-Z0-9]/g, '');
|
|
291
|
-
var index = templates.findIndex((p) => p.title == response.template);
|
|
292
|
-
response.template = templates[index];
|
|
293
|
-
try {
|
|
294
|
-
var stat = fs.statSync(process.cwd() + '/' + response.project);
|
|
295
|
-
return log.error('Ce projet existe dΓ©jΓ !');
|
|
296
|
-
} catch (e) {}
|
|
297
|
-
|
|
298
|
-
OUTPUT_DIRECTORY = `${process.cwd()}`;
|
|
299
|
-
createProject(response);
|
|
300
|
-
})
|
|
328
|
+
.then(launch)
|
|
301
329
|
.catch((error) => {
|
|
302
330
|
log.error(error);
|
|
303
331
|
});
|
package/lib/util.js
CHANGED