0

I'm currently attempting to port some old CoffeeScript code over (old project) to native NodeJS; I'm struggling to understand what exactly this is doing? or the equivalent in Node?

  builder.macro_extensions = [
      'iced'
      'nsi'
      'txt'
  ]

  await exec """
    find #{temp} | grep #{(_.map @macro_extensions, (x) -> "-e '\\.#{x}'").join ' '}
  """, {silent:on}, defer e,r
  if e then return cb e

If anyone could point me in the right direction, that'd be perfect!

1 Answer 1

1

Assuming exec returns a promise, the code passes 2 arguments to the exec function, waits for the returned promise to be fulfilled, and sets the variable r to the resolved value.

If anything goes wrong (ie. the promise gets rejected), it sets the variable e to the rejection reason of that promise.

The JS equivalent of that code would be:

builder.macro_extensions = ['iced', 'nsi', 'txt'];

const grepArgs = _.map(
  this.macro_extensions, // or maybe builder.macro_extensions
  x => ` -e '\\.${x}'`,
).join(''); // -e '\.iced' -e '\.nsi' -e '\.txt'

let r;
try {
  r = await exec(`find ${temp} | grep ${grepArgs}`, {silent: on});
} catch (e) {
  return cb(e);
}

// ...
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for this! although it appears that the _.map function doesn't exist?
I suspect it's a lodash function. You could also write that line like: builder.macro_extensions.map(x => ` -e '\\.${x}'`).join('');
you've saved the day!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.