@jscad/cli 2.2.7 → 2.2.11
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 +36 -0
- package/cli.conversions.test.js +162 -8
- package/cli.js +4 -1
- package/cli.parameters.test.js +27 -1
- package/package.json +5 -5
- package/src/generateOutputData.js +8 -12
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,42 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.2.11](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/cli@2.2.10...@jscad/cli@2.2.11) (2021-12-11)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @jscad/cli
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [2.2.10](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/cli@2.2.9...@jscad/cli@2.2.10) (2021-11-07)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @jscad/cli
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [2.2.9](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/cli@2.2.8...@jscad/cli@2.2.9) (2021-10-17)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* **cli:** corrected cli to exit with non-zero code in case of errors ([#931](https://github.com/jscad/OpenJSCAD.org/issues/931)) ([e66a285](https://github.com/jscad/OpenJSCAD.org/commit/e66a2851693397d2d667f7d64aef7a4f52282d80))
|
|
28
|
+
* **cli:** corrected generateOutputData to use registered deserializers from IO module, and added conversion tests ([ac7cba7](https://github.com/jscad/OpenJSCAD.org/commit/ac7cba7547c75e6d7cfc9fb680eba347d7f6a7ae))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## [2.2.8](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/cli@2.2.7...@jscad/cli@2.2.8) (2021-10-04)
|
|
35
|
+
|
|
36
|
+
**Note:** Version bump only for package @jscad/cli
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
6
42
|
## [2.2.7](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/cli@2.2.6...@jscad/cli@2.2.7) (2021-09-27)
|
|
7
43
|
|
|
8
44
|
**Note:** Version bump only for package @jscad/cli
|
package/cli.conversions.test.js
CHANGED
|
@@ -68,7 +68,7 @@ module.exports = { main, getParameterDefinitions }
|
|
|
68
68
|
return filePath
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
test('cli (conversions)', t => {
|
|
71
|
+
test('cli (conversions STL)', t => {
|
|
72
72
|
const testID = 11
|
|
73
73
|
|
|
74
74
|
// convert from JSCAD script to STL
|
|
@@ -99,15 +99,169 @@ test('cli (conversions)', t => {
|
|
|
99
99
|
cmd = `node ${cliPath} ${file2Path} -o ${file3Path} -v -add-metadata false`
|
|
100
100
|
execSync(cmd, { stdio: [0, 1, 2] })
|
|
101
101
|
t.true(fs.existsSync(file3Path))
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('cli (conversions DXF)', t => {
|
|
105
|
+
const testID = 12
|
|
106
|
+
|
|
107
|
+
// convert from JSCAD to DXF
|
|
108
|
+
const file1Path = createJscad(testID)
|
|
109
|
+
t.true(fs.existsSync(file1Path))
|
|
110
|
+
|
|
111
|
+
t.context.file1Path = file1Path
|
|
112
|
+
|
|
113
|
+
const file2Name = `./test${testID}.dxf`
|
|
114
|
+
const file2Path = path.resolve(__dirname, file2Name)
|
|
115
|
+
t.false(fs.existsSync(file2Path))
|
|
116
|
+
|
|
117
|
+
t.context.file2Path = file2Path
|
|
118
|
+
|
|
119
|
+
const cliPath = t.context.cliPath
|
|
120
|
+
|
|
121
|
+
let cmd = `node ${cliPath} ${file1Path} -of dxf`
|
|
122
|
+
execSync(cmd, { stdio: [0, 1, 2] })
|
|
123
|
+
t.true(fs.existsSync(file2Path))
|
|
124
|
+
|
|
125
|
+
// convert from DXF to JS
|
|
126
|
+
const file3Name = `./test${testID}.js`
|
|
127
|
+
const file3Path = path.resolve(__dirname, file3Name)
|
|
128
|
+
t.false(fs.existsSync(file3Path))
|
|
129
|
+
|
|
130
|
+
t.context.file3Path = file3Path
|
|
131
|
+
|
|
132
|
+
cmd = `node ${cliPath} ${file2Path} -of js`
|
|
133
|
+
execSync(cmd, { stdio: [0, 1, 2] })
|
|
134
|
+
t.true(fs.existsSync(file3Path))
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
test('cli (conversions AMF)', t => {
|
|
138
|
+
const testID = 13
|
|
139
|
+
|
|
140
|
+
// convert from JSCAD to AMF
|
|
141
|
+
const file1Path = createJscad(testID)
|
|
142
|
+
t.true(fs.existsSync(file1Path))
|
|
143
|
+
|
|
144
|
+
t.context.file1Path = file1Path
|
|
145
|
+
|
|
146
|
+
const file2Name = `./test${testID}.amf`
|
|
147
|
+
const file2Path = path.resolve(__dirname, file2Name)
|
|
148
|
+
t.false(fs.existsSync(file2Path))
|
|
149
|
+
|
|
150
|
+
t.context.file2Path = file2Path
|
|
151
|
+
|
|
152
|
+
const cliPath = t.context.cliPath
|
|
153
|
+
|
|
154
|
+
let cmd = `node ${cliPath} ${file1Path} -of amf`
|
|
155
|
+
execSync(cmd, { stdio: [0, 1, 2] })
|
|
156
|
+
t.true(fs.existsSync(file2Path))
|
|
157
|
+
|
|
158
|
+
// convert from AMF to JS
|
|
159
|
+
const file3Name = `./test${testID}.js`
|
|
160
|
+
const file3Path = path.resolve(__dirname, file3Name)
|
|
161
|
+
t.false(fs.existsSync(file3Path))
|
|
162
|
+
|
|
163
|
+
t.context.file3Path = file3Path
|
|
164
|
+
|
|
165
|
+
cmd = `node ${cliPath} ${file2Path} -of js`
|
|
166
|
+
execSync(cmd, { stdio: [0, 1, 2] })
|
|
167
|
+
t.true(fs.existsSync(file3Path))
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
test('cli (conversions JSON)', t => {
|
|
171
|
+
const testID = 14
|
|
172
|
+
|
|
173
|
+
// convert from JSCAD to JSON
|
|
174
|
+
const file1Path = createJscad(testID)
|
|
175
|
+
t.true(fs.existsSync(file1Path))
|
|
176
|
+
|
|
177
|
+
t.context.file1Path = file1Path
|
|
178
|
+
|
|
179
|
+
const file2Name = `./test${testID}.json`
|
|
180
|
+
const file2Path = path.resolve(__dirname, file2Name)
|
|
181
|
+
t.false(fs.existsSync(file2Path))
|
|
182
|
+
|
|
183
|
+
t.context.file2Path = file2Path
|
|
184
|
+
|
|
185
|
+
const cliPath = t.context.cliPath
|
|
186
|
+
|
|
187
|
+
let cmd = `node ${cliPath} ${file1Path} -of json`
|
|
188
|
+
execSync(cmd, { stdio: [0, 1, 2] })
|
|
189
|
+
t.true(fs.existsSync(file2Path))
|
|
190
|
+
|
|
191
|
+
// convert from JSON to JS
|
|
192
|
+
const file3Name = `./test${testID}.js`
|
|
193
|
+
const file3Path = path.resolve(__dirname, file3Name)
|
|
194
|
+
t.false(fs.existsSync(file3Path))
|
|
195
|
+
|
|
196
|
+
t.context.file3Path = file3Path
|
|
197
|
+
|
|
198
|
+
cmd = `node ${cliPath} ${file2Path} -of js`
|
|
199
|
+
execSync(cmd, { stdio: [0, 1, 2] })
|
|
200
|
+
t.true(fs.existsSync(file3Path))
|
|
201
|
+
})
|
|
102
202
|
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
const file4Path = path.resolve(__dirname, file4Name)
|
|
106
|
-
t.false(fs.existsSync(file4Path))
|
|
203
|
+
test('cli (conversions SVG)', t => {
|
|
204
|
+
const testID = 15
|
|
107
205
|
|
|
108
|
-
|
|
206
|
+
// convert from JSCAD to SVG
|
|
207
|
+
const file1Path = createJscad(testID)
|
|
208
|
+
t.true(fs.existsSync(file1Path))
|
|
209
|
+
|
|
210
|
+
t.context.file1Path = file1Path
|
|
211
|
+
|
|
212
|
+
const file2Name = `./test${testID}.svg`
|
|
213
|
+
const file2Path = path.resolve(__dirname, file2Name)
|
|
214
|
+
t.false(fs.existsSync(file2Path))
|
|
215
|
+
|
|
216
|
+
t.context.file2Path = file2Path
|
|
217
|
+
|
|
218
|
+
const cliPath = t.context.cliPath
|
|
109
219
|
|
|
110
|
-
cmd = `node ${cliPath} ${
|
|
220
|
+
let cmd = `node ${cliPath} ${file1Path} -of svg`
|
|
111
221
|
execSync(cmd, { stdio: [0, 1, 2] })
|
|
112
|
-
t.true(fs.existsSync(
|
|
222
|
+
t.true(fs.existsSync(file2Path))
|
|
223
|
+
|
|
224
|
+
// convert from SVG to JS
|
|
225
|
+
const file3Name = `./test${testID}.js`
|
|
226
|
+
const file3Path = path.resolve(__dirname, file3Name)
|
|
227
|
+
t.false(fs.existsSync(file3Path))
|
|
228
|
+
|
|
229
|
+
t.context.file3Path = file3Path
|
|
230
|
+
|
|
231
|
+
cmd = `node ${cliPath} ${file2Path} -of js`
|
|
232
|
+
execSync(cmd, { stdio: [0, 1, 2] })
|
|
233
|
+
t.true(fs.existsSync(file3Path))
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
test('cli (conversions X3D)', t => {
|
|
237
|
+
const testID = 16
|
|
238
|
+
|
|
239
|
+
// convert from JSCAD to X3D
|
|
240
|
+
const file1Path = createJscad(testID)
|
|
241
|
+
t.true(fs.existsSync(file1Path))
|
|
242
|
+
|
|
243
|
+
t.context.file1Path = file1Path
|
|
244
|
+
|
|
245
|
+
const file2Name = `./test${testID}.x3d`
|
|
246
|
+
const file2Path = path.resolve(__dirname, file2Name)
|
|
247
|
+
t.false(fs.existsSync(file2Path))
|
|
248
|
+
|
|
249
|
+
t.context.file2Path = file2Path
|
|
250
|
+
|
|
251
|
+
const cliPath = t.context.cliPath
|
|
252
|
+
|
|
253
|
+
let cmd = `node ${cliPath} ${file1Path} -of x3d`
|
|
254
|
+
execSync(cmd, { stdio: [0, 1, 2] })
|
|
255
|
+
t.true(fs.existsSync(file2Path))
|
|
256
|
+
|
|
257
|
+
// convert from X3D to JS
|
|
258
|
+
const file3Name = `./test${testID}.js`
|
|
259
|
+
const file3Path = path.resolve(__dirname, file3Name)
|
|
260
|
+
t.false(fs.existsSync(file3Path))
|
|
261
|
+
|
|
262
|
+
t.context.file3Path = file3Path
|
|
263
|
+
|
|
264
|
+
cmd = `node ${cliPath} ${file2Path} -of js`
|
|
265
|
+
execSync(cmd, { stdio: [0, 1, 2] })
|
|
266
|
+
t.true(fs.existsSync(file3Path))
|
|
113
267
|
})
|
package/cli.js
CHANGED
|
@@ -60,4 +60,7 @@ const src = fs.readFileSync(inputFile, inputFile.match(/\.stl$/i) ? 'binary' : '
|
|
|
60
60
|
// -- and write it to disk
|
|
61
61
|
generateOutputData(src, params, { outputFile, outputFormat, inputFile, inputFormat, version, addMetaData, inputIsDirectory })
|
|
62
62
|
.then(outputData => writeOutput(outputFile, outputData))
|
|
63
|
-
.catch(error =>
|
|
63
|
+
.catch(error => {
|
|
64
|
+
console.error(error)
|
|
65
|
+
process.exit(1)
|
|
66
|
+
})
|
package/cli.parameters.test.js
CHANGED
|
@@ -126,7 +126,7 @@ test('cli (single input file, output filename)', t => {
|
|
|
126
126
|
t.true(fs.existsSync(outputPath))
|
|
127
127
|
})
|
|
128
128
|
|
|
129
|
-
test('cli (folder, output format', t => {
|
|
129
|
+
test('cli (folder, output format)', t => {
|
|
130
130
|
const testID = 4
|
|
131
131
|
|
|
132
132
|
const inputPath = createJscad(testID)
|
|
@@ -181,3 +181,29 @@ test('cli (single input file, parameters)', t => {
|
|
|
181
181
|
execSync(cmd, { stdio: [0, 1, 2] })
|
|
182
182
|
t.true(fs.existsSync(outputPath))
|
|
183
183
|
})
|
|
184
|
+
|
|
185
|
+
test('cli (no parameters)', t => {
|
|
186
|
+
const cliPath = t.context.cliPath
|
|
187
|
+
|
|
188
|
+
const cmd = `node ${cliPath}`
|
|
189
|
+
t.throws(() => {
|
|
190
|
+
execSync(cmd, { stdio: [0, 1, 2] })
|
|
191
|
+
})
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
test('cli (single input file, invalid jscad)', t => {
|
|
195
|
+
const testID = 6
|
|
196
|
+
|
|
197
|
+
const inputPath = createJscad(testID)
|
|
198
|
+
fs.writeFileSync(inputPath, "INVALID")
|
|
199
|
+
t.true(fs.existsSync(inputPath))
|
|
200
|
+
|
|
201
|
+
t.context.inputPath = inputPath
|
|
202
|
+
|
|
203
|
+
const cliPath = t.context.cliPath
|
|
204
|
+
|
|
205
|
+
const cmd = `node ${cliPath} ${inputPath}`
|
|
206
|
+
t.throws(() => {
|
|
207
|
+
execSync(cmd, { stdio: [0, 1, 2] })
|
|
208
|
+
})
|
|
209
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscad/cli",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.11",
|
|
4
4
|
"description": "Command Line Interface (CLI) for JSCAD",
|
|
5
5
|
"repository": "https://github.com/jscad/OpenJSCAD.org",
|
|
6
6
|
"bin": {
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@jscad/array-utils": "2.1.0",
|
|
38
|
-
"@jscad/core": "2.
|
|
39
|
-
"@jscad/io": "2.
|
|
40
|
-
"@jscad/modeling": "2.
|
|
38
|
+
"@jscad/core": "2.5.1",
|
|
39
|
+
"@jscad/io": "2.2.1",
|
|
40
|
+
"@jscad/modeling": "2.7.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"ava": "3.15.0",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"url": "https://opencollective.com/openjscad",
|
|
49
49
|
"logo": "https://opencollective.com/openjscad/logo.txt"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "fbc9b90f0ae02bea4e6e7b974c65e751c3858269"
|
|
52
52
|
}
|
|
@@ -32,23 +32,19 @@ const generateOutputData = (source, params, options) => {
|
|
|
32
32
|
registerAllExtensions(fs, require)
|
|
33
33
|
|
|
34
34
|
return new Promise((resolve, reject) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
json: data => deserializers.json(data.options, data.source),
|
|
43
|
-
jscad: data => data.source,
|
|
44
|
-
js: data => data.source,
|
|
45
|
-
undefined: data => reject(new Error(`unsuported input format ${inputFormat}`))
|
|
35
|
+
let deserializer = deserializers[inputFormat]
|
|
36
|
+
if (!deserializer) {
|
|
37
|
+
if (inputFormat === 'jscad' || inputFormat === 'js') {
|
|
38
|
+
deserializer = (options, source) => source
|
|
39
|
+
} else {
|
|
40
|
+
reject(new Error(`unsuported input format ${inputFormat}`))
|
|
41
|
+
}
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
// convert any inputs
|
|
49
45
|
const prevsource = source
|
|
50
46
|
const deserializerOptions = Object.assign({}, params, options)
|
|
51
|
-
source =
|
|
47
|
+
source = deserializer(deserializerOptions, source)
|
|
52
48
|
const useFakeFs = (source !== prevsource) // conversion, so use a fake file system when rebuilding
|
|
53
49
|
|
|
54
50
|
if (outputFormat === 'jscad' || outputFormat === 'js') {
|