From f076ae2a3920b18f7fc7d80dde3c3da986cf05d9 Mon Sep 17 00:00:00 2001 From: Georg Date: Mon, 22 Aug 2022 22:27:55 +0200 Subject: [PATCH 1/5] Update README.md ThreeDModule: options.include expects an array --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 68824a0..084e934 100644 --- a/README.md +++ b/README.md @@ -57,11 +57,11 @@ const UnitTestSCAD = require('unittestscad'); ```javascript const cube = new UnitTestSCAD.ThreeDModule({ - include: 'cube.scad' + include: ['cube.scad'] }); cube.height === 5; ``` # API Reference -See [API Documentation](https://hopefulllama.github.io/UnitTestSCAD/) for more details. \ No newline at end of file +See [API Documentation](https://hopefulllama.github.io/UnitTestSCAD/) for more details. From 5cbe1e83abdc72c9326be33cfdc1f99080f1d3ae Mon Sep 17 00:00:00 2001 From: Georg Date: Mon, 22 Aug 2022 22:35:39 +0200 Subject: [PATCH 2/5] Update AbstractParent.js Part 1 of set variable patch --- src/api/AbstractParent.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/AbstractParent.js b/src/api/AbstractParent.js index 469c6b9..742e9f5 100644 --- a/src/api/AbstractParent.js +++ b/src/api/AbstractParent.js @@ -11,6 +11,7 @@ function sanitise(options) { include: valueOrDefault(options, 'include', []), setUpText: valueOrDefault(options, 'setUpText', ''), testText: valueOrDefault(options, 'testText', ''), + setVariables: valueOrDefault(options, 'setVariables', []) }; } @@ -21,6 +22,7 @@ function sanitise(options) { * @property {String[]} include List of .scad files to import as 'include'. * @property {String} setUpText Any required OpenSCAD code to set up the test. * @property {String} testText The OpenSCAD code to be tested and asserted on. + * @property {String[]} setVariables Variables to set in openscad. */ /** @@ -31,6 +33,6 @@ module.exports = class { constructor(dirtyOptions, fileType) { const options = sanitise(dirtyOptions); const header = getHeader(options.openSCADDirectory, options.use, options.include); - this.output = fileType.execute(header, options.setUpText, options.testText); + this.output = fileType.execute(header, options.setUpText, options.testText, options.setVariables); } -}; \ No newline at end of file +}; From d23535de5e6d79226d6a17956ba110b7745a2faa Mon Sep 17 00:00:00 2001 From: Georg Date: Mon, 22 Aug 2022 22:37:47 +0200 Subject: [PATCH 3/5] Update File.js Part 2 of set variables patch --- src/file/File.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/file/File.js b/src/file/File.js index f15400e..86eb34c 100644 --- a/src/file/File.js +++ b/src/file/File.js @@ -9,8 +9,8 @@ function writeSCADFile(header, setUpText, testText) { fs.writeFileSync(scadFile, contents); } -function executeOpenSCAD(tempFile) { - const command = `openscad -o ${tempFile} ${scadFile}`; +function executeOpenSCAD(tempFile, variables) { + const command = `openscad -o ${tempFile} ${variables.reduce((acc,item)=>" -D "+item[0]+"=\""+item[1]+acc+"\"", "")} ${scadFile}`; const out = execSync(command).toString(); const file = fs.readFileSync(tempFile, 'utf-8'); return { @@ -29,7 +29,7 @@ module.exports = { execute(options, tempOutput) { writeSCADFile(options.header, options.setUpText, options.testText); try { - return executeOpenSCAD(tempOutput); + return executeOpenSCAD(tempOutput, options.setVariables); } catch(error) { throw error; } finally { @@ -37,4 +37,4 @@ module.exports = { safeUnlink(scadFile); } } -}; \ No newline at end of file +}; From 26bfb6fec83d441609fcc794bb889788ea6063ee Mon Sep 17 00:00:00 2001 From: Georg Date: Mon, 22 Aug 2022 22:38:46 +0200 Subject: [PATCH 4/5] Update ThreeDModuleFile.js Part 3 of set variables patch --- src/file/ThreeDModuleFile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/file/ThreeDModuleFile.js b/src/file/ThreeDModuleFile.js index 7ffcd7f..e423e64 100644 --- a/src/file/ThreeDModuleFile.js +++ b/src/file/ThreeDModuleFile.js @@ -3,11 +3,12 @@ const File = require('./File'); const stlFile = 'UnitTestSCAD_48967_TEMP_DELETE-ME_THREE_D.stl'; module.exports = { - execute(header, setUpText, testText) { + execute(header, setUpText, testText, setVariables) { return File.execute({ header, setUpText, testText, + setVariables, }, stlFile).file; } }; From f9865d9f0ba9a1a80d71c980763c813433364403 Mon Sep 17 00:00:00 2001 From: Georg Date: Mon, 22 Aug 2022 22:39:32 +0200 Subject: [PATCH 5/5] Update TwoDModuleFile.js Part 4 of set variables patch --- src/file/TwoDModuleFile.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/file/TwoDModuleFile.js b/src/file/TwoDModuleFile.js index 76db034..b9755d0 100644 --- a/src/file/TwoDModuleFile.js +++ b/src/file/TwoDModuleFile.js @@ -3,11 +3,12 @@ const File = require('./File'); const svgFile = 'UnitTestSCAD_48967_TEMP_DELETE-ME_TWO_D.svg'; module.exports = { - execute(header, setUpText, testText) { + execute(header, setUpText, testText, setVariables) { return File.execute({ header, setUpText, testText, + setVariables, }, svgFile).file; } -}; \ No newline at end of file +};