Эх сурвалжийг харах

chore(cli/plugin): update plugin template (#9346)

closes #9342
Amr Bashir 1 жил өмнө
parent
commit
8276ab767b

+ 4 - 4
tooling/cli/src/plugin/init.rs

@@ -194,10 +194,10 @@ pub fn command(mut options: Options) -> Result<()> {
               }
             }
             "ios" if !(options.ios || options.mobile) => return Ok(None),
-            "webview-dist" | "webview-src" | "package.json" => {
-              if options.no_api {
-                return Ok(None);
-              }
+            "guest-js" | "rollup.config.js" | "tsconfig.json" | "package.json"
+              if options.no_api =>
+            {
+              return Ok(None);
             }
             _ => (),
           }

+ 0 - 91
tooling/cli/templates/plugin/.changes/config.json

@@ -1,91 +0,0 @@
-{
-  "gitSiteUrl": "https://www.github.com/your-org/tauri-plugin-{{ plugin_name }}/",
-  "pkgManagers": {
-    "rust": {
-      "version": true,
-      "getPublishedVersion": "cargo search ${ pkg.pkg } --limit 1 | sed -nE 's/^[^\"]*\"//; s/\".*//1p' -",
-      "prepublish": [
-        "sudo apt-get update",
-        "sudo apt-get install -y webkit2gtk-4.1",
-        "cargo install cargo-audit",
-        {
-          "command": "cargo generate-lockfile",
-          "dryRunCommand": true,
-          "pipe": true
-        },
-        {
-          "command": "echo '<details>\n<summary><em><h4>Cargo Audit</h4></em></summary>\n\n```'",
-          "dryRunCommand": true,
-          "pipe": true
-        },
-        {
-          "command": "cargo audit ${ process.env.CARGO_AUDIT_OPTIONS || '' }",
-          "dryRunCommand": true,
-          "pipe": true
-        },
-        {
-          "command": "echo '```\n\n</details>\n'",
-          "dryRunCommand": true,
-          "pipe": true
-        }
-      ],
-      "publish": [
-        {
-          "command": "cargo package --no-verify",
-          "dryRunCommand": true
-        },
-        {
-          "command": "echo '<details>\n<summary><em><h4>Cargo Publish</h4></em></summary>\n\n```'",
-          "dryRunCommand": true,
-          "pipe": true
-        },
-        {
-          "command": "cargo publish",
-          "dryRunCommand": "cargo publish --dry-run",
-          "pipe": true
-        },
-        {
-          "command": "echo '```\n\n</details>\n'",
-          "dryRunCommand": true,
-          "pipe": true
-        }
-      ]
-    },
-    "javascript": {
-      "version": true,
-      "getPublishedVersion": "npm view ${ pkgFile.pkg.name } version",
-      "publish": [
-        {
-          "command": "echo '<details>\n<summary><em><h4>Yarn Publish</h4></em></summary>\n\n```'",
-          "dryRunCommand": true,
-          "pipe": true
-        },
-        {
-          "command": "yarn publish --access public --loglevel silly",
-          "dryRunCommand": "npm publish --dry-run --access public",
-          "pipe": true
-        },
-        {
-          "command": "echo '```\n\n</details>\n'",
-          "dryRunCommand": true,
-          "pipe": true
-        }
-      ]
-    }
-  },
-  "packages": {
-    "tauri-plugin-{{ plugin_name }}": {
-      "path": ".",
-      "manager": "rust",
-      "releaseTag": "crate-v${ pkgFile.version }"
-    },
-    "tauri-plugin-{{ plugin_name }}-api": {
-      "path": ".",
-      "manager": "javascript",
-      "dependencies": [
-        "tauri-plugin-{{ plugin_name }}"
-      ],
-      "releaseTag": "npm-v${ pkgFile.version }"
-    }
-  }
-}

+ 0 - 6
tooling/cli/templates/plugin/.changes/initial-release.md

@@ -1,6 +0,0 @@
----
-"tauri-plugin-{{ plugin_name }}": "minor"
-"tauri-plugin-{{ plugin_name }}-api": "minor"
----
-
-Initial release.

+ 0 - 16
tooling/cli/templates/plugin/.changes/readme.md

