#!/usr/bin/env node

'use strict'

var fs = require('fs')
var path = require('path')

var out = []
process.stdin.setEncoding('utf8')
process.stdin.on('data', function(chunk) {
  if (!chunk) return
  var splits = chunk.split('\n')
  if (splits.length > 1) {
    while (splits.length && splits[0]) {
      out.push(splits.shift())
    }
  }
})

process.stdin.on('end', function() {
  var result = format(out)
  var fp = path.join(__dirname, '..', 'index.js')
  fs.rename(fp, fp + '.bak', function(err) {
    fs.writeFile(fp, result, 'utf8', function(err) {
      if (err) throw err
      console.log('done')
    })
  })
})

function format(data) {
  if (!data.length)
    throw new Error('Unexpected data')

  var result = '\'use strict\'\n\n' +
    'module.exports = [\n' +
    '  \'' + data[0] + '\'\n'

  for (var i = 1, len = data.length; i < len; i++) {
    result += ', \'' + data[i] + '\'\n'
  }

  return result + ']\n'
}

@@ -82,279 +82,723 @@
 h')%0A
-%0Avar out = %5B%5D%0Aprocess.stdin.setEncoding('utf8')%0Aprocess.stdin.on('data', function(chunk)
+const Transform = require('stream').Transform%0A%0Aconst DELIMITER = Buffer('%5Cn')%0Alet buf = ''%0Aconst stream = new Transform(%7B%0A  transform: (chunk, enc, cb) =%3E
  %7B%0A
+  
   if (
-!chunk) return%0A  var splits = chunk.split('%5Cn')%0A  if (splits.length %3E 1) %7B%0A    while (splits.length && splits%5B0%5D) %7B
+buf) %7B%0A      chunk = Buffer.concat(%5Bbuf, chunk%5D)%0A    %7D%0A%0A    let idx = chunk.indexOf(DELIMITER)%0A    if (idx === -1) %7B%0A      buf = chunk%0A      return cb()%0A    %7D%0A%0A    let off = 0%0A    while (idx !== -1) %7B%0A      const slice = chunk.slice(0, idx)%0A      off += slice.length + 1
 %0A      
-out
+stream
 .push(s
-p
 li
-ts.shift())%0A    %7D%0A  %7D%0A%7D)%0A%0Aprocess.stdin
+ce)%0A      chunk = chunk.slice(idx + 1)%0A      idx = chunk.indexOf(DELIMITER)%0A    %7D%0A%0A    buf = chunk%0A    return cb()%0A  %7D%0A%7D)%0A%0Avar out = %5B%5D%0Aprocess.stdin.setEncoding('utf8')%0Aprocess.stdin.pipe(stream).on('data', (item) =%3E %7B%0A  out.push(item.toString())%0A%7D)%0A%0Astream
 .on(

fix update script