diff --git a/js/scripts/.eslintrc.js b/js/scripts/.eslintrc.js index 9e1bda88..c8c40940 100644 --- a/js/scripts/.eslintrc.js +++ b/js/scripts/.eslintrc.js @@ -5,7 +5,8 @@ module.exports = { }, "extends": "eslint:recommended", "parserOptions": { - "sourceType": "script" + "sourceType": "script", + "ecmaVersion": 2017 }, "rules": { "indent": [ diff --git a/js/scripts/generate-enums.js b/js/scripts/generate-enums.js index 308c60ae..aa71043b 100644 --- a/js/scripts/generate-enums.js +++ b/js/scripts/generate-enums.js @@ -109,10 +109,8 @@ function writeJavascriptFile() { return fse.outputFile(jsEnumDst, content); } -function createJavascriptFiles() { - return new Promise(function(resolve) { - resolve(writeJavascriptFile()); - }); +async function createJavascriptFiles() { + return await writeJavascriptFile(); } function writePythonFile() { @@ -144,10 +142,8 @@ function writePythonFile() { return fse.outputFile(pyEnumDst, content); } -function createPythonFiles() { - return new Promise(function(resolve) { - resolve(writePythonFile()); - }); +async function createPythonFiles() { + return await writePythonFile(); } function generateFiles() { diff --git a/js/scripts/generate-shader-utils.js b/js/scripts/generate-shader-utils.js index 951b67a0..27598be1 100644 --- a/js/scripts/generate-shader-utils.js +++ b/js/scripts/generate-shader-utils.js @@ -58,7 +58,7 @@ function mapPromiseFnOverObject(object, mapFn) { } -function createPythonWrapper(name, relativePath) { +async function createPythonWrapper(name, relativePath) { const data = THREE[name]; let serialized; @@ -92,14 +92,14 @@ function createPythonWrapper(name, relativePath) { generatorScriptName: path.basename(__filename), }); promises.push(fse.outputFile(pyPath, output)); - return Promise.all(promises); + await Promise.all(promises); } -function createPythonModuleInitFile(modulePath) { +async function createPythonModuleInitFile(modulePath) { const dirname = path.dirname(modulePath); const pyInitFilePath = path.resolve(pySrcDir, dirname, '__init__.py'); - return fse.ensureFile(pyInitFilePath); + await fse.ensureFile(pyInitFilePath); } @@ -110,12 +110,12 @@ function createPythonFiles() { return Promise.resolve(); } - return mapPromiseFnOverObject(shaderUtilsConfig, function(name, configObj) { + return mapPromiseFnOverObject(shaderUtilsConfig, async function(name, configObj) { const relativePath = configObj.relativePath; - return createPythonWrapper(name, relativePath).then(function() { - // ensures each dir has empty __init__.py file for proper importing of sub dirs - return createPythonModuleInitFile(relativePath); - }); + await createPythonWrapper(name, relativePath); + + // ensures each dir has empty __init__.py file for proper importing of sub dirs + await createPythonModuleInitFile(relativePath); }); } diff --git a/js/scripts/generate-wrappers.js b/js/scripts/generate-wrappers.js index 32597278..f2bab33d 100644 --- a/js/scripts/generate-wrappers.js +++ b/js/scripts/generate-wrappers.js @@ -591,77 +591,75 @@ function writeJavascriptIndexFiles() { // Regexp's const RE_AUTOGEN_EXT = /\.autogen\.js$/; - function writeIndexForDir(dirPath, isTopLevel) { + async function writeIndexForDir(dirPath, isTopLevel) { const dirAbsPath = path.resolve(jsSrcDir, dirPath); // Generate list of files in dir to include in index.js as require lines - return fse.readdir(dirAbsPath).then(function(dirFiles) { + let dirFiles = await fse.readdir(dirAbsPath); - // get proper relative path for file - dirFiles = dirFiles.map(function(filename) { - return './' + path.join(dirPath, filename); - }); + // get proper relative path for file + dirFiles = dirFiles.map(filename => { + return './' + path.join(dirPath, filename); + }); - // filter excluded files - dirFiles = dirFiles.filter(function(filePath) { + // filter excluded files + dirFiles = dirFiles.filter(filePath => { - // ignore autogen files in _base dir - if (/_base/.test(dirPath) && RE_AUTOGEN_EXT.test(filePath)) { - return false; - } + // ignore autogen files in _base dir + if (/_base/.test(dirPath) && RE_AUTOGEN_EXT.test(filePath)) { + return false; + } - // compare filePath to each exclude pattern - const shouldExclude = _.any(excludes, function(testPattern) { - if (testPattern instanceof RegExp) { - return testPattern.test(filePath); - } else if (typeof testPattern === 'string') { - return testPattern === filePath; - } - }); - if (shouldExclude) { - return false; + // compare filePath to each exclude pattern + const shouldExclude = _.any(excludes, function(testPattern) { + if (testPattern instanceof RegExp) { + return testPattern.test(filePath); + } else if (typeof testPattern === 'string') { + return testPattern === filePath; } + }); + if (shouldExclude) { + return false; + } - // if override class exists, load it in favor of the autogen file - // e.g. for WebGLRenderer.js, Object3D.js, DataTexture.js - // override classes should extend the autogen versions - if (RE_AUTOGEN_EXT.test(filePath)) { - - const dirname = path.dirname(filePath); - const basename = path.basename(filePath, JS_AUTOGEN_EXT); - const overrideName = basename + '.js'; - const overridePath = './' + path.join(dirname, overrideName); + // if override class exists, load it in favor of the autogen file + // e.g. for WebGLRenderer.js, Object3D.js, DataTexture.js + // override classes should extend the autogen versions + if (RE_AUTOGEN_EXT.test(filePath)) { - // override file present, so don't include autogen file in index - if (dirFiles.indexOf(overridePath) > -1) { - console.log('override exists for: ' + filePath); - return false; - } + const dirname = path.dirname(filePath); + const basename = path.basename(filePath, JS_AUTOGEN_EXT); + const overrideName = basename + '.js'; + const overridePath = './' + path.join(dirname, overrideName); + // override file present, so don't include autogen file in index + if (dirFiles.indexOf(overridePath) > -1) { + console.log('override exists for: ' + filePath); + return false; } - return true; - }); + } - // convert file paths relative to js src dir to paths relative to dirPath - dirFiles = dirFiles.map(function(filePath) { - return './' + path.basename(filePath); - }); + return true; + }); - // render template - const context = { - now: new Date(), - generatorScriptName: path.basename(__filename), - top_level: isTopLevel, - submodules: dirFiles, - }; - const output = jsIndexTemplate(context); - const outputPath = path.resolve(jsSrcDir, dirPath, 'index.js'); + // convert file paths relative to js src dir to paths relative to dirPath + dirFiles = dirFiles.map(function(filePath) { + return './' + path.basename(filePath); + }); - return fse.outputFile(outputPath, output); + // render template + const context = { + now: new Date(), + generatorScriptName: path.basename(__filename), + top_level: isTopLevel, + submodules: dirFiles, + }; + const output = jsIndexTemplate(context); + const outputPath = path.resolve(jsSrcDir, dirPath, 'index.js'); - }); + return fse.outputFile(outputPath, output); } // map over all directories in js src dir diff --git a/js/scripts/post-build.js b/js/scripts/post-build.js index e5df0237..d6628973 100644 --- a/js/scripts/post-build.js +++ b/js/scripts/post-build.js @@ -45,7 +45,7 @@ async function copyExampleImagesToDocs() { await fse.copy( path.resolve(exampleImagesSrcDir, filePath), path.resolve(exampleImagesDstDir, filePath) - ) + ); console.log(`Copied ${filePath} to docs examples' image folder`); })); }