Skip to content

Commit e19c10c

Browse files
authored
feat(core): V2 : Fix core packaging (#720)
* build(core): corrected main in configuration, and adjusted test script * feat(core): reorganizing code into src directory, following standard library organization * fix(core): added indexes for the contents of each sub-directory * fix(core): moved walkFileTree into core library, as this is key for general use of JSCAD * fix(core): corrected default options for rebuildGeometry, also added doc strings * build(core): a little clean up on the package * docs(core): improved docs for rebuildGeometry * fix(core): improved transformFileList to handle a single file * fix(cli web): corrected require of @jscad/core
1 parent fd58e3d commit e19c10c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+432
-117
lines changed

packages/cli/src/generateOutputData.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const { isAbsolute, resolve } = require('path')
33

44
const { deserializers, solidsAsBlob } = require('@jscad/io')
55

6-
const rebuildSolids = require('@jscad/core/code-evaluation/rebuildGeometryCli')
7-
const { registerAllExtensions } = require('@jscad/core/io/registerExtensions')
6+
const { rebuildGeometryCli } = require('@jscad/core').evaluation
7+
const { registerAllExtensions } = require('@jscad/core').io
88

99
/**
1010
* generate output data from source
@@ -56,7 +56,7 @@ const generateOutputData = (source, params, options) => {
5656
// } else if ((inputFormat === 'jscad' || inputFormat === 'js') &&
5757
// outputFormat !== 'jscad' && outputFormat !== 'js') {
5858
try {
59-
const solids = rebuildSolids({ mainPath: inputPath, parameterValues: params, useFakeFs, source })
59+
const solids = rebuildGeometryCli({ mainPath: inputPath, parameterValues: params, useFakeFs, source })
6060
resolve(solids)
6161
} catch (error) {
6262
reject(error)

packages/cli/src/parseArgs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs')
22

3-
const { getDesignEntryPoint } = require('@jscad/core/code-loading/requireDesignUtilsFs')
3+
const { getDesignEntryPoint } = require('@jscad/core').loading.requireDesignUtilsFs
44
const { supportedInputExtensions, supportedOutputExtensions, supportedOutputFormats } = require('@jscad/io/formats')
55

66
const env = require('./env')

packages/core/code-evaluation/rebuildGeometry.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

packages/core/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
{
22
"name": "@jscad/core",
33
"version": "2.0.0-alpha.9",
4-
"description": "reuseable utilities for the various jscad user interfaces",
4+
"description": "Reuseable utilities for the various JSCAD user interfaces",
55
"repository": "https://github.com/jscad/OpenJSCAD.org",
6-
"main": "module.js",
6+
"main": "src/index.js",
77
"scripts": {
88
"coverage": "nyc --all --reporter=html --reporter=text npm test",
9-
"test": "ava './**/*.test.js' --verbose --timeout 2m",
9+
"test": "ava './src/**/*.test.js' --verbose --timeout 2m",
1010
"release-patch": "git checkout master && git pull origin master && npm version patch",
1111
"release-minor": "git checkout master && git pull origin master && npm version minor",
12-
"release-major": "git checkout master && git pull origin master && npm version major",
13-
"postinstall": "node -e \"console.log('\\u001b[35m\\u001b[1mLove OpenJSCAD? You can now donate to our open collective:\\u001b[22m\\u001b[39m\\n > \\u001b[34mhttps://opencollective.com/openjscad/donate\\u001b[0m')\""
12+
"release-major": "git checkout master && git pull origin master && npm version major"
1413
},
1514
"contributors": [
1615
{
File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
deserializeSolids: require('./deserializeSolids'),
3+
rebuildGeometry: require('./rebuildGeometry'),
4+
rebuildGeometryCli: require('./rebuildGeometryCli'),
5+
rebuildGeometryWorker: require('./rebuildGeometryWorker'),
6+
serializeSolids: require('./serializeSolids')
7+
}
File renamed without changes.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const loadDesign = require('../code-loading/loadDesign')
2+
const instanciateDesign = require('./instanciateDesign')
3+
const applyParameterDefinitions = require('../parameters/applyParameterDefinitions')
4+
5+
/**
6+
* Rebuild JSCAD solids from the given filesAndFolders.
7+
* The provided filesAndFolders is expected to consist of a valid JSCAD design.
8+
* An array consisting of:
9+
* - single file or project folder from the results of walkFileTree()
10+
* - fake single file entry containing { name, ext, source, fullPath }
11+
* @param {Object} data - data (and options) required for rebuilding
12+
* @param {Array} data.filesAndFolders - array of files / directories
13+
* @param {String} [data.mainPath] - path of the file containing the main function (optional)
14+
* @param {Boolean} [data.serialize] - true to serialize the solids into JSON
15+
* @param {Boolean} [data.vtreeMode] - true to use the experimental Vtree caching (optional)
16+
* @param {Object} [data.lookup] - geometry cache lookup (optional)
17+
* @param {Object} [data.lookupCounts] - geometry cache lookup counts (optional)
18+
* @param {Object} [data.parameterValues] - over-rides of parameter values (optional)
19+
* @param {Function} callback - function to process parameters and solids
20+
* @return NONE
21+
* This function extracts the parameters first, and then generates the solids.
22+
* The parsed parameters (definitions and values) are passed back to the given callback function.
23+
* The generated solids are also passed back to the given callback function.
24+
* Everything is together in a single function, because this is usually run in the context of a web worker
25+
* And transfering data back & forth is both complex (see transferables) and costly (time)
26+
**/
27+
const rebuildSolids = (data, callback) => {
28+
console.log('rebuildSolids',data)
29+
const defaults = {
30+
mainPath: '',
31+
vtreeMode: false,
32+
serialize: true,
33+
lookup: null,
34+
lookupCounts: null,
35+
parameterValues: {}
36+
}
37+
let { mainPath, vtreeMode, serialize, lookup, lookupCounts, parameterValues } = Object.assign({}, defaults, data)
38+
39+
const apiMainPath = '@jscad/modeling'// vtreeMode ? '../code-loading/vtreeApi' : '@jscad/modeling'
40+
const filesAndFolders = data.filesAndFolders
41+
42+
// let start = new Date()
43+
const designData = loadDesign(mainPath, apiMainPath, filesAndFolders, parameterValues)
44+
// send back parameter definitions & values
45+
// in a worker this would be a postmessage, this is sent back early so that uis can update
46+
// the parameters editor before the solids are displayed (which takes longer)
47+
callback(null, {
48+
type: 'params',
49+
parameterDefaults: designData.parameterValues,
50+
parameterDefinitions: designData.parameterDefinitions
51+
})
52+
// console.warn(`loadDesignData`, new Date() - start)
53+
// make sure parameters are correct by applying parameter definitions
54+
// this might be redundant with ui-side logic, but it makes sure this core piece works regardless of ui
55+
parameterValues = applyParameterDefinitions(parameterValues, designData.parameterDefinitions)
56+
parameterValues = Object.assign({}, designData.parameterValues, parameterValues)
57+
// start = new Date()
58+
const options = {
59+
vtreeMode,
60+
lookup,
61+
lookupCounts,
62+
serialize
63+
}
64+
const solidsData = instanciateDesign(designData.rootModule, parameterValues, options)
65+
// console.warn(`instanciateDesign`, new Date() - start)
66+
67+
// send back solids & any other metadata
68+
callback(null, {
69+
type: 'solids',
70+
solids: solidsData.solids,
71+
lookup: solidsData.lookup,
72+
lookupCounts: solidsData.lookupCounts
73+
})
74+
}
75+
76+
module.exports = rebuildSolids
File renamed without changes.

packages/core/code-evaluation/rebuildGeometryWorker.js renamed to packages/core/src/code-evaluation/rebuildGeometryWorker.js

File renamed without changes.

0 commit comments

Comments
 (0)