chore: setup husky, eslint, prettier
This commit is contained in:
parent
249caabd67
commit
38addd30bf
8 changed files with 811 additions and 56 deletions
2
.husky/pre-commit
Normal file
2
.husky/pre-commit
Normal file
|
@ -0,0 +1,2 @@
|
|||
npm run lint
|
||||
|
1
.pretterignore
Normal file
1
.pretterignore
Normal file
|
@ -0,0 +1 @@
|
|||
site/**
|
23
eslint.config.mjs
Normal file
23
eslint.config.mjs
Normal file
|
@ -0,0 +1,23 @@
|
|||
import globals from "globals";
|
||||
import pluginJs from "@eslint/js";
|
||||
import tseslint from "typescript-eslint";
|
||||
import astroSwGlobals from '@ayco/astro-sw/globals';
|
||||
|
||||
|
||||
/** @type {import('eslint').Linter.Config[]} */
|
||||
export default [
|
||||
{files: ["**/*.{js,mjs,cjs,ts}"]},
|
||||
{languageOptions: { globals: {...globals.browser, ...globals.node, ...astroSwGlobals } }},
|
||||
pluginJs.configs.recommended,
|
||||
...tseslint.configs.recommended,
|
||||
{
|
||||
ignores: [
|
||||
'dist/*',
|
||||
'.output/*',
|
||||
'.astro/*',
|
||||
'**/node_modules/*',
|
||||
'**/coverage/*',
|
||||
'**/env.d.ts'
|
||||
],
|
||||
},
|
||||
]
|
11
package.json
11
package.json
|
@ -16,7 +16,9 @@
|
|||
"publish:patch": "npm version patch && npm publish --access public",
|
||||
"publish:minor": "npm version minor && npm publish --access public",
|
||||
"deploy:client": "astro build && scp -r dist/client/ ayo@ayco.io:~/cozy/dist/",
|
||||
"test": "vitest"
|
||||
"test": "vitest",
|
||||
"prepare": "husky",
|
||||
"lint": "eslint . --config eslint.config.mjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@astrojs/check": "^0.9.4",
|
||||
|
@ -24,15 +26,20 @@
|
|||
"@astrojs/node": "^8.3.4",
|
||||
"@astrojs/rss": "^4.0.9",
|
||||
"@astrojs/sitemap": "^3.2.1",
|
||||
"@ayco/astro-sw": "^0.8.8",
|
||||
"@ayco/astro-sw": "^0.8.14",
|
||||
"@eslint/js": "^9.17.0",
|
||||
"@extractus/article-extractor": "^8.0.10",
|
||||
"@fastify/middie": "^8.3.1",
|
||||
"@fastify/static": "^7.0.4",
|
||||
"astro": "^4.16.7",
|
||||
"astro-iconify": "^1.2.0",
|
||||
"eslint": "^9.17.0",
|
||||
"fastify": "^4.28.1",
|
||||
"globals": "^15.14.0",
|
||||
"husky": "^9.1.7",
|
||||
"sass": "^1.77.8",
|
||||
"typescript": "^5.5.4",
|
||||
"typescript-eslint": "^8.18.2",
|
||||
"ultrahtml": "^1.5.3",
|
||||
"vitest": "^2.1.4"
|
||||
}
|
||||
|
|
801
pnpm-lock.yaml
801
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
12
prettier.config.mjs
Normal file
12
prettier.config.mjs
Normal file
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* @see https://prettier.io/docs/en/configuration.html
|
||||
* @type {import("prettier").Config}
|
||||
*/
|
||||
const config = {
|
||||
trailingComma: 'es5',
|
||||
tabWidth: 2,
|
||||
semi: false,
|
||||
singleQuote: true,
|
||||
}
|
||||
|
||||
export default config
|
14
src/sw.mjs
14
src/sw.mjs
|
@ -58,11 +58,11 @@ const cacheAndRevalidate = async ({ request, fallbackUrl }) => {
|
|||
// get network response for revalidation of cached assets
|
||||
fetch(request.clone()).then((responseFromNetwork) => {
|
||||
if (responseFromNetwork) {
|
||||
console.info('fetched updated resource...', { force: forceLogging, context: 'cozy-sw', data: responseFromNetwork.url })
|
||||
console.info('fetched updated resource...', responseFromNetwork.url)
|
||||
putInCache(request, responseFromNetwork.clone());
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.info('failed to fetch updated resource', { force: forceLogging, context: 'cozy-sw', data: error })
|
||||
console.info('failed to fetch updated resource', error)
|
||||
});
|
||||
|
||||
return responseFromCache;
|
||||
|
@ -75,15 +75,16 @@ const cacheAndRevalidate = async ({ request, fallbackUrl }) => {
|
|||
// we need to save clone to put one copy in cache
|
||||
// and serve second one
|
||||
putInCache(request, responseFromNetwork.clone());
|
||||
console.info('using network response', { force: forceLogging, context: 'cozy-sw', data: responseFromNetwork.url })
|
||||
console.info('using network response', responseFromNetwork.url)
|
||||
return responseFromNetwork;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
} catch (error) {
|
||||
|
||||
// Try the fallback
|
||||
const fallbackResponse = await cache.match(fallbackUrl);
|
||||
if (fallbackResponse) {
|
||||
console.info('using fallback cached response...', { force: forceLogging, context: 'cozy-sw', data: fallbackResponse.url })
|
||||
console.info('using fallback cached response...', fallbackResponse.url)
|
||||
return fallbackResponse;
|
||||
}
|
||||
|
||||
|
@ -97,14 +98,15 @@ const cacheAndRevalidate = async ({ request, fallbackUrl }) => {
|
|||
}
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
self.addEventListener('activate', (event) => {
|
||||
console.info('activating service worker...', { force: forceLogging, context: 'cozy-sw' })
|
||||
console.info('activating service worker...')
|
||||
cleanOldCaches();
|
||||
});
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
|
||||
console.info('installing service worker...', { force: forceLogging, context: 'cozy-sw' })
|
||||
console.info('installing service worker...')
|
||||
self.skipWaiting(); // go straight to activate
|
||||
|
||||
event.waitUntil(
|
||||
|
|
|
@ -24,6 +24,3 @@ export async function cozify(html: string, baseUrl: string): Promise<string> {
|
|||
])
|
||||
}
|
||||
|
||||
function set(value: string) {
|
||||
return () => value
|
||||
}
|
Loading…
Reference in a new issue