mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 13:37:09 +00:00
parent
ec79e075a9
commit
715cbde384
7
.changes/config-$schema.md
Normal file
7
.changes/config-$schema.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
"tauri-utils": patch
|
||||
"cli.rs": patch
|
||||
"cli.js": patch
|
||||
---
|
||||
|
||||
Added `$schema` support to `tauri.conf.json`.
|
||||
@ -2125,6 +2125,9 @@ impl PackageConfig {
|
||||
#[cfg_attr(feature = "schema", derive(JsonSchema))]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct Config {
|
||||
/// The JSON schema for the Tauri config.
|
||||
#[serde(rename = "$schema")]
|
||||
pub schema: Option<String>,
|
||||
/// Package settings.
|
||||
#[serde(default)]
|
||||
pub package: PackageConfig,
|
||||
@ -2887,12 +2890,13 @@ mod build {
|
||||
|
||||
impl ToTokens for Config {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
let schema = quote!(None);
|
||||
let package = &self.package;
|
||||
let tauri = &self.tauri;
|
||||
let build = &self.build;
|
||||
let plugins = &self.plugins;
|
||||
|
||||
literal_struct!(tokens, Config, package, tauri, build, plugins);
|
||||
literal_struct!(tokens, Config, schema, package, tauri, build, plugins);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@ pub fn noop_assets() -> NoopAsset {
|
||||
pub fn mock_context<A: Assets>(assets: A) -> crate::Context<A> {
|
||||
crate::Context {
|
||||
config: Config {
|
||||
schema: None,
|
||||
package: Default::default(),
|
||||
tauri: TauriConfig {
|
||||
pattern: PatternKind::Brownfield,
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../../../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": "../dist",
|
||||
"devPath": "http://localhost:4000"
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": [],
|
||||
"devPath": []
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": "../dist",
|
||||
"devPath": "http://localhost:5000",
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": ["index.html"],
|
||||
"devPath": ["index.html"],
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": ["index.html"],
|
||||
"devPath": ["index.html"],
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../tooling/cli/schema.json",
|
||||
"package": {
|
||||
"productName": "isolation",
|
||||
"version": "0.1.0"
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": ["index.html"],
|
||||
"devPath": ["index.html"],
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": "public",
|
||||
"devPath": "public",
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": ["index.html"],
|
||||
"devPath": ["index.html"],
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": ["../index.html"],
|
||||
"devPath": ["../index.html"],
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": ["../index.html"],
|
||||
"devPath": ["../index.html"],
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": "dist",
|
||||
"devPath": "dist",
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": ["index.html"],
|
||||
"devPath": ["index.html"],
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": ["index.html"],
|
||||
"devPath": ["index.html"],
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": ["src/index.html"],
|
||||
"devPath": ["src/index.html"],
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": ["../index.html"],
|
||||
"devPath": ["../index.html"],
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../../../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": "../public",
|
||||
"devPath": "../public",
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../../../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": "../public",
|
||||
"devPath": "../public",
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../../../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"distDir": "../public",
|
||||
"devPath": "../public",
|
||||
|
||||
3
tooling/cli/node/.gitignore
vendored
3
tooling/cli/node/.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
# Automatically generated
|
||||
/*.node
|
||||
/*.node
|
||||
schema.json
|
||||
|
||||
@ -38,6 +38,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@napi-rs/cli": "2.7.0",
|
||||
"cross-env": "7.0.3",
|
||||
"cross-spawn": "7.0.3",
|
||||
"fs-extra": "10.1.0",
|
||||
"jest": "28.0.3",
|
||||
@ -52,9 +53,10 @@
|
||||
},
|
||||
"scripts": {
|
||||
"artifacts": "napi artifacts",
|
||||
"build:release": "napi build --platform --release",
|
||||
"build": "napi build --platform",
|
||||
"build:release": "cross-env TARGET=node napi build --platform --release",
|
||||
"build": "cross-env TARGET=node napi build --platform",
|
||||
"prepublishOnly": "napi prepublish -t npm",
|
||||
"prepack": "cp ../schema.json .",
|
||||
"test": "jest --runInBand --forceExit --no-cache",
|
||||
"version": "napi version",
|
||||
"tauri": "node ./tauri.js",
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"$schema": "../../../../../../../../tooling/cli/schema.json",
|
||||
"build": {
|
||||
"devPath": "../dist",
|
||||
"distDir": "../dist",
|
||||
|
||||
@ -1041,7 +1041,14 @@ convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
|
||||
dependencies:
|
||||
safe-buffer "~5.1.1"
|
||||
|
||||
cross-spawn@7.0.3, cross-spawn@^7.0.3:
|
||||
cross-env@^7.0.3:
|
||||
version "7.0.3"
|
||||
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf"
|
||||
integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==
|
||||
dependencies:
|
||||
cross-spawn "^7.0.1"
|
||||
|
||||
cross-spawn@7.0.3, cross-spawn@^7.0.1, cross-spawn@^7.0.3:
|
||||
version "7.0.3"
|
||||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
|
||||
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
|
||||
|
||||
@ -4,6 +4,13 @@
|
||||
"description": "The config type mapped to `tauri.conf.json`.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"$schema": {
|
||||
"description": "The JSON schema for the Tauri config.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
"description": "The build configuration.",
|
||||
"default": {
|
||||
|
||||
@ -27,6 +27,7 @@ use include_dir::{include_dir, Dir};
|
||||
use serde::Deserialize;
|
||||
|
||||
const TEMPLATE_DIR: Dir<'_> = include_dir!("templates/app");
|
||||
const TAURI_CONF_TEMPLATE: &str = include_str!("../templates/tauri.conf.json");
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(about = "Initializes a Tauri project")]
|
||||
@ -185,6 +186,56 @@ pub fn command(mut options: Options) -> Result<()> {
|
||||
to_json(options.window_title.unwrap_or_else(|| "Tauri".to_string())),
|
||||
);
|
||||
|
||||
let mut config = serde_json::from_str(
|
||||
&handlebars
|
||||
.render_template(TAURI_CONF_TEMPLATE, &data)
|
||||
.expect("Failed to render tauri.conf.json template"),
|
||||
)
|
||||
.unwrap();
|
||||
if crate::TARGET == Some("node") {
|
||||
let mut dir = current_dir().expect("failed to read cwd");
|
||||
let mut count = 0;
|
||||
let mut cli_node_module_path = None;
|
||||
let cli_path = "node_modules/@tauri-apps/cli";
|
||||
|
||||
// only go up three folders max
|
||||
while count <= 2 {
|
||||
let test_path = dir.join(cli_path);
|
||||
if test_path.exists() {
|
||||
let mut node_module_path = PathBuf::from("..");
|
||||
for _ in 0..count {
|
||||
node_module_path.push("..");
|
||||
}
|
||||
node_module_path.push(cli_path);
|
||||
node_module_path.push("schema.json");
|
||||
cli_node_module_path.replace(node_module_path);
|
||||
break;
|
||||
}
|
||||
count += 1;
|
||||
match dir.parent() {
|
||||
Some(parent) => {
|
||||
dir = parent.to_path_buf();
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(cli_node_module_path) = cli_node_module_path {
|
||||
let mut map = serde_json::Map::default();
|
||||
map.insert(
|
||||
"$schema".into(),
|
||||
serde_json::Value::String(cli_node_module_path.display().to_string()),
|
||||
);
|
||||
let merge_config = serde_json::Value::Object(map);
|
||||
json_patch::merge(&mut config, &merge_config);
|
||||
}
|
||||
}
|
||||
|
||||
data.insert(
|
||||
"tauri_config",
|
||||
to_json(serde_json::to_string_pretty(&config).unwrap()),
|
||||
);
|
||||
|
||||
template::render(&handlebars, &data, &TEMPLATE_DIR, &options.directory)
|
||||
.with_context(|| "failed to render Tauri template")?;
|
||||
}
|
||||
|
||||
@ -17,6 +17,8 @@ use clap::{FromArgMatches, IntoApp, Parser, Subcommand};
|
||||
|
||||
use std::ffi::OsString;
|
||||
|
||||
const TARGET: Option<&str> = option_env!("TARGET");
|
||||
|
||||
pub(crate) trait CommandExt {
|
||||
fn pipe(&mut self) -> Result<&mut Self>;
|
||||
}
|
||||
|
||||
@ -1,65 +1 @@
|
||||
{
|
||||
"package": {
|
||||
"productName": "{{ app_name }}",
|
||||
"version": "0.1.0"
|
||||
},
|
||||
"build": {
|
||||
"distDir": "{{ dist_dir }}",
|
||||
"devPath": "{{ dev_path }}",
|
||||
"beforeDevCommand": "",
|
||||
"beforeBuildCommand": ""
|
||||
},
|
||||
"tauri": {
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"identifier": "com.tauri.dev",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
],
|
||||
"resources": [],
|
||||
"externalBin": [],
|
||||
"copyright": "",
|
||||
"category": "DeveloperTool",
|
||||
"shortDescription": "",
|
||||
"longDescription": "",
|
||||
"deb": {
|
||||
"depends": []
|
||||
},
|
||||
"macOS": {
|
||||
"frameworks": [],
|
||||
"exceptionDomain": "",
|
||||
"signingIdentity": null,
|
||||
"providerShortName": null,
|
||||
"entitlements": null
|
||||
},
|
||||
"windows": {
|
||||
"certificateThumbprint": null,
|
||||
"digestAlgorithm": "sha256",
|
||||
"timestampUrl": ""
|
||||
}
|
||||
},
|
||||
"updater": {
|
||||
"active": false
|
||||
},
|
||||
"allowlist": {
|
||||
"all": true
|
||||
},
|
||||
"windows": [
|
||||
{
|
||||
"title": "{{ window_title }}",
|
||||
"width": 800,
|
||||
"height": 600,
|
||||
"resizable": true,
|
||||
"fullscreen": false
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": null
|
||||
}
|
||||
}
|
||||
}
|
||||
{{{ tauri_config }}}
|
||||
|
||||
65
tooling/cli/templates/tauri.conf.json
Normal file
65
tooling/cli/templates/tauri.conf.json
Normal file
@ -0,0 +1,65 @@
|
||||
{
|
||||
"package": {
|
||||
"productName": "{{ app_name }}",
|
||||
"version": "0.1.0"
|
||||
},
|
||||
"build": {
|
||||
"distDir": "{{ dist_dir }}",
|
||||
"devPath": "{{ dev_path }}",
|
||||
"beforeDevCommand": "",
|
||||
"beforeBuildCommand": ""
|
||||
},
|
||||
"tauri": {
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"identifier": "com.tauri.dev",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
],
|
||||
"resources": [],
|
||||
"externalBin": [],
|
||||
"copyright": "",
|
||||
"category": "DeveloperTool",
|
||||
"shortDescription": "",
|
||||
"longDescription": "",
|
||||
"deb": {
|
||||
"depends": []
|
||||
},
|
||||
"macOS": {
|
||||
"frameworks": [],
|
||||
"exceptionDomain": "",
|
||||
"signingIdentity": null,
|
||||
"providerShortName": null,
|
||||
"entitlements": null
|
||||
},
|
||||
"windows": {
|
||||
"certificateThumbprint": null,
|
||||
"digestAlgorithm": "sha256",
|
||||
"timestampUrl": ""
|
||||
}
|
||||
},
|
||||
"updater": {
|
||||
"active": false
|
||||
},
|
||||
"allowlist": {
|
||||
"all": true
|
||||
},
|
||||
"windows": [
|
||||
{
|
||||
"title": "{{ window_title }}",
|
||||
"width": 800,
|
||||
"height": 600,
|
||||
"resizable": true,
|
||||
"fullscreen": false
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": null
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user