fix(cli): invalid plugin template (#8161)

This commit is contained in:
Lucas Fernandes Nogueira 2023-11-07 22:56:21 -03:00 committed by GitHub
parent fc571ea2ce
commit bfbbefdb9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 81 additions and 62 deletions

View File

@ -0,0 +1,6 @@
---
"@tauri-apps/cli": patch:bug
"tauri-cli": patch:bug
---
Fix invalid plugin template.

View File

@ -5,38 +5,35 @@
import { defineConfig } from 'vite'
import Unocss from 'unocss/vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { internalIpV4 } from 'internal-ip'
import { internalIpV4Sync } from 'internal-ip'
const mobile = !!/android|ios/.exec(process.env.TAURI_ENV_PLATFORM)
// https://vitejs.dev/config/
export default defineConfig(async ({ command, mode }) => {
const host =
process.env.TAURI_ENV_PLATFORM === 'android' ||
process.env.TAURI_ENV_PLATFORM === 'ios'
? await internalIpV4()
: 'localhost'
return {
plugins: [Unocss(), svelte()],
build: {
rollupOptions: {
output: {
entryFileNames: `assets/[name].js`,
chunkFileNames: `assets/[name].js`,
assetFileNames: `assets/[name].[ext]`
export default defineConfig({
plugins: [Unocss(), svelte()],
build: {
rollupOptions: {
output: {
entryFileNames: `assets/[name].js`,
chunkFileNames: `assets/[name].js`,
assetFileNames: `assets/[name].[ext]`
}
}
},
server: {
host: mobile ? '0.0.0.0' : false,
port: 5173,
strictPort: true,
hmr: mobile
? {
protocol: 'ws',
host: internalIpV4Sync(),
port: 5183
}
}
},
server: {
host: '0.0.0.0',
port: 5173,
strictPort: true,
hmr: {
protocol: 'ws',
host,
port: 5183
},
fs: {
allow: ['.', '../../tooling/api/dist']
}
: undefined,
fs: {
allow: ['.', '../../tooling/api/dist']
}
}
})

View File

@ -68,6 +68,7 @@ pub fn command(cli: Cli) -> Result<()> {
let mut data = BTreeMap::new();
super::init::plugin_name_data(&mut data, &plugin_name);
data.insert("android_package_id", handlebars::to_json(&plugin_id));
let mut created_dirs = Vec::new();
template::render_with_generator(

View File

@ -10,13 +10,14 @@
"tauri": "tauri"
},
"dependencies": {
"@tauri-apps/api": "^1.1.0",
"@tauri-apps/api": "^2.0.0-alpha.11",
"tauri-plugin-{{ plugin_name }}-api": "link:../../"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^1.0.1",
"internal-ip": "^7.0.0",
"svelte": "^3.49.0",
"vite": "^3.0.2",
"@tauri-apps/cli": "^1.1.0"
"@tauri-apps/cli": "^2.0.0-alpha.17"
}
}
}

View File

@ -8,6 +8,10 @@ repository = ""
edition = "2021"
rust-version = "1.70"
[lib]
name = "tauri_app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]

View File

@ -0,0 +1,14 @@
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
.plugin(tauri_plugin_{{ plugin_name_snake_case }}::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -1,16 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
.plugin(tauri_plugin_{{ plugin_name_snake_case }}::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
tauri_app_lib::run();
}

View File

@ -1,5 +1,8 @@
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { internalIpV4Sync } from 'internal-ip'
const mobile = !!/android|ios/.exec(process.env.TAURI_ENV_PLATFORM);
// https://vitejs.dev/config/
export default defineConfig({
@ -10,18 +13,13 @@ export default defineConfig({
clearScreen: false,
// tauri expects a fixed port, fail if that port is not available
server: {
host: mobile ? "0.0.0.0" : false,
port: 1420,
strictPort: true,
hmr: mobile ? {
protocol: 'ws',
host: internalIpV4Sync(),
port: 1421
} : undefined,
},
// to make use of `TAURI_ENV_DEBUG` and other env variables
// https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
envPrefix: ["VITE_", "TAURI_ENV_"],
build: {
// Tauri supports es2021
target: ["es2021", "chrome100", "safari13"],
// don't minify for debug builds
minify: !process.env.TAURI_ENV_DEBUG ? "esbuild" : false,
// produce sourcemaps for debug builds
sourcemap: !!process.env.TAURI_ENV_DEBUG,
},
});
})

View File

@ -9,6 +9,6 @@
"author": "",
"license": "MIT",
"dependencies": {
"@tauri-apps/cli": "^1.0.0"
"@tauri-apps/cli": "^2.0.0-alpha.17"
}
}

View File

@ -8,6 +8,10 @@ repository = ""
edition = "2021"
rust-version = "1.70"
[lib]
name = "tauri_app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]

View File

@ -0,0 +1,7 @@
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_{{ plugin_name_snake_case }}::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -2,8 +2,5 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_{{ plugin_name_snake_case }}::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
tauri_app_lib::run();
}

View File

@ -19,7 +19,7 @@
"typescript": "4.7.3"
},
"dependencies": {
"@tauri-apps/api": "^1.0.0",
"@tauri-apps/api": "^2.0.0-alpha.11",
"tslib": "^2.1.0"
}
}

View File

@ -1,4 +1,4 @@
{#if license_header}}
{{#if license_header}}
{{ license_header }}
{{/if}}
import { invoke } from '@tauri-apps/api/primitives'