-
Notifications
You must be signed in to change notification settings - Fork 693
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
Add a programmatic API (fixes #86) #113
Conversation
Do you think this list is comprehensive? I'm still trying to figure out 4. Any hints on 5? |
@dar5hak Please return an object with a |
lib/api.js
Outdated
const path = require('path') | ||
|
||
// { port: 1337 } => ['--port', '1337'] | ||
const optionsToArgs = options => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use dargs
directly
I think it covers everything now. @leo Could you have a final look? |
I'll push the docs tomorrow. Added that to the checklist. |
lib/api.js
Outdated
module.exports = (options = {}, directory = process.cwd()) => { | ||
const scriptPath = path.join(__dirname, '..', 'bin', 'serve.js') | ||
const aliases = {cors: 'o'} | ||
options._ = [directory] // Let dargs handle the directory argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an empty line before this line.
lib/api.js
Outdated
const aliases = {cors: 'o'} | ||
options._ = [directory] // Let dargs handle the directory argument | ||
|
||
const cli = spawn('node', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split it into multiple lines:
const args = [
scriptPath,
...dargs(options, {aliases})
]
const cli = spawn('node', args, {
stdio: 'inherit'
})
package.json
Outdated
@@ -53,6 +54,7 @@ | |||
"boxen": "1.0.0", | |||
"chalk": "1.1.3", | |||
"copy-paste": "1.3.0", | |||
"dargs": "^5.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please pin this dependency! => 5.1.0
Added docs. Please have a look at |
Also, a small problem. I couldn't get the serve --ignore readme.md package.json ./ This fails with the statement: |
@leo @dar5hak why use comma-separated values? Why not just accept a glob patterns and pass them to some fast matcher like Users are familiar with globs and matching, and think that |
|
@leo There. Everything works now. 🎉 |
@dar5hak Thanks a lot! 😊 |
This is a prototype of
api.js
as discussed in #86. Here's what I think it should do:options
anddirectory
as argumentsstdin
, such as ^C and behave accordingly