Skip to content

Commit

Permalink
Merge pull request #868 from OpenGeoscience/express-serve
Browse files Browse the repository at this point in the history
Refactor the server script to serve dist, website, and _build.
  • Loading branch information
manthey committed Jul 13, 2018
2 parents 5067f0d + 96f491a commit a7a5284
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 182 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Expand Up @@ -41,7 +41,7 @@ function(add_geojs_test test_name)
set_property(TEST "notes-report" APPEND PROPERTY DEPENDS "${test_name}")
endfunction()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/testing/test-runners/geojs_test_runner.py.in
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/runners/geojs_test_runner.py.in
${CMAKE_CURRENT_BINARY_DIR}/test/geojs_test_runner.py
)

Expand Down Expand Up @@ -163,7 +163,7 @@ if(WEBGLHEADLESS_TESTS)
set_property(TEST "headed" APPEND PROPERTY DEPENDS "build_examples")

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/testing/test-runners/baseline_images.py"
"${CMAKE_CURRENT_SOURCE_DIR}/tests/runners/baseline_images.py"
"${CMAKE_CURRENT_BINARY_DIR}/test/baseline_images.py"
COPYONLY
)
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Expand Up @@ -26,7 +26,7 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
basepath = os.path.dirname(os.path.abspath(__file__))
toppath = os.path.join(basepath, '..')
for fname in glob(os.path.join(toppath, 'testing', 'test-runners', '*.py*')):
for fname in glob(os.path.join(toppath, 'tests', 'runners', '*.py*')):
basename = os.path.split(fname)[-1].replace('.in', '')
with open(fname, 'r') as f:
with open(os.path.join(basepath, basename), 'w') as g:
Expand Down
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -76,6 +76,7 @@
"pug-loader": "^2.4.0",
"raw-body": "^2.1.6",
"resemblejs": "^2.9.0",
"serve-index": "^1.9.1",
"sinon": "^1.17.3",
"string-replace-webpack-plugin": "^0.1.3",
"style-loader": "^0.21.0",
Expand Down Expand Up @@ -113,8 +114,8 @@
"codecov": "codecov",
"combine-coverage": "istanbul-combine -d dist/cobertura -r cobertura 'dist/coverage/json/**/coverage-final.json'",
"examples": "webpack-dev-server --config webpack-examples.config.js --host ${HOST-127.0.0.1} --port ${PORT-8082} --content-base dist/",
"start-test": "node examples/build.js; forever start ./testing/test-runners/server.js",
"stop-test": "forever stop ./testing/test-runners/server.js",
"start-test": "node examples/build.js; forever start ./tests/runners/server.js",
"stop-test": "forever stop ./tests/runners/server.js",
"docs": "jsdoc --pedantic -d dist/apidocs -r src -c jsdoc.conf.json",
"website": "cd website && npx hexo server",
"setup-website": "cd website && npm install",
Expand Down
177 changes: 0 additions & 177 deletions testing/test-runners/server.js

This file was deleted.

File renamed without changes.
File renamed without changes.
70 changes: 70 additions & 0 deletions tests/runners/server.js
@@ -0,0 +1,70 @@
/* global require, module */
'use strict';

var serveIndex;
try {
serveIndex = require('serve-index');
} catch (err) { }
var express = require('express'),
app = express(),
help = false,
skip = 2,
port = 30100,
build = false,
dist = false,
website = false;

process.argv.forEach(function (val, idx) {
if (skip) {
skip -= 1;
return;
}
if (val === '--build' || val === '-b') {
build = true;
} else if (val === '--dist' || val === '-d') {
dist = true;
} else if ((val === '--port' || val === '-p') && idx + 1 < process.argv.length) {
port = parseInt(process.argv[idx + 1], 10);
skip = 1;
} else if (val.substr(0, 7) === '--port=') {
port = parseInt(val.substr(7), 10);
} else if (val === '--website' || val === '--web' || val === '-w') {
website = true;
} else {
help = true;
}
});

if (help) {
console.error('Serve the dist, website, and _build directories. Options:\n' +
'--build : serve _build directory as build/\n' +
'--dist : serve distribution directory (default)\n' +
'--port (port) : default 30100\n' +
'--website : serve website directory (if this and dist are specified,\n' +
' dist is located as dist/)\n');
process.exit(1);
}

if (!website) {
if (!build || dist) {
app.use(express.static('dist'));
}
} else {
if (dist) {
app.use('/dist', express.static('dist'));
}
app.use(express.static('website/public'));
}
if (build) {
if (serveIndex) {
app.use('/build', express.static('_build'), serveIndex('_build', {icons: true, view: 'details'}));
} else {
app.use('/build', express.static('_build'));
}
}

app.listen(port, function () {
console.log('Server listening on ' + port);
});

module.exports = app;

0 comments on commit a7a5284

Please sign in to comment.