@jscad/cli 2.3.5 → 3.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -263
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/cli.conversions.test.js +35 -138
- package/cli.js +15 -10
- package/cli.parameters.test.js +39 -35
- package/package.json +11 -9
- package/src/determineOutputNameAndFormat.js +2 -4
- package/src/env.js +5 -8
- package/src/generateOutputData.js +45 -37
- package/src/parseArgs.js +22 -10
- package/src/writeOutput.js +2 -6
- package/test_fixtures/stl_import/binary_stl.stl +0 -0
- package/test_fixtures/stl_import/index.js +0 -4
package/cli.conversions.test.js
CHANGED
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { cwd } from 'process'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
import test from 'ava'
|
|
6
|
+
|
|
7
|
+
import { execSync } from 'child_process'
|
|
6
8
|
|
|
7
9
|
test.afterEach.always((t) => {
|
|
8
10
|
// remove files
|
|
9
11
|
try {
|
|
10
12
|
if (t.context.file1Path) fs.unlinkSync(t.context.file1Path)
|
|
11
|
-
} catch (err) {
|
|
13
|
+
} catch (err) {}
|
|
12
14
|
|
|
13
15
|
try {
|
|
14
16
|
if (t.context.file2Path) fs.unlinkSync(t.context.file2Path)
|
|
15
|
-
} catch (err) {
|
|
17
|
+
} catch (err) {}
|
|
16
18
|
|
|
17
19
|
try {
|
|
18
20
|
if (t.context.file3Path) fs.unlinkSync(t.context.file3Path)
|
|
19
|
-
} catch (err) {
|
|
21
|
+
} catch (err) {}
|
|
20
22
|
|
|
21
23
|
try {
|
|
22
24
|
if (t.context.file4Path) fs.unlinkSync(t.context.file4Path)
|
|
23
|
-
} catch (err) {
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
if (t.context.file5Path) fs.unlinkSync(t.context.file5Path)
|
|
27
|
-
} catch (err) { }
|
|
25
|
+
} catch (err) {}
|
|
28
26
|
})
|
|
29
27
|
|
|
30
28
|
test.beforeEach((t) => {
|
|
31
29
|
const cliName = './cli.js'
|
|
32
30
|
t.context = {
|
|
33
|
-
cliPath: path.resolve(
|
|
31
|
+
cliPath: path.resolve(cwd(), cliName)
|
|
34
32
|
}
|
|
35
33
|
})
|
|
36
34
|
|
|
@@ -42,86 +40,34 @@ test.beforeEach((t) => {
|
|
|
42
40
|
// the script should produce ALL geometry types
|
|
43
41
|
const createJscad = (id) => {
|
|
44
42
|
const jscadScript = `// test script ${id}
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
import { flatten } from '@jscad/array-utils'
|
|
44
|
+
import { arc, ellipse, ellipsoid } from '@jscad/modeling'
|
|
47
45
|
|
|
48
|
-
const getParameterDefinitions = () => {
|
|
46
|
+
export const getParameterDefinitions = () => {
|
|
49
47
|
return flatten([
|
|
50
48
|
{ name: 'segments', caption: 'Segements:', type: 'int', initial: 10, min: 5, max: 20, step: 1 }
|
|
51
49
|
])
|
|
52
50
|
}
|
|
53
51
|
|
|
54
|
-
const main = (params) => {
|
|
52
|
+
export const main = (params) => {
|
|
55
53
|
// parameters
|
|
56
54
|
let segments = params.segments || 16
|
|
57
55
|
|
|
58
56
|
// shapes
|
|
59
|
-
let apath2 =
|
|
60
|
-
let ageom2 =
|
|
61
|
-
let ageom3 =
|
|
57
|
+
let apath2 = arc()
|
|
58
|
+
let ageom2 = ellipse()
|
|
59
|
+
let ageom3 = ellipsoid()
|
|
62
60
|
|
|
63
61
|
return [apath2, ageom2, ageom3]
|
|
64
62
|
}
|
|
65
|
-
|
|
66
|
-
module.exports = { main, getParameterDefinitions }
|
|
67
63
|
`
|
|
68
64
|
|
|
69
|
-
const fileName = `./
|
|
70
|
-
const filePath = path.resolve(
|
|
65
|
+
const fileName = `./base${id}.js`
|
|
66
|
+
const filePath = path.resolve(cwd(), fileName)
|
|
71
67
|
fs.writeFileSync(filePath, jscadScript)
|
|
72
68
|
return filePath
|
|
73
69
|
}
|
|
74
70
|
|
|
75
|
-
const createImportJscad = (id, extension) => {
|
|
76
|
-
const jscadScript = `// test script ${id} -- import
|
|
77
|
-
|
|
78
|
-
const main = () => {
|
|
79
|
-
return require('./test${id}.${extension}')
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
module.exports = { main }
|
|
83
|
-
`
|
|
84
|
-
|
|
85
|
-
const fileName = `./test${id}-import.jscad`
|
|
86
|
-
const filePath = path.resolve(__dirname, fileName)
|
|
87
|
-
fs.writeFileSync(filePath, jscadScript)
|
|
88
|
-
return filePath
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const testBackImport = (t, testID, extension) => {
|
|
92
|
-
const cliPath = t.context.cliPath
|
|
93
|
-
|
|
94
|
-
const file4Path = createImportJscad(testID, extension)
|
|
95
|
-
t.context.file4Path = file4Path
|
|
96
|
-
t.true(fs.existsSync(file4Path))
|
|
97
|
-
|
|
98
|
-
const file5Name = `./test${testID}-import.stl`
|
|
99
|
-
const file5Path = path.resolve(__dirname, file5Name)
|
|
100
|
-
t.context.file5Path = file5Path
|
|
101
|
-
t.false(fs.existsSync(file5Path))
|
|
102
|
-
|
|
103
|
-
const cmd = `node ${cliPath} ${file4Path}`
|
|
104
|
-
execSync(cmd, { stdio: [0, 1, 2] })
|
|
105
|
-
t.true(fs.existsSync(file5Path))
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const runOnFixture = (t, fixtureName) => {
|
|
109
|
-
const inputFile = path.resolve(
|
|
110
|
-
__dirname,
|
|
111
|
-
path.join('test_fixtures', fixtureName, 'index.js'))
|
|
112
|
-
|
|
113
|
-
const outputFile = inputFile.replace('.js', '.stl')
|
|
114
|
-
t.context.file1Path = outputFile
|
|
115
|
-
|
|
116
|
-
t.false(fs.existsSync(outputFile))
|
|
117
|
-
|
|
118
|
-
const cmd = `node ${t.context.cliPath} ${inputFile}`
|
|
119
|
-
execSync(cmd, { stdio: [0, 1, 2] })
|
|
120
|
-
t.true(fs.existsSync(outputFile))
|
|
121
|
-
|
|
122
|
-
return outputFile
|
|
123
|
-
}
|
|
124
|
-
|
|
125
71
|
test('cli (conversions STL)', (t) => {
|
|
126
72
|
const testID = 11
|
|
127
73
|
|
|
@@ -132,20 +78,20 @@ test('cli (conversions STL)', (t) => {
|
|
|
132
78
|
t.context.file1Path = file1Path
|
|
133
79
|
|
|
134
80
|
const file2Name = `./test${testID}.stl`
|
|
135
|
-
const file2Path = path.resolve(
|
|
81
|
+
const file2Path = path.resolve(cwd(), file2Name)
|
|
136
82
|
t.false(fs.existsSync(file2Path))
|
|
137
83
|
|
|
138
84
|
t.context.file2Path = file2Path
|
|
139
85
|
|
|
140
86
|
const cliPath = t.context.cliPath
|
|
141
87
|
|
|
142
|
-
let cmd = `node ${cliPath} ${file1Path}`
|
|
88
|
+
let cmd = `node ${cliPath} ${file1Path} -o ${file2Path}`
|
|
143
89
|
execSync(cmd, { stdio: [0, 1, 2] })
|
|
144
90
|
t.true(fs.existsSync(file2Path))
|
|
145
91
|
|
|
146
92
|
// convert from STL to JSCAD script
|
|
147
93
|
const file3Name = `./test${testID}.js`
|
|
148
|
-
const file3Path = path.resolve(
|
|
94
|
+
const file3Path = path.resolve(cwd(), file3Name)
|
|
149
95
|
t.false(fs.existsSync(file3Path))
|
|
150
96
|
|
|
151
97
|
t.context.file3Path = file3Path
|
|
@@ -153,8 +99,6 @@ test('cli (conversions STL)', (t) => {
|
|
|
153
99
|
cmd = `node ${cliPath} ${file2Path} -o ${file3Path} -v -add-metadata false`
|
|
154
100
|
execSync(cmd, { stdio: [0, 1, 2] })
|
|
155
101
|
t.true(fs.existsSync(file3Path))
|
|
156
|
-
|
|
157
|
-
testBackImport(t, testID, 'stl')
|
|
158
102
|
})
|
|
159
103
|
|
|
160
104
|
test('cli (conversions DXF)', (t) => {
|
|
@@ -167,55 +111,20 @@ test('cli (conversions DXF)', (t) => {
|
|
|
167
111
|
t.context.file1Path = file1Path
|
|
168
112
|
|
|
169
113
|
const file2Name = `./test${testID}.dxf`
|
|
170
|
-
const file2Path = path.resolve(
|
|
114
|
+
const file2Path = path.resolve(cwd(), file2Name)
|
|
171
115
|
t.false(fs.existsSync(file2Path))
|
|
172
116
|
|
|
173
117
|
t.context.file2Path = file2Path
|
|
174
118
|
|
|
175
119
|
const cliPath = t.context.cliPath
|
|
176
120
|
|
|
177
|
-
let cmd = `node ${cliPath} ${file1Path} -
|
|
121
|
+
let cmd = `node ${cliPath} ${file1Path} -o ${file2Path}`
|
|
178
122
|
execSync(cmd, { stdio: [0, 1, 2] })
|
|
179
123
|
t.true(fs.existsSync(file2Path))
|
|
180
124
|
|
|
181
125
|
// convert from DXF to JS
|
|
182
126
|
const file3Name = `./test${testID}.js`
|
|
183
|
-
const file3Path = path.resolve(
|
|
184
|
-
t.false(fs.existsSync(file3Path))
|
|
185
|
-
|
|
186
|
-
t.context.file3Path = file3Path
|
|
187
|
-
|
|
188
|
-
cmd = `node ${cliPath} ${file2Path} -of js`
|
|
189
|
-
execSync(cmd, { stdio: [0, 1, 2] })
|
|
190
|
-
t.true(fs.existsSync(file3Path))
|
|
191
|
-
|
|
192
|
-
testBackImport(t, testID, 'dxf')
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
test('cli (conversions AMF)', (t) => {
|
|
196
|
-
const testID = 13
|
|
197
|
-
|
|
198
|
-
// convert from JSCAD to AMF
|
|
199
|
-
const file1Path = createJscad(testID)
|
|
200
|
-
t.true(fs.existsSync(file1Path))
|
|
201
|
-
|
|
202
|
-
t.context.file1Path = file1Path
|
|
203
|
-
|
|
204
|
-
const file2Name = `./test${testID}.amf`
|
|
205
|
-
const file2Path = path.resolve(__dirname, file2Name)
|
|
206
|
-
t.false(fs.existsSync(file2Path))
|
|
207
|
-
|
|
208
|
-
t.context.file2Path = file2Path
|
|
209
|
-
|
|
210
|
-
const cliPath = t.context.cliPath
|
|
211
|
-
|
|
212
|
-
let cmd = `node ${cliPath} ${file1Path} -of amf`
|
|
213
|
-
execSync(cmd, { stdio: [0, 1, 2] })
|
|
214
|
-
t.true(fs.existsSync(file2Path))
|
|
215
|
-
|
|
216
|
-
// convert from AMF to JS
|
|
217
|
-
const file3Name = `./test${testID}.js`
|
|
218
|
-
const file3Path = path.resolve(__dirname, file3Name)
|
|
127
|
+
const file3Path = path.resolve(cwd(), file3Name)
|
|
219
128
|
t.false(fs.existsSync(file3Path))
|
|
220
129
|
|
|
221
130
|
t.context.file3Path = file3Path
|
|
@@ -223,8 +132,6 @@ test('cli (conversions AMF)', (t) => {
|
|
|
223
132
|
cmd = `node ${cliPath} ${file2Path} -of js`
|
|
224
133
|
execSync(cmd, { stdio: [0, 1, 2] })
|
|
225
134
|
t.true(fs.existsSync(file3Path))
|
|
226
|
-
|
|
227
|
-
testBackImport(t, testID, 'amf')
|
|
228
135
|
})
|
|
229
136
|
|
|
230
137
|
test('cli (conversions JSON)', (t) => {
|
|
@@ -237,20 +144,20 @@ test('cli (conversions JSON)', (t) => {
|
|
|
237
144
|
t.context.file1Path = file1Path
|
|
238
145
|
|
|
239
146
|
const file2Name = `./test${testID}.json`
|
|
240
|
-
const file2Path = path.resolve(
|
|
147
|
+
const file2Path = path.resolve(cwd(), file2Name)
|
|
241
148
|
t.false(fs.existsSync(file2Path))
|
|
242
149
|
|
|
243
150
|
t.context.file2Path = file2Path
|
|
244
151
|
|
|
245
152
|
const cliPath = t.context.cliPath
|
|
246
153
|
|
|
247
|
-
let cmd = `node ${cliPath} ${file1Path} -
|
|
154
|
+
let cmd = `node ${cliPath} ${file1Path} -o ${file2Path}`
|
|
248
155
|
execSync(cmd, { stdio: [0, 1, 2] })
|
|
249
156
|
t.true(fs.existsSync(file2Path))
|
|
250
157
|
|
|
251
158
|
// convert from JSON to JS
|
|
252
159
|
const file3Name = `./test${testID}.js`
|
|
253
|
-
const file3Path = path.resolve(
|
|
160
|
+
const file3Path = path.resolve(cwd(), file3Name)
|
|
254
161
|
t.false(fs.existsSync(file3Path))
|
|
255
162
|
|
|
256
163
|
t.context.file3Path = file3Path
|
|
@@ -258,8 +165,6 @@ test('cli (conversions JSON)', (t) => {
|
|
|
258
165
|
cmd = `node ${cliPath} ${file2Path} -of js`
|
|
259
166
|
execSync(cmd, { stdio: [0, 1, 2] })
|
|
260
167
|
t.true(fs.existsSync(file3Path))
|
|
261
|
-
|
|
262
|
-
testBackImport(t, testID, 'json')
|
|
263
168
|
})
|
|
264
169
|
|
|
265
170
|
test('cli (conversions SVG)', (t) => {
|
|
@@ -272,20 +177,20 @@ test('cli (conversions SVG)', (t) => {
|
|
|
272
177
|
t.context.file1Path = file1Path
|
|
273
178
|
|
|
274
179
|
const file2Name = `./test${testID}.svg`
|
|
275
|
-
const file2Path = path.resolve(
|
|
180
|
+
const file2Path = path.resolve(cwd(), file2Name)
|
|
276
181
|
t.false(fs.existsSync(file2Path))
|
|
277
182
|
|
|
278
183
|
t.context.file2Path = file2Path
|
|
279
184
|
|
|
280
185
|
const cliPath = t.context.cliPath
|
|
281
186
|
|
|
282
|
-
let cmd = `node ${cliPath} ${file1Path} -
|
|
187
|
+
let cmd = `node ${cliPath} ${file1Path} -o ${file2Path}`
|
|
283
188
|
execSync(cmd, { stdio: [0, 1, 2] })
|
|
284
189
|
t.true(fs.existsSync(file2Path))
|
|
285
190
|
|
|
286
191
|
// convert from SVG to JS
|
|
287
192
|
const file3Name = `./test${testID}.js`
|
|
288
|
-
const file3Path = path.resolve(
|
|
193
|
+
const file3Path = path.resolve(cwd(), file3Name)
|
|
289
194
|
t.false(fs.existsSync(file3Path))
|
|
290
195
|
|
|
291
196
|
t.context.file3Path = file3Path
|
|
@@ -305,20 +210,20 @@ test('cli (conversions X3D)', (t) => {
|
|
|
305
210
|
t.context.file1Path = file1Path
|
|
306
211
|
|
|
307
212
|
const file2Name = `./test${testID}.x3d`
|
|
308
|
-
const file2Path = path.resolve(
|
|
213
|
+
const file2Path = path.resolve(cwd(), file2Name)
|
|
309
214
|
t.false(fs.existsSync(file2Path))
|
|
310
215
|
|
|
311
216
|
t.context.file2Path = file2Path
|
|
312
217
|
|
|
313
218
|
const cliPath = t.context.cliPath
|
|
314
219
|
|
|
315
|
-
let cmd = `node ${cliPath} ${file1Path} -
|
|
220
|
+
let cmd = `node ${cliPath} ${file1Path} -o ${file2Path}`
|
|
316
221
|
execSync(cmd, { stdio: [0, 1, 2] })
|
|
317
222
|
t.true(fs.existsSync(file2Path))
|
|
318
223
|
|
|
319
224
|
// convert from X3D to JS
|
|
320
225
|
const file3Name = `./test${testID}.js`
|
|
321
|
-
const file3Path = path.resolve(
|
|
226
|
+
const file3Path = path.resolve(cwd(), file3Name)
|
|
322
227
|
t.false(fs.existsSync(file3Path))
|
|
323
228
|
|
|
324
229
|
t.context.file3Path = file3Path
|
|
@@ -326,12 +231,4 @@ test('cli (conversions X3D)', (t) => {
|
|
|
326
231
|
cmd = `node ${cliPath} ${file2Path} -of js`
|
|
327
232
|
execSync(cmd, { stdio: [0, 1, 2] })
|
|
328
233
|
t.true(fs.existsSync(file3Path))
|
|
329
|
-
|
|
330
|
-
testBackImport(t, testID, 'x3d')
|
|
331
|
-
})
|
|
332
|
-
|
|
333
|
-
test('cli (import STL)', (t) => {
|
|
334
|
-
// const testID = 17
|
|
335
|
-
|
|
336
|
-
runOnFixture(t, 'stl_import')
|
|
337
234
|
})
|
package/cli.js
CHANGED
|
@@ -21,16 +21,17 @@
|
|
|
21
21
|
// jscad test.jscad -of stl
|
|
22
22
|
// jscad name_plate.jscad --name "Just Me" --title "CEO" -o amf test.amf
|
|
23
23
|
//
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
import fs from 'fs'
|
|
25
|
+
import JSZip from 'jszip'
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
import { supportedFormats } from '@jscad/io'
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
import { generateOutputData } from './src/generateOutputData.js'
|
|
30
|
+
import { determineOutputNameAndFormat } from './src/determineOutputNameAndFormat.js'
|
|
31
|
+
import { writeOutput } from './src/writeOutput.js'
|
|
32
|
+
import { parseArgs } from './src/parseArgs.js'
|
|
33
|
+
|
|
34
|
+
const version = '[VI]{version}[/VI]' // version is injected by rollup
|
|
34
35
|
|
|
35
36
|
// handle arguments (inputs, outputs, etc)
|
|
36
37
|
const args = process.argv.splice(2)
|
|
@@ -52,12 +53,16 @@ const clicolors = {
|
|
|
52
53
|
const logFileOutput = (outputFile) => {
|
|
53
54
|
console.log(`${clicolors.blue}JSCAD: generating output ${clicolors.red}
|
|
54
55
|
from: ${clicolors.green} ${inputFile} ${clicolors.red}
|
|
55
|
-
to: ${clicolors.green} ${outputFile} ${clicolors.yellow}(${
|
|
56
|
+
to: ${clicolors.green} ${outputFile} ${clicolors.yellow}(${supportedFormats[outputFormat].description}) ${clicolors.black}
|
|
56
57
|
`)
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
// read input data
|
|
60
|
-
|
|
61
|
+
let encoding = 'UTF8'
|
|
62
|
+
if (inputFile.match(/\.stl$/i)) encoding = 'binary'
|
|
63
|
+
if (inputFile.match(/\.3mf$/i)) encoding = null // force raw buffer
|
|
64
|
+
|
|
65
|
+
const src = fs.readFileSync(inputFile, encoding)
|
|
61
66
|
|
|
62
67
|
// -- convert from JSCAD script into the desired output format
|
|
63
68
|
// -- and write it to disk
|
package/cli.parameters.test.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import { dirname, resolve } from 'path'
|
|
3
|
+
import { execSync } from 'child_process'
|
|
4
|
+
import { cwd } from 'process'
|
|
5
|
+
import { fileURLToPath } from 'url'
|
|
3
6
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
import JSZip from 'jszip'
|
|
8
|
+
|
|
9
|
+
import test from 'ava'
|
|
10
|
+
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
12
|
+
const __dirname = dirname(__filename)
|
|
7
13
|
|
|
8
14
|
test.afterEach.always((t) => {
|
|
9
15
|
// remove files
|
|
@@ -29,7 +35,7 @@ test.afterEach.always((t) => {
|
|
|
29
35
|
test.beforeEach((t) => {
|
|
30
36
|
const cliName = './cli.js'
|
|
31
37
|
t.context = {
|
|
32
|
-
cliPath:
|
|
38
|
+
cliPath: resolve(cwd(), cliName)
|
|
33
39
|
}
|
|
34
40
|
})
|
|
35
41
|
|
|
@@ -41,31 +47,29 @@ test.beforeEach((t) => {
|
|
|
41
47
|
// the script should produce ALL geometry types
|
|
42
48
|
const createJscad = (id, multipart = false) => {
|
|
43
49
|
const jscadScript = `// test script ${id}
|
|
44
|
-
|
|
50
|
+
import { arc, ellipse, ellipsoid } from '@jscad/modeling'
|
|
45
51
|
|
|
46
|
-
const getParameterDefinitions = () => {
|
|
52
|
+
export const getParameterDefinitions = () => {
|
|
47
53
|
return [
|
|
48
|
-
{ name: 'segments', caption: '
|
|
54
|
+
{ name: 'segments', caption: 'Segments:', type: 'int', initial: 10, min: 5, max: 20, step: 1 }
|
|
49
55
|
]
|
|
50
56
|
}
|
|
51
57
|
|
|
52
|
-
const main = (params) => {
|
|
58
|
+
export const main = (params) => {
|
|
53
59
|
// parameters
|
|
54
60
|
let segments = params.segments || 16
|
|
55
61
|
|
|
56
62
|
// shapes
|
|
57
|
-
let apath2 =
|
|
58
|
-
let ageom2 =
|
|
59
|
-
let ageom3 =
|
|
63
|
+
let apath2 = arc()
|
|
64
|
+
let ageom2 = ellipse()
|
|
65
|
+
let ageom3 = ellipsoid()
|
|
60
66
|
|
|
61
67
|
${multipart ? 'return [ageom3, ageom3, ageom3]' : 'return [apath2, ageom2, ageom3]'}
|
|
62
68
|
}
|
|
63
|
-
|
|
64
|
-
module.exports = { main, getParameterDefinitions }
|
|
65
69
|
`
|
|
66
70
|
|
|
67
|
-
const fileName = `./test${id}.
|
|
68
|
-
const filePath =
|
|
71
|
+
const fileName = `./test${id}.js`
|
|
72
|
+
const filePath = resolve(cwd(), fileName)
|
|
69
73
|
fs.writeFileSync(filePath, jscadScript)
|
|
70
74
|
return filePath
|
|
71
75
|
}
|
|
@@ -79,7 +83,7 @@ test('cli (single input file)', (t) => {
|
|
|
79
83
|
t.context.inputPath = inputPath
|
|
80
84
|
|
|
81
85
|
const outputName = `./test${testID}.stl`
|
|
82
|
-
const outputPath =
|
|
86
|
+
const outputPath = resolve(cwd(), outputName)
|
|
83
87
|
t.false(fs.existsSync(outputPath))
|
|
84
88
|
|
|
85
89
|
t.context.outputPath = outputPath
|
|
@@ -100,7 +104,7 @@ test('cli (single input file, output format)', (t) => {
|
|
|
100
104
|
t.context.inputPath = inputPath
|
|
101
105
|
|
|
102
106
|
const outputName = `./test${testID}.dxf`
|
|
103
|
-
const outputPath =
|
|
107
|
+
const outputPath = resolve(cwd(), outputName)
|
|
104
108
|
t.false(fs.existsSync(outputPath))
|
|
105
109
|
|
|
106
110
|
t.context.outputPath = outputPath
|
|
@@ -120,8 +124,8 @@ test('cli (single input file, output filename)', (t) => {
|
|
|
120
124
|
|
|
121
125
|
t.context.inputPath = inputPath
|
|
122
126
|
|
|
123
|
-
const outputName = `./test${testID}.
|
|
124
|
-
const outputPath =
|
|
127
|
+
const outputName = `./test${testID}.obj`
|
|
128
|
+
const outputPath = resolve(cwd(), outputName)
|
|
125
129
|
t.false(fs.existsSync(outputPath))
|
|
126
130
|
|
|
127
131
|
t.context.outputPath = outputPath
|
|
@@ -141,7 +145,7 @@ test('cli (folder, output format)', (t) => {
|
|
|
141
145
|
|
|
142
146
|
t.context.inputPath = inputPath
|
|
143
147
|
|
|
144
|
-
const folderPath =
|
|
148
|
+
const folderPath = resolve(cwd(), './test-folder')
|
|
145
149
|
t.false(fs.existsSync(folderPath))
|
|
146
150
|
|
|
147
151
|
fs.mkdirSync(folderPath)
|
|
@@ -149,14 +153,14 @@ test('cli (folder, output format)', (t) => {
|
|
|
149
153
|
|
|
150
154
|
t.context.folderPath = folderPath
|
|
151
155
|
|
|
152
|
-
const mainPath =
|
|
156
|
+
const mainPath = resolve(cwd(), './test-folder/main.js')
|
|
153
157
|
fs.renameSync(inputPath, mainPath)
|
|
154
158
|
t.true(fs.existsSync(mainPath))
|
|
155
159
|
|
|
156
160
|
t.context.inputPath = mainPath
|
|
157
161
|
|
|
158
162
|
const outputName = './test-folder/main.dxf'
|
|
159
|
-
const outputPath =
|
|
163
|
+
const outputPath = resolve(cwd(), outputName)
|
|
160
164
|
t.false(fs.existsSync(outputPath))
|
|
161
165
|
|
|
162
166
|
t.context.outputPath = outputPath
|
|
@@ -177,7 +181,7 @@ test('cli (single input file, parameters)', (t) => {
|
|
|
177
181
|
t.context.inputPath = inputPath
|
|
178
182
|
|
|
179
183
|
const outputName = `./test${testID}.stl`
|
|
180
|
-
const outputPath =
|
|
184
|
+
const outputPath = resolve(cwd(), outputName)
|
|
181
185
|
t.false(fs.existsSync(outputPath))
|
|
182
186
|
|
|
183
187
|
t.context.outputPath = outputPath
|
|
@@ -189,7 +193,7 @@ test('cli (single input file, parameters)', (t) => {
|
|
|
189
193
|
t.true(fs.existsSync(outputPath))
|
|
190
194
|
})
|
|
191
195
|
|
|
192
|
-
test('cli (no parameters)', (t) => {
|
|
196
|
+
test('cli (no parameters, out help)', (t) => {
|
|
193
197
|
const cliPath = t.context.cliPath
|
|
194
198
|
|
|
195
199
|
const cmd = `node ${cliPath}`
|
|
@@ -224,9 +228,9 @@ test('cli (single input file, multiple output files)', (t) => {
|
|
|
224
228
|
t.context.inputPath = inputPath
|
|
225
229
|
|
|
226
230
|
const outputName = (partNum) => `./test${testID}-part-${partNum}-of-3.stl`
|
|
227
|
-
const outputPath1 =
|
|
228
|
-
const outputPath2 =
|
|
229
|
-
const outputPath3 =
|
|
231
|
+
const outputPath1 = resolve(__dirname, outputName(1))
|
|
232
|
+
const outputPath2 = resolve(__dirname, outputName(2))
|
|
233
|
+
const outputPath3 = resolve(__dirname, outputName(3))
|
|
230
234
|
t.false(fs.existsSync(outputPath1))
|
|
231
235
|
t.false(fs.existsSync(outputPath2))
|
|
232
236
|
t.false(fs.existsSync(outputPath3))
|
|
@@ -253,7 +257,7 @@ test('cli (single multipart input file, zipped output file)', async (t) => {
|
|
|
253
257
|
t.context.inputPath = inputPath
|
|
254
258
|
|
|
255
259
|
const outputName = `./test${testID}.zip`
|
|
256
|
-
const outputPath =
|
|
260
|
+
const outputPath = resolve(__dirname, outputName)
|
|
257
261
|
|
|
258
262
|
t.false(fs.existsSync(outputPath))
|
|
259
263
|
|
|
@@ -268,9 +272,9 @@ test('cli (single multipart input file, zipped output file)', async (t) => {
|
|
|
268
272
|
// check contents of zip file
|
|
269
273
|
const data = await fs.promises.readFile(outputPath)
|
|
270
274
|
const content = await JSZip.loadAsync(data)
|
|
271
|
-
t.true(content.files[
|
|
272
|
-
t.true(content.files[
|
|
273
|
-
t.true(content.files[
|
|
275
|
+
t.true(content.files[resolve(__dirname, `./test${testID}-part-1-of-3.stl`)] !== undefined)
|
|
276
|
+
t.true(content.files[resolve(__dirname, `./test${testID}-part-2-of-3.stl`)] !== undefined)
|
|
277
|
+
t.true(content.files[resolve(__dirname, `./test${testID}-part-3-of-3.stl`)] !== undefined)
|
|
274
278
|
})
|
|
275
279
|
|
|
276
280
|
test('cli (single input file, zipped output file)', async (t) => {
|
|
@@ -282,7 +286,7 @@ test('cli (single input file, zipped output file)', async (t) => {
|
|
|
282
286
|
t.context.inputPath = inputPath
|
|
283
287
|
|
|
284
288
|
const outputName = `./test${testID}.zip`
|
|
285
|
-
const outputPath =
|
|
289
|
+
const outputPath = resolve(__dirname, outputName)
|
|
286
290
|
|
|
287
291
|
t.false(fs.existsSync(outputPath))
|
|
288
292
|
|
|
@@ -297,5 +301,5 @@ test('cli (single input file, zipped output file)', async (t) => {
|
|
|
297
301
|
// check contents of zip file
|
|
298
302
|
const data = await fs.promises.readFile(outputPath)
|
|
299
303
|
const content = await JSZip.loadAsync(data)
|
|
300
|
-
t.true(content.files[
|
|
304
|
+
t.true(content.files[resolve(__dirname, `./test${testID}.stl`)] !== undefined)
|
|
301
305
|
})
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscad/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1-alpha.0",
|
|
4
4
|
"description": "Command Line Interface (CLI) for JSCAD",
|
|
5
5
|
"homepage": "https://openjscad.xyz/",
|
|
6
6
|
"repository": "https://github.com/jscad/OpenJSCAD.org",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"bin": {
|
|
8
9
|
"jscad": "./cli.js"
|
|
9
10
|
},
|
|
10
11
|
"scripts": {
|
|
11
|
-
"coverage": "
|
|
12
|
+
"coverage": "c8 --all --reporter=html --reporter=text npm test",
|
|
12
13
|
"test": "ava '*.test.js' --serial --verbose --timeout 2m",
|
|
13
14
|
"postinstall": "node -e \"console.log('\\u001b[35m\\u001b[1mLove JSCAD? You can now donate to our open collective:\\u001b[22m\\u001b[39m\\n > \\u001b[34mhttps://opencollective.com/openjscad/donate\\u001b[0m')\""
|
|
14
15
|
},
|
|
@@ -35,20 +36,21 @@
|
|
|
35
36
|
],
|
|
36
37
|
"license": "MIT",
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@jscad/array-utils": "
|
|
39
|
-
"@jscad/core": "
|
|
40
|
-
"@jscad/io": "
|
|
41
|
-
"@jscad/
|
|
39
|
+
"@jscad/array-utils": "3.0.1-alpha.0",
|
|
40
|
+
"@jscad/core": "3.0.1-alpha.0",
|
|
41
|
+
"@jscad/io": "3.0.1-alpha.0",
|
|
42
|
+
"@jscad/io-utils": "3.0.1-alpha.0",
|
|
43
|
+
"@jscad/modeling": "3.0.1-alpha.0",
|
|
42
44
|
"jszip": "^3.10.1"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
|
-
"ava": "3.
|
|
46
|
-
"
|
|
47
|
+
"ava": "^4.3.3",
|
|
48
|
+
"c8": "^8.0.0"
|
|
47
49
|
},
|
|
48
50
|
"collective": {
|
|
49
51
|
"type": "opencollective",
|
|
50
52
|
"url": "https://opencollective.com/openjscad",
|
|
51
53
|
"logo": "https://opencollective.com/openjscad/logo.txt"
|
|
52
54
|
},
|
|
53
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "0660b5c1f1a5faf54d4cfae1cb85bb94182a8d32"
|
|
54
56
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { supportedOutputExtensions, supportedOutputFormats } from '@jscad/io'
|
|
2
2
|
|
|
3
|
-
const determineOutputNameAndFormat = (outputFormat, outputFile, inputFile) => {
|
|
3
|
+
export const determineOutputNameAndFormat = (outputFormat, outputFile, inputFile) => {
|
|
4
4
|
const extReg = new RegExp(`\\.(${supportedOutputExtensions().join('|')})$`)
|
|
5
5
|
const forReg = new RegExp(`(${supportedOutputFormats().join('|')})`, 'i')
|
|
6
6
|
|
|
@@ -22,5 +22,3 @@ const determineOutputNameAndFormat = (outputFormat, outputFile, inputFile) => {
|
|
|
22
22
|
}
|
|
23
23
|
return { outputFormat, outputFile }
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
module.exports = determineOutputNameAndFormat
|
package/src/env.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import os from 'os'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const version = '[VI]{version}[/VI]' // version is injected by rollup
|
|
4
|
+
|
|
5
|
+
export const env = () => {
|
|
4
6
|
let env = 'JSCAD ' + version
|
|
5
7
|
if (typeof document !== 'undefined') {
|
|
6
8
|
const w = document.defaultView
|
|
7
9
|
env = env + ' [' + w.navigator.userAgent + ']'
|
|
8
10
|
} else {
|
|
9
|
-
|
|
10
|
-
const os = require('os')
|
|
11
|
-
env = env + ' [' + os.type() + ':' + os.release() + ',' + os.platform() + ':' + os.arch() + ']'
|
|
12
|
-
}
|
|
11
|
+
env = env + ' [' + os.type() + ':' + os.release() + ',' + os.platform() + ':' + os.arch() + ']'
|
|
13
12
|
}
|
|
14
13
|
console.log(env)
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
module.exports = env
|