Skip to content

Commit

Permalink
Do not pack Cesium, use online version (#2016)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnafu authored and mbarto committed Jul 11, 2017
1 parent 7ae7401 commit e01f4de
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 179 deletions.
27 changes: 22 additions & 5 deletions checkCesium.js
Original file line number Diff line number Diff line change
@@ -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);
110 changes: 55 additions & 55 deletions createProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand All @@ -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();
1 change: 0 additions & 1 deletion karma.conf.single-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"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",
"download-cli": "1.0.1",
"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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions project/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>__PROJECTDESCRIPTION__</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.css" />
<link rel="stylesheet" href="https://rawgit.com/Leaflet/Leaflet.draw/v0.2.4/dist/leaflet.draw.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.2.4/leaflet.draw.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ol3/4.0.1/ol.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/mapstore2.css">
<script src="https://maps.google.com/maps/api/js?v=3"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.10/proj4.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.js"></script>
<script src="https://rawgit.com/Leaflet/Leaflet.draw/v0.2.4/dist/leaflet.draw.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.2.4/leaflet.draw.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ol3/4.0.1/ol.js"></script>
<script src="libs/Cesium/Build/Cesium/Cesium.js"></script>
<link rel="stylesheet" href="libs/Cesium/Build/Cesium/Widgets/widgets.css" />
<script src="https://cesiumjs.org/releases/1.17/Build/Cesium/Cesium.js"></script>
<link rel="stylesheet" href="https://cesiumjs.org/releases/1.17/Build/Cesium/Widgets/widgets.css" />
<script src="libs/cesium-navigation/cesium-navigation.js"></script>
<link rel="stylesheet" href="libs/cesium-navigation/cesium-navigation.css" />
</head>
Expand Down
27 changes: 22 additions & 5 deletions project/static/checkCesium.js
Original file line number Diff line number Diff line change
@@ -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);
46 changes: 2 additions & 44 deletions project/web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,6 @@
<build>
<finalName>__PROJECTNAME__</finalName>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>download-files</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- download file -->
<get src=" https://cesiumjs.org/releases/Cesium-1.17.zip"
dest="${basedir}/cesium.zip"
verbose="true"
usetimestamp="true"/>
<mkdir dir="${basedir}/libs/Cesium"/>
<unzip src="${basedir}/cesium.zip"
dest="${basedir}/libs/Cesium">
</unzip>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
Expand All @@ -111,6 +83,8 @@
<excludes>
<exclude>MapStore2/*</exclude>
<exclude>MapStore2/**/*</exclude>
<exclude>**/libs/Cesium/**/*</exclude>
<exclude>**/test-resources/*</exclude>
</excludes>
</resource>
</resources>
Expand Down Expand Up @@ -192,22 +166,6 @@
</resources>
</configuration>
</execution>
<execution>
<id>CesiumJS</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/__PROJECTNAME__/libs/Cesium</outputDirectory>
<encoding>UTF-8</encoding>
<resources>
<resource>
<directory>${basedir}/libs/Cesium</directory>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>CesiumJS-navigation</id>
<phase>process-classes</phase>
Expand Down
2 changes: 1 addition & 1 deletion project/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
extensions: [".js", ".jsx"]
},
module: {
noParse: [/html2canvas/],
noParse: [/html2canvas/],
rules: [
{
test: /\.css$/,
Expand Down
4 changes: 2 additions & 2 deletions projectScripts.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
12 changes: 6 additions & 6 deletions web/client/components/map/cesium/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit e01f4de

Please sign in to comment.