SVN to CodeDB converter
docName = 'lively-fs'; cdb = new CouchDB('code_db'); rev = cdb.open(docName)._rev; rev = rev.substring(0, rev.indexOf('-')); url = cdb.uri; filename = 'lively/miniprototype.js'; resFrom = new WebResource(URL.codeBase.withFilename(filename).toString()); content = resFrom.get().content; resTo = new WebResource(url + 'lively-fs/' + filename + '?rev=' + rev); resTo.put(content, 'application/javascript'); currentFiles = lively.lang.Namespace.bootstrapModules(); currentFiles.each(function(filename) { rev = cdb.open(docName)._rev; resFrom = new WebResource(URL.codeBase.withFilename(filename).toString()); content = resFrom.get().content; resTo = new WebResource(url + 'lively-fs/' + filename + '?rev=' + rev); resTo.put(content, 'application/javascript'); });
Import files as attachment (CouchDB)
X
M
filename = notParsed[9]; res = new WebResource(URL.codeBase.withFilename(filename).toString()).forceUncached(); source = res.get().content + '\n'; //ast = lively.AST.Parser.parse(source); intermediate = OMetaSupport.matchAllWithGrammar(lively.AST.Parser.jsParser, 'topLevel', source); source = 'a = 1 + 12 // foo \nb = 12'; source = 'foo.bar.__proto__'; source = '"a" in ({ a: 23})'; parser.src = "var foo = 23;"; descriptor = parser.callOMeta('func');
Workspace
X
M
JsParser.prototype.debugMode = true; currentModules = lively.lang.Namespace.bootstrapModules(); currentModules = currentModules.withoutAll(['lively/miniprototype.js', 'lively/JSON.js', 'lively/defaultconfig.js', 'lively/localconfig.js', 'lively/Base.js']); notParsed = []; // try { // var ast = lively.AST.Parser.parse(source); // return ast; // } catch (e) { // notParsed.push(filename); // } // return; sectionTypes = codeSections.collect(function(fragments) { return fragments.pluck('type'); }); unknownSections = codeSections.flatten().select(function(fragment) { return fragment.type == 'unknown'; });
Workspace
X
M
cdbImporter = new CDB.Importer('code_db'); cdbImporter.importFile(currentModules[0]); // HANDLE SUB STUFF subElems = moduleDef.subElements(); subElems = subElems.collect(function(elem) { return (elem.type == 'comment' && elem.getSourceCode().trim() == '') ? null : elem; }).compact(); if (typeof mod == 'undefined') mod = cdb.getCodeObject(CDB.Module, moduleName); elem = subElems[0]; subElems.each(function(elem) { switch (elem.type) { case 'klassDef': var cls = new CDB.Klass(elem.name); cls.documentation = ''; cls.superclass = elem.superclassName; elem.subElements().each(function(klassElem) { switch (klassElem.type) { case 'propertyDef': var meth = new CDB.Method(klassElem.name); meth.documentation = ''; CDB.Method.prototype.getWritableDocumentObject var source = klassElem.getSourceCode().match(/[a-zA-Z0-9]+:\s+((\s|.)*)/)[1]; if (source.endsWith(',')) source = source.substr(0, source.length - 1); meth.source = source; if (klassElem.category) meth.category = klassElem.category.name; cls.addMethod(meth); changeSet.add(meth); meth.save(); break; default: throw new Error('SubElement type for class not (yet) supported!'); } }); mod.addClass(cls); changeSet.add(cls); cls.save(); break; default: throw new Error('SubElement type not (yet) supported!'); } }); if (!changeSet.includes(mod)) { changeSet.add(mod); } mod.save(); // END changeSet.commit('Initial upload of parsed file/module "' + filename + '".');
Workspace
X
M