jsoverson / hackium

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

make init command for creating interceptors

jsoverson opened this issue · comments

e.g.

const { parseScript } = require('shift-parser');
const { RefactorSession } = require('shift-refactor');

module.exports = function(hackium, {request, response}, debug) {
  debug(`intercepting ${request.url}`);

  const ast = parseScript(response.body);

  const refactor = new RefactorSession(ast, { autoCleanup: false });

  const numStatements = ast.statements.length;

  refactor.insertAfter(ast.statements[ast.statements.length-1], `console.log("Intercepted file has ${numStatements} statements");`)

  refactor.cleanup();
  const newSource = refactor.print();
  debug(`continuing intercepted request ${request.url}`);
  response.body = newSource;
  return response;
}

added sometime pre-v1