-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-json.mjs
35 lines (28 loc) · 1.11 KB
/
generate-json.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// NodeJS own process module to read from stdin
import process from 'process'
// Import a design (aaron is our go-to example but any will do)
import { Aaron } from '@freesewing/aaron'
// import the theme plugin, this will add styling to the SVG
// Create your own if you'd like to apply your own branding
import { pluginTheme as theme } from '@freesewing/plugin-theme'
// Create an array to push our input onto
const input = []
// Setup stdin
process.stdin.resume()
process.stdin.setEncoding('utf-8')
// Read data
process.stdin.on('data', chunk => input.push(chunk))
// Ready, now do something with it
process.stdin.on('end', () => {
// Join chunks into a string and parse as JSON
const settings = JSON.parse(input.join())
// Create the pattern using the settings from STDIN
const pattern = new Aaron(settings)
.use(theme)
.draft()
const data = pattern.getRenderProps()
// Data holds an object, with circular references
// So we can't dump the entire thing, but feel free to look around
// Meanwhile, we'll dump the parts as they hold all paths/points:
console.log(JSON.stringify(data.parts, null, 2))
})