Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I currently have this code that is controlling my CLI flow:

const FLOW = [
  'Mapping',
  'Extract',
  'Convert',
  'Exports'
].reduce((m, fn) => {
  cli.info(`${fn} phase starting.`);
  let current = extract[fn];

  // Ensure that all my itens inside FLOW are functions
  if (Object.prototype.toString.call(current) !== '[object Function]') {
    cli.error('You have a non-function in your FLOW.');
  }

  let result = new current(m).process(); // Store the new MAP
  cli.info(`${fn} phase ending.`);
  return result;
}, MAP);

I'm working with files, so i'm using sync code.

at each stage I have some code that looks like the other phases:

module.exports = Class NameOfPhase {
   constructor (MAP) {
     this.MAP = MAP || {};
   }

   process () {
    // DO WHAT U NEED AND RETURN
   }
};

And I'm using these lines to print the current phase:

cli.info(`${fn} phase starting.`);
cli.info(`${fn} phase ending.`);

I would like to improve the initializer. I don't want let this lines there. Do you have some suggestions for me? Also, are there any ways to improve the code?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.