From 055bca9267765532cdf99f840333b3c485d7b0fb Mon Sep 17 00:00:00 2001 From: stefano bovio Date: Thu, 5 Nov 2020 14:32:32 +0100 Subject: [PATCH] add more paths to postinstall script (#6162) --- utility/build/postInstall.js | 56 ++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/utility/build/postInstall.js b/utility/build/postInstall.js index 68760a955b..fae5086ab4 100644 --- a/utility/build/postInstall.js +++ b/utility/build/postInstall.js @@ -1,19 +1,51 @@ console.log("********** post install **********"); const fs = require('fs-extra'); +const path = require('path'); const isInProject = fs.existsSync('./MapStore2'); console.log(isInProject ? "* in project" : "* not in project"); -fs.removeSync(`./node_modules/leaflet-simple-graticule/node_modules`); -fs.removeSync(`./node_modules/react-sortable-items/node_modules/react-dom`); -fs.removeSync(`./node_modules/geostyler-openlayers-parser/node_modules/@terrestris`); // explicit dependency in package.json -/** - * this is run 2 times because one from the package.json of the project and one from mapstore2 library - * when run from the project there is an error when the version from mapstore is executed therefore - * we perform a check before do the copy - * */ -if (fs.existsSync('./node_modules/@geosolutions/mocha')) { - console.log("* executing the copy of mocha"); - fs.emptyDirSync(`./node_modules/mocha`); - fs.copySync(`./node_modules/@geosolutions/mocha`, `./node_modules/mocha`); +const nodeModules = [ + { + path: path.join(__dirname, '..', '..', 'node_modules'), // MapStore2, project with submodule or file:MapStore2 + valid: true // sometimes some node_modules are installed also in the submodule + }, + { + path: path.join(__dirname, '..', '..', '..', 'node_modules'), // file:MapStore2 symlink installation + valid: !!fs.existsSync(path.join(__dirname, '..', '..', '..', 'MapStore2')) // check MapStore2 submodule + }, + { + path: path.join(__dirname, '..', '..', '..', '..', 'node_modules'), // node_modules/mapstore installation + valid: !!fs.existsSync(path.join(__dirname, '..', '..', '..', '..', 'node_modules', 'mapstore')) // valid for installation "mapstore": "git+..." + } +]; + +function removeModules(nodeModulesPath) { + const removeModulesList = [ + 'leaflet-simple-graticule/node_modules', + 'geostyler-openlayers-parser/node_modules/@terrestris' + ]; + removeModulesList.forEach((removeModule) => { + const removePath = path.resolve(nodeModulesPath, removeModule); + if (fs.existsSync(removePath)) { + fs.removeSync(removePath); + } + }); + /** + * this is run 2 times because one from the package.json of the project and one from mapstore2 library + * when run from the project there is an error when the version from mapstore is executed therefore + * we perform a check before do the copy + * */ + if (fs.existsSync(path.resolve(nodeModulesPath, '@geosolutions/mocha'))) { + console.log("* executing the copy of mocha"); + fs.emptyDirSync(path.resolve(nodeModulesPath, 'mocha')); + fs.copySync(path.resolve(nodeModulesPath, '@geosolutions/mocha'), path.resolve(nodeModulesPath, 'mocha')); + } } + +nodeModules.forEach((nodeModule) => { + if (fs.existsSync(nodeModule.path) && nodeModule.valid) { + console.log('remove in node_modules path', nodeModule.path); + removeModules(nodeModule.path) + } +});