-
Notifications
You must be signed in to change notification settings - Fork 2
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
Make the prepublish and postpublish logic available from the API #9
Comments
It's not a ton of logic to have to implement without this, but I could see how it would be a nice thing to have. To keep it simple, we could just export it from the CLI (since only the CLI deals with files).
Though I'm not necessarily against a dedicated npm export. |
I'm fine with that 👍🏻 |
I looked closer into this and I was reminded that it's not a simple as exporting two functions. The prepublish operation is, in fact, two steps that wrap the call to the downdoc function. And both prepublish and postpublish rely on multiple arguments that are passed to the CLI. However, I believe there's already a better way to accomplish what we want. If we export the CLI function, it can be called through the API. It was set up this way to make it easy to test, but it works well for this purpose too. Here's how that would look: const downdoc = require('downdoc/cli')
;(async () => {
await downdoc({ args: ['/path/to/README.adoc', '--prepublish'] })
// ...do other work
await downdoc({ args: ['/path/to/README.adoc', '--postpublish'] })
})() What we're missing is the computed output path. I think we can fix that by returning the parsed object from parseArgs (or perhaps just the values object), which would reveal the output path in the output property. {
prepublish: true,
input: 'README.adoc',
output: 'README.md',
attribute: [ 'env=npm', 'env-npm'],
} (It's a little strange that A slightly simpler option would be to return the output path when the const outputPath = await downdoc({ args: ['/path/to/README.adoc', '--prepublish'] }) However, I'm not as much a fan of that as I think it limits what can be done with the CLI. I think we can get this right, but we probably need to do it after the 1.0.0 release so it isn't rushed. |
Btw, it's also possible to capture the output to a string by passing in an object that has the const io = // object with write method
await downdoc({ args: ['README.adoc', '-o', '-'], stdout: io) |
I'm using
downdoc
API in a release script and I want to use the prepublish/postpublish logic:with an input file
with empty argument (i.e., default values)
The text was updated successfully, but these errors were encountered: