Skip to content

Commit

Permalink
Shoptet Prettier added, formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelhusa committed Nov 3, 2024
1 parent 8b27978 commit 15b048d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 25 deletions.
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
*.md
*.json
*.yml
23 changes: 23 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
17 changes: 7 additions & 10 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>', '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>', '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;
8 changes: 2 additions & 6 deletions config.js
Original file line number Diff line number Diff line change
@@ -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')));
21 changes: 13 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ const blankModeScript = {
};

const headerIncludes = {
match: /(?<=<head[\s\S]*?<!--\sUser include\s-->)[\s\S]*?(?=<!--\s\/User include\s-->)/i,
match: /(?<=<head[\s\S]*?<!--\sUser include\s-->)[\s\S]*?(?=<!--\s\/User include\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
Expand All @@ -56,15 +58,18 @@ const headerIncludes = {
};

const footerIncludes = {
match: /(?<=<body[\s\S]*?<!--\sUser include\s-->\s*<div class="container">)[\s\S]*?(?=<\/div>\s*<!--\s\/User include\s-->)/i,
match:
/(?<=<body[\s\S]*?<!--\sUser include\s-->\s*<div class="container">)[\s\S]*?(?=<\/div>\s*<!--\s\/User include\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
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -41,5 +43,8 @@
"cookie": ">=0.7.0",
"follow-redirects": ">=1.15.6",
"braces": ">=3.0.3"
},
"devDependencies": {
"prettier": "^3.3.3"
}
}

0 comments on commit 15b048d

Please sign in to comment.