mirror of
https://github.com/penpot/penpot.git
synced 2026-10-29 14:00:37 +00:00
The file builder behind @penpot/library pinned the features and migrations it writes to the ones Penpot 2.7 accepted, so its files could open there. It now writes the current defaults: the features a new file gets and every available migration. Generated files were already in the current format (paths, for one, are stored as path data), so they now declare fdata/path-data and components/swap-group as they should, and the import runs no migration on them. Files built this way need the Penpot version the library is built with, or a later one. AI-assisted-by: claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Penpot Library
A library that exposes a limited set of Penpot's features for programmatic use. Currently, it provides methods to build Penpot files in memory and export them as .penpot files (ZIP archives containing all the necessary data to import them into a Penpot application).
User Guide
How to install
pnpm add @penpot/library
Example of use
import * as penpot from "@penpot/library";
import { createWriteStream } from 'fs';
import { Writable } from "stream";
const context = penpot.createBuildContext();
context.addFile({name: "Test File 1"});
context.addPage({name: "Foo Page"});
context.addBoard({
name: "Foo Board",
x: 0,
y: 0,
width: 500,
height: 300,
});
context.closeBoard();
context.closeFile();
// Create a file stream to write the zip to
const output = createWriteStream('sample-stream.zip');
// Wrap Node's stream in a WHATWG WritableStream
const writable = Writable.toWeb(output);
await penpot.exportStream(context, writable);
Developer Guide
How to publish
Build the library:
./scripts/build
Login on npm:
npm login
Publish on npm:
npm publish --access public
License
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
Copyright (c) KALEIDOS SUBSIDIARY SL