Skip to content

Instantly share code, notes, and snippets.

@dylancwood
Created May 10, 2014 00:36
Show Gist options
  • Save dylancwood/4d04a754a287ec7373e7 to your computer and use it in GitHub Desktop.
Save dylancwood/4d04a754a287ec7373e7 to your computer and use it in GitHub Desktop.
AppData Cleanup!!
/*
TODO:
write a new file that contains calls to each function found in each of the splitFileDirPath
function getSubjectTags() {
return className->getSubjectTags($args);
}
Address methods that reference other methods as '$this->doSomething()'
+ $this->select() Could be addressed by each class extending BaseAppData
+ Grep for methods defined in File 'A' that are referenced in File 'B' using $this->
+ Alternatively, change all calls to '$this' to be $AppData.
*/
var fs = require('fs');
var splitFilesDirPath = './micis/AppDataClasses/';
var appDataPath = './micis/AppData.inc';
//format {'filename':[func1, func2]...}
var functionNames = {}
fs.readdir(splitFilesDirPath, function readFiles(err, files) {
if (err) throw err;
files.forEach(function readFile(filename) {
var fileFullPath = splitFilesDirPath + filename;
functionNames[filename] = [];
fs.readFile(fileFullPath, 'utf-8', function parseFunctionNames(err, contents) {
var rx = /function *[^\s(]* *\([^)]*\)\s*\{/g;
var funcNameRx = /function *([^\s(]*) *\([^)]*\)\s*\{/;
console.log(filename);
if (contents == undefined) return;
functionNames[filename] = contents.match(rx).map(function extractFunctionName(str) {
var groups = str.match(funcNameRx);
console.log('>>>' + groups[1]);
return groups[1];
});
});
});
});
/*
in app.inc:
require('AppData.inc');
in AppData.inc:
require ('AppDataSomething.inc')
//other sub-classes required
class AppData {
__constructor() {
$this->AppDataSomething = new AppDataSomething($this);
}
someThing() {
return $this->AppDataSomething->someThing($args);
}
...
}
in AppDataSomething.inc:
class AppDataSomething {
__constructor ($parent) {
$this->parent = $parent;
}
someThing() {
//$this->select()
$this->parent->select();
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment