Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(all): changes to comply with lint #1367

Merged
merged 14 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '14', '16' ]
node: [ '16', '18' ]
name: Node ${{ matrix.node }} test
steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"**/old/",
"**/ui/csg-viewer",
"**/io/scad-deserializer",
"**/io/gcode-deserializer"
"**/io/gcode-deserializer",
"**/desktop"
],
"env": {
"browser": true,
Expand Down
59 changes: 29 additions & 30 deletions packages/cli/cli.conversions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,47 +82,46 @@ const main = () => {
module.exports = { main }
`

const fileName = `./test${id}-import.jscad`;
const filePath = path.resolve(__dirname, fileName);
fs.writeFileSync(filePath, jscadScript);
return filePath;
const fileName = `./test${id}-import.jscad`
const filePath = path.resolve(__dirname, fileName)
fs.writeFileSync(filePath, jscadScript)
return filePath
}

const testBackImport = (t, testID, extension) => {
const cliPath = t.context.cliPath;
const cliPath = t.context.cliPath

const file4Path = createImportJscad(testID, extension);
t.context.file4Path = file4Path;
t.true(fs.existsSync(file4Path));
const file4Path = createImportJscad(testID, extension)
t.context.file4Path = file4Path
t.true(fs.existsSync(file4Path))

const file5Name = `./test${testID}-import.stl`;
const file5Path = path.resolve(__dirname, file5Name);
t.context.file5Path = file5Path;
t.false(fs.existsSync(file5Path));
const file5Name = `./test${testID}-import.stl`
const file5Path = path.resolve(__dirname, file5Name)
t.context.file5Path = file5Path
t.false(fs.existsSync(file5Path))

cmd = `node ${cliPath} ${file4Path}`
const cmd = `node ${cliPath} ${file4Path}`
execSync(cmd, { stdio: [0, 1, 2] })
t.true(fs.existsSync(file5Path));
t.true(fs.existsSync(file5Path))
}

const runOnFixture = (t, fixtureName) => {
const inputFile = path.resolve(
__dirname,
path.join('test_fixtures', fixtureName, 'index.js'));
path.join('test_fixtures', fixtureName, 'index.js'))

const outputFile = inputFile.replace('.js', '.stl');
t.context.file1Path = outputFile;
const outputFile = inputFile.replace('.js', '.stl')
t.context.file1Path = outputFile

t.false(fs.existsSync(outputFile));
t.false(fs.existsSync(outputFile))

const cmd = `node ${t.context.cliPath} ${inputFile}`
execSync(cmd, { stdio: [0, 1, 2] });
execSync(cmd, { stdio: [0, 1, 2] })
t.true(fs.existsSync(outputFile))

return outputFile;
return outputFile
}


test('cli (conversions STL)', (t) => {
const testID = 11

Expand All @@ -142,20 +141,20 @@ test('cli (conversions STL)', (t) => {

let cmd = `node ${cliPath} ${file1Path}`
execSync(cmd, { stdio: [0, 1, 2] })
t.true(fs.existsSync(file2Path));
t.true(fs.existsSync(file2Path))

// convert from STL to JSCAD script
const file3Name = `./test${testID}.js`
const file3Path = path.resolve(__dirname, file3Name)
t.false(fs.existsSync(file3Path));
t.false(fs.existsSync(file3Path))

t.context.file3Path = file3Path

cmd = `node ${cliPath} ${file2Path} -o ${file3Path} -v -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.true(fs.existsSync(file3Path));
t.true(fs.existsSync(file3Path))

testBackImport(t, testID, 'stl');
testBackImport(t, testID, 'stl')
})

