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
This commit is contained in:
Jon Atkins 2013-03-19 22:39:16 +00:00
parent 6984510ac9
commit 4ce0da5056
18 changed files with 149 additions and 74 deletions

3
.gitignore vendored
View File

@ -1,3 +1,2 @@
iitc-debug.user.js
push-live
mobile/IngressIntelTC/bin mobile/IngressIntelTC/bin
build

View File

@ -4,6 +4,9 @@ import glob
import time import time
import re import re
import io import io
import os
import shutil
def readfile(fn): def readfile(fn):
with io.open(fn, 'Ur', encoding='utf8') as f: with io.open(fn, 'Ur', encoding='utf8') as f:
@ -17,20 +20,93 @@ def loaderRaw(var):
fn = var.group(1) fn = var.group(1)
return readfile(fn) 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@@') def extractUserScriptMeta(var):
m.insert(1, c) m = re.search ( r"//[ \t]*==UserScript==\n.*?//[ \t]*==/UserScript==\n", var, re.MULTILINE|re.DOTALL )
m = '\n\n'.join(m) 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: # set up vars used for replacements
f.write(m)
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 # vim: ai si ts=4 sw=4 sts=4 et

View File

@ -321,7 +321,7 @@ function boot() {
window.runOnSmartphonesBeforeBoot(); window.runOnSmartphonesBeforeBoot();
// overwrite default Leaflet Marker icon to be a neutral color // 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; L.Icon.Default.imagePath = base;
window.iconEnl = L.Icon.Default.extend({options: { iconUrl: base + '/marker-green.png' } }); window.iconEnl = L.Icon.Default.extend({options: { iconUrl: base + '/marker-green.png' } });

View File

@ -285,7 +285,7 @@
border-radius: 8px; border-radius: 8px;
} }
.leaflet-control-layers-toggle { .leaflet-control-layers-toggle {
background-image: url(http://iitc.jonatkins.com/dist/images/layers.png); background-image: url(@@RESOURCEURLBASE@@/images/layers.png);
width: 36px; width: 36px;
height: 36px; height: 36px;
} }

12
main.js
View File

@ -1,11 +1,11 @@
// ==UserScript== // ==UserScript==
// @id ingress-intel-total-conversion@jonatkins // @id ingress-intel-total-conversion@jonatkins
// @name intel map total conversion // @name IITC: Ingress intel map total conversion
// @version 0.9.0-@@BUILDDATE@@-jonatkins // @version 0.9.1.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL http://iitc.jonatkins.com/dist/total-conversion-build.user.js // @updateURL @@UPDATEURL@@
// @downloadURL http://iitc.jonatkins.com/dist/total-conversion-build.user.js // @downloadURL @@DOWNLOADURL@@
// @description total conversion for the ingress intel map. (jonatkins branch) // @description Total conversion for the ingress intel map. [@@BUILDNAME@@-@@BUILDDATE@@]
// @include http://www.ingress.com/intel* // @include http://www.ingress.com/intel*
// @include https://www.ingress.com/intel* // @include https://www.ingress.com/intel*
// @match http://www.ingress.com/intel* // @match http://www.ingress.com/intel*
@ -236,7 +236,7 @@ window.resonators = {};
if(typeof window.plugin !== 'function') window.plugin = function() {}; if(typeof window.plugin !== 'function') window.plugin = function() {};
@@INJECTHERE@@ @@INJECTCODE@@
} // end of wrapper } // end of wrapper

View File

@ -1,11 +1,11 @@
// ==UserScript== // ==UserScript==
// @id iitc-plugin-ap-list@xelio // @id iitc-plugin-ap-list@xelio
// @name iitc: AP List // @name IITC plugin: AP List
// @version 0.4.1 // @version 0.4.1.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL http://iitc.jonatkins.com/dist/plugins/ap-list.user.js // @updateURL @@UPDATEURL@@
// @downloadURL http://iitc.jonatkins.com/plugins/ap-list.user.js // @downloadURL @@DOWNLOADURL@@
// @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) // @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 https://www.ingress.com/intel*
// @include http://www.ingress.com/intel* // @include http://www.ingress.com/intel*
// @match https://www.ingress.com/intel* // @match https://www.ingress.com/intel*

View File

