Skip to content
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 option to read build options from file #37

Merged
merged 9 commits into from
Sep 19, 2016
Merged

Add option to read build options from file #37

merged 9 commits into from
Sep 19, 2016

Conversation

mstade
Copy link
Member

@mstade mstade commented Sep 14, 2016

Description

Apologies for the somewhat ironic PR title. This change allows users to specify options in a file, which then gets read whenever ez-build is invoked and pointed to that file. There is no magic to how these files are found and loaded – it's entirely explicit. Whenever ez-build encounters a CLI option that starts with @, it will assume the rest of the string is a path to a file (relative to the current working dir) and load it under the assumption that the data within are more options. Files can include @ references themselves, to nest the loading of options. This means there can be any number of options files, making this a pretty flexible feature.

Motivation and Context

It came about when thinking about #27, and specifically when I wrote this comment. We've had a mounting problem of having to be increasingly wordy in our npm scripts, and as we invoke ez-build in different contexts with slightly different options, it is clear we need some way of re-using this configuration. I believe this is a good solution for that.

How Was This Tested?

  • Test added to read options a single file
  • Test added to read options nested files
  • Test added to read options even when separated by newline

These tests were added in opts-file.bats.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change follows the style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the contribution guidelines
  • I have added tests to cover my changes
  • All new and existing tests passed

Well this is ironic. No idea how to test this either.
Without the `run`, we don't get the special vars `status` and `output`
set by bats, which makes testing a pain. This doesn't seem to break
any tests.
Inspired by this [comment][1] on #27, this change adds the ability
for ez-build to read options from files, and placing their contents
precisely in the order the user intended. This is essentially the
same as just printing the contents of the files verbatim, taking
care to allow newlines by splitting on *all* whitespace.

This allows us to re-use ez-build configuration across scripts,
in a very predictable and explicit manner, as opposed to having
magical lookup rules that can be hard to reason about.

[1]: #27 (comment)
Also change the docs to go with the `build:dev` script convention
rather than just `dev`. I don't have any good reasons for this,
other than it looks neater.
@mstade
Copy link
Member Author

mstade commented Sep 14, 2016

Bumped minor version because of the feature change.

@codecov-io
Copy link

codecov-io commented Sep 14, 2016

Current coverage is 85.21% (diff: 100%)

Merging #37 into master will increase coverage by 4.06%

@@             master        #37   diff @@
==========================================
  Files            15         15          
  Lines           244        257    +13   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits            198        219    +21   
+ Misses           46         38     -8   
  Partials          0          0          

Powered by Codecov. Last update d017e6b...9c50241

@mstade mstade changed the title Allow option to read build options from file Add option to read build options from file Sep 14, 2016
@mstade
Copy link
Member Author

mstade commented Sep 15, 2016

@mamapitufo – a penny for your thoughts!

@mstade
Copy link
Member Author

mstade commented Sep 16, 2016

@DimitarChristoff, @Poetro – would love to hear your thoughts on this as well!

@mamapitufo
Copy link

I like it! Good decision on going explicit, and the implementation is very simple.

@mstade
Copy link
Member Author

mstade commented Sep 17, 2016

@mamapitufo I miss working with you on a daily basis man, thanks for the feedback! :o)

```

## Using ez-build in npm scripts

A typical scripts section of a package.json when using ez-build looks something like this:

```json
{ "dev": "ez-build --interactive"
, "build": "ez-build --production"
{ "build": "ez-build --production"
Copy link
Contributor

@DimitarChristoff DimitarChristoff Sep 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would personally prefer to see env === 'production' or env === 'development' due to the nature of many other bits (like react) being aware of the env setting and changing output.

then the script diffs can become cross-env env=production ez-build with a sensible default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I didn't know that. I didn't find much by way of documentation on this, but what I could find, and from the issues in the React repo, it seems there are significant sections of code affected by the __DEV__ global, presumably set to whatever NODE_ENV is set to at build time (although I couldn't find this.) This whole thing also seem somewhat contentious, with changes possibly coming down the line.

I don't think moving to an unconventional environment variable API (with the cross platform issues it entails no less, as you point out) instead of your typical CLI flags makes sense. This would mean there are at least three ways to configure ez-build, and that's at least one too many I'd say. That said, I definitely see the value of setting NODE_ENV (I'm assuming that's what you meant to say, not env, but please do educate me otherwise!) during build time – not least if there are tools we use that provide significant benefits based on the switching of this variable. I created #38, where it can be discussed further – thanks for bringing it up!


```json
{
"build": "ez-build --production --include \"js:**/*.js,js:**/*.jsx\" --flags es2017",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this supports glob patterns, you could write it as js:**/*.{js,jsx} - but it may also potentially benefit from not coupling to a structure that has a js folder - it could well be scripts or src or whatever.

Copy link
Member Author

@mstade mstade Sep 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point re: globs! Unfortunately, due to how ez-build parses this flag, it probably won't work even though it does support globs. I'd consider this a bug, and we should fix it because you're right – this should be supported.

Regarding your second statement about a js folder – the js: part doesn't actually refer to any kind of directory structure. It's just a label for the JS pipeline, so --include "js:**/*.{js,jsx}" just means "for the JS pipeline, include these files in the build process." By default, ez-build assumes sources are found under src/, but this can be overridden by the -i|--src flag or by setting the directories key in package.json. The readme has more info on this as well.

@mstade mstade merged commit 7f88c57 into master Sep 19, 2016
@mstade mstade deleted the opts-file branch September 19, 2016 20:07
@mstade mstade mentioned this pull request Sep 21, 2016
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants