diff --git a/checkCesium.js b/checkCesium.js index cfd3b5ba2e..70fbe17938 100644 --- a/checkCesium.js +++ b/checkCesium.js @@ -1,7 +1,24 @@ -var existsFile = require('exists-file'); - -var exists = existsFile('./web/client/libs/Cesium/Build/Cesium/Cesium.js'); +const fs = require('fs-extra'); +const dir = './web/client/libs/Cesium'; + +const copyFromNodeModules = () => { + console.log("Copying Cesium from node_modules..."); + fs.ensureDirSync(dir); + fs.copySync('./node_modules/cesium', dir); +}; + +const exists = fs.pathExistsSync(dir); if (!exists) { - process.exit(0); + console.log("Cesium not found"); + copyFromNodeModules(); +} else { + const packageInLibs = fs.readJsonSync(dir + '/package.json', { 'throws': false }); + const packageInNodeModules = fs.readJsonSync('./node_modules/cesium/package.json', { 'throws': false }); + if (!packageInLibs || packageInNodeModules && packageInLibs.version !== packageInNodeModules.version) { + console.log("Installed: " + (packageInLibs && packageInLibs.version)); + console.log("Required: " + (packageInNodeModules && packageInNodeModules.version)); + console.log("Cesium version is outdated"); + copyFromNodeModules(); + } + console.log("Cesium installed"); } -process.exit(1); \ No newline at end of file diff --git a/createProject.js b/createProject.js index 7328454eab..94d49c34cf 100644 --- a/createProject.js +++ b/createProject.js @@ -14,51 +14,25 @@ const ncp = require('ncp').ncp; const mkdirp = require('mkdirp'); -function createPackageJSON() { - console.log('Creating package.json...'); - - const packageJSON = require('./package.json'); - packageJSON.name = projectName; - packageJSON.version = projectVersion; - packageJSON.description = projectDescription; - packageJSON.repository = repoURL; - packageJSON.scripts = require('./projectScripts.json'); - - fs.writeFile(outFolder + '/package.json', JSON.stringify(packageJSON, null, 4), copyStaticFiles); - console.log('package.json OK'); -} +const initGit = () => { + console.log('Creating git repo...'); -function copyStaticFiles() { - console.log('Copying static files...'); - var copied = 0; - var streams = ['.editorconfig', '.eslintrc', '.eslintignore', 'LICENSE', '.babelrc'].map(function(fileName) { - const toWrite = fs.createWriteStream(outFolder + '/' + fileName); - fs.createReadStream(fileName).pipe(toWrite); - console.log('Copied ' + fileName); - return toWrite; - }).forEach(function(stream) { - stream.on('finish', function() { - copied++; - if(copied === 4) { - ncp('./project/static', outFolder, function(err) { - if (err) { - return console.log(err); - } - copyTemplates(0,''); - }); - } + const git = require('simple-git')( outFolder ); + git.init(function() { + git.submoduleAdd('https://github.com/geosolutions-it/MapStore2.git', 'MapStore2', function() { + console.log('git repo OK...'); }); }); -} +}; -function copyTemplates(level, path, callback) { +const copyTemplates = (level, path, callback) => { console.log('Copying templated files...'); - fs.readdir('./project' + path, function (err,files) { - if (err) { - return console.log(err); - } - files.forEach(function(file, index) { - fs.stat('./project' + path + '/' + file, function(err, stats) { + fs.readdir('./project' + path, function(err, files) { + if (err) { + return console.log(err); + } + files.forEach(function(file, index) { + fs.stat('./project' + path + '/' + file, function(err, stats) { if (err) { return console.log(err); } @@ -68,8 +42,8 @@ function copyTemplates(level, path, callback) { data = data.replace(/__PROJECTDESCRIPTION__/g, projectDescription); data = data.replace(/__REPOURL__/g, repoURL); - mkdirp(outFolder + path, function (err) { - if (err) console.error(err) + mkdirp(outFolder + path, function(err) { + if (err) console.error(err); else { fs.writeFile(outFolder + path + '/' + file, data, 'UTF-8', function(err) { if (err) { @@ -78,38 +52,64 @@ function copyTemplates(level, path, callback) { console.log('Copied ' + file); if (level === 0 && index === files.length - 1) { initGit(); - } else if(index === files.length - 1 && callback) { + } else if (index === files.length - 1 && callback) { callback.call(); } }); } }); }); - } else if(stats.isDirectory()) { - if(file !== 'static') { + } else if (stats.isDirectory()) { + if (file !== 'static') { copyTemplates(level + 1, path + '/' + file, function() { if (level === 0 && index === files.length - 1) { initGit(); - } else if(index === files.length - 1 && callback) { + } else if (index === files.length - 1 && callback) { callback.call(); } }); } } }); - }); + }); }); -} - -function initGit() { - console.log('Creating git repo...'); +}; - const git = require('simple-git')( outFolder ); - git.init(function() { - git.submoduleAdd('https://github.com/geosolutions-it/MapStore2.git', 'MapStore2', function() { - console.log('git repo OK...'); +const copyStaticFiles = () => { + console.log('Copying static files...'); + let copied = 0; + ['.editorconfig', '.eslintrc', '.eslintignore', 'LICENSE', '.babelrc'].map(function(fileName) { + const toWrite = fs.createWriteStream(outFolder + '/' + fileName); + fs.createReadStream(fileName).pipe(toWrite); + console.log('Copied ' + fileName); + return toWrite; + }).forEach(function(stream) { + stream.on('finish', function() { + copied++; + if (copied === 4) { + ncp('./project/static', outFolder, function(err) { + if (err) { + return console.log(err); + } + copyTemplates(0, ''); + }); + } }); }); +}; + +function createPackageJSON() { + console.log('Creating package.json...'); + + const packageJSON = require('./package.json'); + packageJSON.name = projectName; + packageJSON.version = projectVersion; + packageJSON.description = projectDescription; + packageJSON.repository = repoURL; + packageJSON.scripts = require('./projectScripts.json'); + + fs.writeFile(outFolder + '/package.json', JSON.stringify(packageJSON, null, 4), copyStaticFiles); + console.log('package.json OK'); } createPackageJSON(); diff --git a/karma.conf.single-run.js b/karma.conf.single-run.js index 191a5920ee..ba6f7ad079 100644 --- a/karma.conf.single-run.js +++ b/karma.conf.single-run.js @@ -9,7 +9,6 @@ module.exports = function karmaConfig(config) { frameworks: [ 'mocha' ], files: [ - 'web/client/libs/Cesium/Build/Cesium/Cesium.js', 'tests-travis.webpack.js', { pattern: './web/client/test-resources/**/*', included: false }, { pattern: './web/client/translations/**/*', included: false } diff --git a/package.json b/package.json index 7feed08653..0982a145d5 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "babel-preset-es2015": "6.6.0", "babel-preset-react": "6.5.0", "babel-preset-stage-0": "6.5.0", + "cesium": "1.17.0", "copy-webpack-plugin": "4.0.1", "css-loader": "0.19.0", "docma": "1.5.1", @@ -23,7 +24,6 @@ "escope": "3.2.0", "eslint": "0.24.1", "eslint-plugin-react": "3.3.2", - "exists-file": "1.0.2", "expect": "1.20.1", "extract-text-webpack-plugin": "2.1.0", "file-loader": "0.8.5", @@ -96,6 +96,7 @@ "es6-promise": "2.3.0", "eventlistener": "0.0.1", "file-saver": "1.3.3", + "fs-extra": "3.0.1", "history": "4.6.1", "html2canvas": "0.5.0-beta4", "intl": "1.2.2", @@ -182,7 +183,7 @@ "doc": "docma -c docma-config.json --dest web/docs", "cleandoc": "rimraf web/docs && rimraf web/client/mapstore/docs", "doctest": "docma -c docma-config.json --dest web/client/mapstore/docs && echo documentation is accessible from the mapstore/docs path when running npm start", - "postinstall": "node checkCesium.js && mkdirp ./web/client/libs/Cesium && download --extract --out ./web/client/libs/Cesium https://cesiumjs.org/releases/Cesium-1.17.zip || echo Cesium already installed", + "postinstall": "node checkCesium.js", "clean": "rimraf ./web/client/dist", "compile": "npm run clean && mkdirp ./web/client/dist && webpack --progress --config prod-webpack.config.js", "analyze": "npm run clean && mkdirp ./web/client/dist && webpack --json | webpack-bundle-size-analyzer", diff --git a/project/index.html b/project/index.html index 7296ad93c8..2c59106c20 100644 --- a/project/index.html +++ b/project/index.html @@ -6,17 +6,17 @@ __PROJECTDESCRIPTION__ - + - + - - + + diff --git a/project/static/checkCesium.js b/project/static/checkCesium.js index 1988b94e6c..f97348743c 100644 --- a/project/static/checkCesium.js +++ b/project/static/checkCesium.js @@ -1,7 +1,24 @@ -var existsFile = require('exists-file'); - -var exists = existsFile('./libs/Cesium/Build/Cesium/Cesium.js'); +const fs = require('fs-extra'); +const dir = './libs/Cesium'; + +const copyFromNodeModules = () => { + console.log("Copying Cesium from node_modules..."); + fs.ensureDirSync(dir); + fs.copySync('./node_modules/cesium', dir); +}; + +const exists = fs.pathExistsSync(dir); if (!exists) { - process.exit(0); + console.log("Cesium not found"); + copyFromNodeModules(); +} else { + const packageInLibs = fs.readJsonSync(dir + '/package.json', { 'throws': false }); + const packageInNodeModules = fs.readJsonSync('./node_modules/cesium/package.json', { 'throws': false }); + if (!packageInLibs || packageInNodeModules && packageInLibs.version !== packageInNodeModules.version) { + console.log("Installed: " + (packageInLibs && packageInLibs.version)); + console.log("Required: " + (packageInNodeModules && packageInNodeModules.version)); + console.log("Cesium version is outdated"); + copyFromNodeModules(); + } + console.log("Cesium installed"); } -process.exit(1); \ No newline at end of file diff --git a/project/web/pom.xml b/project/web/pom.xml index 40652b8966..b2d169e7cc 100644 --- a/project/web/pom.xml +++ b/project/web/pom.xml @@ -58,34 +58,6 @@ __PROJECTNAME__ - - - org.apache.maven.plugins - maven-antrun-plugin - 1.6 - - - download-files - compile - - run - - - - - - - - - - - - - maven-resources-plugin 2.6 @@ -111,6 +83,8 @@ MapStore2/* MapStore2/**/* + **/libs/Cesium/**/* + **/test-resources/* @@ -192,22 +166,6 @@ - - CesiumJS - process-classes - - copy-resources - - - ${basedir}/target/__PROJECTNAME__/libs/Cesium - UTF-8 - - - ${basedir}/libs/Cesium - - - - CesiumJS-navigation process-classes diff --git a/project/webpack.config.js b/project/webpack.config.js index 5397c7a83e..c1ff32b968 100644 --- a/project/webpack.config.js +++ b/project/webpack.config.js @@ -48,7 +48,7 @@ module.exports = { extensions: [".js", ".jsx"] }, module: { - noParse: [/html2canvas/], + noParse: [/html2canvas/], rules: [ { test: /\.css$/, diff --git a/projectScripts.json b/projectScripts.json index ab199b7c90..561431e3c5 100644 --- a/projectScripts.json +++ b/projectScripts.json @@ -2,10 +2,10 @@ "clean": "rimraf dist", "compile": "npm run clean && mkdirp ./dist && webpack --config prod-webpack.config.js", "start": "webpack-dev-server --progress --colors --port 8081 --hot --inline --content-base .", - "postinstall": "node checkCesium.js && mkdirp ./libs/Cesium && download --extract --out ./libs/Cesium https://cesiumjs.org/releases/Cesium-1.17.zip || echo Cesium already installed", + "postinstall": "node checkCesium.js", "test": "karma start ./karma.conf.single-run.js", "continuoustest": "karma start ./karma.conf.continuous-test.js", "mvntest": "karma start ./karma.conf.single-run.js --reporters junit,dots,coverage", "lint": "eslint js --ext .jsx,.js", "travis": "eslint js --ext .jsx,.js && karma start ./karma.conf.single-run.js --browsers Firefox --reporters dots,junit,coverage,coveralls" -} \ No newline at end of file +} diff --git a/web/client/components/map/cesium/Map.jsx b/web/client/components/map/cesium/Map.jsx index c7d5cf15cc..84ded39de5 100644 --- a/web/client/components/map/cesium/Map.jsx +++ b/web/client/components/map/cesium/Map.jsx @@ -5,14 +5,14 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ -var Cesium = require('../../../libs/cesium'); +const Cesium = require('../../../libs/cesium'); const PropTypes = require('prop-types'); const Rx = require('rxjs'); -var React = require('react'); -var ReactDOM = require('react-dom'); -var ConfigUtils = require('../../../utils/ConfigUtils'); -var ClickUtils = require('../../../utils/cesium/ClickUtils'); -var assign = require('object-assign'); +const React = require('react'); +const ReactDOM = require('react-dom'); +const ConfigUtils = require('../../../utils/ConfigUtils'); +const ClickUtils = require('../../../utils/cesium/ClickUtils'); +const assign = require('object-assign'); const {throttle} = require('lodash'); class CesiumMap extends React.Component { diff --git a/web/client/examples/3dviewer/index.html b/web/client/examples/3dviewer/index.html index 27cdc59b2d..c0e9a59012 100644 --- a/web/client/examples/3dviewer/index.html +++ b/web/client/examples/3dviewer/index.html @@ -6,8 +6,8 @@ - - + + diff --git a/web/client/index.html b/web/client/index.html index 3920ad4dbc..95510bf482 100644 --- a/web/client/index.html +++ b/web/client/index.html @@ -7,18 +7,18 @@ MapStore 2 HomePage - + - + - - + + diff --git a/web/pom.xml b/web/pom.xml index a7a0a31038..b4861c685b 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -56,33 +56,6 @@ mapstore - - org.apache.maven.plugins - maven-antrun-plugin - 1.6 - - - download-files - compile - - run - - - - - - - - - - - - - maven-resources-plugin 2.6 @@ -125,6 +98,10 @@ **/img/* **/*.less + + **/libs/Cesium/**/* + **/test-resources/* + @@ -218,22 +195,6 @@ - - CesiumJS - process-classes - - copy-resources - - - ${basedir}/target/mapstore/libs/Cesium - UTF-8 - - - ${basedir}/client/libs/Cesium - - - - CesiumJS-navigation process-classes diff --git a/webpack.config.js b/webpack.config.js index 7899bdd008..ef13b0a75f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -41,7 +41,7 @@ module.exports = { "__API_KEY_MAPQUEST__": JSON.stringify(process.env.__API_KEY_MAPQUEST__ || '') }), new NormalModuleReplacementPlugin(/leaflet$/, path.join(__dirname, "web", "client", "libs", "leaflet")), - new NormalModuleReplacementPlugin(/cesium$/, path.join(__dirname, "web", "client", "libs", "cesium")), + // new NormalModuleReplacementPlugin(/cesium$/, path.join(__dirname, "web", "client", "libs", "cesium")), new NormalModuleReplacementPlugin(/openlayers$/, path.join(__dirname, "web", "client", "libs", "openlayers")), new NormalModuleReplacementPlugin(/proj4$/, path.join(__dirname, "web", "client", "libs", "proj4")), new NoEmitOnErrorsPlugin(),