diff options
author | 2023-07-26 06:29:03 -0600 | |
---|---|---|
committer | 2023-07-26 17:59:03 +0530 | |
commit | 9b8f01716774a960073e944823ab727cc867a8f6 (patch) | |
tree | 732b83770baa78f5cf12776aaa33ce65bebfa418 /scripts/create.js | |
parent | Add Excalidraw recipe (#393) (diff) | |
download | ferdium-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.js | 31 |
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 | ||
20 | const recipeName = process.argv[2]; | 21 | const recipeName = process.argv[2]; |
21 | const recipe = recipeName.toLowerCase().replace(/\s/g, '-'); | 22 | const recipe = recipeName.toLowerCase().replaceAll(/\s/g, '-'); |
22 | const folderName = process.argv[3] || 'Ferdium'; | 23 | const folderName = process.argv[3] || 'Ferdium'; |
23 | const filesThatNeedTextReplace = [ | 24 | const filesThatNeedTextReplace = ['package.json', 'index.js', 'webview.js']; |
24 | 'package.json', | ||
25 | 'index.js', | ||
26 | 'webview.js', | ||
27 | ]; | ||
28 | 25 | ||
29 | const toPascalCase = (str) => { | 26 | const 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 | }; |
42 | const pascalCasedName = toPascalCase(recipe); // PascalCased recipe ID only containing a-z, for usage as the JavaScript class name | 39 | const 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 | ||