@@ -1,16 +0,0 @@
-# Changes
-##### via https://github.com/jbolda/covector
-
-As you create PRs and make changes that require a version bump, please add a new markdown file in this folder. You do not note the version *number*, but rather the type of bump that you expect: major, minor, or patch. The filename is not important, as long as it is a `.md`, but we recommend it represents the overall change for our sanity.
-
-When you select the version bump required, you do *not* need to consider dependencies. Only note the package with the actual change, and any packages that depend on that package will be bumped automatically in the process.
-
-Use the following format:
-```md
----
-"tauri-plugin-{{ plugin_name }}": 'patch:enhance'
----
-
-Change summary goes here
-
-```

+ 7 - 4
tooling/cli/templates/plugin/.github/workflows/audit.yml

@@ -8,24 +8,27 @@ on:
     branches:
       - main
     paths:
+      - ".github/workflows/audit.yml"
       - "**/Cargo.lock"
       - "**/Cargo.toml"
   pull_request:
     branches:
       - main
     paths:
+      - ".github/workflows/audit.yml"
       - "**/Cargo.lock"
       - "**/Cargo.toml"
 
+concurrency:
+  group: ${{ github.workflow }}-${{ github.ref }}
+  cancel-in-progress: true
+
 jobs:
   audit:
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
       - uses: rustsec/audit-check@v1
         with:
           token: ${{ secrets.GITHUB_TOKEN }}
-    permissions:
-      issues: write
-      checks: write
 {{{{/raw}}}}

+ 34 - 14
tooling/cli/templates/plugin/.github/workflows/clippy.yml

@@ -1,35 +1,55 @@
 {{{{raw}}}}
-name: Clippy
+name: Check
 
 on:
   push:
     branches:
       - main
+    paths:
+      - ".github/workflows/check.yml"
+      - "**/*.rs"
+      - "**/Cargo.toml"
   pull_request:
     branches:
       - main
-      - dev
+    paths:
+      - ".github/workflows/check.yml"
+      - "**/*.rs"
+      - "**/Cargo.toml"
+
+concurrency:
+  group: ${{ github.workflow }}-${{ github.ref }}
+  cancel-in-progress: true
 
 jobs:
-  clippy:
+  fmt:
     runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout@v4
+      - uses: dtolnay/rust-toolchain@stable
+        with:
+          components: rustfmt
+      - run: cargo fmt --all -- --check
+
+  clippy:
     strategy:
       fail-fast: false
+      matrix:
+        platform: [ubuntu-latest, macos-latest, windows-latest]
 
-    steps:
-      - uses: actions/checkout@v3
+    runs-on: ${{ matrix.platform }}
 
-      - name: Install dependencies
+    steps:
+      - uses: actions/checkout@v4
+      - uses: dtolnay/rust-toolchain@stable
+        with:
+          components: clippy
+      - name: install webkit2gtk
+        if: matrix.platform == 'ubuntu-latest'
         run: |
           sudo apt-get update
           sudo apt-get install -y webkit2gtk-4.1
-
-      - name: Install clippy with stable toolchain
-        uses: dtolnay/rust-toolchain@stable
-        with:
-          components: clippy
-
       - uses: Swatinem/rust-cache@v2
-
-      - run: cargo clippy --manifest-path=Cargo.toml --all-targets --all-features -- -D warnings
+      - run: cargo clippy --all-targets --all-features -- -D warnings
 {{{{/raw}}}}

+ 0 - 48
tooling/cli/templates/plugin/.github/workflows/covector-version-or-publish.yml

@@ -1,48 +0,0 @@
-{{{{raw}}}}
-name: covector version or publish
-on:
-  push:
-    branches:
-    - dev
-
-jobs:
-  covector:
-    runs-on: ubuntu-latest
-
-    steps:
-      - uses: actions/checkout@v3
-        with:
-          fetch-depth: 0
-      - uses: actions/setup-node@v3
-        with:
-          node-version: 18
-          registry-url: 'https://registry.npmjs.org'
-
-      - name: cargo login
-        run: cargo login ${{ secrets.ORG_CRATES_IO_TOKEN }}
-
-      - name: git config
-        run: |
-          git config --global user.name "${{ github.event.pusher.name }}"
-          git config --global user.email "${{ github.event.pusher.email }}"
-
-      - name: covector version-or-publish
-        uses: jbolda/covector/packages/action@covector-v0
-        id: covector
-        with:
-          token: ${{ secrets.GITHUB_TOKEN }}
-          command: 'version-or-publish'
-          createRelease: true
-
-      - name: Create Pull Request With Versions Bumped
-        if: steps.covector.outputs.commandRan == 'version'
-        uses: tauri-apps/create-pull-request@v3
-        with:
-          token: ${{ secrets.GITHUB_TOKEN }}
-          branch: release/version-updates
-          title: Apply Version Updates From Current Changes
-          commit-message: "apply version updates"
-          labels: "version updates"
-          body: ${{ steps.covector.outputs.change }}
-
-{{{{/raw}}}}

