2021-12-28 11:03:28 +01:00
|
|
|
---
|
|
|
|
title: FreeSewing in NodeJS
|
|
|
|
---
|
|
|
|
|
|
|
|
These instructions explain how you can generate patterns in NodeJS.
|
|
|
|
Whether it's in a backend application or on the command line, all
|
|
|
|
it takes is a few lines of code — and a couple of dependencies — to
|
|
|
|
generate a pattern.
|
|
|
|
|
|
|
|
<Tip>
|
|
|
|
|
|
|
|
##### Use FreeSewing.org if you just want a pattern
|
|
|
|
|
|
|
|
These instructions are intended for people who want to generate
|
2022-02-20 14:35:50 +01:00
|
|
|
their own patterns. If you _just want a sewing pattern_ you can
|
2021-12-28 11:03:28 +01:00
|
|
|
get all our designs on [FreeSewing.org](https://FreeSewing.org/),
|
|
|
|
our website for makers.
|
|
|
|
|
|
|
|
</Tip>
|
|
|
|
|
|
|
|
## High level overview
|
|
|
|
|
|
|
|
To generate a pattern, you will need to:
|
|
|
|
|
2022-02-20 14:44:38 +01:00
|
|
|
- Instantiate the pattern (`new ...`)
|
|
|
|
- Pass it the settings and measurements you want to use (`{ ... }`)
|
|
|
|
- Load the theme plugin (using `use()`)
|
|
|
|
- Draft the pattern (using `draft()`)
|
|
|
|
- Render it to SVG (using `render()`)
|
2021-12-28 11:03:28 +01:00
|
|
|
|
|
|
|
Which can be done as a one-liner since `use()`, `draft()` and
|
|
|
|
`render()` are all chainable, as shown below.
|
|
|
|
|
|
|
|
## Code example
|
|
|
|
|
|
|
|
```js
|
|
|
|
import Aaron from '@freesewing/aaron' // Design to use
|
|
|
|
import theme from '@freesewing/plugin-theme' // SVG theme
|
|
|
|
|
|
|
|
const svg = new Aaron( // Instantiate pattern
|
|
|
|
{ // Pass in settings. See reference > core > settings
|
|
|
|
sa: 10, // Seam allowance
|
|
|
|
// ...
|
|
|
|
measurements: { // Pass in measurements
|
|
|
|
biceps: 387,
|
|
|
|
chest: 1105,
|
|
|
|
hips: 928,
|
|
|
|
hpsToWaistBack: 502,
|
|
|
|
neck: 420,
|
|
|
|
shoulderSlope: 13,
|
|
|
|
shoulderToShoulder: 481,
|
|
|
|
waistToHips: 139,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.use(theme) // Load theme plugin
|
|
|
|
.draft() // Draft the pattern
|
|
|
|
.render() // Render to SVG
|
|
|
|
|
|
|
|
// svg now holds the generated SVG code
|
|
|
|
console.log(svg)
|
|
|
|
```
|
|
|
|
|
|
|
|
<Note>
|
|
|
|
|
|
|
|
##### Remarks on the example code
|
|
|
|
|
2022-02-20 14:44:38 +01:00
|
|
|
- We are using `@freesewing/aaron` as the design, but you could use any design
|
|
|
|
- You probably want to [use your own measurements](/reference/api/settings/measurements)
|
|
|
|
or you could use `@freesewing/models` to load measurements from [our sizing grid](https://freesewing.org/sizes/)
|
|
|
|
- We are using `@freesewing/plugin-theme` to theme our SVG, but you
|
|
|
|
could [pass in your own CSS](/guides/plugins/using-hooks-without-plugin)
|
2021-12-28 11:03:28 +01:00
|
|
|
|
|
|
|
</Note>
|
|
|
|
|
|
|
|
## Dependencies
|
|
|
|
|
|
|
|
The code above will only work if you've got the required dependencies installed on your system.
|
|
|
|
Obviously you need NodeJS, but you will also need the following packages:
|
|
|
|
|
2022-02-20 14:44:38 +01:00
|
|
|
- `@freesewing/core`: Our core library
|
|
|
|
- `@freesewing/plugin-bundle`: Set of common plugins
|
|
|
|
- `@freesewing/aaron` or any design you want to use
|
|
|
|
- Any design on which the design you choose is built. In this case, Aaron depends on `@freesewing/brian`
|
|
|
|
- `@freesewing/utils`
|
2021-12-28 11:03:28 +01:00
|
|
|
|
|
|
|
For the example above, your `package.json` **dependencies** section will look like this:
|
|
|
|
|
|
|
|
```json
|
|
|
|
"dependencies": {
|
|
|
|
"@freesewing/core": "latest"
|
|
|
|
"@freesewing/aaron": "latest",
|
|
|
|
"@freesewing/brian": "latest",
|
|
|
|
"@freesewing/models": "latest",
|
|
|
|
"@freesewing/plugin-bundle": "latest",
|
|
|
|
"@freesewing/plugin-theme": "latest",
|
|
|
|
"@freesewing/utils": "latest"
|
|
|
|
}
|
|
|
|
```
|