Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
262d4ab
add wip routing
soyarsauce May 31, 2019
b817dc2
Add prettier deps
soyarsauce Jun 3, 2019
a9bbb60
Add scripts
soyarsauce Jun 3, 2019
db434c7
Add husky
soyarsauce Jun 3, 2019
32f6852
Apply prettier
soyarsauce Jun 3, 2019
25aa4dc
Merge branch 'prettier-apply' into 1757-tm-new-routing
soyarsauce Jun 3, 2019
0b046c3
Move prerendered routes into /prerender/
soyarsauce Jun 6, 2019
5c1ff17
Ensure there are no multiple meta description tags
soyarsauce Jun 6, 2019
3ae279e
Remove seperate prerender index to ejs
soyarsauce Jun 6, 2019
b67a03f
Update proper path for index
soyarsauce Jun 6, 2019
d6da6aa
wip remote stash
soyarsauce Jun 6, 2019
253162d
Add sitemap generator
soyarsauce Jun 19, 2019
4f525fc
Add sitemap generation
soyarsauce Jun 20, 2019
9f5de41
Fix sitemap generation, speed up prerendering
soyarsauce Jun 21, 2019
1daa20c
Merge branch 'prettier-new-apply' into 1757-tm-new-routing
soyarsauce Jun 24, 2019
4c13093
ci test
soyarsauce Jun 24, 2019
81b9616
Use named export
soyarsauce Jun 24, 2019
350b2fa
ci test 2
soyarsauce Jun 24, 2019
3bc1599
ci test3
soyarsauce Jun 24, 2019
e139dcb
disable prerender
soyarsauce Jun 24, 2019
39d3891
revert travis config
soyarsauce Jun 24, 2019
fd808c8
ci
soyarsauce Jun 25, 2019
fe17e91
update package-lock.json
soyarsauce Jun 25, 2019
cbb991c
travis for puppeteer again
soyarsauce Jun 25, 2019
b02cf6c
reenable prerender
soyarsauce Jun 25, 2019
0be00b2
quick timeout test
soyarsauce Jun 25, 2019
65973ab
Merge branch '1757-tm-new-routing' into 1757-tm-ci-test
soyarsauce Jun 25, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules/
.idea/
wwwroot/build/
wwwroot/doc/
wwwroot/prerendered/
npm-debug.log
version.js
wwwroot/init/nm.json
Expand All @@ -17,6 +18,7 @@ datasources/00_National_Data_Sets.json
/error.log
/output.log
privateserverconfig.json
wwwroot/sitemap.xml
wwwroot/privateconfig.json
deploy/packages/
deploy/work/
Expand Down
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
language: node_js
dist: trusty
addons:
apt:
packages:
- libnss3
node_js:
- '8'
script:
- gulp lint release
env:
- NODE_OPTIONS=--max_old_space_size=2048
before_install:
# Enable user namespace cloning
- "sysctl kernel.unprivileged_userns_clone=1"
51 changes: 51 additions & 0 deletions buildprocess/generate-init-routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var fs = require("fs");
var path = require("path");
var URI = require("urijs");
var CATALOG_ROUTE = require("terriajs/lib/ReactViewModels/TerriaRouting").CATALOG_ROUTE;

const rootGroupName = "Root Group";

const getNameFromItem = item => item.name;
const getIdFromItem = item => item.id;


const getRoutes = (topCatalogItem, currentRoute = rootGroupName) =>
topCatalogItem.reduce((acc, catalogItem) => {
const nameForCurrentItem = getNameFromItem(catalogItem);
// Id is used for uniqueid, so disregard any pathing
const idFromItem = getIdFromItem(catalogItem);
const finalRoute = idFromItem || `${currentRoute}/${nameForCurrentItem}`;
const items = catalogItem.items && getRoutes(catalogItem.items, finalRoute);

if (items) {
return [...acc, ...items, finalRoute];
}
return [...acc, finalRoute];
}, []);
/**
* Given an array of init names for files in wwwroot/init/, traverse the catalog
* and generate a list of routes to be prerendered at build time
*
* @param {Array} initUrls
*/
function generateRoutes(initUrls) {
const resUrl = url =>
path.resolve(__dirname, "..", "wwwroot", "init", `${url}.json`);

const getCatalogFromInitName = initName => resUrl(initName);

const routesFromInitCatalogs = initUrls.reduce((acc, initName) => {
const fsPathForInit = getCatalogFromInitName(initName);
const data = fs.readFileSync(fsPathForInit, "utf8");
const literal = JSON.parse(data).catalog;

return [...acc, ...getRoutes(literal, `${rootGroupName}`)];
}, []);

const encodedRoutes = routesFromInitCatalogs.map(route => `${CATALOG_ROUTE}${URI.encode(route)}`);

// Make sure we also prerender /catalog/ incase user reloads on it? or serve up in terriajs server?
return [CATALOG_ROUTE, ...encodedRoutes];
}

module.exports = generateRoutes;
35 changes: 35 additions & 0 deletions buildprocess/generate-terria-sitemap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const generateUrl = (loc, lastmod, changefreq, priority) => (`
<url>
<loc>${loc}</loc>
<lastmod>${lastmod}</lastmod>
<changefreq>${changefreq}</changefreq>
<priority>${priority}</priority>
</url>
`);

