From 15b048d45367ea89757f5504ce89edde53034049 Mon Sep 17 00:00:00 2001 From: Pavel Husa Date: Sun, 3 Nov 2024 13:44:42 +0100 Subject: [PATCH] Shoptet Prettier added, formatted --- .prettierignore | 4 ++++ .prettierrc | 23 +++++++++++++++++++++++ cli.js | 17 +++++++---------- config.js | 8 ++------ index.js | 21 +++++++++++++-------- package.json | 7 ++++++- 6 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..6b80e4a --- /dev/null +++ b/.prettierignore @@ -0,0 +1,4 @@ +dist/ +*.md +*.json +*.yml \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..ad2aead --- /dev/null +++ b/.prettierrc @@ -0,0 +1,23 @@ +{ + "singleQuote": true, + "jsxSingleQuote": true, + "tabWidth": 2, + "printWidth": 120, + "arrowParens": "avoid", + "trailingComma": "es5", + "overrides": [ + { + "files": ".prettierrc", + "options": { "parser": "json" } + }, + { + "files": "{.vscode/*.json,**/tsconfig.json,**/tsconfig.*.json}", + "options": { + "parser": "json5", + "quoteProps": "preserve", + "singleQuote": false, + "trailingComma": "none" + } + } + ] +} diff --git a/cli.js b/cli.js index 574515a..55c79d9 100644 --- a/cli.js +++ b/cli.js @@ -3,17 +3,14 @@ import { packageInfo } from './config.js'; const command = new Command(); -command - .name(packageInfo.name) - .description(packageInfo.description) - .version(packageInfo.version); +command.name(packageInfo.name).description(packageInfo.description).version(packageInfo.version); command - .option('-r, --remote ', 'URL of the remote Eshop with https:// prefix') - .option('-w, --watch', 'watch for changes and reload the page', true) - .option('-b, --blankMode', 'simulate the blank template.', false) - .option('-n, --notify', 'display pop-over notifications in the browser', false) - .option('-rh, --removeHeaderIncludes [removeHeaderIncludes...]', 'remove header includes', false) - .option('-rf, --removeFooterIncludes [removeFooterIncludes...]', 'remove footer includes', false); + .option('-r, --remote ', 'URL of the remote Eshop with https:// prefix') + .option('-w, --watch', 'watch for changes and reload the page', true) + .option('-b, --blankMode', 'simulate the blank template.', false) + .option('-n, --notify', 'display pop-over notifications in the browser', false) + .option('-rh, --removeHeaderIncludes [removeHeaderIncludes...]', 'remove header includes', false) + .option('-rf, --removeFooterIncludes [removeFooterIncludes...]', 'remove footer includes', false); export default command; diff --git a/config.js b/config.js index 7377fed..3d47164 100644 --- a/config.js +++ b/config.js @@ -1,10 +1,6 @@ import { readFileSync } from 'fs'; import path from 'path'; -export const packageInfo = JSON.parse( - readFileSync(path.resolve(process.cwd(), './package.json')) -); +export const packageInfo = JSON.parse(readFileSync(path.resolve(process.cwd(), './package.json'))); -export const config = JSON.parse( - readFileSync(path.resolve(process.cwd(), './config.json')) -); +export const config = JSON.parse(readFileSync(path.resolve(process.cwd(), './config.json'))); diff --git a/index.js b/index.js index b29dddb..38e98e8 100755 --- a/index.js +++ b/index.js @@ -36,15 +36,17 @@ const blankModeScript = { }; const headerIncludes = { - match: /(?<=)[\s\S]*?(?=)/i, + match: /(?<=)[\s\S]*?(?=)/i, fn: function (req, res, match) { // Remove includes from the header const includes = options.removeHeaderIncludes || config.removeHeaderIncludes || []; const matchedServices = match.match(includesCodeRegex); if (matchedServices) { - match = matchedServices.filter(service => { - return !includes.some(removedService => service.includes(removedService)); - }).join('') + match = matchedServices + .filter(service => { + return !includes.some(removedService => service.includes(removedService)); + }) + .join(''); } // Add custom includes to the footer @@ -56,15 +58,18 @@ const headerIncludes = { }; const footerIncludes = { - match: /(?<=\s*
)[\s\S]*?(?=<\/div>\s*)/i, + match: + /(?<=\s*
)[\s\S]*?(?=<\/div>\s*)/i, fn: function (req, res, match) { // Remove includes from the footer const includes = options.removeFooterIncludes || config.removeFooterIncludes || []; const matchedServices = match.match(includesCodeRegex); if (matchedServices) { - match = matchedServices.filter(service => { - return !includes.some(removedService => service.includes(removedService)); - }).join('') + match = matchedServices + .filter(service => { + return !includes.some(removedService => service.includes(removedService)); + }) + .join(''); } // Add custom includes to the footer diff --git a/package.json b/package.json index e08ce57..bc36b7e 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "bin": "index.js", "type": "module", "scripts": { - "start": "node index.js" + "start": "node index.js", + "format": "prettier --check .", + "format:fix": "prettier --write ." }, "author": "Shoptet", "license": "ISC", @@ -41,5 +43,8 @@ "cookie": ">=0.7.0", "follow-redirects": ">=1.15.6", "braces": ">=3.0.3" + }, + "devDependencies": { + "prettier": "^3.3.3" } }