+ 0 - 30
tooling/cli/templates/plugin/.github/workflows/format.yml

@@ -1,30 +0,0 @@
-{{{{raw}}}}
-name: Format
-
-on:
-  push:
-    branches:
-      - main
-  pull_request:
-    branches:
-      - main
-      - dev
-
-jobs:
-  format:
-    runs-on: ubuntu-latest
-    strategy:
-      fail-fast: false
-
-    steps:
-      - uses: actions/checkout@v3
-
-      - name: Install rustfmt with stable toolchain
-        uses: dtolnay/rust-toolchain@stable
-        with:
-          components: rustfmt
-
-      - uses: Swatinem/rust-cache@v2
-
-      - run: cargo fmt --manifest-path=Cargo.toml --all -- --check
-{{{{/raw}}}}

+ 13 - 21
tooling/cli/templates/plugin/.github/workflows/test.yml

@@ -8,36 +8,28 @@ on:
   pull_request:
     branches:
       - main
-      - dev
-    paths-ignore:
-      - 'webview-src/**'
-      - 'webview-dist/**'
-      - 'examples/**'
+
+concurrency:
+  group: ${{ github.workflow }}-${{ github.ref }}
+  cancel-in-progress: true
 
 jobs:
-  build-and-test:
-    runs-on: ${{ matrix.os }}
+  test:
     strategy:
       fail-fast: false
       matrix:
-        os: [ubuntu-latest, macos-latest, windows-latest]
-
-    steps:
-      - uses: actions/checkout@v3
+        platform: [ubuntu-latest, macos-latest, windows-latest]
 
-      - name: Install stable toolchain
-        uses: dtolnay/rust-toolchain@stable
-        with:
-          components: clippy
+    runs-on: ${{ matrix.platform }}
 
-      - name: Install Linux dependencies
-        if: matrix.os == 'ubuntu-latest'
+    steps:
+      - uses: actions/checkout@v4
+      - uses: dtolnay/rust-toolchain@stable
+      - name: install webkit2gtk
+        if: matrix.platform == 'ubuntu-latest'
         run: |
           sudo apt-get update
           sudo apt-get install -y webkit2gtk-4.1
-
       - uses: Swatinem/rust-cache@v2
-
-      - name: Run tests
-        run: cargo test --manifest-path=Cargo.toml --release
+      - run: cargo test --all-targets --all-features -- -D warnings
 {{{{/raw}}}}

+ 3 - 0
tooling/cli/templates/plugin/.gitignore

@@ -12,3 +12,6 @@ yarn.lock
 /target
 Cargo.lock
 node_modules/
+
+dist-js
+dist

+ 0 - 0
tooling/cli/templates/plugin/webview-src/index.ts → tooling/cli/templates/plugin/guest-js/index.ts


+ 21 - 13
tooling/cli/templates/plugin/package.json

@@ -3,23 +3,31 @@
   "version": "0.0.0",
   "author": "{{ author }}",
   "description": "",
-  "browser": "webview-dist/index.js",
-  "main": "webview-dist/index.js",
-  "types": "webview-dist/index.d.ts",
+  "type": "module",
+  "types": "./dist-js/index.d.ts",
+  "main": "./dist-js/index.cjs",
+  "module": "./dist-js/index.js",
+  "exports": {
+    "types": "./dist-js/index.d.ts",
+    "import": "./dist-js/index.js",
+    "require": "./dist-js/index.cjs"
+  },
+  "files": [
+    "dist-js",
+    "README.md"
+  ],
   "scripts": {
-    "build": "rollup -c ./webview-src/rollup.config.js",
+    "build": "rollup -c",
     "prepublishOnly": "yarn build",
     "pretest": "yarn build"
   },
-  "devDependencies": {
-    "@rollup/plugin-node-resolve": "13.3.0",
-    "@rollup/plugin-typescript": "8.3.3",
-    "@rollup/plugin-terser": "0.4.4",
-    "rollup": "2.75.6",
-    "typescript": "4.7.3"
-  },
   "dependencies": {
-    "@tauri-apps/api": "^2.0.0-alpha.11",
-    "tslib": "^2.1.0"
+    "@tauri-apps/api": ">=2.0.0-beta.6"
+  },
+  "devDependencies": {
+    "@rollup/plugin-typescript": "^11.1.6",
+    "rollup": "^4.9.6",
+    "typescript": "^5.3.3",
+    "tslib": "^2.6.2"
   }
 }

