diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..c58023a --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,50 @@ +name: "Build ๐Ÿ—๏ธ" + +on: + workflow_call: + +jobs: + build: + name: "Build" + runs-on: ubuntu-latest + + steps: + - name: "Checkout" + uses: actions/checkout@v3 + + - name: "Setup NodeJS" + uses: actions/setup-node@v3 + with: + node-version: "18" + + - uses: pnpm/action-setup@v2 + name: Install pnpm + id: pnpm-install + with: + version: 7 + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + run: pnpm install --strict-peer-dependencies + + - name: Build + run: pnpm run build + + - uses: actions/upload-artifact@v3 + with: + name: astro-cookieconsent + path: dist diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..a8bca24 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,23 @@ +name: "CI - Pipeline ๐Ÿš€" + +on: + push: + branches: + - "main" + pull_request: + workflow_dispatch: + inputs: + workflow: + description: "Workflow to run" + required: true + default: "lint" + +jobs: + + lint: + uses: "./.github/workflows/lint.yaml" + + build: + needs: + - lint + uses: "./.github/workflows/build.yaml" diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..9bbbcec --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,45 @@ +name: "Lint ๐Ÿงน" + +on: + workflow_call: + +jobs: + lint: + name: "Lint" + runs-on: ubuntu-latest + + steps: + - name: "Checkout" + uses: actions/checkout@v3 + + - name: "Setup NodeJS" + uses: actions/setup-node@v3 + with: + node-version: "18" + + - uses: pnpm/action-setup@v2 + name: Install pnpm + id: pnpm-install + with: + version: 7 + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + run: pnpm install --strict-peer-dependencies + + - name: Build + run: pnpm run build diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..1ef96c5 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,69 @@ +name: "Publish ๐Ÿš€" + +on: + push: + tags: + - "v*" + +jobs: + lint: + uses: "./.github/workflows/lint.yaml" + + build: + uses: "./.github/workflows/build.yaml" + + github-release: + name: "GitHub Release" + runs-on: ubuntu-latest + needs: + - lint + - build + steps: + - name: "Release ๐Ÿš€" + uses: "softprops/action-gh-release@v1" + with: + generate_release_notes: true + + publish-github: + name: "Publish to Github Packages" + needs: + - github-release + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/download-artifact@v3 + with: + name: astro-cookieconsent + path: . + + # Setup .npmrc file to publish to GitHub Packages + - uses: actions/setup-node@v3 + with: + node-version: '18.x' + registry-url: 'https://npm.pkg.github.com' + + - run: pnpm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + publish-npm: + name: "Publish to NPM" + needs: + - github-release + runs-on: "ubuntu-latest" + steps: + - uses: actions/download-artifact@v3 + with: + name: astro-cookieconsent + path: . + + - uses: actions/setup-node@v3 + with: + node-version: '18.x' + registry-url: "https://registry.npmjs.org/" + + - run: pnpm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..3e775ef --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +auto-install-peers=true diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..e69de29 diff --git a/src/main.ts b/src/main.ts index 0acda14..222476a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,17 +1,26 @@ 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);`) - }, - }, - }; + 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 };