@@ -35,29 +35,6 @@ var extractDependencies = function(content) {
3535 return moduleArray ;
3636} ;
3737
38- var getDepVar = function ( lib , file ) {
39- var parsedData = esprima . tokenize ( file ) ;
40-
41- for ( var i = 0 ; i < parsedData . length ; i ++ ) {
42- var o = parsedData [ i ] ;
43-
44- if ( o . type === 'String' &&
45- o . value . substring ( 1 , o . value . length - 1 ) === lib &&
46- parsedData [ i + 1 ] . type === 'Punctuator' &&
47- parsedData [ i + 1 ] . value === ')' &&
48- parsedData [ i - 1 ] . type === 'Punctuator' &&
49- parsedData [ i - 1 ] . value === '(' &&
50- parsedData [ i - 2 ] . type === 'Identifier' &&
51- parsedData [ i - 2 ] . value === 'require' &&
52- parsedData [ i - 3 ] . type === 'Punctuator' &&
53- parsedData [ i - 3 ] . value === '=' &&
54- parsedData [ i - 4 ] . type === 'Identifier' ) {
55-
56- return parsedData [ i - 4 ] . value ;
57- }
58- }
59- } ;
60-
6138exports . addToDB = function ( req , res , next ) {
6239
6340 var filePath = req . body . url ;
@@ -100,7 +77,6 @@ var populateSnippitIds = function(snippitObj, cb) {
10077 return ;
10178 }
10279
103- // console.log(typeof file._snippitIds, ': ', file._snippitIds);
10480 if ( file . _snippitIds . length > 0 ) {
10581 console . log ( snippitObj . filePath ) ;
10682 for ( var i = 0 ; i < file . _snippitIds . length ; i ++ ) {
@@ -145,63 +121,19 @@ exports.findCode = function(req, res, next) {
145121 searchOptions . func = libFunction . length > 0 ? true : false ;
146122 }
147123
148- // console.log('searchQuery', searchQuery);
149- // console.log('searchOptions', searchOptions);
150- var snippIterator = function ( doc , callback ) {
151-
152- var docContent = doc . contents ;
153- var repoUrl = doc . repoUrl || "" ;
154- var filePath = doc . filePath || "" ;
155- var snippitRatings = doc . snippitRatings ?
156- doc . snippitRatings [ libFunction ] : { } ;
157-
158- var dep ;
159- if ( library . length > 0 && libFunction . length > 0 ) {
160- dep = getDepVar ( library , docContent ) ;
161-
162- if ( dep ) {
163- searchQuery = dep + '.' + libFunction ;
164- }
165- }
166-
167- var snippit = codeParser ( docContent , searchQuery , searchOptions ) ;
168-
169- var resultsArr = [ ] ;
170- snippit . forEach ( function ( snippit ) {
171- // console.log(snippit.length);
172- var snippitObj = {
173- repoUrl : repoUrl ,
174- filePath : filePath ,
175- snippit : snippit ,
176- docContent : docContent
177- } ;
178- resultsArr . push ( snippitObj ) ;
179- } ) ;
180- callback ( null , resultsArr ) ;
181- } ;
182-
183124 File . find ( { $text : { $search : searchQuery } } , function ( err , files ) {
184125 console . log ( 'Found \033[35m' , files . length , '\033[39m many files' ) ;
185- console . log ( files . length , { searchOptions : searchOptions , searchQuery : searchQuery } )
186126 res . json ( { files : files , searchOptions : searchOptions , searchQuery : searchQuery } ) ;
187-
188- // async.map(files, snippIterator, function(err, snippitsArr) {
189- // snippitsArr = uu.flatten(snippitsArr);
190- // console.log('done iterating through snippits', snippitsArr.length);
191- // console.log('populating snippit ids');
192- // async.map(snippitsArr, populateSnippitIds, function(err, data) {
193- // console.log('sending response to client', data.length);
194- // res.json({ snippits: data });
195- // });
196- // });
197127 } ) ;
198128
199129} ;
200130
201131exports . popSnips = function ( req , res , next ) {
202- console . log ( 'Popping snippits' ) ;
203- console . log ( req . body . snipPaths . length ) ;
204-
132+ var snipsArr = req . body . data ;
133+ async . map ( snipsArr , populateSnippitIds , function ( err , data ) {
134+ console . log ( 'sending response to client' , data . length ) ;
135+ res . json ( { snippits : data } ) ;
136+ } ) ;
205137} ;
206138
207139var filesInDirectory = function ( dirPath , done ) {
@@ -245,7 +177,6 @@ var isValidJSFile = function(file) {
245177 }
246178} ;
247179
248- // exports.pushFileToDirectory = function(req, res, next){
249180exports . pushFileToDirectory = function ( repoPath , cloneUrl , moduleName ) {
250181 // var jsResults = [];
251182
0 commit comments