Skip to content

Commit

Permalink
add more paths to postinstall script (geosolutions-it#6162)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Nov 5, 2020
1 parent 3e25f9d commit 055bca9
Showing 1 changed file with 44 additions and 12 deletions.
56 changes: 44 additions & 12 deletions utility/build/postInstall.js
Original file line number Diff line number Diff line change
@@ -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)
}
});

0 comments on commit 055bca9

Please sign in to comment.