+ 31 - 0
tooling/cli/templates/plugin/rollup.config.js

@@ -0,0 +1,31 @@
+import { readFileSync } from 'fs'
+import { join } from 'path'
+import { cwd } from 'process'
+import typescript from '@rollup/plugin-typescript'
+
+const pkg = JSON.parse(readFileSync(join(cwd(), 'package.json'), 'utf8'))
+
+export default {
+  input: 'guest-js/index.ts',
+  output: [
+    {
+      file: pkg.exports.import,
+      format: 'esm'
+    },
+    {
+      file: pkg.exports.require,
+      format: 'cjs'
+    }
+  ],
+  plugins: [
+    typescript({
+      declaration: true,
+      declarationDir: `./${pkg.exports.import.split('/')[0]}`
+    })
+  ],
+  external: [
+    /^@tauri-apps\/api/,
+    ...Object.keys(pkg.dependencies || {}),
+    ...Object.keys(pkg.peerDependencies || {})
+  ]
+}

+ 14 - 0
tooling/cli/templates/plugin/tsconfig.json

@@ -0,0 +1,14 @@
+{
+  "compilerOptions": {
+    "target": "es2021",
+    "module": "esnext",
+    "moduleResolution": "bundler",
+    "skipLibCheck": true,
+    "strict": true,
+    "noUnusedLocals": true,
+    "noImplicitAny": true,
+    "noEmit": true
+  },
+  "include": ["guest-js/*.ts"],
+  "exclude": ["dist-js", "node_modules"]
+}

+ 0 - 1
tooling/cli/templates/plugin/webview-dist/index.d.ts

@@ -1 +0,0 @@
-export declare function execute(): Promise<void>

+ 0 - 0
tooling/cli/templates/plugin/webview-dist/index.js


+ 0 - 66
tooling/cli/templates/plugin/webview-src/.gitignore

@@ -1,66 +0,0 @@
-# Build output
-/dist
-/api
-
-
-# Logs
-logs
-*.log
-npm-debug.log*
-yarn-debug.log*
-yarn-error.log*
-
-# Runtime data
-pids
-*.pid
-*.seed
-*.pid.lock
-
-# Directory for instrumented libs generated by jscoverage/JSCover
-lib-cov
-
-# Coverage directory used by tools like istanbul
-coverage
-
-# nyc test coverage
-.nyc_output
-
-# node-waf configuration
-.lock-wscript
-
-# Compiled binary addons (http://nodejs.org/api/addons.html)
-build/Release
-
-# Dependency directories
-node_modules/
-jspm_packages/
-
-# Typescript v1 declaration files
-typings/
-
-# Optional npm cache directory
-.npm
-
-# Optional eslint cache
-.eslintcache
-
-# Optional REPL history
-.node_repl_history
-
-# Output of 'npm pack'
-*.tgz
-
-# Yarn Integrity file
-.yarn-integrity
-
-# dotenv environment variables file
-.env
-
-/.vs
-.DS_Store
-.Thumbs.db
-*.sublime*
-.idea/
-debug.log
-package-lock.json
-.vscode/settings.json

+ 0 - 21
tooling/cli/templates/plugin/webview-src/rollup.config.js

@@ -1,21 +0,0 @@
-import { nodeResolve } from '@rollup/plugin-node-resolve'
-import typescript from '@rollup/plugin-typescript'
-import  terser from '@rollup/plugin-terser'
-
-export default {
-  input: './webview-src/index.ts',
-  output: {
-    dir: './webview-dist',
-    entryFileNames: '[name].js',
-    format: 'es',
-    exports: 'auto'
-  },
-  plugins: [
-    nodeResolve(),
-    terser(),
-    typescript({
-      tsconfig: './webview-src/tsconfig.json',
-      moduleResolution: 'node'
-    })
-  ]
-}

+ 0 - 16
tooling/cli/templates/plugin/webview-src/tsconfig.json

@@ -1,16 +0,0 @@
-{
-  "compilerOptions": {
-    "target": "ES5",
-    "strict": true,
-    "allowJs": true,
-    "esModuleInterop": true,
-    "baseUrl": ".",
-    "paths": {
-      "types": ["@types"]
-    },
-    "declaration": true,
-    "declarationDir": "../webview-dist",
-    "rootDir": "./"
-  },
-  "include": ["./"]
-}