@ -1,10 +1,10 @@
// ==UserScript== // ==UserScript==
// @id iitc-plugin-compute-ap-stats@Hollow011 // @id iitc-plugin-compute-ap-stats@Hollow011
// @name iitc: Compute AP statistics // @name IITC plugin: Compute AP statistics
// @version 0.3.1 // @version 0.3.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL http://iitc.jonatkins.com/dist/plugins/compute-ap-stats.user.js // @updateURL @@UPDATEURL@@
// @downloadURL http://iitc.jonatkins.com/plugins/compute-ap-stats.user.js // @downloadURL @@DOWNLOADURL@@
// @description Tries to determine overal AP stats for the current zoom // @description Tries to determine overal AP stats for the current zoom
// @include https://www.ingress.com/intel* // @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel* // @include http://www.ingress.com/intel*

View File

@ -1,10 +1,10 @@
// ==UserScript== // ==UserScript==
// @id iitc-plugin-draw-tools@breunigs // @id iitc-plugin-draw-tools@breunigs
// @name iitc: draw tools // @name IITC plugin: draw tools
// @version 0.2.3 // @version 0.2.3.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL http://iitc.jonatkins.com/dist/plugins/draw-tools.user.js // @updateURL @@UPDATEURL@@
// @downloadURL http://iitc.jonatkins.com/dist/plugins/draw-tools.user.js // @downloadURL @@DOWNLOADURL@@
// @description Allows you to draw things into the current map so you may plan your next move // @description Allows you to draw things into the current map so you may plan your next move
// @include https://www.ingress.com/intel* // @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel* // @include http://www.ingress.com/intel*

View File

@ -1,10 +1,10 @@
// ==UserScript== // ==UserScript==
// @id iitc-plugin-guess-player-levels@breunigs // @id iitc-plugin-guess-player-levels@breunigs
// @name iitc: guess player level // @name IITC plugin: guess player level
// @version 0.3.1 // @version 0.3.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL http://iitc.jonatkins.com/dist/plugins/guess-player-levels.user.js // @updateURL @@UPDATEURL@@
// @downloadURL http://iitc.jonatkins.com/dist/plugins/guess-player-levels.user.js // @downloadURL @@DOWNLOADURL@@
// @description Tries to determine player levels from the data available in the current view // @description Tries to determine player levels from the data available in the current view
// @include https://www.ingress.com/intel* // @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel* // @include http://www.ingress.com/intel*

View File

@ -1,9 +1,9 @@
// ==UserScript== // ==UserScript==
// @id max-links@boombuler // @id max-links@boombuler
// @name iitc: Max-Links-Plugin // @name IITC plugin: Max Links
// @version 0.2.1 // @version 0.2.1.@@DATETIMEVERSION@@
// @updateURL http://iitc.jonatkins.com/dist/plugins/max-links.user.js // @updateURL @@UPDATEURL@@
// @downloadURL http://iitc.jonatkins.com/dist/plugins/max-links.user.js // @downloadURL @@DOWNLOADURL@@
// @description Calculates how to link the portals to create the maximum number of fields. // @description Calculates how to link the portals to create the maximum number of fields.
// @include https://www.ingress.com/intel* // @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel* // @include http://www.ingress.com/intel*

View File

@ -1,10 +1,10 @@
// ==UserScript== // ==UserScript==
// @id iitc-plugin-player-tracker@breunigs // @id iitc-plugin-player-tracker@breunigs
// @name iitc: player tracker // @name IITC Plugin: player tracker
// @version 0.7.2 // @version 0.7.2.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL http://iitc.jonatkins.com/dist/plugins/player-tracker.user.js // @updateURL @@UPDATEURL@@
// @downloadURL http://iitc.jonatkins.com/dist/plugins/player-tracker.user.js // @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. // @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 https://www.ingress.com/intel*
// @include http://www.ingress.com/intel* // @include http://www.ingress.com/intel*

View File

@ -1,10 +1,10 @@
// ==UserScript== // ==UserScript==
// @id iitc-plugin-render-limit-increase@jonatkins // @id iitc-plugin-render-limit-increase@jonatkins
// @name iitc: render limit increase // @name IITC plugin: render limit increase
// @version 0.2 // @version 0.2.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL http://iitc.jonatkins.com/dist/plugins/render-limit-increase.user.js // @updateURL @@UPDATEURL@@
// @downloadURL http://iitc.jonatkins.com/dist/plugins/render-limit-increase.user.js // @downloadURL @@DOWNLOADURL@@
// @description Increase the render limits, so less likely to be hit in higher density areas // @description Increase the render limits, so less likely to be hit in higher density areas
// @include https://www.ingress.com/intel* // @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel* // @include http://www.ingress.com/intel*

View File

