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 @@