|
| 1 | +#! /usr/bin/env node |
| 2 | + |
| 3 | +var fs = require( 'fs' ); |
| 4 | +var sqlite = require( 'sqlite3' ).verbose(); |
| 5 | + |
| 6 | + |
| 7 | +var file_sql = './src/index.sql'; |
| 8 | +var file_db = './Emmet.docset/Contents/Resources/docSet.dsidx'; |
| 9 | +var table_drop = 'DROP TABLE IF EXISTS searchIndex'; |
| 10 | +var table_create = 'CREATE TABLE searchIndex (id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT)'; |
| 11 | +var index_create = 'CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path)'; |
| 12 | +var index_add = "INSERT INTO searchIndex (name, type, path) VALUES (?, ?, ?)"; |
| 13 | + |
| 14 | + |
| 15 | +var db = new sqlite.Database( file_db ); |
| 16 | +db.serialize(function() { |
| 17 | + // prepare |
| 18 | + db.run( table_drop, function ( err ) { |
| 19 | + if ( err ) console.info( 'table drop fail: %s', err ); |
| 20 | + }); |
| 21 | + db.run( table_create, function( err ) { |
| 22 | + if ( err ) console.info( 'table create fail: %s', err ); |
| 23 | + }); |
| 24 | + db.run( index_create, function( err ) { |
| 25 | + if ( err ) console.info( 'index create fail: %s', err ); |
| 26 | + }); |
| 27 | + |
| 28 | + // fill |
| 29 | + var stmt = db.prepare( index_add ); |
| 30 | + fs.readFileSync( |
| 31 | + file_sql, 'utf-8' |
| 32 | + ).split( '\r' ).forEach(function ( line ) { |
| 33 | + line = line.split( '|' ); |
| 34 | + stmt.run( line[ 2 ], line[ 0 ], 'index.html#' + line[ 1 ] ); |
| 35 | + }); |
| 36 | + stmt.finalize(); |
| 37 | + |
| 38 | + // // dump |
| 39 | + // db.each( "SELECT * FROM searchIndex", function( err, row ) { |
| 40 | + // console.log( row ); |
| 41 | + // }); |
| 42 | +}); |
| 43 | + |
| 44 | +db.close(); |
| 45 | + |
| 46 | + |
| 47 | +// others |
| 48 | +// .... |
0 commit comments