fix(cli.rs): tauri.conf.json > tauri > bundle > targets being ignored (#1945)

* fix(cli.rs): `tauri.conf.json > tauri > bundle > targets` being ignored

* fix: cli.ts run
This commit is contained in:
Lucas Fernandes Nogueira
2021-06-04 00:57:00 -03:00
committed by GitHub
parent ae745189f9
commit 8be35ced78
6 changed files with 45 additions and 14 deletions

View File

@@ -0,0 +1,5 @@
---
"cli.js": patch
---
Allow empty argument when running `cli.rs`.

View File

@@ -0,0 +1,5 @@
---
"cli.rs": patch
---
Fixes `tauri.conf.json > tauri > bundle > targets` not applying to the bundler.

View File

@@ -20,9 +20,9 @@ function toKebabCase(value: string): string {
.toLowerCase()
}
async function runCliCommand(command: string, args: Args): Promise<Cmd> {
async function runCliCommand(command: string, args?: Args): Promise<Cmd> {
const argsArray = []
for (const [argName, argValue] of Object.entries(args)) {
for (const [argName, argValue] of Object.entries(args ?? {})) {
if (argValue === false) {
continue
}
@@ -37,9 +37,9 @@ async function runCliCommand(command: string, args: Args): Promise<Cmd> {
return await runOnRustCli(command, argsArray)
}
export const init = async (args: Args): Promise<Cmd> =>
export const init = async (args?: Args): Promise<Cmd> =>
await runCliCommand('init', args)
export const dev = async (args: Args): Promise<Cmd> =>
export const dev = async (args?: Args): Promise<Cmd> =>
await runCliCommand('dev', args)
export const build = async (args: Args): Promise<Cmd> =>
export const build = async (args?: Args): Promise<Cmd> =>
await runCliCommand('build', args)

View File

@@ -30,15 +30,7 @@ describe('[CLI] cli.js template', () => {
`workspace = { }\n[patch.crates-io]\ntao = { git = "https://github.com/tauri-apps/tao", rev = "a3f533232df25dc30998809094ed5431b449489c" }\n\n${manifestFile}`
)
const { promise: buildPromise } = await build({
config: {
tauri: {
bundle: {
targets: ['deb', 'app', 'msi', 'appimage'] // we can't bundle dmg on CI so we remove it here
}
}
}
})
const { promise: buildPromise } = await build()
await buildPromise
process.chdir(cwd)
})

View File

@@ -18,6 +18,16 @@ pub enum BundleTarget {
One(String),
}
impl BundleTarget {
#[allow(dead_code)]
pub fn to_vec(&self) -> Vec<String> {
match self {
Self::All(list) => list.clone(),
Self::One(i) => vec![i.clone()],
}
}
}
#[skip_serializing_none]
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]

View File

@@ -192,6 +192,25 @@ impl Build {
}
settings_builder = settings_builder.package_types(types);
} else if let Some(targets) = &config_.tauri.bundle.targets {
let mut types = vec![];
let targets = targets.to_vec();
if !targets.contains(&"all".into()) {
for name in targets {
match PackageType::from_short_name(&name) {
Some(package_type) => {
types.push(package_type);
}
None => {
return Err(anyhow::anyhow!(format!(
"Unsupported bundle format: {}",
name
)));
}
}
}
settings_builder = settings_builder.package_types(types);
}
}
// Bundle the project