rejoice icon indicating copy to clipboard operation
rejoice copied to clipboard

Javascript File

Open ar4mirez opened this issue 11 years ago • 10 comments

Would you accept a PR for loading .js file ?

Why?

I would like to use some values based on environments, for example i want to run on the port 1337 if is local and 80 if production, this just an example but give you an idea why i would like to have that feature.

Thanks.

ar4mirez avatar Aug 17 '15 19:08 ar4mirez

Though I am not opposed to this idea, we already use confidence to do what you describe. I usually use it like a command utility and set up a 'env' filter for just such a thing and then use rejoice to start up the generated confidence file. Rejoice is also just based on the 'glue' module and may be more the style you you prefer. After you review these let me know if you still think there is a useful need.

As an aside I was curious how this passes with no extra tests. Obviously the use case of an extra function still seems to be passing despite no tests being added. Seems like we may have a bug in lab maybe with the switch statement (I don't personally use those). So I need to investigate what's going on there.

lloydbenson avatar Aug 18 '15 00:08 lloydbenson

@lloydbenson i totally understand and of course i'll have to write the proper tests but i had some issues running the current tests locally that's why i tried with the travis to see if i was doing something wrong. I see your point and yes Glue really those the job and the approach you suggesting with the CLi with confidence is actually a great idea i just wonder if we could cut some steps just allowing js files that we can just manipulate easier in my case using habitat.

About the switch statement yes agreed with you now that i see we might be able to use a different path like Joi for example something like:

var ExtensionParser = require('./extParser');

...

var allowedExt = Joi.any().valid(['.js', '.json']) // this could be also exported from the extParser
var isValidExt = Joi.validate(manifestExt , allowedExt);
if (!isValidExt.value) {
   thrown new Error('Failed loading configuration file: ' + args.c + ' (' + err.message + ')');
}

manifest = ExtensionParser[manifestExt].parse(manifestPath);

...

The having another file that exports parsers functions like

module.exports = {
  '.js' : jsParser,   // I'm not entirely happy with this just writing draft code
  '.json': jsonParser
};

I don't know if this make more sense, but i think is a little more readable ?

Let me know your thoughts on this ?

ar4mirez avatar Aug 20 '15 13:08 ar4mirez

Ok, sounds like you still find this valuable despite the other tooling. I am still a bit unclear of how this solves your different port problem which was the original use case. I assume the real use case is that you just prefer to use the javascript manifest directly rather than json. Is that accurate?

lloydbenson avatar Aug 20 '15 17:08 lloydbenson

Yes personally I see really helpful to have this feature, but also I respect if you see that there no value or is not in the scope of what you want to accomplish with this package. :D

ar4mirez avatar Aug 21 '15 13:08 ar4mirez

I just wanted to make sure it was addressing the goal. So next step is open an issue, and lets get community feedback quick to see if its a useful feature for more than 1 person. I am more open to this format as its still javascript and no extra dependencies are required. (As opposed to yml, xml, etc).

lloydbenson avatar Aug 21 '15 13:08 lloydbenson

Sorry thought this was still the PR, issue already there.

lloydbenson avatar Aug 21 '15 13:08 lloydbenson

Is anyone else interested in this feature? Please +1 if you are.

lloydbenson avatar Aug 21 '15 13:08 lloydbenson

Ok, theres interest. So to finish this up, let's stick to a simple if statement on the extension rather than a case statement, add a test (this should be required for full coverage) and lets not do any additional require as its pretty small.

lloydbenson avatar Aug 21 '15 15:08 lloydbenson

Thanks @lloydbenson i'm working on this now i was busy with a big project but i'm back now :D

ar4mirez avatar Sep 01 '15 20:09 ar4mirez

Closed via https://github.com/hapijs/rejoice/pull/31.

lloydbenson avatar Sep 10 '15 13:09 lloydbenson