From 9b8f01716774a960073e944823ab727cc867a8f6 Mon Sep 17 00:00:00 2001 From: MCMXC <16797721+mcmxcdev@users.noreply.github.com> Date: Wed, 26 Jul 2023 06:29:03 -0600 Subject: 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 --- scripts/create.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'scripts/create.js') 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 @@ +/* eslint-disable no-console */ /** * Create a new recipe for your service */ @@ -18,19 +19,15 @@ pnpm create WhatsApp FerdiumDev } const recipeName = process.argv[2]; -const recipe = recipeName.toLowerCase().replace(/\s/g, '-'); +const recipe = recipeName.toLowerCase().replaceAll(/\s/g, '-'); const folderName = process.argv[3] || 'Ferdium'; -const filesThatNeedTextReplace = [ - 'package.json', - 'index.js', - 'webview.js', -]; +const filesThatNeedTextReplace = ['package.json', 'index.js', 'webview.js']; -const toPascalCase = (str) => { +const toPascalCase = str => { const words = str - .replace(/[^a-z]/g, '') + .replaceAll(/[^a-z]/g, '') .split(/\W/) - .map((word) => { + .map(word => { if (word.length === 0) { return word; } @@ -38,16 +35,16 @@ const toPascalCase = (str) => { return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); }); return words.join(''); -} +}; const pascalCasedName = toPascalCase(recipe); // PascalCased recipe ID only containing a-z, for usage as the JavaScript class name (async () => { // Folder paths const userData = process.env.APPDATA || - (process.platform == 'darwin' - ? process.env.HOME + '/Library/Application Support' - : process.env.HOME + '/.config'); + (process.platform === 'darwin' + ? `${process.env.HOME}/Library/Application Support` + : `${process.env.HOME}/.config`); const recipesFolder = path.join(userData, folderName, 'recipes'); const devRecipeFolder = path.join(recipesFolder, 'dev'); const newRecipeFolder = path.join(devRecipeFolder, recipe); @@ -60,7 +57,7 @@ const pascalCasedName = toPascalCase(recipe); // PascalCased recipe ID only cont ); return; } - await fs.ensureDir(devRecipeFolder); + fs.ensureDirSync(devRecipeFolder); if (fs.existsSync(newRecipeFolder)) { console.log('⚠️ Recipe already exists'); @@ -70,17 +67,17 @@ const pascalCasedName = toPascalCase(recipe); // PascalCased recipe ID only cont console.log('[Info] Passed pre-checks'); // Copy sample recipe to recipe folder - await fs.copy(sampleRecipe, newRecipeFolder); + fs.copySync(sampleRecipe, newRecipeFolder); console.log('[Info] Copied recipe'); // Replace placeholders with the recipe-specific values for (const file of filesThatNeedTextReplace) { const filePath = path.join(newRecipeFolder, file); - let contents = await fs.readFile(filePath, 'utf8'); + let contents = fs.readFileSync(filePath, 'utf8'); contents = contents.replace(/SERVICE/g, recipe); contents = contents.replace(/SNAME/g, recipeName); contents = contents.replace(/SPASCAL/g, pascalCasedName); - await fs.writeFile(filePath, contents); + fs.writeFileSync(filePath, contents); } console.log('[Info] Prepared new recipe'); -- cgit v1.2.3-70-g09d2