https://github.com/freesewing/pattern-via-io
An example of a stdin -> freesewing -> stdout pipeline
https://github.com/freesewing/pattern-via-io
Last synced: 11 days ago
JSON representation
An example of a stdin -> freesewing -> stdout pipeline
- Host: GitHub
- URL: https://github.com/freesewing/pattern-via-io
- Owner: freesewing
- Created: 2023-06-06T18:56:34.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-15T07:15:45.000Z (over 2 years ago)
- Last Synced: 2025-03-02T03:14:54.171Z (over 1 year ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Example of a STDIN → FreeSewing → STDOUT pipeline
This repository was setup to answer this question (paraphrased):
> I am a Python dev. How can I use FreeSewing when I have a bunch of settings and all I want is an SVG?
To use FreeSewing in a different environment, there are various technical solutions, but the simplest approach is to push your settings as JSON to the `stdin` of a NodeJS script that will then read the settings from `stdin`, parse them as JSON, generate the pattern, and then dump the resulting SVG to `stdout`.
This repo holds an example of how to do that (in `src/index.mjs`) and some further instructions below.
## Getting started
To try this at home, you will need NodeJS on your system.
Assuming you do, you can clone this repository, cd into it, and install dependencies.
```sh
git clone git@github.com:freesewing/pattern-via-io.git
cd pattern-via-io
npm install
```
Once the dependencies are installed you can run this to try it:
```
cat example-settings.json | node generate-pattern.mjs
```
Or to save it to a file:
```
cat example-settings.json | node generate-pattern.mjs > pattern.svg
```
You can find the `pattern.svg` generated by the example above in this repository.
## Using a different design
This example uses `@freesewing/aaron` which extends `@freesewing/brian`.
If you want to use a different design (for example simon) you should install it:
```
npm i --save @freesewing/simon@next
```
And then change the import in the script.
> **Note:** The `@next` suffix is required until v3 is in GA.
## Accessing pattern data, rather then generating an SVG
If you want to interact with the resulting pattern in programmatic way --
rather than just get the SVG -- you can run this:
```
cat example-settings.json | node generate-json.mjs
```
It will dump (by default) the parts as JSON, which contain all parts with their points and paths.
However, you can access any pattern data by adapting the `generate-json.mjs` example.
The relevant lines are:
```mjs
const data = pattern.getRenderProps()
console.log(JSON.stringify(data.parts, null, 2))
```
## Questions?
Join us on Discord at [discord.freesewing.org](https://discord.freesewing.org).