From d33a8db65e10571694ee1019f0d5fa497d99eb48 Mon Sep 17 00:00:00 2001 From: Guo Yunhe Date: Mon, 4 Mar 2024 22:43:53 +0800 Subject: [PATCH] migrate --- .editorconfig | 3 ++- .github/workflows/ci.yml | 40 ++++++++++++++++++++++++++++ .github/workflows/pages.yml | 29 +++++++++++++++++++++ .gitignore | 16 +++--------- .vscode/extensions.json | 6 +++-- .vscode/settings.json | 37 +++++++++++++++++++++++--- CHANGELOG.md | 4 +-- README.md | 16 ++++++++++++ package.json | 52 +++++++++++++++++++++---------------- src/index.ts | 4 +-- tsconfig.json | 28 +++++++++++++++++--- 11 files changed, 187 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/pages.yml diff --git a/.editorconfig b/.editorconfig index 773ca2d..ed272d4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,5 +6,6 @@ end_of_line = lf indent_size = 2 indent_style = space insert_final_newline = true -trim_trailing_whitespace = true +max_line_length = 100 quote_type = single +trim_trailing_whitespace = true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6be4e4b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: CI + +on: + - push + - pull_request + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - uses: pnpm/action-setup@v3 + with: + version: latest + - run: pnpm install + - run: pnpm run lint + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - uses: pnpm/action-setup@v3 + with: + version: latest + - run: pnpm install + - run: pnpm run test + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - uses: pnpm/action-setup@v3 + with: + version: latest + - run: pnpm install + - run: pnpm run build diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 0000000..258872b --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,29 @@ +name: GitHub Pages + +on: + push: + branches: + - main + pull_request: + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + permissions: + contents: write + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - uses: pnpm/action-setup@v3 + with: + version: latest + - run: pnpm install + - run: pnpm run build + - uses: peaceiris/actions-gh-pages@v3 + if: github.ref == 'refs/heads/main' + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./build diff --git a/.gitignore b/.gitignore index dc7e058..de31df3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,8 @@ -# Build output -dist - -# Coverage directory +.rive +build coverage - -# Dependency directories -node_modules/ - -# Lock files +dist +node_modules package-lock.json pnpm-lock.yaml yarn.lock - -# Output of 'npm pack' -*.tgz diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 17fab0c..bab1350 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,6 +2,8 @@ "recommendations": [ "dbaeumer.vscode-eslint", "editorconfig.editorconfig", - "esbenp.prettier-vscode" + "esbenp.prettier-vscode", + "stylelint.vscode-stylelint", + "unifiedjs.vscode-mdx" ] -} +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index b14a167..01f5106 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,11 +1,14 @@ { "eslint.validate": [ "javascript", - "typescript" + "typescript", + "javascriptreact", + "typescriptreact" ], "editor.codeActionsOnSave": { - "source.fixAll.eslint": true, - "source.organizeImports": true + "source.fixAll.eslint": "explicit", + "source.organizeImports": "explicit", + "source.fixAll.stylelint": "explicit" }, "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true, @@ -23,5 +26,31 @@ }, "[jsonc]": { "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "stylelint.validate": [ + "css", + "less", + "scss" + ], + "[javascriptreact]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[typescriptreact]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[vue]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[css]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[less]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[scss]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[html]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" } -} +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d619c8..009ddcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # Changelog -## 1.0.0 - 2023-03-30 +## 2024-03-04 -- First version, support `client` option and `VITE_ADSENSE_CLIENT` env +- Changed license to MIT diff --git a/README.md b/README.md index d28e5ff..28d8902 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ npm i vite-plugin-adsense ## Usage +It is recommended to save your client id into `.env` file. + ```ini # .env VITE_ADSENSE_CLIENT=ca-pub-1234567890123456 @@ -29,3 +31,17 @@ export default defineConfig({ plugins: [adsense()], }); ``` + +If you have more advanced usage, you can also pass `client` to plugin options. + +```ts +// vite.config.ts +import { defineConfig } from 'vite'; +import adsense from 'vite-plugin-adsense'; + +export default defineConfig({ + plugins: [adsense({ + client: 'ca-pub-1234567890123456', + })], +}); +``` diff --git a/package.json b/package.json index 06320d5..a186152 100644 --- a/package.json +++ b/package.json @@ -19,14 +19,15 @@ "url": "git+https://github.com/guoyunhe/vite-plugin-adsense.git" }, "funding": "https://github.com/sponsors/guoyunhe", - "license": "GPL-3.0", + "license": "MIT", "author": { "name": "Guo Yunhe", "email": "i@guoyunhe.me" }, "type": "module", - "main": "dist/index.mjs", - "typings": "dist/index.d.ts", + "main": "dist/cjs/index.js", + "module": "dist/index.js", + "types": "dist/index.d.ts", "files": [ "dist", "CHANGELOG.md", @@ -34,28 +35,35 @@ "README.md" ], "scripts": { - "build": "node-scripts build", - "format": "node-scripts format", - "lint": "node-scripts lint", - "test": "node-scripts test", - "watch": "node-scripts watch" - }, - "prettier": { - "printWidth": 100, - "singleQuote": true + "build": "rive build", + "build:watch": "rive build --watch", + "lint": "rive lint", + "lint:fix": "rive lint --fix", + "start": "rive start", + "test": "rive test", + "test:ui": "rive test --ui", + "test:watch": "rive test --watch" }, + "prettier": "prettier-config-rive", "eslintConfig": { - "extends": "@guoyunhe/node-scripts" - }, - "jest": { - "preset": "@guoyunhe/node-scripts" + "extends": "eslint-config-rive" }, "devDependencies": { - "@guoyunhe/node-scripts": "^2.0.0", - "@tsconfig/node16": "^1.0.0", - "@types/jest": "^29.0.0", - "@types/node": "^16.0.0", - "typescript": "^4.0.0", - "vite": "^4.2.1" + "@mdx-js/react": "^3.0.1", + "@types/node": "^16.18.86", + "@types/react": "^18.2.61", + "@types/react-dom": "^18.2.19", + "react": "^18.2.0", + "react-doc-ui": "^2.2.6", + "react-dom": "^18.2.0", + "rive": "^2.0.33", + "typescript": "^5.3.3" + }, + "rive": { + "template": "node", + "doc": { + "basename": "/vite-plugin-adsense/" + } } } + diff --git a/src/index.ts b/src/index.ts index 18f1d5c..842a964 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,7 +24,7 @@ export default function adsense({ client }: AdSenseOptions = {}): Plugin { // insert adsense script to the end of index.html return html.replace( /<\/body>/, - ` \n` + ` \n`, ); }, closeBundle: async () => { @@ -34,7 +34,7 @@ export default function adsense({ client }: AdSenseOptions = {}): Plugin { // create ads.txt file await writeFile( join(outDir, 'ads.txt'), - `google.com, ${actualClient.substring(3)}, DIRECT, f08c47fec0942fa0\n` + `google.com, ${actualClient.substring(3)}, DIRECT, f08c47fec0942fa0\n`, ); }, }; diff --git a/tsconfig.json b/tsconfig.json index 2e6f260..920da30 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,30 @@ { - "extends": "@tsconfig/node16/tsconfig.json", "compilerOptions": { "resolveJsonModule": true, - "types": ["node", "jest", "@guoyunhe/node-scripts/global"] + "types": [ + "node", + "rive/globals" + ], + "target": "es2015", + "lib": [ + "esnext" + ], + "allowJs": true, + "checkJs": false, + "skipLibCheck": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "node", + "isolatedModules": true }, - "include": ["src"] + "include": [ + "src" + ], + "exclude": [ + ".rive", + "build", + "coverage", + "dist", + "node_modules" + ] }