chore: set up eslint, prettier, husky

This commit is contained in:
Ayo Ayco 2024-12-26 00:54:23 +01:00
parent 75b29eddc5
commit bb056b09f5
9 changed files with 2177 additions and 19 deletions

1
.husky/pre-commit Normal file
View file

@ -0,0 +1 @@
npm run lint

View file

@ -95,30 +95,25 @@ export default function serviceWorker(options) {
registerSW();`
let output = 'static'
// let output = 'static'
const __dirname = resolve(dirname('.'))
return {
name: ASTROSW,
hooks: {
'astro:config:setup': async ({
injectScript,
config: _config,
command,
logger,
}) => {
'astro:config:setup': async ({ injectScript, command, logger }) => {
if (!serviceWorkerPath || serviceWorkerPath === '') {
// REQUIRED OPTION IS MISSING
logger.error('Missing required path to service worker script')
}
// const transformedScript=await transform(registrationScript)
output = _config.output
// output = _config.output
if (command === 'build') {
injectScript('page', registrationScript)
}
},
'astro:config:done': async ({ injectTypes, logger }) => {
'astro:config:done': async ({ injectTypes }) => {
let injectedTypes = `
declare const __assets: string[];
declare const __version: string;

View file

@ -17,6 +17,7 @@ export default defineConfig({
// '/threads'
],
excludeRoutes: ['/exclude'],
assetCachePrefix: 'hey',
logAssets: true,
esbuild: {
minify: true,

43
eslint.config.mjs Normal file
View file

@ -0,0 +1,43 @@
import globals from 'globals'
import eslintPluginAstro from 'eslint-plugin-astro'
import jsPlugin from '@eslint/js'
import tseslint from 'typescript-eslint'
import astroSwGlobals from '@ayco/astro-sw/globals'
import astroParser from 'astro-eslint-parser'
export default [
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...astroSwGlobals,
},
},
},
// add more generic rule sets here, such as:
jsPlugin.configs.recommended,
...tseslint.configs.recommended,
...eslintPluginAstro.configs['recommended'],
...eslintPluginAstro.configs['jsx-a11y-recommended'],
{
ignores: [
'dist/*',
'.output/*',
'.astro/*',
'site/*',
'templates/*',
'**/node_modules/*',
'**/env.d.ts',
],
},
{
files: ['**/*.astro'],
languageOptions: {
parser: astroParser,
parserOptions: {
parser: tseslint.parser,
},
},
},
]

View file

@ -22,11 +22,14 @@
},
"scripts": {
"start": "astro dev",
"dev": "astro dev",
"build": "astro build",
"build:preview:static": "astro build && astro preview",
"build:preview": "astro build && node ./server.mjs",
"test": "echo \"Error: no test specified\" && exit 1",
"format": "prettier . --write"
"format": "prettier . --write",
"lint": "eslint . --config eslint.config.mjs",
"prepare": "husky"
},
"keywords": [
"withastro",
@ -36,12 +39,21 @@
"license": "MIT",
"devDependencies": {
"@astrojs/node": "^8.3.3",
"@eslint/js": "^9.17.0",
"@fastify/middie": "^8.3.1",
"@fastify/static": "^7.0.4",
"astro": "^4.15.2",
"astro-eslint-parser": "^1.1.0",
"eslint": "^9.17.0",
"eslint-plugin-astro": "^1.3.1",
"eslint-plugin-jsx-a11y": "^6.10.2",
"fastify": "^4.28.1",
"globals": "^15.14.0",
"husky": "^9.1.7",
"prettier": "^3.4.2",
"prettier-plugin-astro": "^0.14.1"
"prettier-plugin-astro": "^0.14.1",
"typescript-eslint": "^8.18.2",
"vitest": "^2.1.8"
},
"dependencies": {
"esbuild": "^0.23.1"

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,3 @@
import { log } from './utils'
/**
* Note: @ayco/astro-sw integration injects variables `__prefix`, `__version`, & `__assets`
* -- find usage in package readme; `astro.config.mjs` integrations
@ -12,7 +10,7 @@ const addResourcesToCache = async (resources) => {
await cache.addAll(resources)
}
log('test log', { hello: 'world' })
console.log('test log', { hello: 'world' })
const putInCache = async (request, response) => {
const cache = await caches.open(cacheName)
@ -48,6 +46,7 @@ const cacheFirst = async ({ request, preloadResponsePromise, fallbackUrl }) => {
// and serve second one
putInCache(request, responseFromNetwork.clone())
return responseFromNetwork
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) {
const fallbackResponse = await caches.match(fallbackUrl)
if (fallbackResponse) {

View file

@ -1,3 +0,0 @@
export function log(message: any, ...data) {
console.log(message, ...data)
}

6
test/astro-sw.test.js Normal file
View file

@ -0,0 +1,6 @@
import { expect } from 'vitest'
import { test } from 'vitest'
test('astro-sw', () => {
expect(true).toBeTruthy()
})