@ -1,10 +1,10 @@
// ==UserScript== // ==UserScript==
// @id iitc-plugin-reso-energy-pct-in-portal-detail@xelio // @id iitc-plugin-reso-energy-pct-in-portal-detail@xelio
// @name iitc: reso energy pct in portal detail // @name IITC plugin: reso energy pct in portal detail
// @version 0.1.2 // @version 0.1.2.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL http://iitc.jonatkins.com/dist/plugins/reso-energy-pct-in-portal-detail.user.js // @updateURL @@UPDATEURL@@
// @downloadURL http://iitc.jonatkins.com/dist/plugins/reso-energy-pct-in-portal-detail.user.js // @downloadURL @@DOWNLOADURL@@
// @description Show resonator energy percentage on resonator energy bar in portal detail panel. // @description Show resonator energy percentage on resonator energy bar in portal detail panel.
// @include https://www.ingress.com/intel* // @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel* // @include http://www.ingress.com/intel*

View File

@ -1,10 +1,10 @@
// ==UserScript== // ==UserScript==
// @id iitc-plugin-resonator-display-zoom-level-decrease@xelio // @id iitc-plugin-resonator-display-zoom-level-decrease@xelio
// @name iitc: resonator display zoom level decrease // @name IITC plugin: resonator display zoom level decrease
// @version 1.0.2 // @version 1.0.2.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL http://iitc.jonatkins.com/dist/plugins/resonator-display-zoom-level-decrease.user.js // @updateURL @@UPDATEURL@@
// @downloadURL http://iitc.jonatkins.com/dist/plugins/resonator-display-zoom-level-decrease.user.js // @downloadURL @@DOWNLOADURL@@
// @description Resonator start display earlier // @description Resonator start display earlier
// @include https://www.ingress.com/intel* // @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel* // @include http://www.ingress.com/intel*

View File

@ -1,10 +1,10 @@
// ==UserScript== // ==UserScript==
// @id iitc-plugin-scale-bar@breunigs // @id iitc-plugin-scale-bar@breunigs
// @name iitc: scale bar // @name IITC plugin: scale bar
// @version 0.1.1 // @version 0.1.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL http://iitc.jonatkins.com/dist/plugins/scale-bar.user.js // @updateURL @@UPDATEURL@@
// @downloadURL http://iitc.jonatkins.com/dist/plugins/scale-bar.user.js // @downloadURL @@DOWNLOADURL@@
// @description shows scale bar on the map // @description shows scale bar on the map
// @include https://www.ingress.com/intel* // @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel* // @include http://www.ingress.com/intel*

View File

@ -1,10 +1,10 @@
// ==UserScript== // ==UserScript==
// @id iitc-plugin-scoreboard@vita10gy // @id iitc-plugin-scoreboard@vita10gy
// @name iitc: show a localized scoreboard. // @name IITC plugin: show a localized scoreboard.
// @version 0.1.4 // @version 0.1.4.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL http://iitc.jonatkins.com/dist/plugins/scoreboard.user.js // @updateURL @@UPDATEURL@@
// @downloadURL http://iitc.jonatkins.com/dist/plugins/scoreboard.user.js // @downloadURL @@DOWNLOADURL@@
// @description A localized scoreboard. // @description A localized scoreboard.
// @include https://www.ingress.com/intel* // @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel* // @include http://www.ingress.com/intel*

View File

@ -1,10 +1,10 @@
// ==UserScript== // ==UserScript==
// @id iitc-plugin-show-address@vita10gy // @id iitc-plugin-show-address@vita10gy
// @name iitc: show portal address in sidebar // @name IITC plugin: show portal address in sidebar
// @version 0.2.2 // @version 0.2.2.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL http://iitc.jonatkins.com/dist/plugins/show-address.user.js // @updateURL @@UPDATEURL@@
// @downloadURL http://iitc.jonatkins.com/dist/plugins/show-address.user.js // @downloadURL @@DOWNLOADURL@@
// @description Portal address will show in the sidebar. // @description Portal address will show in the sidebar.
// @include https://www.ingress.com/intel* // @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel* // @include http://www.ingress.com/intel*

View File

@ -1,10 +1,10 @@
// ==UserScript== // ==UserScript==
// @id iitc-plugin-show-portal-weakness@vita10gy // @id iitc-plugin-show-portal-weakness@vita10gy
// @name iitc: show portal weakness // @name IITC plugin: show portal weakness
// @version 0.6.1 // @version 0.6.1.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL http://iitc.jonatkins.com/dist/plugins/show-portal-weakness.user.js // @updateURL @@UPDATEURL@@
// @downloadURL http://iitc.jonatkins.com/dist/plugins/show-portal-weakness.user.js // @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. // @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 https://www.ingress.com/intel*
// @include http://www.ingress.com/intel* // @include http://www.ingress.com/intel*