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

WIP - autogenerate cpp files to use threejs in xeus-cling #158

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions js/scripts/clean-generated-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ function cleanGeneratedFilesAsync() {
var pyPromise = rmFileGlobAsync('../pythreejs/**/*_autogen.py');
var pyIndexPromise = rmFileGlobAsync('../pythreejs/**/__init__.py');

var cppPromise1 = rmFileGlobAsync('../xthreejs/**/*_autogen.hpp');
var cppPromise2 = rmFileGlobAsync('../xthreejs/include/xthreejs/*.hpp');
var cppPromise3 = rmFileGlobAsync('../xthreejs/**/*_autogen.cpp');
var cmakePromise = rmFileGlobAsync('../xthreejs/CMakeLists.txt');

var docPromise = rmFileGlobAsync('../docs/source/**/*_autogen.rst');
var docIndexPromise = rmFileGlobAsync('../docs/source/api/**/index.rst');

Expand All @@ -78,6 +83,10 @@ function cleanGeneratedFilesAsync() {
jsIndexPromise,
pyPromise,
pyIndexPromise,
cppPromise1,
cppPromise2,
cppPromise3,
cmakePromise,
docPromise,
docIndexPromise,
]);
Expand Down
37 changes: 37 additions & 0 deletions js/scripts/generate-enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ const baseDir = path.resolve(scriptDir, '..');

const jsSrcDir = path.resolve(baseDir, 'src/');
const pySrcDir = path.resolve(baseDir, '..', 'pythreejs');
const cppSrcDir = path.resolve(baseDir, '..', 'xthreejs/include/xthreejs');
const templateDir = path.resolve(scriptDir, 'templates');

const threeSrcDir = path.resolve(baseDir, 'node_modules', 'three', 'src');

const jsEnumDst = path.resolve(jsSrcDir, '_base', 'enums.js');
const pyEnumDst = path.resolve(pySrcDir, 'enums.py');
const cppEnumDst = path.resolve(cppSrcDir, 'base', 'xenums.hpp');

//
// Actual THREE constants:
Expand Down Expand Up @@ -47,6 +49,7 @@ function compileTemplate(templateName) {

var jsEnumTemplate = compileTemplate('js_enums');
var pyEnumTemplate = compileTemplate('py_enums');
var cppEnumTemplate = compileTemplate('cpp_enums');


//
Expand Down Expand Up @@ -150,11 +153,45 @@ function createPythonFiles() {
});
}

function writeCppFile() {
// Here we generate lists of enum keys

var categories = [];

_.keys(enumConfigs).map(category => {
var categoryObj = {key: category, enums: []};
categories.push(categoryObj);
enumConfigs[category].forEach(function(enumKey) {
if (Array.isArray(enumKey)) {
// Several keys share the same value, use the first one.
enumKey = enumKey[0];
}
categoryObj.enums.push({ key: enumKey, value: threeEnums[enumKey] });
}, this);
}, this);

var content = cppEnumTemplate({
now: new Date(),
generatorScriptName: path.basename(__filename),

categories: categories
});

return fse.outputFile(cppEnumDst, content);
}

function createCppFiles() {
return new Promise(function(resolve) {
resolve(writeCppFile());
});
}

function generateFiles() {

return Promise.all([
createJavascriptFiles(),
createPythonFiles(),
createCppFiles(),
checkUnused(),
]);

Expand Down
Loading