aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLibravatar Bennett <hello@vantezzen.io>2021-11-01 00:51:01 +0100
committerLibravatar GitHub <noreply@github.com>2021-11-01 05:21:01 +0530
commitd8e3b3fec7d2feb058379647cf3eef09e51cd744 (patch)
tree9b4db76939b3ac3303fb58d104686ee782eb82db /scripts
parentfeature: Add Moodle recipe (diff)
downloadferdium-recipes-d8e3b3fec7d2feb058379647cf3eef09e51cd744.tar.gz
ferdium-recipes-d8e3b3fec7d2feb058379647cf3eef09e51cd744.tar.zst
ferdium-recipes-d8e3b3fec7d2feb058379647cf3eef09e51cd744.zip
Use PascalCasing for generated backend API class name (#759)
Diffstat (limited to 'scripts')
-rw-r--r--scripts/create.js18
-rw-r--r--scripts/sample_recipe/index.js2
2 files changed, 17 insertions, 3 deletions
diff --git a/scripts/create.js b/scripts/create.js
index 184dc70..f171290 100644
--- a/scripts/create.js
+++ b/scripts/create.js
@@ -19,7 +19,6 @@ pnpm run create WhatsApp FerdiDev
19 19
20const recipeName = process.argv[2]; 20const recipeName = process.argv[2];
21const recipe = recipeName.toLowerCase().replace(/\s/g, '-'); 21const recipe = recipeName.toLowerCase().replace(/\s/g, '-');
22const cleanRecipeId = recipe.replace(/[^a-z]/g, ''); // Clean recipe ID only containing a-z, for usage as the JavaScript class name
23const folderName = process.argv[3] || 'Ferdi'; 22const folderName = process.argv[3] || 'Ferdi';
24const filesThatNeedTextReplace = [ 23const filesThatNeedTextReplace = [
25 'package.json', 24 'package.json',
@@ -28,6 +27,21 @@ const filesThatNeedTextReplace = [
28 'README.md', 27 'README.md',
29]; 28];
30 29
30const toPascalCase = (str) => {
31 const words = str
32 .replace(/[^a-z]/g, '')
33 .split(/\W/)
34 .map((word) => {
35 if (word.length === 0) {
36 return word;
37 }
38 // Capitalize the first letter, lowercase the rest
39 return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
40 });
41 return words.join('');
42}
43const pascalCasedName = toPascalCase(recipe); // PascalCased recipe ID only containing a-z, for usage as the JavaScript class name
44
31(async () => { 45(async () => {
32 // Folder paths 46 // Folder paths
33 const userData = 47 const userData =
@@ -66,7 +80,7 @@ const filesThatNeedTextReplace = [
66 let contents = await fs.readFile(filePath, 'utf-8'); 80 let contents = await fs.readFile(filePath, 'utf-8');
67 contents = contents.replace(/SERVICE/g, recipe); 81 contents = contents.replace(/SERVICE/g, recipe);
68 contents = contents.replace(/SNAME/g, recipeName); 82 contents = contents.replace(/SNAME/g, recipeName);
69 contents = contents.replace(/SCLEAN/g, cleanRecipeId); 83 contents = contents.replace(/SPASCAL/g, pascalCasedName);
70 await fs.writeFile(filePath, contents); 84 await fs.writeFile(filePath, contents);
71 } 85 }
72 console.log('[Info] Prepared new recipe'); 86 console.log('[Info] Prepared new recipe');
diff --git a/scripts/sample_recipe/index.js b/scripts/sample_recipe/index.js
index b947467..b0dad05 100644
--- a/scripts/sample_recipe/index.js
+++ b/scripts/sample_recipe/index.js
@@ -1 +1 @@
module.exports = Ferdi => class SCLEAN extends Ferdi {}; module.exports = Ferdi => class SPASCAL extends Ferdi {};