cli/entityfinder.js
function() {
        return new Promise(function(resolve, reject) {
            exec("find . ! -name '" + __filename.split('/').pop() + "' -iname '*\.js' | xargs grep 'CRUD.Entity.call(this);' -isl", {
                timeout: 3000,
                cwd: process.cwd()
            }, function(err, stdout, stdin) {
                var results = stdout.trim().split('\n');
                var entities = {};

                // iterate all found js files and search for CRUD.define calls
                results.map(function(filename) {
                    if (filename.trim() == '') return;
                    var code = fs.readFileSync(filename) + '';
                    var ast = UglifyJS.parse(code);
                    ast.walk(new UglifyJS.TreeWalker(function(node) {
                        if (node instanceof UglifyJS.AST_Call && node.start.value == 'CRUD' && node.expression.property == 'define') {
                            entities[node.args[0].start.value] = filename;
                        }
                    }));
                });

                resolve(entities);
            });
        });
    }
function() {
        return new Promise(function(resolve, reject) {
            exec("find . ! -name '" + __filename.split('/').pop() + "' -iname '*\.js' | xargs grep 'CRUD.Entity.call(this);' -isl", {
                timeout: 3000,
                cwd: process.cwd()
            }, function(err, stdout, stdin) {
                var results = stdout.trim().split('\n');
                var entities = {};

                // iterate all found js files and search for CRUD.define calls
                results.map(function(filename) {
                    if (filename.trim() == '') return;
                    var code = fs.readFileSync(filename) + '';
                    var ast = UglifyJS.parse(code);
                    ast.walk(new UglifyJS.TreeWalker(function(node) {
                        if (node instanceof UglifyJS.AST_Call && node.start.value == 'CRUD' && node.expression.property == 'define') {
                            entities[node.args[0].start.value] = filename;
                        }
                    }));
                });

                resolve(entities);
            });
        });
    }
function ( ) { return new Promise ( function ( resolve , reject ) { exec ( "find . ! -name '" + __filename . split ( '/' ) . pop ( ) + "' -iname '*\.js' | xargs grep 'CRUD.Entity.call(this);' -isl" , { timeout : 3000 , cwd : process . cwd ( ) } , function ( err , stdout , stdin ) { var results = stdout . trim ( ) . split ( '\n' ) ; var entities = { } ; // iterate all found js files and search for CRUD.define calls results . map ( function ( filename ) { if ( filename . trim ( ) == '' ) return ; var code = fs . readFileSync ( filename ) + '' ; var ast = UglifyJS . parse ( code ) ; ast . walk ( new UglifyJS . TreeWalker ( function ( node ) { if ( node instanceof UglifyJS . AST_Call && node . start . value == 'CRUD' && node . expression . property == 'define' ) { entities [ node . args [ 0 ] . start . value ] = filename ; } } ) ) ; } ) ; resolve ( entities ) ; } ) ; } ) ; }
Find the filenames for all CRUD entities under the base dir
@return {Promise} object with keys: entity names, values: filename
Find the filenames for all CRUD entities under the base dir