diff --git a/apps/figcraft-cli/src/files.rs b/apps/figcraft-cli/src/files.rs index 5e9176a5e..a84c6a4cf 100644 --- a/apps/figcraft-cli/src/files.rs +++ b/apps/figcraft-cli/src/files.rs @@ -309,6 +309,13 @@ fn folder_ids(doc: &Document, page: NodeId, target: Option) -> Vec CliResult { + let layout = t.layout.as_deref().filter(|l| *l != "flat"); + // A layout writes a folder: an image, `.fig` or `.penpot` file name would write something else. + if let Some(layout) = layout + && (image_format(&ext(out)).is_some() || matches!(ext(out).as_str(), "fig" | "penpot")) + { + return Err(CliError::Usage(format!("--layout {layout} writes a folder: give --out a folder, not {out}"))); + } let doc = load(file, io)?; // `.fig`: the whole file. if t.format.as_deref().map_or(ext(out) == "fig", |f| f.eq_ignore_ascii_case("fig")) { @@ -330,10 +337,7 @@ pub fn export(file: &str, out: &str, t: &Target, io: &mut Io) -> CliResult }; let target = node.map(|q| find_node(&doc, page, q)).transpose()?; let single = image_format(&ext(out)).is_some(); - if let Some(layout) = t.layout.as_deref().filter(|l| *l != "flat") { - if single { - return Err(CliError::Usage(format!("--layout {layout} writes a folder: give --out a folder, not {out}"))); - } + if let Some(layout) = layout { let ids = folder_ids(&doc, page, target); if ids.is_empty() { return Err(CliError::Failed("the page is empty: nothing to export".into())); @@ -343,6 +347,14 @@ pub fn export(file: &str, out: &str, t: &Target, io: &mut Io) -> CliResult for f in r["files"].as_array().into_iter().flatten() { outln!(io, "{}", f["path"].as_str().unwrap_or_default()); } + // The engine stops at its file limit; the layers past it were not written. + let skipped = r["skipped"].as_u64().unwrap_or(0); + if skipped > 0 { + return Err(CliError::Failed(format!( + "{skipped} of {} layers weren't written: too many files for one export (pick fewer with --node)", + ids.len() + ))); + } return Ok(0); } // The bytes and what an Android Vector Drawable changed or left out, like the .fig notes. diff --git a/apps/figcraft-cli/tests/it/cli.rs b/apps/figcraft-cli/tests/it/cli.rs index f199f35a7..f8ae705fd 100644 --- a/apps/figcraft-cli/tests/it/cli.rs +++ b/apps/figcraft-cli/tests/it/cli.rs @@ -241,8 +241,10 @@ fn export_layout_writes_an_app_projects_folders() { assert!(png.is_file(), "{png:?}"); } assert_eq!(String::from_utf8_lossy(&out.stdout).lines().count(), densities.len(), "one line per file written"); - let one = bin().arg("export").arg(&file).arg("-o").arg(d.join("icon.png")).args(["--layout", "ios"]).output().unwrap(); - assert!(!one.status.success() && !d.join("icon.png").exists(), "an image file is no folder for an image set"); + for one in ["icon.png", "icons.fig", "icons.penpot"] { + let r = bin().arg("export").arg(&file).arg("-o").arg(d.join(one)).args(["--layout", "ios"]).output().unwrap(); + assert!(!r.status.success() && !d.join(one).exists(), "{one} is no folder for an image set"); + } std::fs::remove_dir_all(&d).ok(); } diff --git a/crates/ui-egui/locales/en.toml b/crates/ui-egui/locales/en.toml index d942105cb..c40d05fa0 100644 --- a/crates/ui-egui/locales/en.toml +++ b/crates/ui-egui/locales/en.toml @@ -598,6 +598,7 @@ name = "English" "{m} min {s} s" = "{m} min {s} s" "{name} is not an image this app reads: {error}" = "{name} is not an image this app reads: {error}" "{n} layers as PNGs in an app project's folders" = { one = "{n} layer as PNGs in an app project's folders", other = "{n} layers as PNGs in an app project's folders" } +"{n} layers were left out: too many files for one export" = { one = "{n} layer was left out: too many files for one export", other = "{n} layers were left out: too many files for one export" } "{n} s" = "{n} s" "≈ ${cost} at API rates" = "≈ ${cost} at API rates" "⌘ click a padding field" = "⌘ click a padding field" diff --git a/crates/ui-egui/src/panels/export_panel.rs b/crates/ui-egui/src/panels/export_panel.rs index d56f99ec2..4e0f88704 100644 --- a/crates/ui-egui/src/panels/export_panel.rs +++ b/crates/ui-egui/src/panels/export_panel.rs @@ -470,31 +470,40 @@ pub(crate) fn export_layers(app: &mut FigApp, ids: &[NodeId], assets: bool) { /// Run `file.exportLayers` with `params` into a folder the user picks. No folders in the browser, /// and it lets a page start one download at a time: the files arrive together as one zip (#969). pub(crate) fn export_files(app: &mut FigApp, mut params: Value) { + let layout = params.get("layout").is_some(); if app.services.downloads() { let name = format!("{}.zip", app.session.doc().map_or("Export", |d| d.name.as_str())); params["zip"] = json!(true); if let Some(r) = app.run("file.exportLayers", params) && app.download(&name, &r) { - app.toast(trn("Exported {n} files", r["files"].as_array().map_or(0, Vec::len), &[])); + exported_toast(app, &r, layout); } return; } app.pick_folder(tr("Export"), move |app, dir| { params["dir"] = json!(dir.to_string_lossy()); if let Some(r) = app.run("file.exportLayers", params) { - let files = r["files"].as_array().cloned().unwrap_or_default(); - // Android Vector Drawables say what they changed or left out. - let changed = files.iter().any(|f| f["warnings"].as_array().is_some_and(|w| !w.is_empty())); - app.toast(if changed { - trn("Exported {n} files; some content was changed or left out", files.len(), &[]) - } else { - trn("Exported {n} files", files.len(), &[]) - }); + exported_toast(app, &r, layout); } }); } +/// What a `file.exportLayers` result `r` wrote. With a `layout`, the layers the engine's file +/// limit left out come first; Android Vector Drawables say what they changed or left out. +fn exported_toast(app: &mut FigApp, r: &Value, layout: bool) { + let files = r["files"].as_array().map_or(&[][..], Vec::as_slice); + let left_out = if layout { r["skipped"].as_u64().unwrap_or(0) as usize } else { 0 }; + let changed = files.iter().any(|f| f["warnings"].as_array().is_some_and(|w| !w.is_empty())); + app.toast(if left_out > 0 { + trn("{n} layers were left out: too many files for one export", left_out, &[]) + } else if changed { + trn("Exported {n} files; some content was changed or left out", files.len(), &[]) + } else { + trn("Exported {n} files", files.len(), &[]) + }); +} + /// Export `ids` together as one file with `setting`, through a save dialog suggesting `file`. pub(crate) fn save_one(app: &mut FigApp, ids: &[NodeId], setting: &ExportSetting, file: &str) { let ext = setting.format.ext(); diff --git a/docs/cli.md b/docs/cli.md index a529270a7..35a671d65 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -187,8 +187,10 @@ are identical. (`Home Icon` → `home_icon`): `flutter` writes `name.png`, `2.0x/name.png` and `3.0x/name.png`; `ios` an image set, `name.imageset/` with `name.png`, `name@2x.png`, `name@3x.png` and its `Contents.json`; `android` `drawable-mdpi/` to `drawable-xxxhdpi/` at 1x, 1.5x, 2x, 3x and 4x. - `flat` (the default) is the usual export. `` must be a folder, and `--format` and `--scale` - don't go with it. It is `file.exportLayers {layout}` (see `docs/mcp.md`). + `flat` (the default) is the usual export. `` must be a folder (an image, `.fig` or `.penpot` + name is a usage error), and `--format` and `--scale` don't go with it. One export writes at most + 1000 files: past that, the error says how many layers were left out and the exit code is 1. It is + `file.exportLayers {layout}` (see `docs/mcp.md`). - The format comes from `--format`, else ``'s extension, else png. `--scale` (default 1, max 64) applies to raster formats. - SVG/PDF/XML exports with visible descendants more than 256 levels below an exported root fail with