Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cngJo committed May 30, 2023
0 parents commit f749d4e
Show file tree
Hide file tree
Showing 7 changed files with 792 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/node_modules
/package-lock.json
/pnpm-lock.yaml
/dist

/.idea
/.vscode
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Astro Cookie Consent

Astro wrapper for [vanilla-cookieconsent](https://github.com/orestbida/cookieconsent)
54 changes: 54 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@jop-software/astro-cookieconsent",
"version": "1.0.0",
"description": "vanilla-cookieconsent for astro",
"type": "module",
"license": "GPL-3.0-or-later",
"types": "./dist/index.d.ts",
"keywords": [
"astro-integration",
"astro-component",
"cookieconsent",
"consent",
"tracking",
"gdpr"
],
"contributors": [
{
"name": "Johannes Przymusinski",
"email": "[email protected]",
"url": "https://jop-software.de"
}
],
"exports": {
".": {
"import": "./dist/astro-cookieconsent.es.js",
"require": "./dist/astro-cookieconsent.umd.js"
}
},
"main": "./dist/astro-cookieconsent.umd.js",
"module": "./dist/astro-cookieconsent.es.js",
"files": [
"dist"
],
"scripts": {
"build": "vite build && tsc --emitDeclarationOnly",
"build:watch": "vite build --watch",
"dev": "vite",
"prettier:check": "prettier --check src",
"prettier:write": "prettier --write src"
},
"devDependencies": {
"astro": "^1.8.0",
"prettier": "^2.7.1",
"typescript": "^4.9.4",
"vite": "^4.0.3"
},
"repository": {
"type": "git",
"url": "https://github.com/jop-software/astro-cookieconsent"
},
"peerDependencies": {
"vanilla-cookieconsent": "^2.9.1"
}
}
19 changes: 19 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as CookieConsent from "vanilla-cookieconsent";

const createPlugin = (config: UserConfig) => {
return {
name: "@jop-software/astro-cookie-consent",
hooks: {
"astro:config:setup": async ({ injectScript }: any) => {
injectScript("page", "import 'vanilla-cookieconsent'; import 'vanilla-cookieconsent/dist/cookieconsent.css';");
injectScript("page", `window.cookieConentConfiguration = ${JSON.stringify(config)}`);
injectScript("page", `window.cookieConent = initCookieConsent();`)
injectScript("page", `window.cookieConent.run(window.cookieConentConfiguration);`)
},
},
};
};

export type { CookieConsent };

export default createPlugin;
19 changes: 19 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"module": "ES2022",
"outDir": "./dist",
"target": "ES2021",
"typeRoots": [
"./node_modules/vanilla-cookieconsent/types"
]
},
"include": [
"src"
]
}
16 changes: 16 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// vite.config.js
import { resolve } from 'path'
import { defineConfig } from 'vite'

export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, 'src/main.ts'),
name: 'AstroCookieconsent',
// the proper extensions will be added
fileName: (format) => `astro-cookieconsent.${format}.js`,

},
},
})

0 comments on commit f749d4e

Please sign in to comment.