-
Notifications
You must be signed in to change notification settings - Fork 46
Ability to launch SourceJS via NodeJS Script #241
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
Conversation
…sing global.pathToApp
…er script file using require()
| silent = _silent; | ||
|
|
||
| var pathToApp = basePath || path.dirname(require.main.filename); | ||
| var pathToApp = basePath || global.pathToApp; |
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.
Using globals is considered a bad practice, since it requires some special environment setup of the callee. I'll need to double-check how these changes affect the current setup.
From other side require.main.filename is also limited, and was the reason to be replaced, since you execute SourceJS code from other location.
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.
Globals are indeed a bad practice.
However, beyond my reasoning for running from other location, it was also inconsistent with the rest of the SourceJS code base.
I used the global.pathToApp, since it was used by the rest of the core files (see processMd, specUtils, etc). =)
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.
You are right, it's just the rest of the codebase also needs to be improved in that sense :) But as I said, there's no better alternative, except passing the properties directly, as it's also done here in the main execution scenario.
But first let's discuss other SourceJS calling scenarios, since we may find a better option (following this discussion #240 (comment)).
app.js
Outdated
|
|
||
| spawn('./node_modules/grunt-cli/bin/grunt', [commander.postGrunt, '--port='+port], {stdio: 'inherit'}) | ||
| module.exports = function () { | ||
| var serverOpts = global.opts.core.server; |
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 keep the original 4 space indentation
app.js
Outdated
| var spawn = require('cross-spawn'); | ||
|
|
||
| spawn('./node_modules/grunt-cli/bin/grunt', [commander.postGrunt, '--port='+port], {stdio: 'inherit'}) | ||
| module.exports = function () { |
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 create a named function and add it into exports below the file
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.
Something like
module.exports = {
startServer: function() { ... }
};
Work for you?
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.
It would be cleaner like this:
var startServer = function() {}
module.exports = {
startServer: startServer
}
It's a nice practice to keep module exports below, so everybody could easily overview the exported interface.
|
I made the changes so that module.exports and fixed the indent spacing to 4 spaces. |
|
I think adding the ability to pass an "options" object to the startServer function might need to wait for the next release. Just looking it over, seems like it'll need more thinking since host/port are stored in global options as well, and used in other files. I'm not sure of the time-of-use (just briefly scanning) if there would have already been used, and thus too late to modify in startServer |
|
Thanks again for the PR, now everything looks fine. Let's continue with next stage of passing options as soon as you're ready. Cheers |
These are the fixes for #240