From c4029fb9b6f7ad4de5dd28c7cd35f8692011468a Mon Sep 17 00:00:00 2001 From: Toilal Date: Fri, 24 Mar 2017 12:15:04 +0100 Subject: [PATCH] Fix custom build when openlayers is installed from yarn package manager This enhance the procedure to find path of jsdoc binary by checking if the file exists. It also use 2 possible paths to perform this check, one for npm and the other for yarn. Close #6633 --- tasks/generate-info.js | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tasks/generate-info.js b/tasks/generate-info.js index 72b0653657..7e349293f7 100644 --- a/tasks/generate-info.js +++ b/tasks/generate-info.js @@ -14,14 +14,33 @@ var externsPaths = [ ]; var infoPath = path.join(__dirname, '..', 'build', 'info.json'); -var jsdocResolved = require.resolve('jsdoc/jsdoc.js'); -var jsdoc = path.resolve(path.dirname(jsdocResolved), '../.bin/jsdoc'); +/** + * Get checked path of a binary. + * @param {string} binaryName Binary name of the binary path to find. + */ +function getBinaryPath(binaryName) { + if (isWindows) { + binaryName += '.cmd' + } -// on Windows, use jsdoc.cmd -if (isWindows) { - jsdoc += '.cmd'; + var jsdocResolved = require.resolve('jsdoc/jsdoc.js'); + var expectedPaths = [ + path.join(__dirname, '..', 'node_modules', '.bin', binaryName), + path.resolve(path.join(path.dirname(jsdocResolved), '..', '.bin', binaryName)) + ] + + for (var i = 0; i < expectedPaths.length; i++) { + var expectedPath = expectedPaths[i]; + if (fs.existsSync(expectedPath)) { + return expectedPath; + } + } + + throw Error("JsDoc binary was not found in any of the expected paths: " + expectedPaths); } +var jsdoc = getBinaryPath('jsdoc'); + var jsdocConfig = path.join( __dirname, '..', 'config', 'jsdoc', 'info', 'conf.json');