test('cli (conversions DXF)', (t) => {
Expand Down Expand Up @@ -190,7 +189,7 @@ test('cli (conversions DXF)', (t) => {
execSync(cmd, { stdio: [0, 1, 2] })
t.true(fs.existsSync(file3Path))

testBackImport(t, testID, 'dxf');
testBackImport(t, testID, 'dxf')
})

test('cli (conversions AMF)', (t) => {
Expand Down Expand Up @@ -225,7 +224,7 @@ test('cli (conversions AMF)', (t) => {
execSync(cmd, { stdio: [0, 1, 2] })
t.true(fs.existsSync(file3Path))

testBackImport(t, testID, 'amf');
testBackImport(t, testID, 'amf')
})

test('cli (conversions JSON)', (t) => {
Expand Down Expand Up @@ -260,7 +259,7 @@ test('cli (conversions JSON)', (t) => {
execSync(cmd, { stdio: [0, 1, 2] })
t.true(fs.existsSync(file3Path))

testBackImport(t, testID, 'json');
testBackImport(t, testID, 'json')
})

test('cli (conversions SVG)', (t) => {
Expand Down Expand Up @@ -328,11 +327,11 @@ test('cli (conversions X3D)', (t) => {
execSync(cmd, { stdio: [0, 1, 2] })
t.true(fs.existsSync(file3Path))

testBackImport(t, testID, 'x3d');
testBackImport(t, testID, 'x3d')
})

test('cli (import STL)', (t) => {
const testID = 17
// const testID = 17

runOnFixture(t, 'stl_import')
})
6 changes: 3 additions & 3 deletions packages/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ generateOutputData(src, params, { outputFile, outputFormat, inputFile, inputForm
if (err) {
console.error(err)
} else {
logFileOutput(zipFilename)
logFileOutput(zipFilename)
}
})
})
} else {
for (let i = 0; i < outputData.length; i++) {
const filename = outputFile.replace(/\.(\w+)$/, `-part-${i + 1}-of-${outputData.length}.$1`)
const filename = outputFile.replace(/\.(\w+)$/, `-part-${i + 1}-of-${outputData.length}.$1`)
logFileOutput(filename)
writeOutput(filename, outputData[i])
}
Expand All @@ -97,7 +97,7 @@ generateOutputData(src, params, { outputFile, outputFormat, inputFile, inputForm
if (err) {
console.error(err)
} else {
logFileOutput(zipFilename)
logFileOutput(zipFilename)
}
})
})
Expand Down
15 changes: 7 additions & 8 deletions packages/cli/cli.parameters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const main = (params) => {
let ageom2 = primitives.ellipse()
let ageom3 = primitives.ellipsoid()

${multipart ? `return [ageom3, ageom3, ageom3]` : `return [apath2, ageom2, ageom3]`}
${multipart ? 'return [ageom3, ageom3, ageom3]' : 'return [apath2, ageom2, ageom3]'}
}

module.exports = { main, getParameterDefinitions }
Expand Down Expand Up @@ -215,7 +215,6 @@ test('cli (single input file, invalid jscad)', (t) => {
})
})


test('cli (single input file, multiple output files)', (t) => {
const testID = 7

Expand All @@ -239,7 +238,7 @@ test('cli (single input file, multiple output files)', (t) => {
const cliPath = t.context.cliPath

const cmd = `node ${cliPath} ${inputPath} -gp`
execSync(cmd, { stdio: [0,1,2] })
execSync(cmd, { stdio: [0, 1, 2] })
t.true(fs.existsSync(outputPath1))
t.true(fs.existsSync(outputPath2))
t.true(fs.existsSync(outputPath3))
Expand All @@ -257,13 +256,13 @@ test('cli (single multipart input file, zipped output file)', async (t) => {
const outputPath = path.resolve(__dirname, outputName)

t.false(fs.existsSync(outputPath))

t.context.outputPath = outputPath

const cliPath = t.context.cliPath

const cmd = `node ${cliPath} ${inputPath} -gp -z`
execSync(cmd, { stdio: [0,1,2] })
execSync(cmd, { stdio: [0, 1, 2] })
t.true(fs.existsSync(outputPath))

// check contents of zip file
Expand All @@ -281,18 +280,18 @@ test('cli (single input file, zipped output file)', async (t) => {
t.true(fs.existsSync(inputPath))

t.context.inputPath = inputPath

const outputName = `./test${testID}.zip`
const outputPath = path.resolve(__dirname, outputName)

t.false(fs.existsSync(outputPath))

t.context.outputPath = outputPath

const cliPath = t.context.cliPath

const cmd = `node ${cliPath} ${inputPath} -z`
execSync(cmd, { stdio: [0,1,2] })
execSync(cmd, { stdio: [0, 1, 2] })
t.true(fs.existsSync(outputPath))

// check contents of zip file
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/generateOutputData.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const generateOutputData = (source, params, options) => {
.then((solids) => {
const serializerOptions = Object.assign({ format: outputFormat }, params)
if (generateParts) {
let blobs = []
const blobs = []
for (let i = 0; i < solids.length; i++) {
blobs.push(solidsAsBlob(solids[i], serializerOptions))
}
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/test_fixtures/stl_import/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

function main() {
return require('./binary_stl.stl');
}
const main = () => require('./binary_stl.stl')

module.exports = { main }
module.exports = { main }
12 changes: 6 additions & 6 deletions packages/core/src/io/registerExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ const registerDeserializer = (extension, fs, _require) => {
const deserializer = deserializers[extension]
const fileExtension = '.' + extension
_require.extensions[fileExtension] = (module, filename) => {
const fileReadResult = fs.readFileSync(filename);
const fileReadResult = fs.readFileSync(filename)

// https://nodejs.org/api/buffer.html#bufbuffer: Buffer.buffer is not
// guaranteed to correspond exactly to the original Buffer.
// https://nodejs.org/api/buffer.html#bufbuffer: Buffer.buffer is not
// guaranteed to correspond exactly to the original Buffer.
const fileContent = fileReadResult.buffer
? fileReadResult.buffer.slice(
fileReadResult.byteOffset,
fileReadResult.byteOffset + fileReadResult.length)
: fileReadResult;
fileReadResult.byteOffset,
fileReadResult.byteOffset + fileReadResult.length)
: fileReadResult

const parsed = deserializer({ filename, output: 'geometry' }, fileContent)
module.exports = parsed
Expand Down
6 changes: 2 additions & 4 deletions packages/io/3mf-serializer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Notes:
* const { serializer, mimeType } = require('@jscad/3mf-serializer')
*/


const zipSync = require('fflate').zipSync
const strToU8 = require('fflate').strToU8

Expand All @@ -39,7 +38,6 @@ const stringify = require('onml/lib/stringify')
const { colors, geometries, modifiers } = require('@jscad/modeling')
const { flatten, toArray } = require('@jscad/array-utils')


const mimeType = 'model/3mf'
const fileExtension = '3mf'

Expand All @@ -61,15 +59,15 @@ const serialize = (options, ...objects) => {
const defaults = {
unit: 'millimeter', // micron, millimeter, centimeter, inch, foot, meter
metadata: true,
defaultcolor: [255/255, 160/255, 0, 1], // JSCAD Orange
defaultcolor: [255 / 255, 160 / 255, 0, 1], // JSCAD Orange
compress: true
}
options = Object.assign({}, defaults, options)

objects = flatten(objects)

// convert only 3D geometries
let objects3d = objects.filter((object) => geometries.geom3.isA(object))
const objects3d = objects.filter((object) => geometries.geom3.isA(object))

if (objects3d.length === 0) throw new Error('only 3D geometries can be serialized to 3MF')
if (objects.length !== objects3d.length) console.warn('some objects could not be serialized to 3MF')
Expand Down
8 changes: 4 additions & 4 deletions packages/io/3mf-serializer/tests/serialize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ test('serialize (single, color)', (t) => {
test('serialize (multiple, color)', (t) => {
let cube1 = primitives.cuboid({ size: [4, 5, 6], center: [5, 5, 5] })
cube1 = colors.colorize([0.0, 0.0, 1.0, 0.8], cube1)
cube1.name = "CUBE A"
cube1.name = 'CUBE A'
const cube2 = primitives.cube()
cube2.name = "CUBE B"
cube2.name = 'CUBE B'
const buffer = serializer.serialize({ metadata: false, compress: false, defaultcolor: [1, 0, 0, 1] }, cube1, cube2)
t.deepEqual(buffer, expected4)
})

test('serialize (multiple, compress)', (t) => {
const cube1 = colors.colorize([1.0, 0.0, 0.5, 0.8], primitives.cube())
cube1.name = "CUBE A"
cube1.name = 'CUBE A'
const cube2 = primitives.cuboid({ size: [4, 5, 6], center: [5, 5, 5] })
cube2.name = "CUBE B"
cube2.name = 'CUBE B'

const results = serializer.serialize({ compress: true }, cube1, cube2)
t.is(results.length, 1)
Expand Down
2 changes: 1 addition & 1 deletion packages/io/amf-deserializer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const deserialize = (options, input) => {
}
options = Object.assign({}, defaults, options)

input = ensureString(input);
input = ensureString(input)
return options.output === 'script' ? translate(options, input) : instantiate(options, input)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/io/dxf-deserializer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ const deserialize = (options, src) => {
}
options = Object.assign({}, defaults, options)

src = ensureString(src);
src = ensureString(src)
return options.output === 'script' ? translate(src, options) : instantiate(src, options)
}

Expand Down
6 changes: 3 additions & 3 deletions packages/io/io-utils/ensureString.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const ensureString = (stringOrArrayBuffer, defaultBinaryEncoding = 'utf-8') => {
if (typeof (stringOrArrayBuffer) === 'string') {
return stringOrArrayBuffer;
return stringOrArrayBuffer
}

return new TextDecoder(defaultBinaryEncoding).decode(new Uint8Array(stringOrArrayBuffer));
return new TextDecoder(defaultBinaryEncoding).decode(new Uint8Array(stringOrArrayBuffer))
}

module.exports = ensureString;
module.exports = ensureString
2 changes: 1 addition & 1 deletion packages/io/json-deserializer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const deserialize = (options, input) => {
options = Object.assign({}, defaults, options)

// convert the JSON notation into anonymous object(s)
input = ensureString(input);
input = ensureString(input)
let objects = JSON.parse(input)

// cleanup the objects
Expand Down
2 changes: 1 addition & 1 deletion packages/io/obj-deserializer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const deserialize = (options, input) => {
options = Object.assign({}, defaults, options)
const { output } = options

input = ensureString(input);
input = ensureString(input)

options && options.statusCallback && options.statusCallback({ progress: 0 })

Expand Down
Loading
Loading