mirror of
https://github.com/penpot/penpot.git
synced 2025-07-28 11:47:23 +02:00
🎉 Add support for progress reporting to library export method
This commit is contained in:
parent
27d2724153
commit
644dd9ff44
4 changed files with 79 additions and 23 deletions
|
@ -1,5 +1,10 @@
|
||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
|
||||||
|
## 1.0.5
|
||||||
|
|
||||||
|
- Add progress reporting support
|
||||||
|
- Remove leaked console.log
|
||||||
|
|
||||||
## 1.0.4
|
## 1.0.4
|
||||||
|
|
||||||
- Fix incorrect shapes filtering on creating boolean shapes within components
|
- Fix incorrect shapes filtering on creating boolean shapes within components
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@penpot/library",
|
"name": "@penpot/library",
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"author": "Kaleidos INC",
|
"author": "Kaleidos INC",
|
||||||
"packageManager": "yarn@4.9.1+sha512.f95ce356460e05be48d66401c1ae64ef84d163dd689964962c6888a9810865e39097a5e9de748876c2e0bf89b232d583c33982773e9903ae7a76257270986538",
|
"packageManager": "yarn@4.9.1+sha512.f95ce356460e05be48d66401c1ae64ef84d163dd689964962c6888a9810865e39097a5e9de748876c2e0bf89b232d583c33982773e9903ae7a76257270986538",
|
||||||
|
|
|
@ -80,7 +80,11 @@ import { Writable } from "stream";
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let result = await penpot.exportAsBytes(context);
|
const onProgress = (opts) => {
|
||||||
|
console.log(`Procesing ${opts.item}/${opts.total}: ${opts.path}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
let result = await penpot.exportAsBytes(context, {onProgress});
|
||||||
await writeFile("sample-sync.zip", result);
|
await writeFile("sample-sync.zip", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -195,31 +195,78 @@
|
||||||
:relations []}]
|
:relations []}]
|
||||||
["manifest.json" (delay (json/encode params))]))
|
["manifest.json" (delay (json/encode params))]))
|
||||||
|
|
||||||
(defn- export
|
(defn- generate-procs
|
||||||
[state writer]
|
[state]
|
||||||
(->> (p/reduce (fn [writer [path data]]
|
(let [state (deref state)]
|
||||||
(let [data (if (delay? data) (deref data) data)]
|
(cons (generate-manifest-procs state)
|
||||||
(js/console.log "export" path)
|
|
||||||
(->> (zip/add writer path data)
|
|
||||||
(p/fmap (constantly writer)))))
|
|
||||||
|
|
||||||
writer
|
|
||||||
(cons (generate-manifest-procs @state)
|
|
||||||
(concat
|
(concat
|
||||||
(generate-files-export-procs @state)
|
(generate-files-export-procs state)
|
||||||
(generate-media-export-procs @state))))
|
(generate-media-export-procs state)))))
|
||||||
|
|
||||||
|
(def ^:private
|
||||||
|
xf:add-proc-index
|
||||||
|
(map-indexed
|
||||||
|
(fn [index proc]
|
||||||
|
(conj proc index))))
|
||||||
|
|
||||||
|
(def ^:private ^:function noop-fn
|
||||||
|
(constantly nil))
|
||||||
|
|
||||||
|
(defn- export
|
||||||
|
[state writer progress-fn]
|
||||||
|
(let [procs (into [] xf:add-proc-index (generate-procs state))
|
||||||
|
total (count procs)]
|
||||||
|
(->> (p/reduce (fn [writer [path data index]]
|
||||||
|
(let [data (if (delay? data) (deref data) data)
|
||||||
|
report #js {:total total
|
||||||
|
:item (inc index)
|
||||||
|
:path path}]
|
||||||
|
(->> (zip/add writer path data)
|
||||||
|
(p/fmap (fn [_]
|
||||||
|
(progress-fn report)
|
||||||
|
writer)))))
|
||||||
|
writer
|
||||||
|
procs)
|
||||||
(p/mcat (fn [writer]
|
(p/mcat (fn [writer]
|
||||||
(zip/close writer)))))
|
(zip/close writer))))))
|
||||||
|
|
||||||
(defn export-bytes
|
(defn export-bytes
|
||||||
[state]
|
([state]
|
||||||
(export state (zip/writer (zip/bytes-writer))))
|
(export state (zip/writer (zip/bytes-writer)) noop-fn))
|
||||||
|
([state options]
|
||||||
|
(let [options
|
||||||
|
(if (object? options)
|
||||||
|
(json/->clj options)
|
||||||
|
options)
|
||||||
|
|
||||||
|
progress-fn
|
||||||
|
(get options :on-progress noop-fn)]
|
||||||
|
|
||||||
|
(export state (zip/writer (zip/bytes-writer)) progress-fn))))
|
||||||
|
|
||||||
(defn export-blob
|
(defn export-blob
|
||||||
[state]
|
([state]
|
||||||
(export state (zip/writer (zip/blob-writer))))
|
(export state (zip/writer (zip/blob-writer)) noop-fn))
|
||||||
|
([state options]
|
||||||
|
(let [options
|
||||||
|
(if (object? options)
|
||||||
|
(json/->clj options)
|
||||||
|
options)
|
||||||
|
|
||||||
|
progress-fn
|
||||||
|
(get options :on-progress noop-fn)]
|
||||||
|
|
||||||
|
(export state (zip/writer (zip/blob-writer)) progress-fn))))
|
||||||
|
|
||||||
(defn export-stream
|
(defn export-stream
|
||||||
[state stream]
|
([state stream]
|
||||||
(export state (zip/writer stream)))
|
(export state (zip/writer stream) noop-fn))
|
||||||
|
([state stream options]
|
||||||
|
(let [options
|
||||||
|
(if (object? options)
|
||||||
|
(json/->clj options)
|
||||||
|
options)
|
||||||
|
|
||||||
|
progress-fn
|
||||||
|
(get options :on-progress noop-fn)]
|
||||||
|
(export state (zip/writer stream) progress-fn))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue