Skip to content

Conversation

@Alanoll
Copy link

@Alanoll Alanoll commented Dec 12, 2016

These are the fixes for #240

silent = _silent;

var pathToApp = basePath || path.dirname(require.main.filename);
var pathToApp = basePath || global.pathToApp;
Copy link
Member

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.

Copy link
Author

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). =)

Copy link
Member

@robhrt7 robhrt7 Dec 13, 2016

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;
Copy link
Member

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 () {
Copy link
Member

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

Copy link
Author

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?

Copy link
Member

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.

@Alanoll
Copy link
Author

Alanoll commented Dec 13, 2016

I made the changes so that module.exports and fixed the indent spacing to 4 spaces.

@Alanoll
Copy link
Author

Alanoll commented Dec 13, 2016

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

@robhrt7
Copy link
Member

robhrt7 commented Dec 20, 2016

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

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

Successfully merging this pull request may close these issues.

2 participants