diff --git a/src/cli.js b/src/cli.js index a0aced1..a8f4db4 100755 --- a/src/cli.js +++ b/src/cli.js @@ -67,9 +67,7 @@ const single = (data, rel) => { if (!data) return const abs = path.join(args.o, rel) fs.mkdirpSync(path.dirname(abs)) - if (abs.endsWith('.json')) { - fs.writeJSONSync(abs, data, {spaces: 4}) - } else if (abs.endsWith('.yaml')) { + if (abs.endsWith('.yaml')) { fs.writeFileSync(abs, yaml.dump(data, {indent: 4})) } else { fs.writeFileSync(abs, data) @@ -79,9 +77,9 @@ const single = (data, rel) => { const composite = (data, rel) => { if (!data) return const abs = path.join(args.o, rel) - if (data.json) { + if (data.yaml) { fs.mkdirpSync(path.dirname(abs)) - fs.writeJSONSync(abs + '.json', data.json, {spaces: 4}) + fs.writeFileSync(abs + '.yaml', yaml.dump(data.yaml, {indent: 4})) } for (const format of ['svg', 'dxf', 'jscad', 'stl']) { if (data[format]) { @@ -101,11 +99,11 @@ if (args.clean) { console.log('Writing output to disk...') fs.mkdirpSync(args.o) -single(results.raw, 'raw.txt') -single(results.canonical, 'canonical.yaml') -single(results.units, 'units.json') +single(results.raw, 'source/raw.txt') +single(results.canonical, 'source/canonical.yaml') -single(results.points, 'points/points.json') +single(results.units, 'points/units.yaml') +single(results.points, 'points/points.yaml') composite(results.demo, 'points/demo') for (const [name, outline] of Object.entries(results.outlines)) { diff --git a/src/io.js b/src/io.js index f32c82d..ea3e8fc 100644 --- a/src/io.js +++ b/src/io.js @@ -60,7 +60,7 @@ exports.twodee = (model, debug) => { dxf: makerjs.exporter.toDXF(assembly), } if (debug) { - result.json = assembly + result.yaml = assembly result.svg = makerjs.exporter.toSVG(assembly) } return result diff --git a/test/cli/big/reference/outlines/_export.json b/test/cli/big/reference/outlines/_export.json deleted file mode 100644 index 74d8810..0000000 --- a/test/cli/big/reference/outlines/_export.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "models": { - "export": { - "models": { - "a": { - "models": {}, - "origin": [ - 0, - 0 - ] - }, - "b": { - "models": { - "a": { - "models": {}, - "origin": [ - 0, - 0 - ] - }, - "b": { - "paths": { - "ShapeLine1": { - "type": "line", - "origin": [ - -9, - -9 - ], - "end": [ - 9, - -9 - ] - }, - "ShapeLine2": { - "type": "line", - "origin": [ - 9, - -9 - ], - "end": [ - 9, - 9 - ] - }, - "ShapeLine3": { - "type": "line", - "origin": [ - 9, - 9 - ], - "end": [ - -9, - 9 - ] - }, - "ShapeLine4": { - "type": "line", - "origin": [ - -9, - 9 - ], - "end": [ - -9, - -9 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "units": "mm", - "origin": [ - 0, - 0 - ] -} diff --git a/test/cli/big/reference/outlines/_export.yaml b/test/cli/big/reference/outlines/_export.yaml new file mode 100644 index 0000000..b901b68 --- /dev/null +++ b/test/cli/big/reference/outlines/_export.yaml @@ -0,0 +1,62 @@ +models: + export: + models: + a: + models: {} + origin: + - 0 + - 0 + b: + models: + a: + models: {} + origin: + - 0 + - 0 + b: + paths: + ShapeLine1: + type: line + origin: + - -9 + - -9 + end: + - 9 + - -9 + ShapeLine2: + type: line + origin: + - 9 + - -9 + end: + - 9 + - 9 + ShapeLine3: + type: line + origin: + - 9 + - 9 + end: + - -9 + - 9 + ShapeLine4: + type: line + origin: + - -9 + - 9 + end: + - -9 + - -9 + origin: + - 0 + - 0 + origin: + - 0 + - 0 + origin: + - 0 + - 0 +units: mm +origin: + - 0 + - 0 diff --git a/test/cli/big/reference/outlines/export.json b/test/cli/big/reference/outlines/export.json deleted file mode 100644 index 74d8810..0000000 --- a/test/cli/big/reference/outlines/export.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "models": { - "export": { - "models": { - "a": { - "models": {}, - "origin": [ - 0, - 0 - ] - }, - "b": { - "models": { - "a": { - "models": {}, - "origin": [ - 0, - 0 - ] - }, - "b": { - "paths": { - "ShapeLine1": { - "type": "line", - "origin": [ - -9, - -9 - ], - "end": [ - 9, - -9 - ] - }, - "ShapeLine2": { - "type": "line", - "origin": [ - 9, - -9 - ], - "end": [ - 9, - 9 - ] - }, - "ShapeLine3": { - "type": "line", - "origin": [ - 9, - 9 - ], - "end": [ - -9, - 9 - ] - }, - "ShapeLine4": { - "type": "line", - "origin": [ - -9, - 9 - ], - "end": [ - -9, - -9 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "units": "mm", - "origin": [ - 0, - 0 - ] -} diff --git a/test/cli/big/reference/outlines/export.yaml b/test/cli/big/reference/outlines/export.yaml new file mode 100644 index 0000000..b901b68 --- /dev/null +++ b/test/cli/big/reference/outlines/export.yaml @@ -0,0 +1,62 @@ +models: + export: + models: + a: + models: {} + origin: + - 0 + - 0 + b: + models: + a: + models: {} + origin: + - 0 + - 0 + b: + paths: + ShapeLine1: + type: line + origin: + - -9 + - -9 + end: + - 9 + - -9 + ShapeLine2: + type: line + origin: + - 9 + - -9 + end: + - 9 + - 9 + ShapeLine3: + type: line + origin: + - 9 + - 9 + end: + - -9 + - 9 + ShapeLine4: + type: line + origin: + - -9 + - 9 + end: + - -9 + - -9 + origin: + - 0 + - 0 + origin: + - 0 + - 0 + origin: + - 0 + - 0 +units: mm +origin: + - 0 + - 0 diff --git a/test/cli/big/reference/points/demo.json b/test/cli/big/reference/points/demo.json deleted file mode 100644 index d400097..0000000 --- a/test/cli/big/reference/points/demo.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "models": { - "export": { - "models": { - "matrix_col_row": { - "paths": { - "top": { - "type": "line", - "origin": [ - -9, - 9 - ], - "end": [ - 9, - 9 - ] - }, - "right": { - "type": "line", - "origin": [ - 9, - 9 - ], - "end": [ - 9, - -9 - ] - }, - "bottom": { - "type": "line", - "origin": [ - 9, - -9 - ], - "end": [ - -9, - -9 - ] - }, - "left": { - "type": "line", - "origin": [ - -9, - -9 - ], - "end": [ - -9, - 9 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "units": "mm", - "origin": [ - 0, - 0 - ] -} diff --git a/test/cli/big/reference/points/demo.yaml b/test/cli/big/reference/points/demo.yaml new file mode 100644 index 0000000..658aacd --- /dev/null +++ b/test/cli/big/reference/points/demo.yaml @@ -0,0 +1,47 @@ +models: + export: + models: + matrix_col_row: + paths: + top: + type: line + origin: + - -9 + - 9 + end: + - 9 + - 9 + right: + type: line + origin: + - 9 + - 9 + end: + - 9 + - -9 + bottom: + type: line + origin: + - 9 + - -9 + end: + - -9 + - -9 + left: + type: line + origin: + - -9 + - -9 + end: + - -9 + - 9 + origin: + - 0 + - 0 + origin: + - 0 + - 0 +units: mm +origin: + - 0 + - 0 diff --git a/test/cli/big/reference/points/points.json b/test/cli/big/reference/points/points.json deleted file mode 100644 index 17e880a..0000000 --- a/test/cli/big/reference/points/points.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "matrix_col_row": { - "x": 0, - "y": 0, - "r": 0, - "meta": { - "shift": [ - 0, - 0 - ], - "rotate": 0, - "padding": 19, - "width": 1, - "height": 1, - "skip": false, - "asym": "both", - "name": "matrix_col_row", - "colrow": "col_row", - "col": { - "stagger": 0, - "spread": 0, - "rotate": 0, - "origin": [ - 0, - 0 - ], - "rows": {}, - "key": {}, - "name": "col" - }, - "row": "row" - } - } -} diff --git a/test/cli/big/reference/points/points.yaml b/test/cli/big/reference/points/points.yaml new file mode 100644 index 0000000..091b01a --- /dev/null +++ b/test/cli/big/reference/points/points.yaml @@ -0,0 +1,27 @@ +matrix_col_row: + x: 0 + 'y': 0 + r: 0 + meta: + shift: + - 0 + - 0 + rotate: 0 + padding: 19 + width: 1 + height: 1 + skip: false + asym: both + name: matrix_col_row + colrow: col_row + col: + stagger: 0 + spread: 0 + rotate: 0 + origin: + - 0 + - 0 + rows: {} + key: {} + name: col + row: row diff --git a/test/cli/big/reference/points/units.yaml b/test/cli/big/reference/points/units.yaml new file mode 100644 index 0000000..71aa93b --- /dev/null +++ b/test/cli/big/reference/points/units.yaml @@ -0,0 +1,4 @@ +u: 19 +cx: 18 +cy: 17 +a: 47 diff --git a/test/cli/big/reference/canonical.yaml b/test/cli/big/reference/source/canonical.yaml similarity index 100% rename from test/cli/big/reference/canonical.yaml rename to test/cli/big/reference/source/canonical.yaml diff --git a/test/cli/big/reference/raw.txt b/test/cli/big/reference/source/raw.txt similarity index 100% rename from test/cli/big/reference/raw.txt rename to test/cli/big/reference/source/raw.txt diff --git a/test/cli/big/reference/units.json b/test/cli/big/reference/units.json deleted file mode 100644 index 1ae3c36..0000000 --- a/test/cli/big/reference/units.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "u": 19, - "cx": 18, - "cy": 17, - "a": 47 -} diff --git a/test/cli/minimal/reference/points/demo.json b/test/cli/minimal/reference/points/demo.json deleted file mode 100644 index d400097..0000000 --- a/test/cli/minimal/reference/points/demo.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "models": { - "export": { - "models": { - "matrix_col_row": { - "paths": { - "top": { - "type": "line", - "origin": [ - -9, - 9 - ], - "end": [ - 9, - 9 - ] - }, - "right": { - "type": "line", - "origin": [ - 9, - 9 - ], - "end": [ - 9, - -9 - ] - }, - "bottom": { - "type": "line", - "origin": [ - 9, - -9 - ], - "end": [ - -9, - -9 - ] - }, - "left": { - "type": "line", - "origin": [ - -9, - -9 - ], - "end": [ - -9, - 9 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "units": "mm", - "origin": [ - 0, - 0 - ] -} diff --git a/test/cli/minimal/reference/points/demo.yaml b/test/cli/minimal/reference/points/demo.yaml new file mode 100644 index 0000000..658aacd --- /dev/null +++ b/test/cli/minimal/reference/points/demo.yaml @@ -0,0 +1,47 @@ +models: + export: + models: + matrix_col_row: + paths: + top: + type: line + origin: + - -9 + - 9 + end: + - 9 + - 9 + right: + type: line + origin: + - 9 + - 9 + end: + - 9 + - -9 + bottom: + type: line + origin: + - 9 + - -9 + end: + - -9 + - -9 + left: + type: line + origin: + - -9 + - -9 + end: + - -9 + - 9 + origin: + - 0 + - 0 + origin: + - 0 + - 0 +units: mm +origin: + - 0 + - 0 diff --git a/test/cli/minimal/reference/points/points.json b/test/cli/minimal/reference/points/points.json deleted file mode 100644 index 17e880a..0000000 --- a/test/cli/minimal/reference/points/points.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "matrix_col_row": { - "x": 0, - "y": 0, - "r": 0, - "meta": { - "shift": [ - 0, - 0 - ], - "rotate": 0, - "padding": 19, - "width": 1, - "height": 1, - "skip": false, - "asym": "both", - "name": "matrix_col_row", - "colrow": "col_row", - "col": { - "stagger": 0, - "spread": 0, - "rotate": 0, - "origin": [ - 0, - 0 - ], - "rows": {}, - "key": {}, - "name": "col" - }, - "row": "row" - } - } -} diff --git a/test/cli/minimal/reference/points/points.yaml b/test/cli/minimal/reference/points/points.yaml new file mode 100644 index 0000000..091b01a --- /dev/null +++ b/test/cli/minimal/reference/points/points.yaml @@ -0,0 +1,27 @@ +matrix_col_row: + x: 0 + 'y': 0 + r: 0 + meta: + shift: + - 0 + - 0 + rotate: 0 + padding: 19 + width: 1 + height: 1 + skip: false + asym: both + name: matrix_col_row + colrow: col_row + col: + stagger: 0 + spread: 0 + rotate: 0 + origin: + - 0 + - 0 + rows: {} + key: {} + name: col + row: row diff --git a/test/cli/minimal/reference/points/units.yaml b/test/cli/minimal/reference/points/units.yaml new file mode 100644 index 0000000..f50c8d8 --- /dev/null +++ b/test/cli/minimal/reference/points/units.yaml @@ -0,0 +1,3 @@ +u: 19 +cx: 18 +cy: 17 diff --git a/test/cli/minimal/reference/canonical.yaml b/test/cli/minimal/reference/source/canonical.yaml similarity index 100% rename from test/cli/minimal/reference/canonical.yaml rename to test/cli/minimal/reference/source/canonical.yaml diff --git a/test/cli/minimal/reference/raw.txt b/test/cli/minimal/reference/source/raw.txt similarity index 100% rename from test/cli/minimal/reference/raw.txt rename to test/cli/minimal/reference/source/raw.txt diff --git a/test/cli/minimal/reference/units.json b/test/cli/minimal/reference/units.json deleted file mode 100644 index 3d3777b..0000000 --- a/test/cli/minimal/reference/units.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "u": 19, - "cx": 18, - "cy": 17 -}