1// Copyright 2020 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5/** 6 * @fileoverview Collect JS nodes. 7 */ 8 9const program = require('commander'); 10 11const corpus = require('./corpus.js'); 12const db = require('./db.js'); 13const path = require('path'); 14 15const sourceHelpers = require('./source_helpers.js'); 16 17function main() { 18 Error.stackTraceLimit = Infinity; 19 20 program 21 .version('0.0.1') 22 .option('-i, --input_dir <path>', 'Input directory.') 23 .option('-o, --output_dir <path>', 'Output directory.') 24 .parse(process.argv); 25 26 if (!program.args.length) { 27 console.log('Need to specify corpora.'); 28 return; 29 } 30 31 if (!program.output_dir) { 32 console.log('Need to specify output dir.'); 33 return; 34 } 35 36 const mutateDb = new db.MutateDbWriter(program.output_dir); 37 38 const inputDir = path.resolve(program.input_dir); 39 for (const corpusName of program.args) { 40 const curCorpus = new corpus.Corpus(inputDir, corpusName); 41 for (const relPath of curCorpus.relFiles()) { 42 let source; 43 try { 44 source = sourceHelpers.loadSource(inputDir, relPath); 45 } catch (e) { 46 console.log(e); 47 continue; 48 } 49 50 if (!source) { 51 continue; 52 } 53 54 try{ 55 mutateDb.process(source); 56 } catch (e) { 57 console.log(e); 58 } 59 } 60 } 61 62 mutateDb.writeIndex(); 63} 64 65main(); 66