@jscad/core 2.6.12 → 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 +8 -268
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/jscad-core.min.js +546 -576
- package/package.json +15 -16
- package/src/code-evaluation/index.js +4 -6
- package/src/code-evaluation/instanciateDesign.js +5 -9
- package/src/code-evaluation/rebuildGeometry.js +6 -8
- package/src/code-evaluation/rebuildGeometryCli.js +14 -11
- package/src/code-evaluation/rebuildGeometryWorker.js +3 -5
- package/src/code-evaluation/serializeSolids.js +2 -4
- package/src/code-loading/index.js +2 -4
- package/src/code-loading/isCommonJsModule.js +1 -3
- package/src/code-loading/loadDesign.js +8 -10
- package/src/code-loading/makeFakeFs.js +2 -3
- package/src/code-loading/modulifySource.js +6 -24
- package/src/code-loading/normalizeDesignModule.js +1 -3
- package/src/code-loading/requireDesignFromModule.js +4 -9
- package/src/code-loading/requireDesignUtilsFs.js +5 -9
- package/src/code-loading/transformSources.js +2 -4
- package/src/code-loading/validateDesignModule.js +1 -3
- package/src/code-loading/vtreeApi.js +1 -1
- package/src/code-loading/webRequire.js +36 -28
- package/src/code-loading/webRequire.test.js +8 -9
- package/src/index.js +14 -7
- package/src/io/index.js +2 -4
- package/src/io/registerExtensions.js +11 -18
- package/src/parameters/applyParameterDefinitions.js +1 -4
- package/src/parameters/getParameterDefinitionsAndValues.js +5 -6
- package/src/parameters/getParameterDefinitionsFromSource.js +10 -12
- package/src/parameters/getParameterDefinitionsFromSource.test.js +2 -3
- package/src/parameters/getParameterValuesFromParameters.js +2 -4
- package/src/parameters/getParameterValuesFromUIControls.js +2 -4
- package/src/parameters/index.js +4 -6
- package/src/utils/getFileExtensionFromString.js +1 -3
- package/src/utils/index.js +2 -4
- package/src/utils/version.js +1 -3
- package/src/web/index.js +1 -3
- package/src/web/walkFileTree.js +7 -9
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import test from 'ava'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { registerAllExtensions } from '../io/registerExtensions.js'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { makeWebRequire } from './webRequire.js'
|
|
6
|
+
import { makeFakeFs } from './makeFakeFs.js'
|
|
7
7
|
|
|
8
8
|
test.beforeEach((t) => {
|
|
9
9
|
})
|
|
@@ -76,10 +76,9 @@ test('webRequire: should support require, from a directory with dependent files'
|
|
|
76
76
|
|
|
77
77
|
test('webRequire: should allow using require.extensions like the native node require (simple)', (t) => {
|
|
78
78
|
const registerJscadExtension = (fs, _require) => {
|
|
79
|
-
const stripBom = require('strip-bom')
|
|
80
79
|
_require.extensions['.jscad'] = (module, filename) => {
|
|
81
80
|
const content = fs.readFileSync(filename, 'utf8')
|
|
82
|
-
module._compile(
|
|
81
|
+
module._compile(content, filename)
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
84
|
|
|
@@ -107,7 +106,7 @@ test('webRequire: should allow using require.extensions like the native node req
|
|
|
107
106
|
t.true(designRootModule.main instanceof Function)
|
|
108
107
|
})
|
|
109
108
|
|
|
110
|
-
test('webRequire: should allow using require.extensions like the native node require (parser)', (t) => {
|
|
109
|
+
test.skip('webRequire: should allow using require.extensions like the native node require (parser)', (t) => {
|
|
111
110
|
const registerStlExtension = (fs, _require) => {
|
|
112
111
|
const { deserializers } = require('@jscad/io')
|
|
113
112
|
const deserializer = deserializers.stl
|
|
@@ -168,7 +167,7 @@ const singleFileJs = [
|
|
|
168
167
|
fullPath: '/logo.js',
|
|
169
168
|
name: 'logo.js',
|
|
170
169
|
source: `
|
|
171
|
-
const { cube } = require('@jscad/modeling')
|
|
170
|
+
const { cube } = require('@jscad/modeling')
|
|
172
171
|
|
|
173
172
|
const main = () => {
|
|
174
173
|
return cube()
|
|
@@ -317,7 +316,7 @@ const directoryWithDependencies = [
|
|
|
317
316
|
fullPath: '/project/file2.js',
|
|
318
317
|
name: 'file2.js',
|
|
319
318
|
source: `
|
|
320
|
-
const { cube } = require('@jscad/modeling')
|
|
319
|
+
const { cube } = require('@jscad/modeling')
|
|
321
320
|
|
|
322
321
|
const file2 = () => {
|
|
323
322
|
return cube()
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import * as evaluation from './code-evaluation/index.js'
|
|
2
|
+
import * as io from './io/index.js'
|
|
3
|
+
import * as loading from './code-loading/index.js'
|
|
4
|
+
import * as parameters from './parameters/index.js'
|
|
5
|
+
import * as utils from './utils/index.js'
|
|
6
|
+
import * as web from './web/index.js'
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
evaluation,
|
|
10
|
+
io,
|
|
11
|
+
loading,
|
|
12
|
+
parameters,
|
|
13
|
+
utils,
|
|
14
|
+
web
|
|
8
15
|
}
|
package/src/io/index.js
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
unRegisterAllExtensions: require('./registerExtensions').unRegisterAllExtensions
|
|
4
|
-
}
|
|
1
|
+
export { registerAllExtensions } from './registerExtensions.js'
|
|
2
|
+
export { unRegisterAllExtensions } from './registerExtensions.js'
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import stripBom from 'strip-bom'
|
|
2
|
+
|
|
3
|
+
import { deserializers } from '@jscad/io'
|
|
2
4
|
|
|
3
5
|
// FIXME: the unregistering does not work, look into it
|
|
4
6
|
const registerJscadExtension = (fs, _require) => {
|
|
5
|
-
const stripBom = require('strip-bom')
|
|
6
7
|
_require.extensions['.jscad'] = (module, filename) => {
|
|
7
8
|
const content = fs.readFileSync(filename, 'utf8')
|
|
8
9
|
module._compile(stripBom(content), filename)
|
|
@@ -16,17 +17,14 @@ const registerDeserializer = (extension, fs, _require) => {
|
|
|
16
17
|
const deserializer = deserializers[extension]
|
|
17
18
|
const fileExtension = '.' + extension
|
|
18
19
|
_require.extensions[fileExtension] = (module, filename) => {
|
|
19
|
-
const fileReadResult = fs.readFileSync(filename)
|
|
20
|
-
|
|
21
|
-
// https://nodejs.org/api/buffer.html#bufbuffer: Buffer.buffer is not
|
|
20
|
+
const fileReadResult = fs.readFileSync(filename) // read into buffer
|
|
21
|
+
// NOTE: https://nodejs.org/api/buffer.html#bufbuffer: Buffer.buffer is not
|
|
22
22
|
// guaranteed to correspond exactly to the original Buffer.
|
|
23
|
-
const
|
|
24
|
-
? fileReadResult.buffer.slice(
|
|
25
|
-
|
|
26
|
-
fileReadResult.byteOffset + fileReadResult.length)
|
|
27
|
-
: fileReadResult
|
|
23
|
+
const content = fileReadResult.buffer
|
|
24
|
+
? fileReadResult.buffer.slice(fileReadResult.byteOffset, fileReadResult.byteOffset + fileReadResult.length)
|
|
25
|
+
: fileReadResult;
|
|
28
26
|
|
|
29
|
-
const parsed = deserializer({ filename, output: 'geometry' },
|
|
27
|
+
const parsed = deserializer({ filename, output: 'geometry' }, content)
|
|
30
28
|
module.exports = parsed
|
|
31
29
|
}
|
|
32
30
|
}
|
|
@@ -35,7 +33,7 @@ const unregisterDeserializer = (extension, fs, _require) => {
|
|
|
35
33
|
delete _require.extensions[fileExtension]
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
const registerAllExtensions = (fs, _require) => {
|
|
36
|
+
export const registerAllExtensions = (fs, _require) => {
|
|
39
37
|
registerJscadExtension(fs, _require)
|
|
40
38
|
|
|
41
39
|
for (const extension of Object.keys(deserializers)) {
|
|
@@ -43,15 +41,10 @@ const registerAllExtensions = (fs, _require) => {
|
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
const unRegisterAllExtensions = (fs, _require) => {
|
|
44
|
+
export const unRegisterAllExtensions = (fs, _require) => {
|
|
47
45
|
unRegisterJscadExtension(fs, _require)
|
|
48
46
|
|
|
49
47
|
for (const extension of Object.keys(deserializers)) {
|
|
50
48
|
unregisterDeserializer(extension, fs, _require)
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
|
-
|
|
54
|
-
module.exports = {
|
|
55
|
-
registerAllExtensions,
|
|
56
|
-
unRegisterAllExtensions
|
|
57
|
-
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* casts the parameters/ get their correct values based on the
|
|
4
3
|
* raw parameters (passed into the CLI tool for example) and the
|
|
@@ -7,7 +6,7 @@
|
|
|
7
6
|
* @param {Array} parameterDefinitions
|
|
8
7
|
* @returns {Object} the parameter values, as an object
|
|
9
8
|
*/
|
|
10
|
-
const applyParameterDefinitions = (inputParameters, parameterDefinitions, throwOnNoDefinition = false) => {
|
|
9
|
+
export const applyParameterDefinitions = (inputParameters, parameterDefinitions, throwOnNoDefinition = false) => {
|
|
11
10
|
const values = Object.keys(inputParameters).reduce((paramValues, paramName) => {
|
|
12
11
|
let value = inputParameters[paramName]
|
|
13
12
|
|
|
@@ -71,5 +70,3 @@ const valueForChoices = (inputValue, definition) => {
|
|
|
71
70
|
value = definition.values.length > 0 && typeof value === 'boolean' ? !!value : value
|
|
72
71
|
return value
|
|
73
72
|
}
|
|
74
|
-
|
|
75
|
-
module.exports = applyParameterDefinitions
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { getParameterValuesFromParameters } from './getParameterValuesFromParameters.js'
|
|
2
|
+
import { applyParameterDefinitions } from './applyParameterDefinitions.js'
|
|
3
3
|
|
|
4
4
|
const doesModuleExportParameterDefiniitions = (moduleToCheck) => moduleToCheck && 'getParameterDefinitions' in moduleToCheck
|
|
5
5
|
|
|
@@ -13,7 +13,8 @@ const getRawParameterDefinitionsAndValues = (rootModule, overrides) => {
|
|
|
13
13
|
return { parameterDefinitions, parameterValues }
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/*
|
|
17
|
+
* given the root/main module and optional parameter value overrides,
|
|
17
18
|
* returns parameterDefinitions & 'default' parameter values
|
|
18
19
|
* the overrides are passed for to enable the parameter definitions to access the PREVIOUS
|
|
19
20
|
* version of the parameter values
|
|
@@ -22,12 +23,10 @@ const getRawParameterDefinitionsAndValues = (rootModule, overrides) => {
|
|
|
22
23
|
* @param {Object} overrides an object containing parameter values, used as overrides
|
|
23
24
|
* @returns {Object} { parameterValues, parameterDefinitions }
|
|
24
25
|
*/
|
|
25
|
-
const
|
|
26
|
+
export const getParameterDefinitionsAndValues = (rootModule, overrides) => {
|
|
26
27
|
let { parameterDefinitions, parameterValues } = getRawParameterDefinitionsAndValues(rootModule, overrides)
|
|
27
28
|
parameterValues = Object.assign({}, parameterValues, overrides)
|
|
28
29
|
parameterValues = parameterValues ? applyParameterDefinitions(parameterValues, parameterDefinitions) : parameterValues
|
|
29
30
|
|
|
30
31
|
return { parameterValues, parameterDefinitions }
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
-
module.exports = getAllParameterDefintionsAndValues
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import JSON5 from 'json5'
|
|
2
2
|
|
|
3
3
|
/* Count leading spaces in a line.
|
|
4
4
|
This helps provide more descriptive comments after the parameter.
|
|
@@ -8,17 +8,17 @@ When comment line is indented more than parameter(incl. parameter name)
|
|
|
8
8
|
it is considered as description of previous parameter and not a group definition.
|
|
9
9
|
|
|
10
10
|
*/
|
|
11
|
-
const countSpaces = (
|
|
11
|
+
const countSpaces = (line) => {
|
|
12
12
|
let count = 0
|
|
13
|
-
for (let i = 0; i <
|
|
14
|
-
if (
|
|
15
|
-
else if (
|
|
13
|
+
for (let i = 0; i < line.length; i++) {
|
|
14
|
+
if (line[i] === ' ') count++
|
|
15
|
+
else if (line[i] === '\t') count += 2
|
|
16
16
|
else break
|
|
17
17
|
}
|
|
18
18
|
return count
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const getParameterDefinitionsFromSource = (script) => {
|
|
21
|
+
export const getParameterDefinitionsFromSource = (script) => {
|
|
22
22
|
const lines = []
|
|
23
23
|
script.split('\n').forEach((l, i) => {
|
|
24
24
|
const trim = l.trim()
|
|
@@ -94,7 +94,7 @@ const getParameterDefinitionsFromSource = (script) => {
|
|
|
94
94
|
return defs
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
const parseOne = (comment, code, line1, line2) => {
|
|
97
|
+
export const parseOne = (comment, code, line1, line2) => {
|
|
98
98
|
let def = parseDef(code, line2)
|
|
99
99
|
const { caption, options } = parseComment(comment, line1, def.name)
|
|
100
100
|
def.caption = caption || def.name
|
|
@@ -126,7 +126,7 @@ const extractTextFromComment = (c, lineNum) => {
|
|
|
126
126
|
return c
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
const parseComment = (comment, lineNum, paramName) => {
|
|
129
|
+
export const parseComment = (comment, lineNum, paramName) => {
|
|
130
130
|
comment = extractTextFromComment(comment, lineNum)
|
|
131
131
|
|
|
132
132
|
const ret = {}
|
|
@@ -145,7 +145,7 @@ const parseComment = (comment, lineNum, paramName) => {
|
|
|
145
145
|
return ret
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
const parseDef = (code, line) => {
|
|
148
|
+
export const parseDef = (code, line) => {
|
|
149
149
|
if (code[code.length - 1] === ',') code = code.substring(0, code.length - 1).trim()
|
|
150
150
|
let idx = code.indexOf('=')
|
|
151
151
|
|
|
@@ -179,7 +179,7 @@ const parseDef = (code, line) => {
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
const combineParameterDefinitions = (paramDefFromSource, extraDef) => {
|
|
182
|
+
export const combineParameterDefinitions = (paramDefFromSource, extraDef) => {
|
|
183
183
|
const def = [...paramDefFromSource]
|
|
184
184
|
if (extraDef) {
|
|
185
185
|
extraDef.forEach((param) => {
|
|
@@ -190,5 +190,3 @@ const combineParameterDefinitions = (paramDefFromSource, extraDef) => {
|
|
|
190
190
|
}
|
|
191
191
|
return def
|
|
192
192
|
}
|
|
193
|
-
|
|
194
|
-
module.exports = { getParameterDefinitionsFromSource, parseOne, parseComment, parseDef, combineParameterDefinitions }
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
const test = require('ava')
|
|
1
|
+
import test from 'ava'
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
import { getParameterDefinitionsFromSource, parseOne, parseComment, parseDef } from './getParameterDefinitionsFromSource.js'
|
|
5
4
|
|
|
6
5
|
const sampleParams = [
|
|
7
6
|
{ name: 'width', caption: 'Width', type: 'int', initial: 145 },
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
2
|
* @param {} parameterDefinitions
|
|
3
3
|
* @param {} inputParameters
|
|
4
4
|
*/
|
|
5
|
-
const getParameterValuesFromParameters = (parameterDefinitions, inputParameters) => {
|
|
5
|
+
export const getParameterValuesFromParameters = (parameterDefinitions, inputParameters) => {
|
|
6
6
|
const parameterValues = {}
|
|
7
7
|
for (const a in parameterDefinitions) { // defaults, given by getParameterDefinitions()
|
|
8
8
|
const x = parameterDefinitions[a]
|
|
@@ -19,5 +19,3 @@ const getParameterValuesFromParameters = (parameterDefinitions, inputParameters)
|
|
|
19
19
|
}
|
|
20
20
|
return parameterValues
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
module.exports = getParameterValuesFromParameters
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
2
|
* extracts the parameter
|
|
3
3
|
* @param {Array} paramControls
|
|
4
4
|
* @param {Boolean} onlyChanged
|
|
5
5
|
* @returns {Object} the parameter values, as an object
|
|
6
6
|
*/
|
|
7
|
-
const getParameterValuesFromUIControls = (paramControls, parameterDefinitions, onlyChanged) => {
|
|
7
|
+
export const getParameterValuesFromUIControls = (paramControls, parameterDefinitions, onlyChanged) => {
|
|
8
8
|
const parameterValues = {}
|
|
9
9
|
let value
|
|
10
10
|
for (let i = 0; i < paramControls.length; i++) {
|
|
@@ -58,5 +58,3 @@ const getParameterValuesFromUIControls = (paramControls, parameterDefinitions, o
|
|
|
58
58
|
}
|
|
59
59
|
return parameterValues
|
|
60
60
|
}
|
|
61
|
-
|
|
62
|
-
module.exports = getParameterValuesFromUIControls
|
package/src/parameters/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
getParameterValuesFromUIControls: require('./getParameterValuesFromUIControls')
|
|
6
|
-
}
|
|
1
|
+
export { applyParameterDefinitions } from './applyParameterDefinitions.js'
|
|
2
|
+
export { getParameterDefinitionsAndValues } from './getParameterDefinitionsAndValues.js'
|
|
3
|
+
export { getParameterValuesFromParameters } from './getParameterValuesFromParameters.js'
|
|
4
|
+
export { getParameterValuesFromUIControls } from './getParameterValuesFromUIControls.js'
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
const getFileExtensionFromString = (input) => {
|
|
1
|
+
export const getFileExtensionFromString = (input) => {
|
|
2
2
|
if (input.indexOf('.') === -1) {
|
|
3
3
|
return undefined
|
|
4
4
|
}
|
|
5
5
|
return (input.substring(input.lastIndexOf('.') + 1)).toLowerCase()
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
module.exports = getFileExtensionFromString
|
package/src/utils/index.js
CHANGED
package/src/utils/version.js
CHANGED
package/src/web/index.js
CHANGED
package/src/web/walkFileTree.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import path from 'path'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { flatten } from '@jscad/array-utils'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { supportedFormats } from '@jscad/io'
|
|
6
|
+
|
|
7
|
+
import { getFileExtensionFromString } from '../utils/index.js'
|
|
6
8
|
|
|
7
9
|
const binaryMimetypes = {
|
|
8
10
|
bmp: 'image/bmp',
|
|
@@ -64,7 +66,7 @@ const readFileAsync = (file, fileMeta) => {
|
|
|
64
66
|
// all known formats are supported
|
|
65
67
|
const isSupportedFormat = (file) => {
|
|
66
68
|
const ext = getFileExtensionFromString(file.name)
|
|
67
|
-
const mimetype =
|
|
69
|
+
const mimetype = supportedFormats[ext] ? supportedFormats[ext].mimetype : binaryMimetypes[ext]
|
|
68
70
|
file.mimetype = file.type && file.type.length ? file.type : mimetype
|
|
69
71
|
return file.mimetype && file.mimetype.length
|
|
70
72
|
}
|
|
@@ -161,8 +163,6 @@ const processDirectory = (directory) => {
|
|
|
161
163
|
* Transform the flat list of files (from HTML input) to a heiarchy of files (from drag-n-drop).
|
|
162
164
|
*/
|
|
163
165
|
const transformFileList = (fileList) => {
|
|
164
|
-
const path = require('path')
|
|
165
|
-
|
|
166
166
|
if (fileList.length === 1) {
|
|
167
167
|
const file = fileList[0]
|
|
168
168
|
const filePath = file.webkitRelativePath ? file.webkitRelativePath : file.name
|
|
@@ -228,7 +228,7 @@ const transformFileList = (fileList) => {
|
|
|
228
228
|
// 1) walk the tree
|
|
229
229
|
// 2) read the files (readFileAsync)
|
|
230
230
|
// 3) return a flattened list of promises containing all file entries
|
|
231
|
-
const walkFileTree = (fileList) => {
|
|
231
|
+
export const walkFileTree = (fileList) => {
|
|
232
232
|
let items = fileList
|
|
233
233
|
if (fileList.length && (fileList[0] instanceof File)) {
|
|
234
234
|
// transform the flat list of File entries
|
|
@@ -236,5 +236,3 @@ const walkFileTree = (fileList) => {
|
|
|
236
236
|
}
|
|
237
237
|
return processEntries(items)
|
|
238
238
|
}
|
|
239
|
-
|
|
240
|
-
module.exports = walkFileTree
|