/**
* Generate a sitemap to be written out during build
*
* @param {string} baseUrl absolute URL to where your map is going to be deployed to, with a trailing slash
* @param {array} catalogRoutes list of routes, e.g. ['/catalog', '/catalog/someId']
*/
const generateTerriaSitemap = (baseUrl, catalogRoutes) => {
if (typeof baseUrl !== 'string') {
throw 'baseUrl passed to generateTerriaSitemap is not a string?';
}
if (baseUrl.substr(0,4) !== 'http') {
throw 'baseUrl does not look absolute, check that it begins with http or https';
}
const baseUrlWithoutTrailingSlash = (baseUrl.substr(-1) === '/') ? baseUrl.slice(0,-1) : baseUrl;
const date = new Date().toISOString().substr(0, 10);

const start = '<?xml version="1.0" encoding="UTF-8"?>';
const urlsetStart = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
const urlsetEnd = `</urlset>`;
const homeUrl = generateUrl(baseUrl, date, 'daily', '0.9');
const routeUrls = catalogRoutes.map(route => generateUrl(`${baseUrlWithoutTrailingSlash}${route}`, date, 'weekly', '0.5'));

return `${start}${urlsetStart}${homeUrl}${routeUrls.join('')}${urlsetEnd}`;
};

module.exports = generateTerriaSitemap;
52 changes: 52 additions & 0 deletions buildprocess/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
'use strict';

/*global require*/
var fs = require('fs');
var configureWebpackForTerriaJS = require('terriajs/buildprocess/configureWebpack');
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
var generateRoutes = require("./generate-init-routes");
var generateTerriaSitemap = require("./generate-terria-sitemap");
var PrerenderSPAPlugin = require("prerender-spa-plugin");
var Renderer = PrerenderSPAPlugin.PuppeteerRenderer;
var path = require('path');
var json5 = require("json5");

module.exports = function(devMode, hot) {
var config = {
Expand Down Expand Up @@ -108,5 +114,51 @@ module.exports = function(devMode, hot) {
}
};
config.resolve.alias['terriajs-variables'] = require.resolve('../lib/Styles/variables.scss');

if (!devMode) {
var configJsonPath = fs.readFileSync(path.resolve(__dirname, '..','wwwroot', 'config.json'), 'utf8');
var configJson = json5.parse(configJsonPath);
var prerenderRoutes =
(configJson &&
configJson.initializationUrls &&
configJson.initializationUrls.length > 0 &&
generateRoutes(configJson.initializationUrls)) ||
[];
var appBaseUrl =
(configJson &&
configJson.parameters &&
configJson.parameters.appBaseUrl &&
configJson.parameters.appBaseUrl.length > 0 &&
configJson.parameters.appBaseUrl);

console.log('The following routes generated from config.json\'s initializationUrls will be prerendered:');
console.log(prerenderRoutes);

if (appBaseUrl) {
try {
console.log('Attempting to write sitemap with appBaseUrl: ', appBaseUrl);
var sitemap = generateTerriaSitemap(appBaseUrl, prerenderRoutes);
var sitemapPath = path.resolve(__dirname, '..', 'wwwroot', 'sitemap.xml');
fs.writeFileSync(sitemapPath, new Buffer(sitemap));
console.log('Wrote out sitemap to: ' + sitemapPath);
} catch (e) {
console.error("Couldn't generate sitemap?", e);
}
} else {
console.warn("Warning - no appBaseUrl specified, no sitemap will be generated.")
}
config.plugins = [...config.plugins, new PrerenderSPAPlugin({
staticDir: path.resolve(__dirname, '..', 'wwwroot', ),
outputDir: path.resolve(__dirname, '..', 'wwwroot', 'prerendered'),
indexPath: path.resolve(__dirname, '..', 'wwwroot', 'index.html'),
routes: prerenderRoutes,
renderer: new Renderer({
timeout: 3000,
renderAfterDocumentEvent: 'prerender-end',
maxConcurrentRoutes: 12,
// headless: false, // set to false for debugging
}),
})];
}
return configureWebpackForTerriaJS(path.dirname(require.resolve('terriajs/package.json')), config, devMode, hot, MiniCssExtractPlugin);
};
2 changes: 2 additions & 0 deletions deploy/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
FROM node:8

RUN apt-get update && apt-get install -y gdal-bin
RUN apt-get -qq -y install gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget


RUN mkdir -p /usr/src/app && mkdir -p /etc/config/client
WORKDIR /usr/src/app/component
Expand Down
2 changes: 2 additions & 0 deletions devserverconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"port": 3001,

"baseHref": "/",

"allowProxyFor" : [
"nicta.com.au",
"gov.au",
Expand Down
8 changes: 8 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ function mergeConfigs(original, override) {
gulp.task('render-datasource-templates', function(done) {
var ejs = require('ejs');
var JSON5 = require('json5');
var serverConfig = JSON5.parse(fs.readFileSync('devserverconfig.json', 'utf8'));

var index = fs.readFileSync('wwwroot/index.ejs', 'utf8');
var baseHrefFromConfig = serverConfig.baseHref;
var indexResult = ejs.render(index, { baseHref: baseHrefFromConfig || "/"});

fs.writeFileSync(path.join('wwwroot', 'index.html'), new Buffer(indexResult));

var templateDir = 'datasources';
try {
fs.accessSync(templateDir);
Expand Down
3 changes: 3 additions & 0 deletions lib/Styles/loader.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.tjs-explorer-window__modal-wrapper {
z-index:10000 !important;
}
.loader-ui-right img{
display: block;
margin: calc(50vh - 150px) auto;
Expand Down
2 changes: 1 addition & 1 deletion lib/Views/UserInterface.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import PropTypes from "prop-types";
import React from "react";
import RelatedMaps from "./RelatedMaps";
import SplitPoint from "terriajs/lib/ReactViews/SplitPoint";
import StandardUserInterface from "terriajs/lib/ReactViews/StandardUserInterface/StandardUserInterface.jsx";
import { StandardUserInterface } from "terriajs/lib/ReactViews/StandardUserInterface/StandardUserInterface.jsx";
import version from "../../version";

import "./global.scss";
Expand Down
Loading