1#!/usr/bin/env node
2'use strict';
3
4var _ = require('../lodash'),
5    fs = require('fs'),
6    path = require('path');
7
8var args = (args = process.argv)
9  .slice((args[0] === process.execPath || args[0] === 'node') ? 2 : 0);
10
11var filePath = path.resolve(args[1]),
12    reLine = /.*/gm;
13
14var pattern = (function() {
15  var result = args[0],
16      delimiter = result.charAt(0),
17      lastIndex = result.lastIndexOf(delimiter);
18
19  return RegExp(result.slice(1, lastIndex), result.slice(lastIndex + 1));
20}());
21
22/*----------------------------------------------------------------------------*/
23
24fs.writeFileSync(filePath, fs.readFileSync(filePath, 'utf8').replace(pattern, function(match) {
25  var snippet = _.slice(arguments, -3, -2)[0];
26  return match.replace(snippet, snippet.replace(reLine, ''));
27}));
28