Last active
September 30, 2016 18:42
-
-
Save Catsync/bdeec3d348d151f324dd0569796aaf78 to your computer and use it in GitHub Desktop.
mongo script to find levels that still need converting to hero
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Search for this/self in level code / solutions | |
// Prints the level slug if this or self is still present. | |
// NOTE: add/change this campaign slug array as needed | |
var campaignSlug = ['intro','course-2','course-3','course-4']; | |
print("Levels that still need converting to hero:"); | |
campaignSlug.forEach(function(slug) { | |
print("*** " + slug + " ***"); | |
var campaign = db.campaigns.findOne({slug: slug }); | |
var levelOriginals = Object.keys(campaign.levels); | |
// *** Each level in the campaign | |
levelOriginals.some(function(original) { | |
var level = db.levels.findOne({original: ObjectId(original), slug: {$exists: true}}); | |
eachLevel(level); | |
// this stops the .some() after one, for testing | |
return true; | |
}); | |
}); | |
// ***** // | |
var THIS = /this\./g; | |
var SELF = /self[\.\:]+/g; | |
var CTHIS = /\@/g; | |
var LOOP = /loop[\n\:]+/g; | |
function eachLevel(level) { | |
var hasSelfOrThis = false; | |
// *** Find the Hero Placeholder thang | |
for(var i=0; i < level.thangs.length; i++) { | |
var t = level.thangs[i]; | |
if(t.id !== 'Hero Placeholder') { continue; } | |
// *** Find the programmableMethods component | |
for(var j=0; j < t.components.length; j++) { | |
var comp = t.components[j]; | |
if(!comp.config || !comp.config.programmableMethods) { continue; } | |
hasSelfOrThis = findSelfOrThis(comp.config.programmableMethods.plan); | |
if(hasSelfOrThis) { | |
print(level.slug); | |
return; | |
} | |
} | |
} | |
// ** Documentation | |
var documentation = level.documentation; | |
// print(JSON.stringify(documentation)); | |
if(documentation.specificArticles) { | |
for(article of documentation.specificArticles) { | |
for(key in article) { | |
print(key); | |
if(key.name && (key.name == "Intro" || key.name == "Overview")) { | |
if(key.body.match(THIS) || key.body.match(SELF) || key.body.match(CTHIS) || key.body.match(LOOP)) { | |
print(level.slug); | |
return; | |
} | |
if(key.i18n) { | |
for(var k in key.i18n) { | |
var t = key.i18n[k]; | |
if(t.body) { | |
// TODO: check body for stuff | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
function findSelfOrThis(plan) { | |
var found = null; | |
// JS sample code | |
if(plan.source) { | |
if(plan.source.match(THIS) || plan.source.match(LOOP)) { | |
return true; | |
} | |
} | |
// python sample code | |
if(plan.languages && plan.languages.python) { | |
if(plan.languages.python.match(SELF) || plan.languages.python.match(LOOP)) { return true; } | |
} | |
// coffee sample code | |
if(plan.languages && plan.languages.coffeescript) { | |
if(plan.languages.coffeescript.match(CTHIS) || plan.languages.coffeescript.match(LOOP)) { | |
print('coffeescript'); | |
return true; | |
} | |
} | |
// lua sample code | |
if(plan.languages && plan.languages.lua) { | |
if(plan.languages.lua.match(SELF) || plan.languages.lua.match(LOOP)) { | |
print('lua'); | |
return true; | |
} | |
} | |
if(plan.solutions) { | |
for(var i=0; i < plan.solutions.length; i++) { | |
var sol = plan.solutions[i]; | |
if(sol.language === "javascript") { | |
found = sol.source.match(THIS); | |
if(found !== null) { return true; } | |
} | |
if(sol.language === "python") { | |
found = sol.source.match(SELF); | |
if(found !== null) { return true; } | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment