Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide done callback #23

Open
ezekielchentnik opened this issue Jan 10, 2017 · 7 comments
Open

provide done callback #23

ezekielchentnik opened this issue Jan 10, 2017 · 7 comments

Comments

@ezekielchentnik
Copy link

can we add a node style done callback?

I was thinking of something like this:

 nodeRev({
  files: './build/public/bundle.css,./build/public/bundle.js',
  outputDir: './build/public/',
  file: './build/manifest.json',
  hash: true
}, (err, result) => {
  if(err){ 
    // handle
  }
  console.log(result)
})

then we can promisify it

const _nodeRev = require('node-rev').default

const promisify = (ctx, func = ctx) => (...args) => {
  return new Promise((resolve, reject) => {
    func.apply(ctx, [...args, (err, result) => err ? reject(err) : resolve(result)])
  })
}

const nodeRev = promisify(_nodeRev)

const rev = () => nodeRev({
  files: './build/public/bundle.css,./build/public/bundle.js',
  outputDir: './build/public/',
  file: './build/assets.json',
  hash: true
})

rev().then((manifest) => console.log(manifest))
@kellyrmilligan
Copy link
Owner

we can! that totally makes sense, just wasn't using it that way at the time I made this. I guess the question is, when you call the node api now it writes the manifest for you. are you wanting it to keep doing that, or if you use the callback then don't write it to the filesystem and leave it up to whoever is using it that way?

@kellyrmilligan
Copy link
Owner

i'll totally add the babel plugin for the exports stuff so we don't have to do .default as well, ugh forgot about that.

@kellyrmilligan
Copy link
Owner

i'm thinking if a person is using the node api, then they should use the manifest however they want and it won't write the file?

@ezekielchentnik
Copy link
Author

@kellyrmilligan apologies for late reply. I agree, if you provide a callback it makes sense to prevent file write and let the consumer do what they want. That way they can decide what to do with the file (write, inject into next build step, keep in memory, write async, etc.)

@ezekielchentnik
Copy link
Author

@kellyrmilligan if you don't mind I'd like to take a stab at a PR for this?!

@ezekielchentnik
Copy link
Author

@kellyrmilligan +1 for babel, .default. FYI, in my example, i stole it from a build process where I don't have the luxury of transpile

@kellyrmilligan
Copy link
Owner

Go for it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants