Remove unused code, get tests passing on Travis
This commit is contained in:
@@ -1,14 +1,9 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- '8'
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
before_script:
|
||||
- rm src/ol/renderer/webgl/*shader.js
|
||||
- rm src/ol/renderer/webgl/*shader/locations.js
|
||||
script: make ci
|
||||
after_success:
|
||||
- cat coverage/lcov.info | coveralls
|
||||
branches:
|
||||
|
||||
273
Makefile
273
Makefile
@@ -1,280 +1,13 @@
|
||||
OS := $(shell uname)
|
||||
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
||||
|
||||
SRC_GLSL := $(shell find src -type f -name '*.glsl')
|
||||
SRC_SHADER_JS := $(patsubst %shader.glsl,%shader.js,$(SRC_GLSL))
|
||||
SRC_SHADERLOCATIONS_JS := $(patsubst %shader.glsl,%shader/locations.js,$(SRC_GLSL))
|
||||
SRC_JS := $(filter-out $(SRC_SHADER_JS) $(SRC_SHADERLOCATIONS_JS),$(shell find src -name '*.js'))
|
||||
SRC_JSDOC = $(shell find src -type f -name '*.jsdoc')
|
||||
|
||||
EXAMPLES := $(shell find examples -type f)
|
||||
EXAMPLES_HTML := $(filter-out examples/index.html,$(shell find examples -maxdepth 1 -type f -name '*.html'))
|
||||
EXAMPLES_JS := $(patsubst %.html,%.js,$(EXAMPLES_HTML))
|
||||
|
||||
BUILD_EXAMPLES := $(subst examples,build/examples,$(EXAMPLES)) build/examples/index.js
|
||||
|
||||
BUILD_HOSTED := build/hosted/$(BRANCH)
|
||||
BUILD_HOSTED_EXAMPLES := $(addprefix $(BUILD_HOSTED)/,$(EXAMPLES))
|
||||
BUILD_HOSTED_EXAMPLES_JS := $(addprefix $(BUILD_HOSTED)/,$(EXAMPLES_JS))
|
||||
|
||||
UNPHANTOMABLE_EXAMPLES = examples/shaded-relief.html examples/raster.html examples/region-growing.html examples/color-manipulation.html
|
||||
CHECK_EXAMPLE_TIMESTAMPS = $(patsubst examples/%.html,build/timestamps/check-%-timestamp,$(filter-out $(UNPHANTOMABLE_EXAMPLES),$(EXAMPLES_HTML)))
|
||||
|
||||
TASKS_JS := $(shell find tasks -name '*.js')
|
||||
|
||||
ifeq (CYGWIN,$(findstring CYGWIN,$(OS)))
|
||||
CLOSURE_LIB = $(shell cygpath -u $(shell node -e 'process.stdout.write(require("closure-util").getLibraryPath())'))
|
||||
else
|
||||
CLOSURE_LIB = $(shell node -e 'process.stdout.write(require("closure-util").getLibraryPath())')
|
||||
endif
|
||||
|
||||
ifeq ($(OS),Darwin)
|
||||
STAT_COMPRESSED = stat -f ' compressed: %z bytes'
|
||||
STAT_UNCOMPRESSED = stat -f 'uncompressed: %z bytes'
|
||||
else
|
||||
STAT_COMPRESSED = stat -c ' compressed: %s bytes'
|
||||
STAT_UNCOMPRESSED = stat -c 'uncompressed: %s bytes'
|
||||
endif
|
||||
|
||||
.PHONY: default
|
||||
default: help
|
||||
|
||||
.PHONY: help
|
||||
help:
|
||||
@echo
|
||||
@echo "The most common targets are:"
|
||||
@echo
|
||||
@echo "- install Install node dependencies"
|
||||
@echo "- serve Start dev server for running examples and tests"
|
||||
@echo "- test Run unit tests in the console"
|
||||
@echo "- check Perform a number of checks on the code"
|
||||
@echo "- clean Remove generated files"
|
||||
@echo "- help Display this help message"
|
||||
@echo
|
||||
@echo "Other less frequently used targets are:"
|
||||
@echo
|
||||
@echo "- build Build ol.js, ol-debug.js, ol.js.map and ol.css"
|
||||
@echo "- ci Run the full continuous integration process"
|
||||
@echo "- apidoc Build the API documentation using JSDoc"
|
||||
@echo "- cleanall Remove all the build artefacts"
|
||||
@echo "- check-deps Check if the required dependencies are installed"
|
||||
@echo
|
||||
|
||||
.PHONY: apidoc
|
||||
apidoc: build/timestamps/jsdoc-$(BRANCH)-timestamp
|
||||
|
||||
.PHONY: build
|
||||
build: build/ol.css build/ol.js build/ol-debug.js build/ol.js.map
|
||||
|
||||
.PHONY: check
|
||||
check: build/ol.js test
|
||||
|
||||
.PHONY: check-examples
|
||||
check-examples: $(CHECK_EXAMPLE_TIMESTAMPS)
|
||||
|
||||
.PHONY: check-deps
|
||||
check-deps: EXECUTABLES = git node python java
|
||||
check-deps:
|
||||
@for exe in $(EXECUTABLES) ;\
|
||||
do \
|
||||
which $${exe} > /dev/null && \
|
||||
echo "Program $${exe} OK" || \
|
||||
echo "Program $${exe} MISSING!" ;\
|
||||
done ;\
|
||||
|
||||
.PHONY: ci
|
||||
ci: build test package compile-examples check-examples apidoc
|
||||
|
||||
.PHONY: compile-examples
|
||||
compile-examples: build/compiled-examples/all.combined.js
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f build/timestamps/check-*-timestamp
|
||||
rm -f build/ol.css
|
||||
rm -f build/ol.js
|
||||
rm -f build/ol.js.map
|
||||
rm -f build/ol-debug.js
|
||||
rm -rf build/examples
|
||||
rm -rf build/compiled-examples
|
||||
rm -rf build/package
|
||||
rm -rf $(BUILD_HOSTED)
|
||||
|
||||
.PHONY: cleanall
|
||||
cleanall:
|
||||
rm -rf build
|
||||
|
||||
.PHONY: css
|
||||
css: build/ol.css
|
||||
|
||||
.PHONY: examples
|
||||
examples: $(BUILD_EXAMPLES)
|
||||
|
||||
.PHONY: install
|
||||
install: build/timestamps/node-modules-timestamp
|
||||
|
||||
.PHONY: npm-install
|
||||
npm-install: build/timestamps/node-modules-timestamp
|
||||
|
||||
.PHONY: shaders
|
||||
shaders: $(SRC_SHADER_JS $(SRC_SHADERLOCATIONS_JS)
|
||||
shaders: $(SRC_SHADER_JS) $(SRC_SHADERLOCATIONS_JS)
|
||||
|
||||
.PHONY: serve
|
||||
serve:
|
||||
node tasks/serve.js
|
||||
|
||||
.PHONY: test
|
||||
test: build/timestamps/node-modules-timestamp
|
||||
npm test
|
||||
|
||||
.PHONY: host-examples
|
||||
host-examples: $(BUILD_HOSTED_EXAMPLES) \
|
||||
$(BUILD_HOSTED)/build/ol.js \
|
||||
$(BUILD_HOSTED)/build/ol-debug.js \
|
||||
$(BUILD_HOSTED)/css/ol.css \
|
||||
$(BUILD_HOSTED)/examples/loader.js \
|
||||
$(BUILD_HOSTED)/examples/index.js \
|
||||
$(BUILD_HOSTED)/build/ol-deps.js
|
||||
|
||||
.PHONY: host-libraries
|
||||
host-libraries: build/timestamps/node-modules-timestamp
|
||||
@rm -rf $(BUILD_HOSTED)/closure-library
|
||||
@mkdir -p $(BUILD_HOSTED)/closure-library
|
||||
@cp -r $(CLOSURE_LIB)/* $(BUILD_HOSTED)/closure-library/
|
||||
@rm -rf $(BUILD_HOSTED)/ol/ol
|
||||
@mkdir -p $(BUILD_HOSTED)/ol/ol
|
||||
@cp -r src/ol/* $(BUILD_HOSTED)/ol/ol/
|
||||
@rm -rf $(BUILD_HOSTED)/ol.ext
|
||||
@mkdir -p $(BUILD_HOSTED)/ol.ext
|
||||
@cp -r build/ol.ext/* $(BUILD_HOSTED)/ol.ext/
|
||||
|
||||
$(BUILD_EXAMPLES): $(EXAMPLES) package.json
|
||||
@mkdir -p $(@D)
|
||||
@node tasks/build-examples.js
|
||||
|
||||
build/timestamps/check-%-timestamp: $(BUILD_HOSTED)/examples/%.html \
|
||||
$(BUILD_HOSTED)/examples/%.js \
|
||||
$(filter $(BUILD_HOSTED)/examples/resources/%,$(BUILD_HOSTED_EXAMPLES)) \
|
||||
$(filter $(BUILD_HOSTED)/examples/data/%,$(BUILD_HOSTED_EXAMPLES)) \
|
||||
$(BUILD_HOSTED)/examples/loader.js \
|
||||
$(BUILD_HOSTED)/build/ol.js \
|
||||
$(BUILD_HOSTED)/css/ol.css
|
||||
@mkdir -p $(@D)
|
||||
node tasks/check-example.js $<
|
||||
@touch $@
|
||||
|
||||
build/compiled-examples/all.js: $(EXAMPLES_JS)
|
||||
@mkdir -p $(@D)
|
||||
@python bin/combine-examples.py $^ > $@
|
||||
|
||||
build/compiled-examples/all.combined.js: config/examples-all.json build/compiled-examples/all.js \
|
||||
$(SRC_JS) $(SRC_SHADER_JS) $(SRC_SHADERLOCATIONS_JS) \
|
||||
build/timestamps/node-modules-timestamp
|
||||
@mkdir -p $(@D)
|
||||
node tasks/build.js $< $@
|
||||
|
||||
build/compiled-examples/%.json: config/example.json build/examples/%.js \
|
||||
build/timestamps/node-modules-timestamp
|
||||
@mkdir -p $(@D)
|
||||
@sed -e 's|{{id}}|$*|' $< > $@
|
||||
|
||||
build/compiled-examples/%.combined.js: build/compiled-examples/%.json \
|
||||
$(SRC_JS) $(SRC_SHADER_JS) $(SRC_SHADERLOCATIONS_JS)\
|
||||
build/timestamps/node-modules-timestamp
|
||||
@mkdir -p $(@D)
|
||||
node tasks/build.js $< $@
|
||||
|
||||
build/timestamps/jsdoc-$(BRANCH)-timestamp: config/jsdoc/api/index.md \
|
||||
config/jsdoc/api/conf.json $(SRC_JS) \
|
||||
$(SRC_SHADER_JS) $(SRC_SHADERLOCATIONS_JS) \
|
||||
$(shell find config/jsdoc/api/template -type f) \
|
||||
build/timestamps/node-modules-timestamp
|
||||
@mkdir -p $(@D)
|
||||
@rm -rf $(BUILD_HOSTED)/apidoc
|
||||
./node_modules/.bin/jsdoc config/jsdoc/api/index.md -c config/jsdoc/api/conf.json --package package.json -d $(BUILD_HOSTED)/apidoc
|
||||
@touch $@
|
||||
|
||||
$(BUILD_HOSTED_EXAMPLES_JS): $(BUILD_HOSTED)/examples/%.js: build/examples/%.js
|
||||
@mkdir -p $(@D)
|
||||
@python bin/split-example.py $< $(@D)
|
||||
|
||||
$(BUILD_HOSTED)/examples/loader.js: bin/loader_hosted_examples.js
|
||||
@mkdir -p $(@D)
|
||||
@cp $< $@
|
||||
|
||||
$(BUILD_HOSTED)/examples/%: build/examples/%
|
||||
@mkdir -p $(@D)
|
||||
@cp $< $@
|
||||
|
||||
$(BUILD_HOSTED)/build/ol.js: build/ol.js
|
||||
@mkdir -p $(@D)
|
||||
@cp $< $@
|
||||
|
||||
$(BUILD_HOSTED)/build/ol-debug.js: build/ol-debug.js
|
||||
@mkdir -p $(@D)
|
||||
@cp $< $@
|
||||
|
||||
$(BUILD_HOSTED)/css/ol.css: build/ol.css
|
||||
@mkdir -p $(@D)
|
||||
@cp $< $@
|
||||
|
||||
$(BUILD_HOSTED)/build/ol-deps.js: host-libraries
|
||||
@mkdir -p $(@D)
|
||||
@python $(CLOSURE_LIB)/closure/bin/build/depswriter.py \
|
||||
--root_with_prefix "src ../../../ol" \
|
||||
--root_with_prefix "build/ol.ext ../../../ol.ext" \
|
||||
--root $(BUILD_HOSTED)/closure-library/closure/goog \
|
||||
--root_with_prefix "$(BUILD_HOSTED)/closure-library/third_party ../../third_party" \
|
||||
--output_file $@
|
||||
|
||||
build/timestamps/node-modules-timestamp: package.json
|
||||
@mkdir -p $(@D)
|
||||
npm install
|
||||
@touch $@
|
||||
|
||||
build/ol.css: css/ol.css build/timestamps/node-modules-timestamp
|
||||
@mkdir -p $(@D)
|
||||
@echo "Running cleancss..."
|
||||
@./node_modules/.bin/cleancss $< > $@
|
||||
|
||||
build/ol.js: config/ol.json $(SRC_JS) $(SRC_SHADER_JS) $(SRC_SHADERLOCATIONS_JS) \
|
||||
build/timestamps/node-modules-timestamp
|
||||
@mkdir -p $(@D)
|
||||
node tasks/build.js $< $@
|
||||
@$(STAT_UNCOMPRESSED) $@
|
||||
@cp $@ /tmp/
|
||||
@gzip /tmp/ol.js
|
||||
@$(STAT_COMPRESSED) /tmp/ol.js.gz
|
||||
@rm /tmp/ol.js.gz
|
||||
|
||||
build/ol.js.map: config/ol.json $(SRC_JS) $(SRC_SHADER_JS) $(SRC_SHADERLOCATIONS_JS) \
|
||||
build/timestamps/node-modules-timestamp
|
||||
@mkdir -p $(@D)
|
||||
node tasks/build.js $< $@
|
||||
|
||||
build/ol-debug.js: config/ol-debug.json $(SRC_JS) $(SRC_SHADER_JS) $(SRC_SHADERLOCATIONS_JS) \
|
||||
build/timestamps/node-modules-timestamp
|
||||
@mkdir -p $(@D)
|
||||
node tasks/build.js $< $@
|
||||
@$(STAT_UNCOMPRESSED) $@
|
||||
@cp $@ /tmp/
|
||||
@gzip /tmp/ol-debug.js
|
||||
@$(STAT_COMPRESSED) /tmp/ol-debug.js.gz
|
||||
@rm /tmp/ol-debug.js.gz
|
||||
|
||||
%shader.js: %shader.glsl src/ol/webgl/shader.mustache tasks/glslunit.js build/timestamps/node-modules-timestamp
|
||||
%shader.js: %shader.glsl src/ol/webgl/shader.mustache tasks/glslunit.js
|
||||
@node tasks/glslunit.js --input $< | ./node_modules/.bin/mustache - src/ol/webgl/shader.mustache > $@
|
||||
|
||||
%shader/locations.js: %shader.glsl src/ol/webgl/shaderlocations.mustache tasks/glslunit.js build/timestamps/node-modules-timestamp
|
||||
%shader/Locations.js: %shader.glsl src/ol/webgl/shaderlocations.mustache tasks/glslunit.js
|
||||
@mkdir -p $(@D)
|
||||
@node tasks/glslunit.js --input $< | ./node_modules/.bin/mustache - src/ol/webgl/shaderlocations.mustache > $@
|
||||
|
||||
.PHONY: package
|
||||
package:
|
||||
@rm -rf build/package
|
||||
@cp -r package build
|
||||
@cd ./src && cp -r ol/* ../build/package
|
||||
@rm build/package/typedefs.js
|
||||
@cp css/ol.css build/package
|
||||
./node_modules/.bin/jscodeshift --transform transforms/module.js build/package
|
||||
npm run lint-package
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
//
|
||||
// A PhantomJS script used to check that the hosted examples load
|
||||
// without errors. This script is executed by the build tool's
|
||||
// check-examples target.
|
||||
//
|
||||
var args = require('system').args;
|
||||
if (args.length != 2) {
|
||||
phantom.exit(2);
|
||||
}
|
||||
var examplePath = args[1];
|
||||
var page = require('webpage').create();
|
||||
page.onError = function(msg, trace) {
|
||||
var msgStack = ['JavaScript ERROR: ' + msg];
|
||||
if (trace) {
|
||||
msgStack.push('TRACE:');
|
||||
trace.forEach(function(t) {
|
||||
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : ''));
|
||||
});
|
||||
}
|
||||
console.error(msgStack.join('\n'));
|
||||
phantom.exit(1);
|
||||
};
|
||||
page.open(examplePath, function(s) {
|
||||
var exitCode = 0;
|
||||
if (s != 'success') {
|
||||
exitCode = 1;
|
||||
console.error('PAGE LOAD ERROR');
|
||||
}
|
||||
phantom.exit(exitCode);
|
||||
});
|
||||
page.onConsoleMessage = function(msg) {
|
||||
console.log('console:', msg);
|
||||
};
|
||||
@@ -1,27 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def main(argv):
|
||||
examples = {}
|
||||
requires = set()
|
||||
for filename in argv[1:]:
|
||||
lines = open(filename, 'rU').readlines()
|
||||
if len(lines) > 0 and lines[0].startswith('// NOCOMPILE'):
|
||||
continue
|
||||
requires.update(line for line in lines if line.startswith('goog.require'))
|
||||
examples[filename] = [line for line in lines if not line.startswith('goog.require')]
|
||||
for require in sorted(requires):
|
||||
sys.stdout.write(require)
|
||||
for filename in sorted(examples.keys()):
|
||||
sys.stdout.write('// ' + filename + '\n')
|
||||
sys.stdout.write('(function(){\n')
|
||||
for line in examples[filename]:
|
||||
sys.stdout.write(line)
|
||||
sys.stdout.write('})();\n')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
||||
@@ -1,180 +0,0 @@
|
||||
|
||||
|
||||
/**
|
||||
* This script is supposed to be executed via phantomjs. It will generate
|
||||
* screenshots of the html files in the directory specified by a commandline
|
||||
* option when these files are served through a webserver which can also be
|
||||
* specified. The screenshots will be in the current working directory.
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* user@host:~/openlayers/bin $ phantomjs example-screenshot.js \
|
||||
* http://localhost:8000/openlayers/examples/ \
|
||||
* ../examples
|
||||
*
|
||||
* The above command will generate `*.png` files in `examples/` for all html
|
||||
* files that are served through `http://localhost:8000/openlayers/examples/`.
|
||||
*
|
||||
* So if there is a file `my-humpty-example.html` inside of the relative folder
|
||||
* `../examples/` which is being served through the webserver so that
|
||||
* `http://localhost:8000/openlayers/examples/my-humpty-example.html` is a valid and
|
||||
* reachable URL, this script will generate a screenshot and store it as
|
||||
* `my-humpty-example.html.png`.
|
||||
*
|
||||
* The query string `?mode=raw` will be appended to the generated URL.
|
||||
*
|
||||
* Known limitations:
|
||||
*
|
||||
* As phantomjs doesn't support WebGL (see e.g.
|
||||
* https://github.com/ariya/phantomjs/wiki/Supported-Web-Standards and
|
||||
* http://code.google.com/p/phantomjs/issues/detail?id=273) This won't render
|
||||
* OpenLayers maps rendered through the webglrenderer.
|
||||
*
|
||||
* In parts based upon this gist: https://gist.github.com/crazy4groovy/3160121
|
||||
*/
|
||||
(function() { // global closure
|
||||
|
||||
var page = require('webpage').create(), // imports
|
||||
fs = require('fs'),
|
||||
system = require('system'),
|
||||
// arguments
|
||||
baseExamplesUrl = system.args[1],
|
||||
exampleDir = system.args[2],
|
||||
// various settings
|
||||
ignoreFiles = [
|
||||
'index.html'
|
||||
],
|
||||
intervalMillisecs = 25,
|
||||
renderMillisecs = 2000,
|
||||
// basic variables
|
||||
curDir = fs.workingDirectory,
|
||||
exampleDirList = fs.list(exampleDir),
|
||||
pageindex = 0,
|
||||
fileName = '',
|
||||
htmlFiles = [],
|
||||
lenHtmlFiles = 0,
|
||||
loadInProgress = false;
|
||||
|
||||
// simple object with helper functions
|
||||
var util = {
|
||||
/**
|
||||
* Returns the basename of a file given a path.
|
||||
*/
|
||||
baseName: function(path) {
|
||||
var parts = path.split(fs.separator);
|
||||
return parts[parts.length - 1];
|
||||
},
|
||||
/**
|
||||
* Super basic test whether a file can be considered a HTML-file.
|
||||
*/
|
||||
isHtmlFile: function(filename) {
|
||||
return (/\.html?$/).test(filename);
|
||||
},
|
||||
/**
|
||||
* Appends a slash to given string if it isn't there already.
|
||||
*/
|
||||
appendSlash: function(str) {
|
||||
return ((/\/$/).test(str)) ? str : str + '/';
|
||||
},
|
||||
/**
|
||||
* Generates an URL out of given baseurl and path.
|
||||
*/
|
||||
buildUrl: function(baseurl, path) {
|
||||
var name = util.baseName(path),
|
||||
mode = 'raw';
|
||||
return util.appendSlash(baseurl) + name + '?mode=' + mode;
|
||||
},
|
||||
/**
|
||||
* Simple progressbar logger that uses our globals pageindex & lenHtmlFiles.
|
||||
*/
|
||||
logProgress: function() {
|
||||
var doneSymbol = '-',
|
||||
todoSymbol = ' ',
|
||||
currentSymbol = '>',
|
||||
barStrLeft = '[',
|
||||
barStrRight = ']',
|
||||
progresStep = 5, // one doneSymbol equals this percentage
|
||||
totalSteps = Math.round(100 / progresStep),
|
||||
ratio = (lenHtmlFiles === 0) ? 0 : (pageindex / lenHtmlFiles),
|
||||
percent = (ratio === 0) ? 0 : ratio * 100,
|
||||
normalizedNumDone = Math.floor(ratio * totalSteps),
|
||||
normalizedNumTodo = totalSteps - normalizedNumDone,
|
||||
progressLine = '',
|
||||
i = 0;
|
||||
// the progress bar
|
||||
progressLine += barStrLeft;
|
||||
for (; i < normalizedNumDone; i++) {
|
||||
progressLine += doneSymbol;
|
||||
}
|
||||
for (i = 0; i < normalizedNumTodo; i++) {
|
||||
progressLine += (i === 0) ? currentSymbol : todoSymbol;
|
||||
}
|
||||
progressLine += barStrRight;
|
||||
// the percentage information
|
||||
// pad if necessary
|
||||
if (percent < 10) {
|
||||
progressLine += ' ';
|
||||
} else if (percent < 100) {
|
||||
progressLine += ' ';
|
||||
}
|
||||
progressLine += ' ' + percent.toFixed(1) + ' % done';
|
||||
// additional information
|
||||
if (fileName !== '') {
|
||||
progressLine += ', ' + util.baseName(fileName) + '';
|
||||
}
|
||||
console.log(progressLine);
|
||||
}
|
||||
};
|
||||
|
||||
// iterate over all files in examples directory
|
||||
// and find the HTML files.
|
||||
for (var i = 0; i < exampleDirList.length; i++) {
|
||||
var fullpath = exampleDir + fs.separator + exampleDirList[i];
|
||||
if (fs.isFile(fullpath) && util.isHtmlFile(fullpath) &&
|
||||
ignoreFiles.indexOf(util.baseName(fullpath)) === -1) {
|
||||
//TODO: make this more async (i.e. pop on/off stack WHILE rending pages)
|
||||
htmlFiles.push(fullpath);
|
||||
}
|
||||
}
|
||||
lenHtmlFiles = htmlFiles.length;
|
||||
|
||||
console.log('Capturing ' + lenHtmlFiles + ' example screenshots.');
|
||||
|
||||
// The main interval function that is executed regularly and renders a
|
||||
// page to a file
|
||||
var interval = setInterval(function() {
|
||||
if (!loadInProgress && pageindex < lenHtmlFiles) {
|
||||
util.logProgress();
|
||||
fileName = htmlFiles[pageindex];
|
||||
page.viewportSize = { width: 800, height: 600 };
|
||||
page.clipRect = {
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: page.viewportSize.width,
|
||||
height: page.viewportSize.height
|
||||
};
|
||||
page.open(util.buildUrl(baseExamplesUrl, htmlFiles[pageindex]));
|
||||
}
|
||||
if (pageindex == lenHtmlFiles) {
|
||||
util.logProgress();
|
||||
console.log(lenHtmlFiles + ' screenshots captured.');
|
||||
phantom.exit();
|
||||
}
|
||||
}, intervalMillisecs);
|
||||
|
||||
// set loadInProgress flag so we only process one image at time.
|
||||
page.onLoadStarted = function() {
|
||||
loadInProgress = true;
|
||||
};
|
||||
|
||||
// When the page is loaded, render it to an image
|
||||
page.onLoadFinished = function() {
|
||||
var dest = exampleDir + fs.separator + util.baseName(fileName) + '.png';
|
||||
window.setTimeout(function() {
|
||||
loadInProgress = false;
|
||||
page.render(dest); // actually render the page.
|
||||
pageindex++;
|
||||
}, renderMillisecs);
|
||||
};
|
||||
|
||||
})(); // eof global closure
|
||||
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
* This loader is used for the hosted examples. It is used in place of the
|
||||
* development loader (examples/loader.js).
|
||||
*
|
||||
* The loader loads ol.js and the example's script in "production" mode; it
|
||||
* loads Closure Library's base.js, ol-deps.js, the example's "goog.require"
|
||||
* script, and the example's script in "development" mode.
|
||||
*
|
||||
* The ol.js and ol-deps.js scripts are built using OpenLayers's Makefile. They are
|
||||
* located in the ../build/ directory, relative to this script.
|
||||
*
|
||||
* The script must be named loader.js.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* <script src="../loader.js?id=my-demo"></script>
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
var i, pair;
|
||||
|
||||
var href = window.location.href, start, end, paramsString, pairs,
|
||||
pageParams = {};
|
||||
if (href.indexOf('?') > 0) {
|
||||
start = href.indexOf('?') + 1;
|
||||
end = href.indexOf('#') > 0 ? href.indexOf('#') : href.length;
|
||||
paramsString = href.substring(start, end);
|
||||
pairs = paramsString.split(/[&;]/);
|
||||
for (i = 0; i < pairs.length; ++i) {
|
||||
pair = pairs[i].split('=');
|
||||
if (pair[0]) {
|
||||
pageParams[decodeURIComponent(pair[0])] =
|
||||
decodeURIComponent(pair[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
var src, index, search, chunks, scriptParams = {};
|
||||
for (i = scripts.length - 1; i >= 0; --i) {
|
||||
src = scripts[i].getAttribute('src');
|
||||
if (~(index = src.indexOf('loader.js?'))) {
|
||||
search = src.substr(index + 10);
|
||||
chunks = search ? search.split('&') : [];
|
||||
for (i = chunks.length - 1; i >= 0; --i) {
|
||||
pair = chunks[i].split('=');
|
||||
if (pair[0]) {
|
||||
scriptParams[decodeURIComponent(pair[0])] =
|
||||
decodeURIComponent(pair[1]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var raw = pageParams.mode && pageParams.mode.toLowerCase() === 'raw';
|
||||
|
||||
var scriptId = encodeURIComponent(scriptParams.id);
|
||||
if (!raw) {
|
||||
document.write('<scr' + 'ipt type="text/javascript" src="../build/ol.js"></scr' + 'ipt>');
|
||||
} else {
|
||||
window.CLOSURE_NO_DEPS = true; // we've got our own deps file
|
||||
document.write('<scr' + 'ipt type="text/javascript" src="../closure-library/closure/goog/base.js"></scr' + 'ipt>');
|
||||
document.write('<scr' + 'ipt type="text/javascript" src="../build/ol-deps.js"></scr' + 'ipt>');
|
||||
document.write('<scr' + 'ipt type="text/javascript" src="' + scriptId + '-require.js"></scr' + 'ipt>');
|
||||
}
|
||||
document.write('<scr' + 'ipt type="text/javascript" src="' + scriptId + '.js"></scr' + 'ipt>');
|
||||
}());
|
||||
@@ -1,39 +0,0 @@
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def split_example_file(example, dst_dir):
|
||||
lines = open(example, 'rU').readlines()
|
||||
|
||||
target_lines = []
|
||||
target_require_lines = []
|
||||
|
||||
found_requires = False
|
||||
found_code = False
|
||||
for line in lines:
|
||||
m = re.match(r'goog.require\(\'(.*)\'\);', line)
|
||||
if m:
|
||||
found_requires = True
|
||||
target_require_lines.append(line)
|
||||
elif found_requires:
|
||||
if found_code or line not in ('\n', '\r\n'):
|
||||
found_code = True
|
||||
target_lines.append(line)
|
||||
|
||||
target = open(
|
||||
os.path.join(dst_dir, os.path.basename(example)), 'wb')
|
||||
target_require = open(
|
||||
os.path.join(dst_dir, os.path.basename(example)
|
||||
.replace('.js', '-require.js')),
|
||||
'wb')
|
||||
|
||||
target.writelines(target_lines)
|
||||
target.close()
|
||||
|
||||
target_require.writelines(target_require_lines)
|
||||
target_require.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
split_example_file(*sys.argv[1:])
|
||||
66
package.json
66
package.json
@@ -9,24 +9,14 @@
|
||||
],
|
||||
"homepage": "https://openlayers.org/",
|
||||
"scripts": {
|
||||
"install": "node tasks/install.js",
|
||||
"postinstall": "closure-util update",
|
||||
"start": "node tasks/serve.js",
|
||||
"lint": "eslint tasks test src examples transforms",
|
||||
"lint-package": "eslint --fix build/package",
|
||||
"pretest": "npm run lint",
|
||||
"test": "npm run karma -- --single-run",
|
||||
"debug-server": "node tasks/serve-lib.js",
|
||||
"karma": "karma start test/karma.config.js",
|
||||
"transform-src": "jscodeshift --transform transforms/module.js src",
|
||||
"changecase-src": "node tasks/filename-case-from-module.js",
|
||||
"transform-examples": "jscodeshift --transform transforms/module.js examples",
|
||||
"transform-test": "jscodeshift --transform transforms/module.js test",
|
||||
"transform": "npm run changecase-src && npm run transform-src && npm run transform-examples && npm run transform-test && npm run lint -- --fix",
|
||||
"serve-examples": "mkdir -p build/examples && webpack --config examples/webpack/config.js --watch & serve build/examples",
|
||||
"build-examples": "webpack --config examples/webpack/config.js --env=prod"
|
||||
},
|
||||
"main": "dist/ol.js",
|
||||
"main": "src/ol/index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/openlayers/openlayers.git"
|
||||
@@ -40,63 +30,49 @@
|
||||
"css/ol.css"
|
||||
],
|
||||
"dependencies": {
|
||||
"async": "2.6.0",
|
||||
"closure-util": "1.26.0",
|
||||
"fs-extra": "5.0.0",
|
||||
"jsdoc": "3.5.5",
|
||||
"nomnom": "1.8.1",
|
||||
"pbf": "3.1.0",
|
||||
"pixelworks": "1.1.0",
|
||||
"rbush": "2.0.1",
|
||||
"rollup": "^0.52.0",
|
||||
"rollup-plugin-cleanup": "^2.0.0",
|
||||
"rollup-plugin-commonjs": "^8.2.6",
|
||||
"rollup-plugin-node-resolve": "^3.0.0",
|
||||
"temp": "0.8.3",
|
||||
"walk": "2.3.9"
|
||||
"rbush": "2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"async": "2.6.0",
|
||||
"babel-minify-webpack-plugin": "^0.2.0",
|
||||
"clean-css-cli": "4.1.10",
|
||||
"copy-webpack-plugin": "^4.0.1",
|
||||
"coveralls": "3.0.0",
|
||||
"debounce": "^1.1.0",
|
||||
"eslint": "4.13.1",
|
||||
"eslint-config-openlayers": "7.0.0",
|
||||
"eslint-plugin-openlayers-internal": "^3.1.0",
|
||||
"expect.js": "0.3.1",
|
||||
"front-matter": "^2.1.2",
|
||||
"gaze": "^1.0.0",
|
||||
"fs-extra": "5.0.0",
|
||||
"glob": "7.1.1",
|
||||
"handlebars": "4.0.11",
|
||||
"html-webpack-plugin": "^2.30.1",
|
||||
"istanbul": "0.4.5",
|
||||
"jquery": "3.2.1",
|
||||
"jscodeshift": "^0.4.0",
|
||||
"jsdoc": "3.5.5",
|
||||
"karma": "^1.7.1",
|
||||
"karma-chrome-launcher": "^2.1.1",
|
||||
"karma-coverage": "^1.1.1",
|
||||
"karma-firefox-launcher": "^1.0.1",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"karma-sauce-launcher": "^1.1.0",
|
||||
"karma-webpack": "^2.0.4",
|
||||
"karma-mocha": "1.3.0",
|
||||
"karma-sauce-launcher": "1.2.0",
|
||||
"karma-webpack": "2.0.6",
|
||||
"marked": "0.3.7",
|
||||
"metalsmith": "2.3.0",
|
||||
"metalsmith-layouts": "1.8.1",
|
||||
"mocha": "4.0.1",
|
||||
"mocha-phantomjs-core": "^2.1.0",
|
||||
"mustache": "2.3.0",
|
||||
"phantomjs-prebuilt": "2.1.16",
|
||||
"mustache": "^2.3.0",
|
||||
"nomnom": "1.8.1",
|
||||
"pixelmatch": "^4.0.2",
|
||||
"proj4": "2.4.4",
|
||||
"serve": "^6.0.6",
|
||||
"serve-files": "1.0.1",
|
||||
"sinon": "4.1.3",
|
||||
"slimerjs": "0.10.3",
|
||||
"url-polyfill": "^1.0.7",
|
||||
"webpack": "^3.5.5",
|
||||
"webpack-dev-server": "^2.7.1",
|
||||
"webpack-merge": "^4.1.0"
|
||||
"walk": "^2.3.9",
|
||||
"webpack": "3.10.0",
|
||||
"webpack-dev-server": "2.9.7",
|
||||
"webpack-merge": "4.1.1"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "openlayers",
|
||||
@@ -148,17 +124,5 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"ext": [{
|
||||
"module": "rbush"
|
||||
},
|
||||
{
|
||||
"module": "pbf",
|
||||
"name": "PBF"
|
||||
},
|
||||
{
|
||||
"module": "pixelworks",
|
||||
"import": "Processor"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! NAMESPACE=ol.render.webgl.circlereplay.defaultshader
|
||||
//! NAMESPACE=_ol_render_webgl_circlereplay_defaultshader_
|
||||
|
||||
|
||||
//! COMMON
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
/**
|
||||
* @module ol/render/webgl/circlereplay/defaultshader
|
||||
*/
|
||||
// This file is automatically generated, do not edit
|
||||
// This file is automatically generated, do not edit.
|
||||
// Run `make shaders` to generate, and commit the result.
|
||||
|
||||
import _ol_ from '../../../index.js';
|
||||
import _ol_webgl_Fragment_ from '../../../webgl/Fragment.js';
|
||||
import _ol_webgl_Vertex_ from '../../../webgl/Vertex.js';
|
||||
var _ol_render_webgl_circlereplay_defaultshader_ = {};
|
||||
|
||||
|
||||
_ol_render_webgl_circlereplay_defaultshader_.fragment = new _ol_webgl_Fragment_(_ol_.DEBUG_WEBGL ?
|
||||
'precision mediump float;\nvarying vec2 v_center;\nvarying vec2 v_offset;\nvarying float v_halfWidth;\nvarying float v_pixelRatio;\n\n\n\nuniform float u_opacity;\nuniform vec4 u_fillColor;\nuniform vec4 u_strokeColor;\nuniform vec2 u_size;\n\nvoid main(void) {\n vec2 windowCenter = vec2((v_center.x + 1.0) / 2.0 * u_size.x * v_pixelRatio,\n (v_center.y + 1.0) / 2.0 * u_size.y * v_pixelRatio);\n vec2 windowOffset = vec2((v_offset.x + 1.0) / 2.0 * u_size.x * v_pixelRatio,\n (v_offset.y + 1.0) / 2.0 * u_size.y * v_pixelRatio);\n float radius = length(windowCenter - windowOffset);\n float dist = length(windowCenter - gl_FragCoord.xy);\n if (dist > radius + v_halfWidth) {\n if (u_strokeColor.a == 0.0) {\n gl_FragColor = u_fillColor;\n } else {\n gl_FragColor = u_strokeColor;\n }\n gl_FragColor.a = gl_FragColor.a - (dist - (radius + v_halfWidth));\n } else if (u_fillColor.a == 0.0) {\n // Hooray, no fill, just stroke. We can use real antialiasing.\n gl_FragColor = u_strokeColor;\n if (dist < radius - v_halfWidth) {\n gl_FragColor.a = gl_FragColor.a - (radius - v_halfWidth - dist);\n }\n } else {\n gl_FragColor = u_fillColor;\n float strokeDist = radius - v_halfWidth;\n float antialias = 2.0 * v_pixelRatio;\n if (dist > strokeDist) {\n gl_FragColor = u_strokeColor;\n } else if (dist >= strokeDist - antialias) {\n float step = smoothstep(strokeDist - antialias, strokeDist, dist);\n gl_FragColor = mix(u_fillColor, u_strokeColor, step);\n }\n }\n gl_FragColor.a = gl_FragColor.a * u_opacity;\n if (gl_FragColor.a <= 0.0) {\n discard;\n }\n}\n' :
|
||||
'precision mediump float;varying vec2 a;varying vec2 b;varying float c;varying float d;uniform float m;uniform vec4 n;uniform vec4 o;uniform vec2 p;void main(void){vec2 windowCenter=vec2((a.x+1.0)/2.0*p.x*d,(a.y+1.0)/2.0*p.y*d);vec2 windowOffset=vec2((b.x+1.0)/2.0*p.x*d,(b.y+1.0)/2.0*p.y*d);float radius=length(windowCenter-windowOffset);float dist=length(windowCenter-gl_FragCoord.xy);if(dist>radius+c){if(o.a==0.0){gl_FragColor=n;}else{gl_FragColor=o;}gl_FragColor.a=gl_FragColor.a-(dist-(radius+c));}else if(n.a==0.0){gl_FragColor=o;if(dist<radius-c){gl_FragColor.a=gl_FragColor.a-(radius-c-dist);}} else{gl_FragColor=n;float strokeDist=radius-c;float antialias=2.0*d;if(dist>strokeDist){gl_FragColor=o;}else if(dist>=strokeDist-antialias){float step=smoothstep(strokeDist-antialias,strokeDist,dist);gl_FragColor=mix(n,o,step);}} gl_FragColor.a=gl_FragColor.a*m;if(gl_FragColor.a<=0.0){discard;}}');
|
||||
@@ -15,4 +13,5 @@ _ol_render_webgl_circlereplay_defaultshader_.fragment = new _ol_webgl_Fragment_(
|
||||
_ol_render_webgl_circlereplay_defaultshader_.vertex = new _ol_webgl_Vertex_(_ol_.DEBUG_WEBGL ?
|
||||
'varying vec2 v_center;\nvarying vec2 v_offset;\nvarying float v_halfWidth;\nvarying float v_pixelRatio;\n\n\nattribute vec2 a_position;\nattribute float a_instruction;\nattribute float a_radius;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform mat4 u_offsetRotateMatrix;\nuniform float u_lineWidth;\nuniform float u_pixelRatio;\n\nvoid main(void) {\n mat4 offsetMatrix = u_offsetScaleMatrix * u_offsetRotateMatrix;\n v_center = vec4(u_projectionMatrix * vec4(a_position, 0.0, 1.0)).xy;\n v_pixelRatio = u_pixelRatio;\n float lineWidth = u_lineWidth * u_pixelRatio;\n v_halfWidth = lineWidth / 2.0;\n if (lineWidth == 0.0) {\n lineWidth = 2.0 * u_pixelRatio;\n }\n vec2 offset;\n // Radius with anitaliasing (roughly).\n float radius = a_radius + 3.0 * u_pixelRatio;\n // Until we get gl_VertexID in WebGL, we store an instruction.\n if (a_instruction == 0.0) {\n // Offsetting the edges of the triangle by lineWidth / 2 is necessary, however\n // we should also leave some space for the antialiasing, thus we offset by lineWidth.\n offset = vec2(-1.0, 1.0);\n } else if (a_instruction == 1.0) {\n offset = vec2(-1.0, -1.0);\n } else if (a_instruction == 2.0) {\n offset = vec2(1.0, -1.0);\n } else {\n offset = vec2(1.0, 1.0);\n }\n\n gl_Position = u_projectionMatrix * vec4(a_position + offset * radius, 0.0, 1.0) +\n offsetMatrix * vec4(offset * lineWidth, 0.0, 0.0);\n v_offset = vec4(u_projectionMatrix * vec4(a_position.x + a_radius, a_position.y,\n 0.0, 1.0)).xy;\n\n if (distance(v_center, v_offset) > 20000.0) {\n gl_Position = vec4(v_center, 0.0, 1.0);\n }\n}\n\n\n' :
|
||||
'varying vec2 a;varying vec2 b;varying float c;varying float d;attribute vec2 e;attribute float f;attribute float g;uniform mat4 h;uniform mat4 i;uniform mat4 j;uniform float k;uniform float l;void main(void){mat4 offsetMatrix=i*j;a=vec4(h*vec4(e,0.0,1.0)).xy;d=l;float lineWidth=k*l;c=lineWidth/2.0;if(lineWidth==0.0){lineWidth=2.0*l;}vec2 offset;float radius=g+3.0*l;//Until we get gl_VertexID in WebGL,we store an instruction.if(f==0.0){//Offsetting the edges of the triangle by lineWidth/2 is necessary,however//we should also leave some space for the antialiasing,thus we offset by lineWidth.offset=vec2(-1.0,1.0);}else if(f==1.0){offset=vec2(-1.0,-1.0);}else if(f==2.0){offset=vec2(1.0,-1.0);}else{offset=vec2(1.0,1.0);}gl_Position=h*vec4(e+offset*radius,0.0,1.0)+offsetMatrix*vec4(offset*lineWidth,0.0,0.0);b=vec4(h*vec4(e.x+g,e.y,0.0,1.0)).xy;if(distance(a,b)>20000.0){gl_Position=vec4(a,0.0,1.0);}}');
|
||||
|
||||
export default _ol_render_webgl_circlereplay_defaultshader_;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! NAMESPACE=ol.render.webgl.linestringreplay.defaultshader
|
||||
//! NAMESPACE=_ol_render_webgl_linestringreplay_defaultshader_
|
||||
|
||||
|
||||
//! COMMON
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,4 +1,4 @@
|
||||
//! NAMESPACE=ol.render.webgl.polygonreplay.defaultshader
|
||||
//! NAMESPACE=_ol_render_webgl_polygonreplay_defaultshader_
|
||||
|
||||
|
||||
//! COMMON
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
/**
|
||||
* @module ol/render/webgl/polygonreplay/defaultshader
|
||||
*/
|
||||
// This file is automatically generated, do not edit
|
||||
// This file is automatically generated, do not edit.
|
||||
// Run `make shaders` to generate, and commit the result.
|
||||
|
||||
import _ol_ from '../../../index.js';
|
||||
import _ol_webgl_Fragment_ from '../../../webgl/Fragment.js';
|
||||
import _ol_webgl_Vertex_ from '../../../webgl/Vertex.js';
|
||||
var _ol_render_webgl_polygonreplay_defaultshader_ = {};
|
||||
|
||||
|
||||
_ol_render_webgl_polygonreplay_defaultshader_.fragment = new _ol_webgl_Fragment_(_ol_.DEBUG_WEBGL ?
|
||||
'precision mediump float;\n\n\n\nuniform vec4 u_color;\nuniform float u_opacity;\n\nvoid main(void) {\n gl_FragColor = u_color;\n float alpha = u_color.a * u_opacity;\n if (alpha == 0.0) {\n discard;\n }\n gl_FragColor.a = alpha;\n}\n' :
|
||||
'precision mediump float;uniform vec4 e;uniform float f;void main(void){gl_FragColor=e;float alpha=e.a*f;if(alpha==0.0){discard;}gl_FragColor.a=alpha;}');
|
||||
@@ -15,4 +13,5 @@ _ol_render_webgl_polygonreplay_defaultshader_.fragment = new _ol_webgl_Fragment_
|
||||
_ol_render_webgl_polygonreplay_defaultshader_.vertex = new _ol_webgl_Vertex_(_ol_.DEBUG_WEBGL ?
|
||||
'\n\nattribute vec2 a_position;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform mat4 u_offsetRotateMatrix;\n\nvoid main(void) {\n gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0);\n}\n\n\n' :
|
||||
'attribute vec2 a;uniform mat4 b;uniform mat4 c;uniform mat4 d;void main(void){gl_Position=b*vec4(a,0.0,1.0);}');
|
||||
|
||||
export default _ol_render_webgl_polygonreplay_defaultshader_;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! NAMESPACE=ol.render.webgl.texturereplay.defaultshader
|
||||
//! NAMESPACE=_ol_render_webgl_texturereplay_defaultshader_
|
||||
|
||||
|
||||
//! COMMON
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
/**
|
||||
* @module ol/render/webgl/texturereplay/defaultshader
|
||||
*/
|
||||
// This file is automatically generated, do not edit
|
||||
// This file is automatically generated, do not edit.
|
||||
// Run `make shaders` to generate, and commit the result.
|
||||
|
||||
import _ol_ from '../../../index.js';
|
||||
import _ol_webgl_Fragment_ from '../../../webgl/Fragment.js';
|
||||
import _ol_webgl_Vertex_ from '../../../webgl/Vertex.js';
|
||||
var _ol_render_webgl_texturereplay_defaultshader_ = {};
|
||||
|
||||
|
||||
_ol_render_webgl_texturereplay_defaultshader_.fragment = new _ol_webgl_Fragment_(_ol_.DEBUG_WEBGL ?
|
||||
'precision mediump float;\nvarying vec2 v_texCoord;\nvarying float v_opacity;\n\nuniform float u_opacity;\nuniform sampler2D u_image;\n\nvoid main(void) {\n vec4 texColor = texture2D(u_image, v_texCoord);\n gl_FragColor.rgb = texColor.rgb;\n float alpha = texColor.a * v_opacity * u_opacity;\n if (alpha == 0.0) {\n discard;\n }\n gl_FragColor.a = alpha;\n}\n' :
|
||||
'precision mediump float;varying vec2 a;varying float b;uniform float k;uniform sampler2D l;void main(void){vec4 texColor=texture2D(l,a);gl_FragColor.rgb=texColor.rgb;float alpha=texColor.a*b*k;if(alpha==0.0){discard;}gl_FragColor.a=alpha;}');
|
||||
@@ -15,4 +13,5 @@ _ol_render_webgl_texturereplay_defaultshader_.fragment = new _ol_webgl_Fragment_
|
||||
_ol_render_webgl_texturereplay_defaultshader_.vertex = new _ol_webgl_Vertex_(_ol_.DEBUG_WEBGL ?
|
||||
'varying vec2 v_texCoord;\nvarying float v_opacity;\n\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nattribute vec2 a_offsets;\nattribute float a_opacity;\nattribute float a_rotateWithView;\n\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_offsetScaleMatrix;\nuniform mat4 u_offsetRotateMatrix;\n\nvoid main(void) {\n mat4 offsetMatrix = u_offsetScaleMatrix;\n if (a_rotateWithView == 1.0) {\n offsetMatrix = u_offsetScaleMatrix * u_offsetRotateMatrix;\n }\n vec4 offsets = offsetMatrix * vec4(a_offsets, 0.0, 0.0);\n gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0) + offsets;\n v_texCoord = a_texCoord;\n v_opacity = a_opacity;\n}\n\n\n' :
|
||||
'varying vec2 a;varying float b;attribute vec2 c;attribute vec2 d;attribute vec2 e;attribute float f;attribute float g;uniform mat4 h;uniform mat4 i;uniform mat4 j;void main(void){mat4 offsetMatrix=i;if(g==1.0){offsetMatrix=i*j;}vec4 offsets=offsetMatrix*vec4(e,0.0,0.0);gl_Position=h*vec4(c,0.0,1.0)+offsets;a=d;b=f;}');
|
||||
|
||||
export default _ol_render_webgl_texturereplay_defaultshader_;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! NAMESPACE=ol.renderer.webgl.defaultmapshader
|
||||
//! NAMESPACE=_ol_renderer_webgl_defaultmapshader_
|
||||
|
||||
|
||||
//! COMMON
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
/**
|
||||
* @module ol/renderer/webgl/defaultmapshader
|
||||
*/
|
||||
// This file is automatically generated, do not edit
|
||||
// This file is automatically generated, do not edit.
|
||||
// Run `make shaders` to generate, and commit the result.
|
||||
|
||||
import _ol_ from '../../index.js';
|
||||
import _ol_webgl_Fragment_ from '../../webgl/Fragment.js';
|
||||
import _ol_webgl_Vertex_ from '../../webgl/Vertex.js';
|
||||
var _ol_renderer_webgl_defaultmapshader_ = {};
|
||||
|
||||
|
||||
_ol_renderer_webgl_defaultmapshader_.fragment = new _ol_webgl_Fragment_(_ol_.DEBUG_WEBGL ?
|
||||
'precision mediump float;\nvarying vec2 v_texCoord;\n\n\nuniform float u_opacity;\nuniform sampler2D u_texture;\n\nvoid main(void) {\n vec4 texColor = texture2D(u_texture, v_texCoord);\n gl_FragColor.rgb = texColor.rgb;\n gl_FragColor.a = texColor.a * u_opacity;\n}\n' :
|
||||
'precision mediump float;varying vec2 a;uniform float f;uniform sampler2D g;void main(void){vec4 texColor=texture2D(g,a);gl_FragColor.rgb=texColor.rgb;gl_FragColor.a=texColor.a*f;}');
|
||||
@@ -15,4 +13,5 @@ _ol_renderer_webgl_defaultmapshader_.fragment = new _ol_webgl_Fragment_(_ol_.DEB
|
||||
_ol_renderer_webgl_defaultmapshader_.vertex = new _ol_webgl_Vertex_(_ol_.DEBUG_WEBGL ?
|
||||
'varying vec2 v_texCoord;\n\n\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\n\nuniform mat4 u_texCoordMatrix;\nuniform mat4 u_projectionMatrix;\n\nvoid main(void) {\n gl_Position = u_projectionMatrix * vec4(a_position, 0., 1.);\n v_texCoord = (u_texCoordMatrix * vec4(a_texCoord, 0., 1.)).st;\n}\n\n\n' :
|
||||
'varying vec2 a;attribute vec2 b;attribute vec2 c;uniform mat4 d;uniform mat4 e;void main(void){gl_Position=e*vec4(b,0.,1.);a=(d*vec4(c,0.,1.)).st;}');
|
||||
|
||||
export default _ol_renderer_webgl_defaultmapshader_;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! NAMESPACE=ol.renderer.webgl.tilelayershader
|
||||
//! NAMESPACE=_ol_renderer_webgl_tilelayershader_
|
||||
|
||||
|
||||
//! COMMON
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
/**
|
||||
* @module ol/renderer/webgl/tilelayershader
|
||||
*/
|
||||
// This file is automatically generated, do not edit
|
||||
// This file is automatically generated, do not edit.
|
||||
// Run `make shaders` to generate, and commit the result.
|
||||
|
||||
import _ol_ from '../../index.js';
|
||||
import _ol_webgl_Fragment_ from '../../webgl/Fragment.js';
|
||||
import _ol_webgl_Vertex_ from '../../webgl/Vertex.js';
|
||||
var _ol_renderer_webgl_tilelayershader_ = {};
|
||||
|
||||
|
||||
_ol_renderer_webgl_tilelayershader_.fragment = new _ol_webgl_Fragment_(_ol_.DEBUG_WEBGL ?
|
||||
'precision mediump float;\nvarying vec2 v_texCoord;\n\n\nuniform sampler2D u_texture;\n\nvoid main(void) {\n gl_FragColor = texture2D(u_texture, v_texCoord);\n}\n' :
|
||||
'precision mediump float;varying vec2 a;uniform sampler2D e;void main(void){gl_FragColor=texture2D(e,a);}');
|
||||
@@ -15,4 +13,5 @@ _ol_renderer_webgl_tilelayershader_.fragment = new _ol_webgl_Fragment_(_ol_.DEBU
|
||||
_ol_renderer_webgl_tilelayershader_.vertex = new _ol_webgl_Vertex_(_ol_.DEBUG_WEBGL ?
|
||||
'varying vec2 v_texCoord;\n\n\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nuniform vec4 u_tileOffset;\n\nvoid main(void) {\n gl_Position = vec4(a_position * u_tileOffset.xy + u_tileOffset.zw, 0., 1.);\n v_texCoord = a_texCoord;\n}\n\n\n' :
|
||||
'varying vec2 a;attribute vec2 b;attribute vec2 c;uniform vec4 d;void main(void){gl_Position=vec4(b*d.xy+d.zw,0.,1.);a=c;}');
|
||||
|
||||
export default _ol_renderer_webgl_tilelayershader_;
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
// This file is automatically generated, do not edit
|
||||
goog.provide('{{namespace}}');
|
||||
// This file is automatically generated, do not edit.
|
||||
// Run `make shaders` to generate, and commit the result.
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.webgl.Fragment');
|
||||
goog.require('ol.webgl.Vertex');
|
||||
import _ol_ from '../../index.js';
|
||||
import _ol_webgl_Fragment_ from '../../webgl/Fragment.js';
|
||||
import _ol_webgl_Vertex_ from '../../webgl/Vertex.js';
|
||||
var {{namespace}} = {};
|
||||
|
||||
|
||||
{{namespace}}.fragment = new ol.webgl.Fragment(ol.DEBUG_WEBGL ?
|
||||
{{namespace}}.fragment = new _ol_webgl_Fragment_(_ol_.DEBUG_WEBGL ?
|
||||
'precision mediump float;\n{{{originalFragmentSource}}}' :
|
||||
'precision mediump float;{{{fragmentSource}}}');
|
||||
|
||||
{{namespace}}.vertex = new ol.webgl.Vertex(ol.DEBUG_WEBGL ?
|
||||
{{namespace}}.vertex = new _ol_webgl_Vertex_(_ol_.DEBUG_WEBGL ?
|
||||
'{{{originalVertexSource}}}' :
|
||||
'{{{vertexSource}}}');
|
||||
|
||||
export default {{namespace}};
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// This file is automatically generated, do not edit
|
||||
goog.provide('{{namespace}}.Locations');
|
||||
|
||||
goog.require('ol');
|
||||
// Run `make shaders` to generate, and commit the result.
|
||||
|
||||
import _ol_ from '../../../index.js';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
@@ -10,14 +9,14 @@ goog.require('ol');
|
||||
* @param {WebGLProgram} program Program.
|
||||
* @struct
|
||||
*/
|
||||
{{namespace}}.Locations = function(gl, program) {
|
||||
{{namespace}}_Locations_ = function(gl, program) {
|
||||
{{#uniforms}}
|
||||
|
||||
/**
|
||||
* @type {WebGLUniformLocation}
|
||||
*/
|
||||
this.{{originalName}} = gl.getUniformLocation(
|
||||
program, ol.DEBUG_WEBGL ? '{{originalName}}' : '{{shortName}}');
|
||||
program, _ol_.DEBUG_WEBGL ? '{{originalName}}' : '{{shortName}}');
|
||||
{{/uniforms}}
|
||||
{{#attributes}}
|
||||
|
||||
@@ -25,6 +24,8 @@ goog.require('ol');
|
||||
* @type {number}
|
||||
*/
|
||||
this.{{originalName}} = gl.getAttribLocation(
|
||||
program, ol.DEBUG_WEBGL ? '{{originalName}}' : '{{shortName}}');
|
||||
program, _ol_.DEBUG_WEBGL ? '{{originalName}}' : '{{shortName}}');
|
||||
{{/attributes}}
|
||||
};
|
||||
|
||||
export default {{namespace}}_Locations_;
|
||||
|
||||
@@ -1,272 +0,0 @@
|
||||
var path = require('path');
|
||||
|
||||
var Metalsmith = require('metalsmith');
|
||||
var handlebars = require('handlebars');
|
||||
var templates = require('metalsmith-layouts');
|
||||
var marked = require('marked');
|
||||
var pkg = require('../package.json');
|
||||
|
||||
var markupRegEx = /([^\/^\.]*)\.html$/;
|
||||
var cleanupJSRegEx = /.*(\/\/ NOCOMPILE|goog\.require\(.*\);)[\r\n]*/g;
|
||||
var requiresRegEx = /.*goog\.require\('(ol\.\S*)'\);/g;
|
||||
var isCssRegEx = /\.css$/;
|
||||
var isJsRegEx = /\.js(\?.*)?$/;
|
||||
|
||||
var srcDir = path.join(__dirname, '..', 'examples');
|
||||
var destDir = path.join(__dirname, '..', 'build', 'examples');
|
||||
var templatesDir = path.join(__dirname, '..', 'config', 'examples');
|
||||
|
||||
/**
|
||||
* Returns an array of names that are explicitly required inside the source
|
||||
* by calling `goog.require('ol.…')`. Only returns `ol.` prefixed names.
|
||||
*
|
||||
* @param {string} src The JavaScript sourcecode to search for goog.require.
|
||||
* @returns {Array.<string>} An array of `ol.*` names.
|
||||
*/
|
||||
function getRequires(src) {
|
||||
var requires = [];
|
||||
var match = requiresRegEx.exec(src);
|
||||
while (match) {
|
||||
requires.push(match[1]);
|
||||
match = requiresRegEx.exec(src);
|
||||
}
|
||||
return requires;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an array of the names of required OpenLayers symbols and returns an
|
||||
* HTML-snippet with an unordered list to the API-docs for the particular
|
||||
* classes.
|
||||
*
|
||||
* @param {Array.<string>} requires An array of `ol.` names that the source
|
||||
* requires.
|
||||
* @returns {string} The HTML-snippet with the list of links to API-docs.
|
||||
*/
|
||||
function getLinkToApiHtml(requires) {
|
||||
var lis = requires.map(function(symb) {
|
||||
var href = '../apidoc/' + symb + '.html';
|
||||
return '<li><a href="' + href + '" title="API documentation for ' +
|
||||
symb + '">' + symb + '</a></li>';
|
||||
});
|
||||
return '<ul class="inline">' + lis.join() + '</ul>';
|
||||
}
|
||||
|
||||
/**
|
||||
* A Metalsmith plugin that adds metadata to the example HTML files. For each
|
||||
* example HTML file, this adds metadata for related js and css resources. When
|
||||
* these files are run through the example template, the extra metadata is used
|
||||
* to show the complete example source in the textarea and submit the parts to
|
||||
* CodePen.
|
||||
*
|
||||
* @param {Object} files The file lookup provided by Metalsmith. Property names
|
||||
* are file paths relative to the source directory. The file objects
|
||||
* include any existing metadata (e.g. from YAML front-matter), the file
|
||||
* contents, and stats.
|
||||
* @param {Object} metalsmith The metalsmith instance the plugin is being used
|
||||
* with.
|
||||
* @param {function(Error)} done Called when done (with any error).
|
||||
*/
|
||||
function augmentExamples(files, metalsmith, done) {
|
||||
setImmediate(done); // all remaining code is synchronous
|
||||
for (var filename in files) {
|
||||
var file = files[filename];
|
||||
var match = filename.match(markupRegEx);
|
||||
if (match && filename !== 'index.html') {
|
||||
if (!file.layout) {
|
||||
throw new Error(filename + ': Missing "layout" in YAML front-matter');
|
||||
}
|
||||
var id = match[1];
|
||||
|
||||
// add js tag and source
|
||||
var jsFilename = id + '.js';
|
||||
if (!(jsFilename in files)) {
|
||||
throw new Error('No .js file found for ' + filename);
|
||||
}
|
||||
var jsSource = files[jsFilename].contents.toString()
|
||||
// Change data paths to absolute urls
|
||||
.replace(/'data\//g, '\'https://openlayers.org/en/v' + pkg.version + '/examples/data/');
|
||||
if (file.cloak) {
|
||||
for (var key in file.cloak) {
|
||||
jsSource = jsSource.replace(new RegExp(key, 'g'), file.cloak[key]);
|
||||
}
|
||||
}
|
||||
var requires = getRequires(jsSource);
|
||||
file.requires = requires;
|
||||
file.js = {
|
||||
tag: '<script src="loader.js?id=' + id + '"></script>',
|
||||
source: jsSource.replace(cleanupJSRegEx, ''),
|
||||
apiHtml: getLinkToApiHtml(requires)
|
||||
};
|
||||
|
||||
// add css tag and source
|
||||
var cssFilename = id + '.css';
|
||||
if (cssFilename in files) {
|
||||
file.css = {
|
||||
tag: '<link rel="stylesheet" href="' + cssFilename + '">',
|
||||
source: files[cssFilename].contents.toString()
|
||||
};
|
||||
}
|
||||
|
||||
// add additional resources
|
||||
if (file.resources) {
|
||||
var resources = [];
|
||||
var remoteResources = [];
|
||||
var codePenResources = [];
|
||||
for (var i = 0, ii = file.resources.length; i < ii; ++i) {
|
||||
var resource = file.resources[i];
|
||||
var remoteResource = resource.indexOf('//') === -1 ?
|
||||
'https://openlayers.org/en/v' + pkg.version + '/examples/' +
|
||||
resource : resource;
|
||||
codePenResources[i] = remoteResource;
|
||||
if (isJsRegEx.test(resource)) {
|
||||
resources[i] = '<script src="' + resource + '"></script>';
|
||||
remoteResources[i] = '<script src="' + remoteResource +
|
||||
'"></script>';
|
||||
} else if (isCssRegEx.test(resource)) {
|
||||
if (resource.indexOf('bootstrap.min.css') === -1) {
|
||||
resources[i] = '<link rel="stylesheet" href="' + resource + '">';
|
||||
}
|
||||
remoteResources[i] = '<link rel="stylesheet" href="' +
|
||||
remoteResource + '">';
|
||||
} else {
|
||||
throw new Error('Invalid value for resource: ' +
|
||||
resource + ' is not .js or .css: ' + filename);
|
||||
}
|
||||
}
|
||||
file.extraHead = {
|
||||
local: resources.join('\n'),
|
||||
remote: remoteResources.join('\n')
|
||||
};
|
||||
file.extraResources = file.resources.length ?
|
||||
',' + codePenResources.join(',') : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inverted index of keywords from examples. Property names are
|
||||
* lowercased words. Property values are objects mapping example index to word
|
||||
* count.
|
||||
* @param {Array.<Object>} exampleInfos Array of example info objects.
|
||||
* @return {Object} Word index.
|
||||
*/
|
||||
function createWordIndex(exampleInfos) {
|
||||
var index = {};
|
||||
var keys = ['shortdesc', 'title', 'tags', 'requires'];
|
||||
exampleInfos.forEach(function(info, i) {
|
||||
keys.forEach(function(key) {
|
||||
var text = info[key];
|
||||
if (Array.isArray(text)) {
|
||||
text = text.join(' ');
|
||||
}
|
||||
var words = text ? text.split(/\W+/) : [];
|
||||
words.forEach(function(word) {
|
||||
if (word) {
|
||||
word = word.toLowerCase();
|
||||
var counts = index[word];
|
||||
if (counts) {
|
||||
if (index in counts) {
|
||||
counts[i] += 1;
|
||||
} else {
|
||||
counts[i] = 1;
|
||||
}
|
||||
} else {
|
||||
counts = {};
|
||||
counts[i] = 1;
|
||||
index[word] = counts;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* A plugin that generates the example index.js file. This file includes a
|
||||
* list of example metadata objects and a word index used when searching for
|
||||
* examples.
|
||||
* @param {Object} files The file lookup provided by Metalsmith. Property names
|
||||
* are file paths relative to the source directory. The file objects
|
||||
* include any existing metadata (e.g. from YAML front-matter), the file
|
||||
* contents, and stats.
|
||||
* @param {Object} metalsmith The metalsmith instance the plugin is being used
|
||||
* with.
|
||||
* @param {function(Error)} done Called when done (with any error).
|
||||
*/
|
||||
function createIndex(files, metalsmith, done) {
|
||||
setImmediate(done); // all remaining code is synchronous
|
||||
var exampleInfos = [];
|
||||
for (var filename in files) {
|
||||
var example = files[filename];
|
||||
if (markupRegEx.test(filename) && filename !== 'index.html') {
|
||||
exampleInfos.push({
|
||||
link: filename,
|
||||
example: filename,
|
||||
title: example.title,
|
||||
shortdesc: example.shortdesc,
|
||||
tags: example.tags,
|
||||
requires: example.requires
|
||||
});
|
||||
}
|
||||
}
|
||||
var info = {
|
||||
examples: exampleInfos,
|
||||
index: createWordIndex(exampleInfos)
|
||||
};
|
||||
files['index.js'] = {
|
||||
contents: new Buffer('var info = ' + JSON.stringify(info)),
|
||||
mode: '0644'
|
||||
};
|
||||
}
|
||||
|
||||
function main(callback) {
|
||||
var smith = new Metalsmith('.')
|
||||
.source(srcDir)
|
||||
.destination(destDir)
|
||||
.concurrency(25)
|
||||
.metadata({
|
||||
olVersion: pkg.version
|
||||
})
|
||||
.use(augmentExamples)
|
||||
.use(createIndex)
|
||||
.use(templates({
|
||||
engine: 'handlebars',
|
||||
directory: templatesDir,
|
||||
helpers: {
|
||||
md: function(str) {
|
||||
return new handlebars.SafeString(marked(str));
|
||||
},
|
||||
indent: function(text, options) {
|
||||
if (!text) {
|
||||
return text;
|
||||
}
|
||||
var count = options.hash.spaces || 2;
|
||||
var spaces = new Array(count + 1).join(' ');
|
||||
return text.split('\n').map(function(line) {
|
||||
return line ? spaces + line : '';
|
||||
}).join('\n');
|
||||
}
|
||||
}
|
||||
}))
|
||||
.build(function(err) {
|
||||
callback(err);
|
||||
});
|
||||
return smith;
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main(function(err) {
|
||||
if (err) {
|
||||
process.stderr.write(
|
||||
'Building examples failed. See the full trace below.\n\n' +
|
||||
err.stack + '\n');
|
||||
process.exit(1);
|
||||
} else {
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = main;
|
||||
@@ -1,75 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const cleanup = require('rollup-plugin-cleanup');
|
||||
const common = require('rollup-plugin-commonjs');
|
||||
const node = require('rollup-plugin-node-resolve');
|
||||
const path = require('path');
|
||||
const pkg = require('../package.json');
|
||||
const rollup = require('rollup').rollup;
|
||||
|
||||
/**
|
||||
* Wrap a bundled dependency for consumption by the Compiler.
|
||||
* @param {Object} ext Details from the `ext` object in package.json.
|
||||
* @return {Object} A rollup plugin.
|
||||
*/
|
||||
function wrap(ext) {
|
||||
return {
|
||||
name: 'googup',
|
||||
transformBundle: function(source) {
|
||||
let name = `ol.ext.${ext.name || ext.module}`;
|
||||
let postamble = '';
|
||||
if (ext.import) {
|
||||
name += '.' + ext.import;
|
||||
} else {
|
||||
postamble = `${name} = ${name}.default;\n`;
|
||||
}
|
||||
return `
|
||||
/**
|
||||
* @fileoverview
|
||||
* @suppress {accessControls, ambiguousFunctionDecl, checkDebuggerStatement, checkRegExp, checkTypes, checkVars, const, constantProperty, deprecated, duplicate, es5Strict, fileoverviewTags, missingProperties, nonStandardJsDocs, strictModuleDepCheck, suspiciousCode, undefinedNames, undefinedVars, unknownDefines, unusedLocalVariables, uselessCode, visibility}
|
||||
*/
|
||||
goog.provide('${name}');
|
||||
|
||||
/** @typedef {function(*)} */
|
||||
${name} = function() {};
|
||||
|
||||
(function() {${source}}).call(ol.ext);
|
||||
${postamble}`;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Build all external modules.
|
||||
* @return {Promise} Resolves on successful completion.
|
||||
*/
|
||||
function main() {
|
||||
return Promise.all(pkg.ext.map(ext => {
|
||||
const moduleName = ext.name || ext.module;
|
||||
const options = {
|
||||
extend: true,
|
||||
input: require.resolve(ext.module),
|
||||
format: 'iife',
|
||||
exports: 'named',
|
||||
plugins: [
|
||||
node(),
|
||||
common(),
|
||||
cleanup(),
|
||||
wrap(ext)
|
||||
]
|
||||
};
|
||||
return rollup(options).then(bundle => {
|
||||
options.name = moduleName;
|
||||
options.file = `${path.join(__dirname, '..', 'build', 'ol.ext', moduleName.toLowerCase())}.js`;
|
||||
bundle.write(options);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main().catch(err => {
|
||||
process.stderr.write(`${err.message}\n`, () => process.exit(1));
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = main;
|
||||
324
tasks/build.js
324
tasks/build.js
@@ -1,324 +0,0 @@
|
||||
/**
|
||||
* This task builds OpenLayers with the Closure Compiler.
|
||||
*/
|
||||
var path = require('path');
|
||||
|
||||
var async = require('async');
|
||||
var closure = require('closure-util');
|
||||
var fs = require('fs-extra');
|
||||
var nomnom = require('nomnom');
|
||||
var temp = require('temp').track();
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
var generateExports = require('./generate-exports');
|
||||
|
||||
var log = closure.log;
|
||||
var root = path.join(__dirname, '..');
|
||||
|
||||
var umdWrapper = ';(function (root, factory) {\n' +
|
||||
' if (typeof exports === "object") {\n' +
|
||||
' module.exports = factory();\n' +
|
||||
' } else if (typeof define === "function" && define.amd) {\n' +
|
||||
' define([], factory);\n' +
|
||||
' } else {\n' +
|
||||
' root.ol = factory();\n' +
|
||||
' }\n' +
|
||||
'}(this, function () {\n' +
|
||||
' var OPENLAYERS = {};\n' +
|
||||
' %output%\n' +
|
||||
' return OPENLAYERS.ol;\n' +
|
||||
'}));\n';
|
||||
|
||||
var version;
|
||||
|
||||
|
||||
/**
|
||||
* Apply defaults and assert that a provided config object is valid.
|
||||
* @param {Object} config Build configuration object.
|
||||
* @param {function(Error)} callback Called with an error if config is invalid.
|
||||
*/
|
||||
function assertValidConfig(config, callback) {
|
||||
process.nextTick(function() {
|
||||
if (!Array.isArray(config.exports)) {
|
||||
callback(new Error('Config missing "exports" array'));
|
||||
return;
|
||||
}
|
||||
if (config.namespace && typeof config.namespace !== 'string') {
|
||||
callback(new Error('Config "namespace" must be a string'));
|
||||
return;
|
||||
}
|
||||
if (config.compile && typeof config.compile !== 'object') {
|
||||
callback(new Error('Config "compile" must be an object'));
|
||||
return;
|
||||
}
|
||||
if (config.jvm && !Array.isArray(config.jvm)) {
|
||||
callback(new Error('Config "jvm" must be an array'));
|
||||
return;
|
||||
}
|
||||
if (config.src && !Array.isArray(config.src)) {
|
||||
callback(new Error('Config "src" must be an array'));
|
||||
return;
|
||||
}
|
||||
if (config.umd) {
|
||||
config.namespace = 'OPENLAYERS';
|
||||
if (config.compile) {
|
||||
config.compile.output_wrapper = umdWrapper;
|
||||
if (version) {
|
||||
if (!config.compile.define) {
|
||||
config.compile.define = [];
|
||||
}
|
||||
config.compile.define.push('ol.VERSION=\'' + version + '\'');
|
||||
}
|
||||
}
|
||||
}
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read the build configuration file.
|
||||
* @param {string} configPath Path to config file.
|
||||
* @param {function(Error, Object)} callback Callback.
|
||||
*/
|
||||
function readConfig(configPath, callback) {
|
||||
fs.readFile(configPath, function(err, data) {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
err = new Error('Unable to find config file: ' + configPath);
|
||||
}
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
var config;
|
||||
try {
|
||||
config = JSON.parse(String(data));
|
||||
} catch (err2) {
|
||||
callback(new Error('Trouble parsing config as JSON: ' + err2.message));
|
||||
return;
|
||||
}
|
||||
callback(null, config);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write the exports code to a temporary file.
|
||||
* @param {string} exports Exports code.
|
||||
* @param {function(Error, string)} callback Called with the path to the temp
|
||||
* file (or any error).
|
||||
*/
|
||||
function writeExports(exports, callback) {
|
||||
temp.open({prefix: 'exports', suffix: '.js'}, function(err, info) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
log.verbose('build', 'Writing exports: ' + info.path);
|
||||
fs.writeFile(info.path, exports, function(err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
fs.close(info.fd, function(err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
callback(null, info.path);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the list of sources sorted in dependency order.
|
||||
* @param {Object} config Build configuration object.
|
||||
* @param {string} exports Exports code (with goog.exportSymbol calls).
|
||||
* @param {function(Error, Array.<string>)} callback Called with a list of paths
|
||||
* or any error.
|
||||
*/
|
||||
function getDependencies(config, exports, callback) {
|
||||
writeExports(exports, function(err, exportsPath) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
log.info('ol', 'Parsing dependencies');
|
||||
var options;
|
||||
if (config.src) {
|
||||
options = {
|
||||
lib: config.src,
|
||||
cwd: config.cwd
|
||||
};
|
||||
} else {
|
||||
options = {
|
||||
lib: ['src/**/*.js', 'build/ol.ext/*.js'],
|
||||
cwd: root
|
||||
};
|
||||
}
|
||||
closure.getDependencies(options, function(err, paths) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
paths.push(exportsPath);
|
||||
callback(null, paths);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Concatenate all sources.
|
||||
* @param {Array.<string>} paths List of paths to source files.
|
||||
* @param {function(Error, string)} callback Called with the concatenated
|
||||
* output or any error.
|
||||
*/
|
||||
function concatenate(paths, callback) {
|
||||
async.map(paths, fs.readFile, function(err, results) {
|
||||
if (err) {
|
||||
var msg = 'Trouble concatenating sources. ' + err.message;
|
||||
callback(new Error(msg));
|
||||
} else {
|
||||
var parts = umdWrapper.split('%output%');
|
||||
var src = parts[0] +
|
||||
'var goog = this.goog = {};\n' +
|
||||
'this.CLOSURE_NO_DEPS = true;\n' +
|
||||
results.join('\n') +
|
||||
'ol.VERSION = \'' + version + '\';\n' +
|
||||
'OPENLAYERS.ol = ol;\n' +
|
||||
parts[1];
|
||||
callback(null, src);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the compiler.
|
||||
* @param {Object} config Build configuration object.
|
||||
* @param {Array.<string>} paths List of paths to source files.
|
||||
* @param {function(Error, string)} callback Called with the compiled output or
|
||||
* any error.
|
||||
*/
|
||||
function build(config, paths, callback) {
|
||||
var options = {
|
||||
compile: config.compile,
|
||||
cwd: config.cwd || root,
|
||||
jvm: config.jvm
|
||||
};
|
||||
if (!options.compile) {
|
||||
log.info('ol', 'No compile options found. Concatenating ' +
|
||||
paths.length + ' sources');
|
||||
concatenate(paths, callback);
|
||||
} else {
|
||||
log.info('ol', 'Compiling ' + paths.length + ' sources');
|
||||
paths = paths.concat('src/ol/typedefs.js');
|
||||
options.compile.js = paths.concat(options.compile.js || []);
|
||||
closure.compile(options, callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the version from the Git tag.
|
||||
* @param {function(Error, string)} callback Called with the output
|
||||
* ready to be written into a file, or any error.
|
||||
*/
|
||||
function getVersion(callback) {
|
||||
exec('git describe --tags', function(error, stdout, stderr) {
|
||||
version = stdout.trim();
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a file header with the most recent Git tag.
|
||||
* @param {string} compiledSource The compiled library.
|
||||
* @param {function(Error, string)} callback Called with the output
|
||||
* ready to be written into a file, or any error.
|
||||
*/
|
||||
function addHeader(compiledSource, callback) {
|
||||
var header = '// OpenLayers. See https://openlayers.org/\n';
|
||||
header += '// License: https://raw.githubusercontent.com/openlayers/' +
|
||||
'openlayers/master/LICENSE.md\n';
|
||||
if (version !== '') {
|
||||
header += '// Version: ' + version + '\n';
|
||||
}
|
||||
callback(null, header + compiledSource);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a build of the library.
|
||||
* @param {Object} config Build configuration object. Must have an "exports"
|
||||
* array and a "compile" object with options for the compiler.
|
||||
* @param {function(Error, string)} callback Called with the compiled source
|
||||
* or any error.
|
||||
*/
|
||||
function main(config, callback) {
|
||||
async.waterfall([
|
||||
getVersion,
|
||||
assertValidConfig.bind(null, config),
|
||||
generateExports.bind(null, config),
|
||||
getDependencies.bind(null, config),
|
||||
build.bind(null, config),
|
||||
addHeader
|
||||
], callback);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If running this module directly, read the config file and call the main
|
||||
* function.
|
||||
*/
|
||||
if (require.main === module) {
|
||||
var options = nomnom.options({
|
||||
config: {
|
||||
position: 0,
|
||||
required: true,
|
||||
help: 'Path to JSON config file'
|
||||
},
|
||||
output: {
|
||||
position: 1,
|
||||
required: true,
|
||||
help: 'Output file path'
|
||||
},
|
||||
loglevel: {
|
||||
abbr: 'l',
|
||||
choices: ['silly', 'verbose', 'info', 'warn', 'error'],
|
||||
default: 'info',
|
||||
help: 'Log level',
|
||||
metavar: 'LEVEL'
|
||||
}
|
||||
}).parse();
|
||||
|
||||
/**
|
||||
* Set the log level.
|
||||
* @type {string}
|
||||
*/
|
||||
log.level = options.loglevel;
|
||||
|
||||
// read the config, run the main function, and write the output file
|
||||
async.waterfall([
|
||||
readConfig.bind(null, options.config),
|
||||
main,
|
||||
fs.outputFile.bind(fs, options.output)
|
||||
], function(err) {
|
||||
if (err) {
|
||||
log.error(err.message);
|
||||
process.exit(1);
|
||||
} else {
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Export main function.
|
||||
*/
|
||||
module.exports = main;
|
||||
@@ -1,64 +0,0 @@
|
||||
/*eslint-env es6*/
|
||||
|
||||
const http = require('http');
|
||||
const path = require('path');
|
||||
const serveFiles = require('serve-files');
|
||||
const spawn = require('child_process').spawn;
|
||||
|
||||
if (!process.argv[2]) {
|
||||
process.stdout.write(`USAGE: node ${path.basename(module.filename)} [example_path]\n`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const root = process.cwd();
|
||||
const port = 8000;
|
||||
const host = null;
|
||||
const examplePath = process.argv[2];
|
||||
const phantomPath = require('phantomjs-prebuilt').path;
|
||||
|
||||
const server = http.createServer(serveFiles.createFileResponseHandler({
|
||||
documentRoot: root,
|
||||
followSymbolicLinks: false,
|
||||
cacheTimeInSeconds: 3600
|
||||
}));
|
||||
|
||||
server.listen(port, host, null, function() {
|
||||
const childProcess = spawn(phantomPath, ['--ssl-protocol=any', '--ignore-ssl-errors=true', path.join(__dirname, '..', 'bin', 'check-example.js'), 'http://localhost:8000/' + examplePath]);
|
||||
childProcess.stdout.pipe(process.stdout);
|
||||
childProcess.stderr.pipe(process.stderr);
|
||||
process.stdin.pipe(childProcess.stdin);
|
||||
|
||||
childProcess.on('error', function(err) {
|
||||
process.stderr.write(`Error executing phantom on ${phantomPath}\n`);
|
||||
process.stderr.write(err.stack + '\n');
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
childProcess.on('exit', function(code) {
|
||||
process.exit(code);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// Keep track of connections, to enforce killing them when server must be stopped.
|
||||
var connections = {};
|
||||
server.on('connection', function(socket) {
|
||||
socket._cid = process.hrtime();
|
||||
connections[socket._cid] = socket;
|
||||
|
||||
socket.on('end', function() {
|
||||
delete connections[this._cid];
|
||||
});
|
||||
});
|
||||
|
||||
['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT', 'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGTERM'].forEach(signal => {
|
||||
process.once(signal, () => {
|
||||
process.stdout.write(`Got ${signal}, stopping...\n`),
|
||||
server.close(() => {
|
||||
process.stdout.write('Stopped.\n');
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
Object.keys(connections).forEach(cid => connections[cid].destroy());
|
||||
});
|
||||
});
|
||||
@@ -1,29 +0,0 @@
|
||||
const glob = require('glob');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
glob('src/**/*.js', {}, function(err, files) {
|
||||
if (!err) {
|
||||
process.stdout.write(`Checking ${files.length} files...\n`);
|
||||
let renamed = 0;
|
||||
files.forEach(function(filename) {
|
||||
const contents = fs.readFileSync(filename, 'utf-8');
|
||||
const lines = contents.split('\n');
|
||||
for (let i = lines.length - 1; i >= 0; --i) {
|
||||
const line = lines[i];
|
||||
const match = line.match(/goog\.provide\('.*\.([^']*)'\);$/);
|
||||
if (match && match.length) {
|
||||
const newName = match[1] + '.js';
|
||||
if (newName != newName.toLowerCase()) {
|
||||
fs.renameSync(filename, path.resolve(path.dirname(filename), newName));
|
||||
++renamed;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
process.stdout.write(`Renamed ${renamed} files.\n`);
|
||||
} else {
|
||||
process.stdout.write(err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
@@ -1,10 +0,0 @@
|
||||
var buildExt = require('./build-ext');
|
||||
|
||||
buildExt(function(err) {
|
||||
if (err) {
|
||||
process.stderr.write(err + '\n');
|
||||
process.exit(1);
|
||||
} else {
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
@@ -106,22 +106,6 @@ Called internally to parse the library for annotations and write out a `build/in
|
||||
|
||||
Builds examples and the example index.
|
||||
|
||||
## `check-example.js`
|
||||
|
||||
Runs an example in PhantomJS and returns an exit code != 0 after printing a stack trace when something is wrong with the example.
|
||||
|
||||
To check the `simple.html` example when on master, first run the `build-examples.js` task, then invoke
|
||||
|
||||
node tasks/check-example.js build/hosted/master/simple.html
|
||||
|
||||
|
||||
## `serve.js`
|
||||
|
||||
Run a debug server that provides all library sources unminified. Provides a static server for examples and tests. See the `--help` option for more detail.
|
||||
|
||||
node tasks/serve.js --help
|
||||
|
||||
|
||||
## `test.js`
|
||||
|
||||
Run the tests once in a headless browser. Note that you can also run the tests by running the `serve.js` task and then visiting the root of the test directory in your browser.
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
/**
|
||||
* This task starts a dev server that provides a script loader for the
|
||||
* OpenLayers library.
|
||||
*/
|
||||
|
||||
var path = require('path');
|
||||
|
||||
var closure = require('closure-util');
|
||||
var nomnom = require('nomnom');
|
||||
|
||||
var log = closure.log;
|
||||
var name = path.basename(__filename, '.js');
|
||||
|
||||
/**
|
||||
* Create a debug server for the OpenLayers and Closure Library sources.
|
||||
* @param {function(Error, closure.Server)} callback Callback.
|
||||
*/
|
||||
var createServer = exports.createServer = function(callback) {
|
||||
var server;
|
||||
var manager = new closure.Manager({
|
||||
lib: [
|
||||
'src/**/*.js',
|
||||
'build/ol.ext/*.js'
|
||||
],
|
||||
cwd: path.join(__dirname, '..')
|
||||
});
|
||||
manager.on('error', function(err) {
|
||||
if (server) {
|
||||
log.error('serve', err.message);
|
||||
} else {
|
||||
callback(err);
|
||||
}
|
||||
});
|
||||
manager.on('ready', function() {
|
||||
server = new closure.Server({
|
||||
manager: manager,
|
||||
loader: '/loader.js'
|
||||
});
|
||||
callback(null, server);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Try listening for incoming connections on a range of ports.
|
||||
* @param {number} min Minimum port to try.
|
||||
* @param {number} max Maximum port to try.
|
||||
* @param {http.Server} server The server.
|
||||
* @param {function(Error)} callback Callback called with any error.
|
||||
*/
|
||||
function listen(min, max, server, callback) {
|
||||
function _listen(port) {
|
||||
server.once('error', function(err) {
|
||||
if (err.code === 'EADDRINUSE') {
|
||||
log.warn(name, 'Port %d in use, trying next one', port);
|
||||
++port;
|
||||
if (port < max) {
|
||||
_listen(port);
|
||||
} else {
|
||||
callback(new Error('Could not find an open port'));
|
||||
}
|
||||
} else {
|
||||
callback(err);
|
||||
}
|
||||
});
|
||||
server.listen(port);
|
||||
}
|
||||
server.once('listening', function() {
|
||||
callback(null);
|
||||
});
|
||||
_listen(min);
|
||||
}
|
||||
|
||||
/**
|
||||
* If running this module directly start the server.
|
||||
*/
|
||||
if (require.main === module) {
|
||||
var options = nomnom.options({
|
||||
port: {
|
||||
abbr: 'p',
|
||||
default: 3000,
|
||||
help: 'Port for incoming connections (will try additional ports if used)',
|
||||
metavar: 'PORT'
|
||||
},
|
||||
loglevel: {
|
||||
abbr: 'l',
|
||||
choices: ['silly', 'verbose', 'info', 'warn', 'error'],
|
||||
default: 'info',
|
||||
help: 'Log level',
|
||||
metavar: 'LEVEL'
|
||||
}
|
||||
}).parse();
|
||||
|
||||
/** @type {string} */
|
||||
log.level = options.loglevel;
|
||||
|
||||
log.info(name, 'Parsing dependencies.');
|
||||
createServer(function(err, server) {
|
||||
if (err) {
|
||||
log.error(name, 'Parsing failed');
|
||||
log.error(name, err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
listen(options.port, options.port + 4, server, function(err) {
|
||||
if (err) {
|
||||
log.error(name, 'Server failed to start: ' + err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
log.info(name, 'Debug server running http://localhost:' +
|
||||
server.address().port + '/loader.js (Ctrl+C to stop)');
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
158
tasks/serve.js
158
tasks/serve.js
@@ -1,158 +0,0 @@
|
||||
/**
|
||||
* This task starts a dev server that provides a script loader for OpenLayers
|
||||
* and Closure Library. In addition, a static server hosts all files in the
|
||||
* repository.
|
||||
*/
|
||||
|
||||
var path = require('path');
|
||||
var url = require('url');
|
||||
|
||||
var Gaze = require('gaze').Gaze;
|
||||
var closure = require('closure-util');
|
||||
var debounce = require('debounce');
|
||||
var fs = require('fs-extra');
|
||||
var nomnom = require('nomnom');
|
||||
|
||||
var buildExamples = require('./build-examples');
|
||||
var log = closure.log;
|
||||
|
||||
|
||||
/**
|
||||
* Create a debug server for ol and Closure Library sources.
|
||||
* @param {function(Error, closure.Server)} callback Callback.
|
||||
*/
|
||||
var createServer = exports.createServer = function(callback) {
|
||||
var server;
|
||||
var manager = new closure.Manager({
|
||||
lib: [
|
||||
'src/**/*.js',
|
||||
'build/ol.ext/*.js',
|
||||
'test/spec/**/*.test.js',
|
||||
'test_rendering/spec/**/*.test.js',
|
||||
'build/test_requires.js',
|
||||
'build/test_rendering_requires.js'
|
||||
],
|
||||
main: 'build/examples/*.js'
|
||||
});
|
||||
manager.on('error', function(err) {
|
||||
if (server) {
|
||||
log.error('serve', err.message);
|
||||
} else {
|
||||
callback(err);
|
||||
}
|
||||
});
|
||||
manager.on('ready', function() {
|
||||
server = new closure.Server({
|
||||
manager: manager,
|
||||
loader: /^\/(?:(?:build\/examples)|(?:test(?:_rendering)?))\/loader\.js/,
|
||||
getMain: function(req) {
|
||||
var main;
|
||||
var query = url.parse(req.url, true).query;
|
||||
var referer = req.headers.referer;
|
||||
var pathName = url.parse(referer).pathname;
|
||||
if (pathName.indexOf('/test/') === 0) {
|
||||
main = path.resolve(
|
||||
path.join(process.cwd(), 'build'), 'test_requires.js');
|
||||
} else if (pathName.indexOf('/test_rendering/') === 0) {
|
||||
main = path.resolve(
|
||||
path.join(process.cwd(), 'build'), 'test_rendering_requires.js');
|
||||
} else {
|
||||
if (query.id) {
|
||||
if (referer) {
|
||||
var from = path.join(process.cwd(),
|
||||
path.dirname(url.parse(referer).pathname));
|
||||
main = path.resolve(from, query.id + '.js');
|
||||
}
|
||||
}
|
||||
}
|
||||
return main;
|
||||
}
|
||||
});
|
||||
callback(null, server);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Build the examples and exit on any error.
|
||||
* @param {Function=} opt_callback Called when done building examples.
|
||||
*/
|
||||
function buildExamplesOrFatal(opt_callback) {
|
||||
log.info('serve', 'Building examples.');
|
||||
buildExamples(function(err) {
|
||||
if (err) {
|
||||
log.error('serve', 'Building examples failed.');
|
||||
log.error('serve', err.message);
|
||||
log.error('serve', 'Use "verbose" logging to see the full stack trace.');
|
||||
log.verbose('serve', err.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
// This is awkward, but then so is CSS itself
|
||||
var src = path.join(__dirname, '..', 'css', 'ol.css');
|
||||
var dest = path.join(__dirname, '..', 'build', 'css', 'ol.css');
|
||||
fs.copy(src, dest, function(err2) {
|
||||
if (err2) {
|
||||
log.error('serve', 'Failed to copy CSS.');
|
||||
log.error('serve', err.message);
|
||||
log.error('serve',
|
||||
'Use "verbose" logging to see the full stack trace.');
|
||||
log.verbose('serve', err.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
log.verbose('serve', 'Done building examples.');
|
||||
if (opt_callback) {
|
||||
opt_callback();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* If running this module directly start the server.
|
||||
*/
|
||||
if (require.main === module) {
|
||||
var options = nomnom.options({
|
||||
port: {
|
||||
abbr: 'p',
|
||||
default: 3000,
|
||||
help: 'Port for incoming connections',
|
||||
metavar: 'PORT'
|
||||
},
|
||||
loglevel: {
|
||||
abbr: 'l',
|
||||
choices: ['silly', 'verbose', 'info', 'warn', 'error'],
|
||||
default: 'info',
|
||||
help: 'Log level',
|
||||
metavar: 'LEVEL'
|
||||
}
|
||||
}).parse();
|
||||
|
||||
/** @type {string} */
|
||||
log.level = options.loglevel;
|
||||
|
||||
buildExamplesOrFatal(function() {
|
||||
log.info('serve', 'Parsing dependencies.');
|
||||
createServer(function(err, server) {
|
||||
if (err) {
|
||||
log.error('serve', 'Parsing failed');
|
||||
log.error('serve', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
server.listen(options.port, function() {
|
||||
log.info('serve', 'Listening on http://localhost:' +
|
||||
options.port + '/ (Ctrl+C to stop)');
|
||||
});
|
||||
server.on('error', function(err) {
|
||||
log.error('serve', 'Server failed to start: ' + err.message);
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
|
||||
var gaze = new Gaze('examples/**/*');
|
||||
var debouncedBuild = debounce(buildExamplesOrFatal, 250);
|
||||
gaze.on('all', function(event, filepath) {
|
||||
log.verbose('serve', 'Watch event: ' + event + ' ' + filepath);
|
||||
debouncedBuild();
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
102
tasks/test.js
102
tasks/test.js
@@ -1,102 +0,0 @@
|
||||
const Server = require('karma').Server;
|
||||
const closure = require('closure-util');
|
||||
const path = require('path');
|
||||
const processCliArgs = require('karma/lib/cli').process;
|
||||
|
||||
function insertDependencies(manager, files, previousLookup) {
|
||||
previousLookup = previousLookup || {};
|
||||
let firstIndex = NaN;
|
||||
const original = files.filter((obj, index) => {
|
||||
if (previousLookup[obj.pattern]) {
|
||||
if (isNaN(firstIndex)) {
|
||||
firstIndex = index;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (isNaN(firstIndex)) {
|
||||
firstIndex = 0;
|
||||
}
|
||||
const lookup = {};
|
||||
const dependencies = manager.getDependencies().map(script => {
|
||||
lookup[script.path] = true;
|
||||
return {
|
||||
pattern: script.path,
|
||||
included: true,
|
||||
served: true,
|
||||
watched: false
|
||||
};
|
||||
});
|
||||
original.splice.apply(original, [firstIndex, 0].concat(dependencies));
|
||||
files.length = 0;
|
||||
files.push.apply(files, original);
|
||||
|
||||
return lookup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Karma. This prepends the Karma `files` config with all library files
|
||||
* sorted in dependency order.
|
||||
* @param {Object} config Karma options.
|
||||
* @param {Manager} manager The dependency file manager.
|
||||
* @param {function(Error)} callback Called with any error.
|
||||
*/
|
||||
function serve(config, manager, callback) {
|
||||
function exit(code) {
|
||||
let error = null;
|
||||
if (code) {
|
||||
error = new Error(`Karma exited with ${code}`);
|
||||
error.code = code;
|
||||
}
|
||||
callback(error);
|
||||
}
|
||||
const server = new Server(config, exit);
|
||||
|
||||
const files = server.get('config.files');
|
||||
|
||||
let lookup = insertDependencies(manager, files);
|
||||
|
||||
// stop goog base.js from trying to load deps.js
|
||||
files.unshift({
|
||||
pattern: path.resolve(__dirname, '../test/no-deps.js'),
|
||||
included: true,
|
||||
served: true,
|
||||
watched: false
|
||||
});
|
||||
|
||||
manager.on('update', () => {
|
||||
lookup = insertDependencies(manager, files, lookup);
|
||||
server.refreshFiles();
|
||||
});
|
||||
|
||||
server.start();
|
||||
}
|
||||
|
||||
function main(config, callback) {
|
||||
const manager = new closure.Manager({
|
||||
lib: [
|
||||
'src/**/*.js',
|
||||
'build/ol.ext/*.js'
|
||||
]
|
||||
});
|
||||
|
||||
manager.on('error', callback);
|
||||
|
||||
manager.on('ready', () => {
|
||||
serve(config, manager, callback);
|
||||
});
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
const config = processCliArgs();
|
||||
main(config, (err, manager) => {
|
||||
if (err) {
|
||||
process.stderr.write(err.message, () => process.exit(1));
|
||||
return;
|
||||
} else {
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -3,14 +3,6 @@
|
||||
const path = require('path');
|
||||
const pkg = require('../package.json');
|
||||
|
||||
/**
|
||||
* The config below is not enough to run Karma. In addition, we need to add
|
||||
* all library files in dependency order. This could be done with a plugin if
|
||||
* Karma supported async plugins (there may be other alternatives as well). But
|
||||
* for now we start Karma with the `tasks/test.js` script. This script
|
||||
* sorts dependencies and adds files to the Karma config below.
|
||||
*/
|
||||
|
||||
module.exports = function(karma) {
|
||||
karma.set({
|
||||
frameworks: ['mocha'],
|
||||
@@ -61,18 +53,6 @@ module.exports = function(karma) {
|
||||
'**/*.js': ['webpack']
|
||||
},
|
||||
reporters: ['progress'],
|
||||
coverageReporter: {
|
||||
reporters: [
|
||||
{
|
||||
type: 'lcov', // produces HTML output and lcov
|
||||
dir: '../coverage/',
|
||||
subdir: '.'
|
||||
},
|
||||
{
|
||||
type: 'text-summary' // prints the textual summary to the terminal
|
||||
}
|
||||
]
|
||||
},
|
||||
webpackMiddleware: {
|
||||
noInfo: true
|
||||
}
|
||||
@@ -119,7 +99,7 @@ module.exports = function(karma) {
|
||||
}
|
||||
},
|
||||
hostname: 'travis.dev',
|
||||
reporters: ['dots', 'saucelabs', 'coverage'],
|
||||
reporters: ['dots', 'saucelabs'],
|
||||
browserDisconnectTimeout: 10000,
|
||||
browserDisconnectTolerance: 1,
|
||||
captureTimeout: 240000,
|
||||
@@ -127,9 +107,6 @@ module.exports = function(karma) {
|
||||
customLaunchers: customLaunchers,
|
||||
browsers: Object.keys(customLaunchers),
|
||||
preprocessors: {
|
||||
// source files, that you wanna generate coverage for
|
||||
// do not include tests or libraries
|
||||
// (these files will be instrumented by Istanbul)
|
||||
'../src/**/*.js': ['coverage']
|
||||
},
|
||||
coverageReporter: {
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
// TODO: get rid of this when we get rid of goog base.js
|
||||
var CLOSURE_NO_DEPS = true; // eslint-disable-line
|
||||
Reference in New Issue
Block a user