index.js
/**
 * Main Search function
 * Starts a new search and uses the search command input to query
 */
Main Search function
Starts a new search and uses the search command input to query
Main Search function Starts a new search and uses the search command input to query
async function newSearch() {
    const browser = await puppeteer.launch({
        headless: headless_Mode
    });
    if (should_Authenticate) {
        let didAuthenticate = await auth.login(browser, program.credentials);
        console.log('Authentication successful?: ' + didAuthenticate);
    }
    let search_Output_Array = [];
    for (let index in search_Array) {
        if (!search_Array[index] || search_Array[index].length < 1) {
            winston.error('Search query array index null: ' + index);
            continue;
        }
        let current_Search = new search(browser, search_Array[index], search_Limit);
        let current_Search_Results = await current_Search.getResults();
        search_Output_Array.push(current_Search_Results);
    }
    if (!program.output || program.output.length < 1) {
        console.log(JSON.stringify(search_Output_Array, null, 4));
    } else {
        let shouldWrite = true;
        if (fs.existsSync(program.output)) {
            await inquirer.prompt(
                    [{
                        type: 'list',
                        name: 'yesno',
                        message: 'File: ' + program.output + ' already exists.  Overwrite?',
                        choices: ['Yes', 'No']
                    }])
                .then(function (answers) {
                    if (answers.yesno != "Yes") {
                        shouldWrite = false;
                        console.log('Not saving output to: ' + program.output);
                        console.log(JSON.stringify(search_Output_Array, null, 4));
                    }
                });
        }
        if (shouldWrite) {
            fs.writeFile(program.output, JSON.stringify(search_Output_Array, null, 4), function (err) {
                if (err) {
                    return console.log(err);
                }
                console.log('Saved output to: ' + program.output);
            });
        }
    }
    browser.close();
}
async function newSearch ( ) { const browser = await puppeteer . launch ( { headless : headless_Mode } ) ; if ( should_Authenticate ) { let didAuthenticate = await auth . login ( browser , program . credentials ) ; console . log ( 'Authentication successful?: ' + didAuthenticate ) ; } let search_Output_Array = [ ] ; for ( let index in search_Array ) { if ( ! search_Array [ index ] || search_Array [ index ] . length < 1 ) { winston . error ( 'Search query array index null: ' + index ) ; continue ; } let current_Search = new search ( browser , search_Array [ index ] , search_Limit ) ; let current_Search_Results = await current_Search . getResults ( ) ; search_Output_Array . push ( current_Search_Results ) ; } if ( ! program . output || program . output . length < 1 ) { console . log ( JSON . stringify ( search_Output_Array , null , 4 ) ) ; } else { let shouldWrite = true ; if ( fs . existsSync ( program . output ) ) { await inquirer . prompt ( [ { type : 'list' , name : 'yesno' , message : 'File: ' + program . output + ' already exists.  Overwrite?' , choices : [ 'Yes' , 'No' ] } ] ) . then ( function ( answers ) { if ( answers . yesno != "Yes" ) { shouldWrite = false ; console . log ( 'Not saving output to: ' + program . output ) ; console . log ( JSON . stringify ( search_Output_Array , null , 4 ) ) ; } } ) ; } if ( shouldWrite ) { fs . writeFile ( program . output , JSON . stringify ( search_Output_Array , null , 4 ) , function ( err ) { if ( err ) { return console . log ( err ) ; } console . log ( 'Saved output to: ' + program . output ) ; } ) ; } } browser . close ( ) ; }
Main Search function
 Starts a new search and uses the search command input to query
Main Search function Starts a new search and uses the search command input to query
// Launch the browser // Check if the user wants to authenticate // Authenticate the user and get the results // Create the output results array // Go through the search array // Check the search array to verify no null index was accessed // Create a new search object // Get the search results async // Add the search results to the output array // Check if the CLI flags want the output in the console or in a file // Close the browser