From 4ce0da5056fbd3e144fe6cf1896cdd49ae512fe3 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Tue, 19 Mar 2013 22:39:16 +0000 Subject: [PATCH] large chunk of work towards a nicer build system - plugins are now parsed for @@..@@ replacements - main script and plugins have separate .meta.js files created - less web server load for update checks - build script has variables for resource URL, update URL, etc, substituted via @@..@@ into main script and all plugins --- .gitignore | 3 +- build.py | 98 ++++++++++++++++--- code/boot.js | 2 +- external/leaflet.css | 2 +- main.js | 12 +-- plugins/ap-list.user.js | 10 +- plugins/compute-ap-stats.user.js | 8 +- plugins/draw-tools.user.js | 8 +- plugins/guess-player-levels.user.js | 8 +- plugins/max-links.user.js | 8 +- plugins/player-tracker.user.js | 8 +- plugins/render-limit-increase.user.js | 8 +- .../reso-energy-pct-in-portal-detail.user.js | 8 +- ...onator-display-zoom-level-decrease.user.js | 8 +- plugins/scale-bar.user.js | 8 +- plugins/scoreboard.user.js | 8 +- plugins/show-address.user.js | 8 +- plugins/show-portal-weakness.user.js | 8 +- 18 files changed, 149 insertions(+), 74 deletions(-) diff --git a/.gitignore b/.gitignore index 26d6cdbc..82fbbec4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -iitc-debug.user.js -push-live mobile/IngressIntelTC/bin +build diff --git a/build.py b/build.py index 7676483e..e655be84 100755 --- a/build.py +++ b/build.py @@ -4,6 +4,9 @@ import glob import time import re import io +import os +import shutil + def readfile(fn): with io.open(fn, 'Ur', encoding='utf8') as f: @@ -17,20 +20,93 @@ def loaderRaw(var): fn = var.group(1) return readfile(fn) +def loadCode(ignore): + return '\n\n'.join(map(readfile, glob.glob('code/*'))) -c = '\n\n'.join(map(readfile, glob.glob('code/*'))) -n = time.strftime('%Y-%m-%d-%H%M%S') -m = readfile('main.js') -m = m.split('@@INJECTHERE@@') -m.insert(1, c) -m = '\n\n'.join(m) +def extractUserScriptMeta(var): + m = re.search ( r"//[ \t]*==UserScript==\n.*?//[ \t]*==/UserScript==\n", var, re.MULTILINE|re.DOTALL ) + return m.group(0) -m = m.replace('@@BUILDDATE@@', n) -m = re.sub('@@INCLUDERAW:([0-9a-zA-Z_./-]+)@@', loaderRaw, m) -m = re.sub('@@INCLUDESTRING:([0-9a-zA-Z_./-]+)@@', loaderString, m) -with io.open('iitc-debug.user.js', 'w', encoding='utf8') as f: - f.write(m) +# set up vars used for replacements + + +utcTime = time.gmtime() +buildDate = time.strftime('%Y-%m-%d-%H%M%S',utcTime) +dateTimeVersion = time.strftime('%Y%m%d.%H%M%S',utcTime) + +# TODO: some kind of settings files for these +resourceUrlBase = 'http://iitc.jonatkins.com/dist' +distUrlBase = 'http://iitc.jonatkins.com/dist' +buildName = 'jonatkins' + + + +def doReplacements(script,updateUrl,downloadUrl): + + script = re.sub('@@INJECTCODE@@',loadCode,script) + + script = re.sub('@@INCLUDERAW:([0-9a-zA-Z_./-]+)@@', loaderRaw, script) + script = re.sub('@@INCLUDESTRING:([0-9a-zA-Z_./-]+)@@', loaderString, script) + + script = script.replace('@@BUILDDATE@@', buildDate) + script = script.replace('@@DATETIMEVERSION@@', dateTimeVersion) + script = script.replace('@@RESOURCEURLBASE@@', resourceUrlBase) + script = script.replace('@@BUILDNAME@@', buildName) + + script = script.replace('@@UPDATEURL@@', updateUrl) + script = script.replace('@@DOWNLOADURL@@', downloadUrl) + + return script + + +def saveScriptAndMeta(script,fn,metafn): + with io.open(fn, 'w', encoding='utf8') as f: + f.write(script) + + with io.open(metafn, 'w', encoding='utf8') as f: + meta = extractUserScriptMeta(script) + f.write(meta) + + +outDir = 'build/jonatkins-dist' + + +# create the build output + +# first, delete any existing build +if os.path.exists(outDir): + shutil.rmtree(outDir) + +# copy the 'dist' folder - this creates the target directory (and any missing parent dirs) +# FIXME? replace with manual copy, and any .css and .js files are parsed for replacement tokens? +shutil.copytree('dist', outDir) + + + +# load main.js, parse, and create main total-conversion.user.js +main = readfile('main.js') + +downloadUrl = distUrlBase + '/total-conversion.user.js' +updateUrl = distUrlBase + '/total-conversion.meta.js' +main = doReplacements(main,downloadUrl=downloadUrl,updateUrl=updateUrl) + +saveScriptAndMeta(main, os.path.join(outDir,'total-conversion.user.js'), os.path.join(outDir,'total-conversion.meta.js')) + + +# for each plugin, load, parse, and save output +os.mkdir(os.path.join(outDir,'plugins')) + +for fn in glob.glob("plugins/*.user.js"): + script = readfile(fn) + + downloadUrl = distUrlBase + '/' + fn.replace("\\","/") + updateUrl = downloadUrl.replace('.user.js', '.meta.js') + script = doReplacements(script, downloadUrl=downloadUrl, updateUrl=updateUrl) + + metafn = fn.replace('.user.js', '.meta.js') + saveScriptAndMeta(script, os.path.join(outDir,fn), os.path.join(outDir,metafn)) + # vim: ai si ts=4 sw=4 sts=4 et diff --git a/code/boot.js b/code/boot.js index 211817ec..135d52b5 100644 --- a/code/boot.js +++ b/code/boot.js @@ -321,7 +321,7 @@ function boot() { window.runOnSmartphonesBeforeBoot(); // overwrite default Leaflet Marker icon to be a neutral color - var base = 'http://iitc.jonatkins.com/dist/images'; + var base = '@@RESOURCEURLBASE@@/images'; L.Icon.Default.imagePath = base; window.iconEnl = L.Icon.Default.extend({options: { iconUrl: base + '/marker-green.png' } }); diff --git a/external/leaflet.css b/external/leaflet.css index 92d5b8dd..13287729 100644 --- a/external/leaflet.css +++ b/external/leaflet.css @@ -285,7 +285,7 @@ border-radius: 8px; } .leaflet-control-layers-toggle { - background-image: url(http://iitc.jonatkins.com/dist/images/layers.png); + background-image: url(@@RESOURCEURLBASE@@/images/layers.png); width: 36px; height: 36px; } diff --git a/main.js b/main.js index 60cdf16c..d43ae7a1 100644 --- a/main.js +++ b/main.js @@ -1,11 +1,11 @@ // ==UserScript== // @id ingress-intel-total-conversion@jonatkins -// @name intel map total conversion -// @version 0.9.0-@@BUILDDATE@@-jonatkins +// @name IITC: Ingress intel map total conversion +// @version 0.9.1.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion -// @updateURL http://iitc.jonatkins.com/dist/total-conversion-build.user.js -// @downloadURL http://iitc.jonatkins.com/dist/total-conversion-build.user.js -// @description total conversion for the ingress intel map. (jonatkins branch) +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ +// @description Total conversion for the ingress intel map. [@@BUILDNAME@@-@@BUILDDATE@@] // @include http://www.ingress.com/intel* // @include https://www.ingress.com/intel* // @match http://www.ingress.com/intel* @@ -236,7 +236,7 @@ window.resonators = {}; if(typeof window.plugin !== 'function') window.plugin = function() {}; -@@INJECTHERE@@ +@@INJECTCODE@@ } // end of wrapper diff --git a/plugins/ap-list.user.js b/plugins/ap-list.user.js index 63043a9a..072c26bc 100644 --- a/plugins/ap-list.user.js +++ b/plugins/ap-list.user.js @@ -1,11 +1,11 @@ // ==UserScript== // @id iitc-plugin-ap-list@xelio -// @name iitc: AP List -// @version 0.4.1 +// @name IITC plugin: AP List +// @version 0.4.1.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion -// @updateURL http://iitc.jonatkins.com/dist/plugins/ap-list.user.js -// @downloadURL http://iitc.jonatkins.com/plugins/ap-list.user.js -// @description List top 10 portals by AP of either faction. Other functions and controls please refer to the Userguide. (https://github.com/breunigs/ingress-intel-total-conversion/wiki/Userguide-%28Main-Vanilla-IITC%29#wiki-pluginsAPListUserGuide) +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ +// @description List top 10 portals by AP of either faction. Other functions and controls please refer to the Userguide. // @include https://www.ingress.com/intel* // @include http://www.ingress.com/intel* // @match https://www.ingress.com/intel* diff --git a/plugins/compute-ap-stats.user.js b/plugins/compute-ap-stats.user.js index 1ea88dd7..ba9dc47d 100644 --- a/plugins/compute-ap-stats.user.js +++ b/plugins/compute-ap-stats.user.js @@ -1,10 +1,10 @@ // ==UserScript== // @id iitc-plugin-compute-ap-stats@Hollow011 -// @name iitc: Compute AP statistics -// @version 0.3.1 +// @name IITC plugin: Compute AP statistics +// @version 0.3.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion -// @updateURL http://iitc.jonatkins.com/dist/plugins/compute-ap-stats.user.js -// @downloadURL http://iitc.jonatkins.com/plugins/compute-ap-stats.user.js +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ // @description Tries to determine overal AP stats for the current zoom // @include https://www.ingress.com/intel* // @include http://www.ingress.com/intel* diff --git a/plugins/draw-tools.user.js b/plugins/draw-tools.user.js index e95e56ed..1b64d539 100644 --- a/plugins/draw-tools.user.js +++ b/plugins/draw-tools.user.js @@ -1,10 +1,10 @@ // ==UserScript== // @id iitc-plugin-draw-tools@breunigs -// @name iitc: draw tools -// @version 0.2.3 +// @name IITC plugin: draw tools +// @version 0.2.3.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion -// @updateURL http://iitc.jonatkins.com/dist/plugins/draw-tools.user.js -// @downloadURL http://iitc.jonatkins.com/dist/plugins/draw-tools.user.js +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ // @description Allows you to draw things into the current map so you may plan your next move // @include https://www.ingress.com/intel* // @include http://www.ingress.com/intel* diff --git a/plugins/guess-player-levels.user.js b/plugins/guess-player-levels.user.js index 011a7cee..a1b83762 100644 --- a/plugins/guess-player-levels.user.js +++ b/plugins/guess-player-levels.user.js @@ -1,10 +1,10 @@ // ==UserScript== // @id iitc-plugin-guess-player-levels@breunigs -// @name iitc: guess player level -// @version 0.3.1 +// @name IITC plugin: guess player level +// @version 0.3.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion -// @updateURL http://iitc.jonatkins.com/dist/plugins/guess-player-levels.user.js -// @downloadURL http://iitc.jonatkins.com/dist/plugins/guess-player-levels.user.js +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ // @description Tries to determine player levels from the data available in the current view // @include https://www.ingress.com/intel* // @include http://www.ingress.com/intel* diff --git a/plugins/max-links.user.js b/plugins/max-links.user.js index 888e53ac..1e492c35 100644 --- a/plugins/max-links.user.js +++ b/plugins/max-links.user.js @@ -1,9 +1,9 @@ // ==UserScript== // @id max-links@boombuler -// @name iitc: Max-Links-Plugin -// @version 0.2.1 -// @updateURL http://iitc.jonatkins.com/dist/plugins/max-links.user.js -// @downloadURL http://iitc.jonatkins.com/dist/plugins/max-links.user.js +// @name IITC plugin: Max Links +// @version 0.2.1.@@DATETIMEVERSION@@ +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ // @description Calculates how to link the portals to create the maximum number of fields. // @include https://www.ingress.com/intel* // @include http://www.ingress.com/intel* diff --git a/plugins/player-tracker.user.js b/plugins/player-tracker.user.js index d55ae6c8..430fe1ba 100644 --- a/plugins/player-tracker.user.js +++ b/plugins/player-tracker.user.js @@ -1,10 +1,10 @@ // ==UserScript== // @id iitc-plugin-player-tracker@breunigs -// @name iitc: player tracker -// @version 0.7.2 +// @name IITC Plugin: player tracker +// @version 0.7.2.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion -// @updateURL http://iitc.jonatkins.com/dist/plugins/player-tracker.user.js -// @downloadURL http://iitc.jonatkins.com/dist/plugins/player-tracker.user.js +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ // @description draws trails for the path a user went onto the map. Only draws the last hour. Does not request chat data on its own, even if that would be useful. // @include https://www.ingress.com/intel* // @include http://www.ingress.com/intel* diff --git a/plugins/render-limit-increase.user.js b/plugins/render-limit-increase.user.js index 5522a2bd..4481f31b 100644 --- a/plugins/render-limit-increase.user.js +++ b/plugins/render-limit-increase.user.js @@ -1,10 +1,10 @@ // ==UserScript== // @id iitc-plugin-render-limit-increase@jonatkins -// @name iitc: render limit increase -// @version 0.2 +// @name IITC plugin: render limit increase +// @version 0.2.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion -// @updateURL http://iitc.jonatkins.com/dist/plugins/render-limit-increase.user.js -// @downloadURL http://iitc.jonatkins.com/dist/plugins/render-limit-increase.user.js +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ // @description Increase the render limits, so less likely to be hit in higher density areas // @include https://www.ingress.com/intel* // @include http://www.ingress.com/intel* diff --git a/plugins/reso-energy-pct-in-portal-detail.user.js b/plugins/reso-energy-pct-in-portal-detail.user.js index 95164122..c55646f0 100644 --- a/plugins/reso-energy-pct-in-portal-detail.user.js +++ b/plugins/reso-energy-pct-in-portal-detail.user.js @@ -1,10 +1,10 @@ // ==UserScript== // @id iitc-plugin-reso-energy-pct-in-portal-detail@xelio -// @name iitc: reso energy pct in portal detail -// @version 0.1.2 +// @name IITC plugin: reso energy pct in portal detail +// @version 0.1.2.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion -// @updateURL http://iitc.jonatkins.com/dist/plugins/reso-energy-pct-in-portal-detail.user.js -// @downloadURL http://iitc.jonatkins.com/dist/plugins/reso-energy-pct-in-portal-detail.user.js +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ // @description Show resonator energy percentage on resonator energy bar in portal detail panel. // @include https://www.ingress.com/intel* // @include http://www.ingress.com/intel* diff --git a/plugins/resonator-display-zoom-level-decrease.user.js b/plugins/resonator-display-zoom-level-decrease.user.js index 831337f9..93c2afb1 100644 --- a/plugins/resonator-display-zoom-level-decrease.user.js +++ b/plugins/resonator-display-zoom-level-decrease.user.js @@ -1,10 +1,10 @@ // ==UserScript== // @id iitc-plugin-resonator-display-zoom-level-decrease@xelio -// @name iitc: resonator display zoom level decrease -// @version 1.0.2 +// @name IITC plugin: resonator display zoom level decrease +// @version 1.0.2.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion -// @updateURL http://iitc.jonatkins.com/dist/plugins/resonator-display-zoom-level-decrease.user.js -// @downloadURL http://iitc.jonatkins.com/dist/plugins/resonator-display-zoom-level-decrease.user.js +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ // @description Resonator start display earlier // @include https://www.ingress.com/intel* // @include http://www.ingress.com/intel* diff --git a/plugins/scale-bar.user.js b/plugins/scale-bar.user.js index c924a723..4d0a659c 100644 --- a/plugins/scale-bar.user.js +++ b/plugins/scale-bar.user.js @@ -1,10 +1,10 @@ // ==UserScript== // @id iitc-plugin-scale-bar@breunigs -// @name iitc: scale bar -// @version 0.1.1 +// @name IITC plugin: scale bar +// @version 0.1.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion -// @updateURL http://iitc.jonatkins.com/dist/plugins/scale-bar.user.js -// @downloadURL http://iitc.jonatkins.com/dist/plugins/scale-bar.user.js +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ // @description shows scale bar on the map // @include https://www.ingress.com/intel* // @include http://www.ingress.com/intel* diff --git a/plugins/scoreboard.user.js b/plugins/scoreboard.user.js index 4fd10650..8f17e462 100644 --- a/plugins/scoreboard.user.js +++ b/plugins/scoreboard.user.js @@ -1,10 +1,10 @@ // ==UserScript== // @id iitc-plugin-scoreboard@vita10gy -// @name iitc: show a localized scoreboard. -// @version 0.1.4 +// @name IITC plugin: show a localized scoreboard. +// @version 0.1.4.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion -// @updateURL http://iitc.jonatkins.com/dist/plugins/scoreboard.user.js -// @downloadURL http://iitc.jonatkins.com/dist/plugins/scoreboard.user.js +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ // @description A localized scoreboard. // @include https://www.ingress.com/intel* // @include http://www.ingress.com/intel* diff --git a/plugins/show-address.user.js b/plugins/show-address.user.js index 76fe8e15..fb090b75 100644 --- a/plugins/show-address.user.js +++ b/plugins/show-address.user.js @@ -1,10 +1,10 @@ // ==UserScript== // @id iitc-plugin-show-address@vita10gy -// @name iitc: show portal address in sidebar -// @version 0.2.2 +// @name IITC plugin: show portal address in sidebar +// @version 0.2.2.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion -// @updateURL http://iitc.jonatkins.com/dist/plugins/show-address.user.js -// @downloadURL http://iitc.jonatkins.com/dist/plugins/show-address.user.js +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ // @description Portal address will show in the sidebar. // @include https://www.ingress.com/intel* // @include http://www.ingress.com/intel* diff --git a/plugins/show-portal-weakness.user.js b/plugins/show-portal-weakness.user.js index db7ad6d6..08f54db8 100644 --- a/plugins/show-portal-weakness.user.js +++ b/plugins/show-portal-weakness.user.js @@ -1,10 +1,10 @@ // ==UserScript== // @id iitc-plugin-show-portal-weakness@vita10gy -// @name iitc: show portal weakness -// @version 0.6.1 +// @name IITC plugin: show portal weakness +// @version 0.6.1.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion -// @updateURL http://iitc.jonatkins.com/dist/plugins/show-portal-weakness.user.js -// @downloadURL http://iitc.jonatkins.com/dist/plugins/show-portal-weakness.user.js +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ // @description Uses the fill color of the portals to denote if the portal is weak (Needs recharging, missing a resonator, needs shields) Red, needs energy and shields. Orange, only needs energy (either recharge or resonators). Yellow, only needs shields. // @include https://www.ingress.com/intel* // @include http://www.ingress.com/intel*