diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index fbc40f70c2..07788e5865 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -279,6 +279,9 @@ endif(UNIX) # assume we are using a Qt build without bearer management add_definitions(-DQT_NO_BEARERMANAGEMENT) +# require JSDoc to be build before interface is deployed (Console Auto-complete) +add_dependencies(${TARGET_NAME} jsdoc) + if (APPLE) # link in required OS X frameworks and include the right GL headers find_library(OpenGL OpenGL) @@ -299,6 +302,9 @@ if (APPLE) COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_SOURCE_DIR}/scripts" "$/../Resources/scripts" + COMMAND "${CMAKE_COMMAND}" -E copy + "${CMAKE_SOURCE_DIR}/tools/jsdoc/out/hifiJSDoc.json" + "$/../Resources/auto-complete" ) # call the fixup_interface macro to add required bundling commands for installation @@ -313,6 +319,9 @@ else (APPLE) COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_SOURCE_DIR}/scripts" "$/scripts" + COMMAND "${CMAKE_COMMAND}" -E copy + "${CMAKE_SOURCE_DIR}/tools/jsdoc/out/hifiJSDoc.json" + "$/resources/auto-complete" ) # link target to external libraries @@ -349,16 +358,6 @@ endif() add_bugsplat() -# generate the JSDoc JSON for the JSConsole auto-completer -add_custom_command(TARGET ${TARGET_NAME} #POST_BUILD - COMMAND npm install - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tools/jsdoc -) -add_custom_command(TARGET ${TARGET_NAME} - COMMAND node_modules/.bin/jsdoc . -c config.json - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tools/jsdoc -) - if (WIN32) set(EXTRA_DEPLOY_OPTIONS "--qmldir \"${PROJECT_SOURCE_DIR}/resources/qml\"") diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 16446c5071..ac920d930d 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -2,6 +2,9 @@ add_subdirectory(scribe) set_target_properties(scribe PROPERTIES FOLDER "Tools") +add_subdirectory(jsdoc) +set_target_properties(jsdoc PROPERTIES FOLDER "Tools") + if (BUILD_TOOLS) add_subdirectory(udt-test) set_target_properties(udt-test PROPERTIES FOLDER "Tools") @@ -27,4 +30,3 @@ if (BUILD_TOOLS) add_subdirectory(auto-tester) set_target_properties(auto-tester PROPERTIES FOLDER "Tools") endif() - diff --git a/tools/jsdoc/CMakeLists.txt b/tools/jsdoc/CMakeLists.txt new file mode 100644 index 0000000000..9a9883a6ad --- /dev/null +++ b/tools/jsdoc/CMakeLists.txt @@ -0,0 +1,14 @@ +set(TARGET_NAME jsdoc) + +add_custom_target(${TARGET_NAME}) + +SET(JSDOC_WORKING_DIR ${CMAKE_SOURCE_DIR}/tools/jsdoc) +file(TO_NATIVE_PATH ${JSDOC_WORKING_DIR}/node_modules/.bin/jsdoc JSDOC_PATH) +file(TO_NATIVE_PATH ${JSDOC_WORKING_DIR}/config.json JSDOC_CONFIG_PATH) +file(TO_NATIVE_PATH ${JSDOC_WORKING_DIR} NATIVE_JSDOC_WORKING_DIR) + +add_custom_command(TARGET ${TARGET_NAME} + COMMAND (npm --no-progress install) & (${JSDOC_PATH} ${NATIVE_JSDOC_WORKING_DIR} -c ${JSDOC_CONFIG_PATH}) + WORKING_DIRECTORY ${JSDOC_WORKING_DIR} + COMMENT "generate the JSDoc JSON for the JSConsole auto-completer" +) diff --git a/tools/jsdoc/plugins/hifi.js b/tools/jsdoc/plugins/hifi.js index afa3285c37..c434ecc0d6 100644 --- a/tools/jsdoc/plugins/hifi.js +++ b/tools/jsdoc/plugins/hifi.js @@ -10,6 +10,8 @@ function endsWith(path, exts) { exports.handlers = { beforeParse: function(e) { + const pathTools = require('path'); + var rootFolder = pathTools.dirname(e.filename); console.log("Scanning hifi source for jsdoc comments..."); // directories to scan for jsdoc comments @@ -34,9 +36,10 @@ exports.handlers = { const fs = require('fs'); dirList.forEach(function (dir) { - var files = fs.readdirSync(dir) + var joinedDir = pathTools.join(rootFolder, dir); + var files = fs.readdirSync(joinedDir) files.forEach(function (file) { - var path = dir + "/" + file; + var path = pathTools.join(joinedDir, file); if (fs.lstatSync(path).isFile() && endsWith(path, exts)) { var data = fs.readFileSync(path, "utf8"); var reg = /(\/\*\*jsdoc(.|[\r\n])*?\*\/)/gm; @@ -48,7 +51,7 @@ exports.handlers = { }); }); - fs.writeFile("out/hifiJSDoc.js", e.source, function(err) { + fs.writeFile(pathTools.join(rootFolder, "out/hifiJSDoc.js"), e.source, function(err) { if (err) { return console.log(err); } diff --git a/tools/jsdoc/plugins/hifiJSONExport.js b/tools/jsdoc/plugins/hifiJSONExport.js index 7948fd2673..5531d3ff25 100644 --- a/tools/jsdoc/plugins/hifiJSONExport.js +++ b/tools/jsdoc/plugins/hifiJSONExport.js @@ -1,9 +1,11 @@ exports.handlers = { processingComplete: function(e) { + const pathTools = require('path'); + var rootFolder = pathTools.join(__dirname, '..'); var doclets = e.doclets.map(doclet => Object.assign({}, doclet)); const fs = require('fs'); doclets.map(doclet => {delete doclet.meta; delete doclet.comment}); - fs.writeFile("out/hifiJSDoc.json", JSON.stringify(doclets, null, 4), function(err) { + fs.writeFile(pathTools.join(rootFolder, "out/hifiJSDoc.json"), JSON.stringify(doclets, null, 4), function(err) { if (err) { return console.log(err); }