简体   繁体   中英

CoffeeScript to NodeJS

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!

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);
}

// ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM