Generate exports automatically from src/ol/exports.txt
This commit is contained in:
13
Makefile
13
Makefile
@@ -3,8 +3,9 @@ JSDOC = jsdoc
|
||||
PHANTOMJS = phantomjs
|
||||
PLOVR_JAR = bin/plovr-b254c26318c5.jar
|
||||
SPEC = $(shell find test/spec -name \*.js)
|
||||
SRC = $(shell find exports externs src/ol -name \*.js)
|
||||
SRC = $(shell find externs src/ol -name \*.js)
|
||||
INTERNAL_SRC = build/src/internal/src/requireall.js build/src/internal/src/types.js
|
||||
EXTERNAL_SRC = build/src/external/externs/types.js build/src/external/src/exports.js
|
||||
EXAMPLES = $(shell find examples -maxdepth 1 -name \*.html)
|
||||
comma := ,
|
||||
empty :=
|
||||
@@ -22,7 +23,7 @@ build: build/ol.css build/ol.js
|
||||
build/ol.css: build/ol.js
|
||||
touch $@
|
||||
|
||||
build/ol.js: $(PLOVR_JAR) $(SRC) base.json build/ol.json build/src/external/externs/types.js
|
||||
build/ol.js: $(PLOVR_JAR) $(SRC) $(EXTERNAL_SRC) base.json build/ol.json
|
||||
java -jar $(PLOVR_JAR) build build/ol.json >$@
|
||||
@echo $@ "uncompressed:" $$(wc -c <$@) bytes
|
||||
@echo $@ " compressed:" $$(gzip -9 -c <$@ | wc -c) bytes
|
||||
@@ -37,6 +38,10 @@ build/src/external/externs/types.js: bin/generate-types src/ol/types.txt
|
||||
mkdir -p $(dir $@)
|
||||
bin/generate-types --externs src/ol/types.txt >$@
|
||||
|
||||
build/src/external/src/exports.js: bin/generate-exports src/ol/exports.txt
|
||||
mkdir -p $(dir $@)
|
||||
bin/generate-exports src/ol/exports.txt >$@
|
||||
|
||||
build/src/internal/src/requireall.js: bin/generate-requireall $(SRC)
|
||||
mkdir -p $(dir $@)
|
||||
bin/generate-requireall --require=goog.dom src/ol >$@
|
||||
@@ -70,8 +75,8 @@ serve-precommit: $(PLOVR_JAR) $(INTERNAL_SRC)
|
||||
.PHONY: lint
|
||||
lint: build/lint-src-timestamp build/lint-spec-timestamp
|
||||
|
||||
build/lint-src-timestamp: $(SRC) $(INTERNAL_SRC)
|
||||
gjslint --strict --limited_doc_files=$(subst $(space),$(comma),$(shell find externs -name \*.js)) $(SRC) $(INTERNAL_SRC) $(filter-out $(shell find examples -name \*.combined.js),$(shell find examples -name \*.js)) && touch $@
|
||||
build/lint-src-timestamp: $(SRC) $(INTERNAL_SRC) $(EXTERNAL_SRC)
|
||||
gjslint --strict --limited_doc_files=$(subst $(space),$(comma),$(shell find externs build/src/external/externs -name \*.js)) $(SRC) $(INTERNAL_SRC) $(EXTERNAL_SRC) $(filter-out $(shell find examples -name \*.combined.js),$(shell find examples -name \*.js)) && touch $@
|
||||
|
||||
build/lint-spec-timestamp: $(SPEC)
|
||||
gjslint $(SPEC) && touch $@
|
||||
|
||||
92
bin/generate-exports
Executable file
92
bin/generate-exports
Executable file
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from collections import defaultdict
|
||||
from optparse import OptionParser
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
class Type(object):
|
||||
|
||||
def __init__(self, name, members=None):
|
||||
self.name = name
|
||||
self.namespace = '.'.join(self.name.split('.')[:-1]) or None
|
||||
self.members = members or {}
|
||||
|
||||
def extern(self):
|
||||
lines = []
|
||||
lines.append('/**\n')
|
||||
lines.append(' * @interface\n')
|
||||
lines.append(' */\n')
|
||||
lines.append('%s = function() {};\n' % (self.name,))
|
||||
for key in sorted(self.members.keys()):
|
||||
lines.append('\n')
|
||||
lines.append('\n')
|
||||
lines.append('/**\n')
|
||||
lines.append(' * @type {%s}\n' % (self.members[key],))
|
||||
lines.append(' */\n')
|
||||
lines.append('%s.prototype.%s;\n' % (self.name, key))
|
||||
return ''.join(lines)
|
||||
|
||||
def provide(self):
|
||||
return 'goog.provide(\'%sType\');\n' % (self.name,)
|
||||
|
||||
def typedef(self):
|
||||
lines = []
|
||||
lines.append('/**\n')
|
||||
for i, key in enumerate(sorted(self.members.keys())):
|
||||
prefix = ' * @typedef {{' if i == 0 else ' * '
|
||||
suffix = '}}' if i == len(self.members) - 1 else ','
|
||||
type = self.members[key]
|
||||
if '|' in type:
|
||||
type = '(%s)' % (type,)
|
||||
lines.append('%s%s: %s%s\n' % (prefix, key, type, suffix))
|
||||
lines.append(' */\n')
|
||||
lines.append('%s;\n' % (self.name,))
|
||||
return ''.join(lines)
|
||||
|
||||
|
||||
def main(argv):
|
||||
|
||||
option_parser = OptionParser()
|
||||
options, args = option_parser.parse_args(argv[1:])
|
||||
|
||||
requires = set()
|
||||
symbols = set()
|
||||
properties = defaultdict(set)
|
||||
for arg in args:
|
||||
for line in open(arg):
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
m = re.match('@exportSymbol\s*(?P<symbol>\S+)\Z', line)
|
||||
if m:
|
||||
requires.add(m.group('symbol'))
|
||||
symbols.add(m.group('symbol'))
|
||||
continue
|
||||
m = re.match('@exportProperty\s*(?P<property>\S+)\Z', line)
|
||||
if m:
|
||||
components = m.group('property').split('.')
|
||||
if components[-2] == 'prototype':
|
||||
requires.add('.'.join(components[:-2]))
|
||||
else:
|
||||
requires.add('.'.join(components[:-1]))
|
||||
properties['.'.join(components[:-1])].add(components[-1])
|
||||
continue
|
||||
raise RuntimeError(line)
|
||||
|
||||
if requires:
|
||||
for require in sorted(requires):
|
||||
sys.stdout.write('goog.require(\'%s\');\n' % (require,))
|
||||
sys.stdout.write('\n\n')
|
||||
for i, obj in enumerate(sorted(symbols | set(properties.keys()))):
|
||||
if i:
|
||||
sys.stdout.write('\n')
|
||||
if obj in symbols:
|
||||
sys.stdout.write('goog.exportSymbol(\n \'%s\',\n %s);\n' % (obj, obj))
|
||||
for prop in properties[obj]:
|
||||
sys.stdout.write('goog.exportProperty(\n %s,\n \'%s\',\n %s.%s);\n' % (obj, prop, obj, prop))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
||||
@@ -22,17 +22,7 @@
|
||||
"inherits": "../base.json",
|
||||
|
||||
"inputs": [
|
||||
"exports/ol/collection.js",
|
||||
"exports/ol/coordinate.js",
|
||||
"exports/ol/extent.js",
|
||||
"exports/ol/layer/tilelayer.js",
|
||||
"exports/ol/map.js",
|
||||
"exports/ol/object.js",
|
||||
"exports/ol/overlay/overlay.js",
|
||||
"exports/ol/projection.js",
|
||||
"exports/ol/source/mapquest.js",
|
||||
"exports/ol/source/openstreetmap.js",
|
||||
"exports/ol/source/stamen.js"
|
||||
"build/src/external/src/exports.js"
|
||||
],
|
||||
|
||||
"output-wrapper": "(function(){%output%})();",
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
goog.require('ol.Collection');
|
||||
|
||||
goog.exportSymbol('ol.Collection', ol.Collection);
|
||||
goog.exportProperty(ol.Collection.prototype,
|
||||
'clear', ol.Collection.prototype.clear);
|
||||
goog.exportProperty(ol.Collection.prototype,
|
||||
'forEach', ol.Collection.prototype.forEach);
|
||||
goog.exportProperty(ol.Collection.prototype,
|
||||
'getArray', ol.Collection.prototype.getArray);
|
||||
goog.exportProperty(ol.Collection.prototype,
|
||||
'getAt', ol.Collection.prototype.getAt);
|
||||
goog.exportProperty(ol.Collection.prototype,
|
||||
'getLength', ol.Collection.prototype.getLength);
|
||||
goog.exportProperty(ol.Collection.prototype,
|
||||
'insertAt', ol.Collection.prototype.insertAt);
|
||||
goog.exportProperty(ol.Collection.prototype,
|
||||
'pop', ol.Collection.prototype.pop);
|
||||
goog.exportProperty(ol.Collection.prototype,
|
||||
'push', ol.Collection.prototype.push);
|
||||
goog.exportProperty(ol.Collection.prototype,
|
||||
'removeAt', ol.Collection.prototype.removeAt);
|
||||
goog.exportProperty(ol.Collection.prototype,
|
||||
'setAt', ol.Collection.prototype.setAt);
|
||||
@@ -1,3 +0,0 @@
|
||||
goog.require('ol.Coordinate');
|
||||
|
||||
goog.exportSymbol('ol.Coordinate', ol.Coordinate);
|
||||
@@ -1,3 +0,0 @@
|
||||
goog.require('ol.Extent');
|
||||
|
||||
goog.exportSymbol('ol.Extent', ol.Extent);
|
||||
@@ -1,3 +0,0 @@
|
||||
goog.require('ol.layer.TileLayer');
|
||||
|
||||
goog.exportSymbol('ol.layer.TileLayer', ol.layer.TileLayer);
|
||||
@@ -1,3 +0,0 @@
|
||||
goog.require('ol.Map');
|
||||
|
||||
goog.exportSymbol('ol.Map', ol.Map);
|
||||
@@ -1,21 +0,0 @@
|
||||
goog.require('ol.Object');
|
||||
|
||||
goog.exportSymbol('ol.Object', ol.Object);
|
||||
goog.exportProperty(ol.Object.prototype,
|
||||
'bindTo', ol.Object.prototype.bindTo);
|
||||
goog.exportProperty(ol.Object.prototype,
|
||||
'changed', ol.Object.prototype.changed);
|
||||
goog.exportProperty(ol.Object.prototype,
|
||||
'get', ol.Object.prototype.get);
|
||||
goog.exportProperty(ol.Object.prototype,
|
||||
'notify', ol.Object.prototype.notify);
|
||||
goog.exportProperty(ol.Object.prototype,
|
||||
'set', ol.Object.prototype.set);
|
||||
goog.exportProperty(ol.Object.prototype,
|
||||
'setOptions', ol.Object.prototype.setOptions);
|
||||
goog.exportProperty(ol.Object.prototype,
|
||||
'setValues', ol.Object.prototype.setValues);
|
||||
goog.exportProperty(ol.Object.prototype,
|
||||
'unbind', ol.Object.prototype.unbind);
|
||||
goog.exportProperty(ol.Object.prototype,
|
||||
'unbindAll', ol.Object.prototype.unbindAll);
|
||||
@@ -1,3 +0,0 @@
|
||||
goog.require('ol.overlay.Overlay');
|
||||
|
||||
goog.exportSymbol('ol.overlay.Overlay', ol.overlay.Overlay);
|
||||
@@ -1,19 +0,0 @@
|
||||
goog.require('ol.Projection');
|
||||
|
||||
goog.exportSymbol('ol.Projection', ol.Projection);
|
||||
goog.exportProperty(ol.Projection,
|
||||
'getFromCode', ol.Projection.getFromCode);
|
||||
goog.exportProperty(ol.Projection,
|
||||
'getTransform', ol.Projection.getTransform);
|
||||
goog.exportProperty(ol.Projection,
|
||||
'getTransformFromCodes', ol.Projection.getTransformFromCodes);
|
||||
goog.exportProperty(ol.Projection,
|
||||
'transform', ol.Projection.transform);
|
||||
goog.exportProperty(ol.Projection,
|
||||
'transformWithCodes', ol.Projection.transformWithCodes);
|
||||
goog.exportProperty(ol.Projection.prototype,
|
||||
'getCode', ol.Projection.prototype.getCode);
|
||||
goog.exportProperty(ol.Projection.prototype,
|
||||
'getExtent', ol.Projection.prototype.getExtent);
|
||||
goog.exportProperty(ol.Projection.prototype,
|
||||
'getUnits', ol.Projection.prototype.getUnits);
|
||||
@@ -1,3 +0,0 @@
|
||||
goog.require('ol.source.BingMaps');
|
||||
|
||||
goog.exportSymbol('ol.source.BingMaps', ol.source.BingMaps);
|
||||
@@ -1,5 +0,0 @@
|
||||
goog.require('ol.source.MapQuestOSM');
|
||||
goog.require('ol.source.MapQuestOpenAerial');
|
||||
|
||||
goog.exportSymbol('ol.source.MapQuestOSM', ol.source.MapQuestOSM);
|
||||
goog.exportSymbol('ol.source.MapQuestOpenAerial', ol.source.MapQuestOpenAerial);
|
||||
@@ -1,3 +0,0 @@
|
||||
goog.require('ol.source.OpenStreetMap');
|
||||
|
||||
goog.exportSymbol('ol.source.OpenStreetMap', ol.source.OpenStreetMap);
|
||||
@@ -1,3 +0,0 @@
|
||||
goog.require('ol.source.Stamen');
|
||||
|
||||
goog.exportSymbol('ol.source.Stamen', ol.source.Stamen);
|
||||
@@ -1,3 +0,0 @@
|
||||
goog.require('ol.source.TileJSON');
|
||||
|
||||
goog.exportSymbol('ol.source.TileJSON', ol.source.TileJSON);
|
||||
53
src/ol/exports.txt
Normal file
53
src/ol/exports.txt
Normal file
@@ -0,0 +1,53 @@
|
||||
@exportSymbol ol.Collection
|
||||
@exportProperty ol.Collection.prototype.clear
|
||||
@exportProperty ol.Collection.prototype.forEach
|
||||
@exportProperty ol.Collection.prototype.getArray
|
||||
@exportProperty ol.Collection.prototype.getAt
|
||||
@exportProperty ol.Collection.prototype.getLength
|
||||
@exportProperty ol.Collection.prototype.insertAt
|
||||
@exportProperty ol.Collection.prototype.pop
|
||||
@exportProperty ol.Collection.prototype.push
|
||||
@exportProperty ol.Collection.prototype.removeAt
|
||||
@exportProperty ol.Collection.prototype.setAt
|
||||
|
||||
@exportSymbol ol.Coordinate
|
||||
|
||||
@exportSymbol ol.Extent
|
||||
|
||||
@exportSymbol ol.Map
|
||||
|
||||
@exportSymbol ol.Object
|
||||
@exportProperty ol.Object.prototype.bindTo
|
||||
@exportProperty ol.Object.prototype.changed
|
||||
@exportProperty ol.Object.prototype.get
|
||||
@exportProperty ol.Object.prototype.notify
|
||||
@exportProperty ol.Object.prototype.set
|
||||
@exportProperty ol.Object.prototype.setOptions
|
||||
@exportProperty ol.Object.prototype.setValues
|
||||
@exportProperty ol.Object.prototype.unbind
|
||||
@exportProperty ol.Object.prototype.unbindAll
|
||||
|
||||
@exportSymbol ol.Projection
|
||||
@exportProperty ol.Projection.getFromCode
|
||||
@exportProperty ol.Projection.getTransform
|
||||
@exportProperty ol.Projection.getTransformFromCodes
|
||||
@exportProperty ol.Projection.transform
|
||||
@exportProperty ol.Projection.prototype.getCode
|
||||
@exportProperty ol.Projection.prototype.getExtent
|
||||
@exportProperty ol.Projection.prototype.getUnits
|
||||
|
||||
@exportSymbol ol.layer.TileLayer
|
||||
|
||||
@exportSymbol ol.overlay.Overlay
|
||||
|
||||
@exportSymbol ol.source.BingMaps
|
||||
|
||||
@exportSymbol ol.source.MapQuestOSM
|
||||
|
||||
@exportSymbol ol.source.MapQuestOpenAerial
|
||||
|
||||
@exportSymbol ol.source.OpenStreetMap
|
||||
|
||||
@exportSymbol ol.source.Stamen
|
||||
|
||||
@exportSymbol ol.source.TileJSON
|
||||
Reference in New Issue
Block a user