aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/create.js
diff options
context:
space:
mode:
authorLibravatar MCMXC <16797721+mcmxcdev@users.noreply.github.com>2023-07-26 06:29:03 -0600
committerLibravatar GitHub <noreply@github.com>2023-07-26 17:59:03 +0530
commit9b8f01716774a960073e944823ab727cc867a8f6 (patch)
tree732b83770baa78f5cf12776aaa33ce65bebfa418 /scripts/create.js
parentAdd Excalidraw recipe (#393) (diff)
downloadferdium-recipes-9b8f01716774a960073e944823ab727cc867a8f6.tar.gz
ferdium-recipes-9b8f01716774a960073e944823ab727cc867a8f6.tar.zst
ferdium-recipes-9b8f01716774a960073e944823ab727cc867a8f6.zip
chore: improve lint setup (#397)
- update eslint config to closely mirror the ones from ferdium-app - add .eslintignore - opt in to eslint `reportUnusedDisableDirectives` config option - remove `trailingComma: all` from `prettier` config which is default in `prettier` v3 - autofix or disable a lot of lint issues throughout codebase - add `volta` configuration to `package.json` to autoload correct `node` and `pnpm` versions - upgrade all `eslint` and `prettier` related dependencies to latest - update lint:fix npm script - reformat touched files with prettier - bumped up minor version for all recipes that have changes - introduced injection of 'service.css' where it was missing in many recipes --------- Co-authored-by: Vijay A <vraravam@users.noreply.github.com>
Diffstat (limited to 'scripts/create.js')
-rw-r--r--scripts/create.js31
1 files changed, 14 insertions, 17 deletions
diff --git a/scripts/create.js b/scripts/create.js
index 199a23b..158b2f2 100644
--- a/scripts/create.js
+++ b/scripts/create.js
@@ -1,3 +1,4 @@
1/* eslint-disable no-console */
1/** 2/**
2 * Create a new recipe for your service 3 * Create a new recipe for your service
3 */ 4 */
@@ -18,19 +19,15 @@ pnpm create WhatsApp FerdiumDev
18} 19}
19 20
20const recipeName = process.argv[2]; 21const recipeName = process.argv[2];
21const recipe = recipeName.toLowerCase().replace(/\s/g, '-'); 22const recipe = recipeName.toLowerCase().replaceAll(/\s/g, '-');
22const folderName = process.argv[3] || 'Ferdium'; 23const folderName = process.argv[3] || 'Ferdium';
23const filesThatNeedTextReplace = [ 24const filesThatNeedTextReplace = ['package.json', 'index.js', 'webview.js'];
24 'package.json',
25 'index.js',
26 'webview.js',
27];
28 25
29const toPascalCase = (str) => { 26const toPascalCase = str => {
30 const words = str 27 const words = str
31 .replace(/[^a-z]/g, '') 28 .replaceAll(/[^a-z]/g, '')
32 .split(/\W/) 29 .split(/\W/)
33 .map((word) => { 30 .map(word => {
34 if (word.length === 0) { 31 if (word.length === 0) {
35 return word; 32 return word;
36 } 33 }
@@ -38,16 +35,16 @@ const toPascalCase = (str) => {
38 return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); 35 return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
39 }); 36 });
40 return words.join(''); 37 return words.join('');
41} 38};
42const pascalCasedName = toPascalCase(recipe); // PascalCased recipe ID only containing a-z, for usage as the JavaScript class name 39const pascalCasedName = toPascalCase(recipe); // PascalCased recipe ID only containing a-z, for usage as the JavaScript class name
43 40
44(async () => { 41(async () => {
45 // Folder paths 42 // Folder paths
46 const userData = 43 const userData =
47 process.env.APPDATA || 44 process.env.APPDATA ||
48 (process.platform == 'darwin' 45 (process.platform === 'darwin'
49 ? process.env.HOME + '/Library/Application Support' 46 ? `${process.env.HOME}/Library/Application Support`
50 : process.env.HOME + '/.config'); 47 : `${process.env.HOME}/.config`);
51 const recipesFolder = path.join(userData, folderName, 'recipes'); 48 const recipesFolder = path.join(userData, folderName, 'recipes');
52 const devRecipeFolder = path.join(recipesFolder, 'dev'); 49 const devRecipeFolder = path.join(recipesFolder, 'dev');
53 const newRecipeFolder = path.join(devRecipeFolder, recipe); 50 const newRecipeFolder = path.join(devRecipeFolder, recipe);
@@ -60,7 +57,7 @@ const pascalCasedName = toPascalCase(recipe); // PascalCased recipe ID only cont
60 ); 57 );
61 return; 58 return;
62 } 59 }
63 await fs.ensureDir(devRecipeFolder); 60 fs.ensureDirSync(devRecipeFolder);
64 61
65 if (fs.existsSync(newRecipeFolder)) { 62 if (fs.existsSync(newRecipeFolder)) {
66 console.log('⚠️ Recipe already exists'); 63 console.log('⚠️ Recipe already exists');
@@ -70,17 +67,17 @@ const pascalCasedName = toPascalCase(recipe); // PascalCased recipe ID only cont
70 console.log('[Info] Passed pre-checks'); 67 console.log('[Info] Passed pre-checks');
71 68
72 // Copy sample recipe to recipe folder 69 // Copy sample recipe to recipe folder
73 await fs.copy(sampleRecipe, newRecipeFolder); 70 fs.copySync(sampleRecipe, newRecipeFolder);
74 console.log('[Info] Copied recipe'); 71 console.log('[Info] Copied recipe');
75 72
76 // Replace placeholders with the recipe-specific values 73 // Replace placeholders with the recipe-specific values
77 for (const file of filesThatNeedTextReplace) { 74 for (const file of filesThatNeedTextReplace) {
78 const filePath = path.join(newRecipeFolder, file); 75 const filePath = path.join(newRecipeFolder, file);
79 let contents = await fs.readFile(filePath, 'utf8'); 76 let contents = fs.readFileSync(filePath, 'utf8');
80 contents = contents.replace(/SERVICE/g, recipe); 77 contents = contents.replace(/SERVICE/g, recipe);
81 contents = contents.replace(/SNAME/g, recipeName); 78 contents = contents.replace(/SNAME/g, recipeName);
82 contents = contents.replace(/SPASCAL/g, pascalCasedName); 79 contents = contents.replace(/SPASCAL/g, pascalCasedName);
83 await fs.writeFile(filePath, contents); 80 fs.writeFileSync(filePath, contents);
84 } 81 }
85 console.log('[Info] Prepared new recipe'); 82 console.log('[Info] Prepared new recipe');
86 83