diff options
Diffstat (limited to 'scripts/create.js')
-rw-r--r-- | scripts/create.js | 18 |
1 files changed, 16 insertions, 2 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 | ||
20 | const recipeName = process.argv[2]; | 20 | const recipeName = process.argv[2]; |
21 | const recipe = recipeName.toLowerCase().replace(/\s/g, '-'); | 21 | const recipe = recipeName.toLowerCase().replace(/\s/g, '-'); |
22 | const cleanRecipeId = recipe.replace(/[^a-z]/g, ''); // Clean recipe ID only containing a-z, for usage as the JavaScript class name | ||
23 | const folderName = process.argv[3] || 'Ferdi'; | 22 | const folderName = process.argv[3] || 'Ferdi'; |
24 | const filesThatNeedTextReplace = [ | 23 | const filesThatNeedTextReplace = [ |
25 | 'package.json', | 24 | 'package.json', |
@@ -28,6 +27,21 @@ const filesThatNeedTextReplace = [ | |||
28 | 'README.md', | 27 | 'README.md', |
29 | ]; | 28 | ]; |
30 | 29 | ||
30 | const 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 | } | ||
43 | const 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'); |