#!/usr/bin/env node const elasticlunr = require( './elasticlunr.min' ); const fs = require( 'fs' ); const JSONStream = require( 'JSONStream' ); const es = require( 'event-stream' ); console.log( 'Creating ElasticLunr index..' ); const index = new elasticlunr.Index( ); index.addField( 'title' ); index.addField( 'content' ); index.setRef( 'uri' ); index.saveDocument( true ); var stream = fs.createReadStream( './posts.json' ); stream.pipe( JSONStream.parse( '*') ) .pipe( es.mapSync( function( data ) { index.addDoc( data ); return data; } ) .on( 'end', function( ) { fs.writeFile( './posts.index', JSON.stringify( index ), function( err ) { if( err ) throw err; console.log( 'Finished creating index..' ); } ); } ) )