Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Serve and open built files #219

Merged
merged 30 commits into from
Aug 23, 2017
Merged

Serve and open built files #219

merged 30 commits into from
Aug 23, 2017

Conversation

Blackbaud-BobbyEarl
Copy link

@Blackbaud-BobbyEarl Blackbaud-BobbyEarl commented Jul 13, 2017

This modification exposes the -l or --launch flag to skyux build, which will accept local and host as values. Essentially, it easily allows a "built" SPA to be served.

blackbaud/skyux2#562
blackbaud/skyux2#890

@codecov-io
Copy link

codecov-io commented Jul 14, 2017

Codecov Report

Merging #219 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #219   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          56     58    +2     
  Lines        1305   1340   +35     
  Branches      195    197    +2     
=====================================
+ Hits         1305   1340   +35
Flag Coverage Δ
#builder 100% <100%> (ø) ⬆️
#runtime 100% <ø> (ø) ⬆️
#srcapp 100% <ø> (ø) ⬆️
Impacted Files Coverage Δ
cli/build.js 100% <100%> (ø) ⬆️
config/webpack/serve.webpack.config.js 100% <100%> (ø) ⬆️
cli/utils/browser.js 100% <100%> (ø)
utils/runtime-test-utils.js 100% <100%> (ø) ⬆️
cli/e2e.js 100% <100%> (ø) ⬆️
loader/sky-pages-module/index.js 100% <100%> (ø) ⬆️
lib/sky-pages-module-generator.js 100% <100%> (ø) ⬆️
cli/utils/stage-library-ts.js 100% <100%> (ø) ⬆️
index.js 100% <100%> (ø) ⬆️
cli/utils/server.js 100% <100%> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 96960aa...bdc59f5. Read the comment docs.

@@ -66,10 +66,10 @@ function getFileContents(filePath) {
switch (path.extname(filePath)) {
case '.scss':
contents = compileSass(filePath);
break;
break;

Choose a reason for hiding this comment

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

It's unclear how this got in to start with, but the linter complained to be about the spacing.

@Blackbaud-BobbyEarl Blackbaud-BobbyEarl changed the title Serve and open built files [HOLD] Serve and open built files Jul 14, 2017
@Blackbaud-BobbyEarl
Copy link
Author

Hey @Blackbaud-SteveBrush and @Blackbaud-PaulCrowder, this one is ready for review.

The factoring out of server.js and browser.js so they could be shared across different CLI commands, unfortunately meant I had to move quite a bit of the hoisting I would doing for tests to different locations (which is why the PR looks so large).

Let me know if you have any questions or want to talk through any of it.

@Blackbaud-BobbyEarl Blackbaud-BobbyEarl changed the title [HOLD] Serve and open built files Serve and open built files Aug 18, 2017
@Blackbaud-SteveBrush
Copy link
Member

@Blackbaud-BobbyEarl: Launching on localhost works great!

skyux build --launch local
skyux build -l local

However, when using --launch host, it seems that locales aren't being parsed correctly:

screen shot 2017-08-18 at 2 27 32 pm

@Blackbaud-SteveBrush
Copy link
Member

One last comment, and this is just a matter of preference: it might be nice to have a default value, so that consumers could type skyux build -l.

@Blackbaud-BobbyEarl
Copy link
Author

Thanks for the feedback @Blackbaud-SteveBrush. Based on it, I've implemented the following changes:

  • Adjusted the flag to --serve or -s. This frees up the --launch flag to be used exactly as it is with skyux serve, accepting none, local, and host (default) as values. This is also handy when running the command more than once, meaning you can skyux build -s the first time, and skyux build -s -l none on subsequent runs.
  • Fixed the resources/assets not loading when launching host.

These together mean you can run some pretty neat commands, for example to launch the local url in safari... skyux build -s -l local -b safari. Anyway, it's ready for review again.

@@ -91,6 +85,7 @@ function spawnProtractor(chunks, port, skyPagesConfig) {
protractorPath,
[
getProtractorConfigPath(),
`--disableChecks`,

Choose a reason for hiding this comment

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

FYI, adding this check to solve the "unknown arguments" warning (soon to be error) that's shown. https://github.com/angular/protractor/blob/master/CHANGELOG.md#features-3

cli/build.js Outdated
} else if (argv.serve) {
buildServe(argv, skyPagesConfig, webpack, isAot);
} else {
return buildPromise(argv, skyPagesConfig, webpack, isAot);

Choose a reason for hiding this comment

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

Curious why we're returning the promise for buildPromise, but not for buildServe? Would it be appropriate to also catch any server errors?

function buildServe(argv, skyPagesConfig, webpack, isAot) {
  return server.start(skyPagesConfigUtil.getAppBase(skyPagesConfig))
    .then(port => {
      argv.assets = argv.assets || `https://localhost:${port}`;
      return buildPromise(argv, skyPagesConfig, webpack, isAot);
    })
    .then(stats => browser(argv, skyPagesConfig, stats, port));
}

Choose a reason for hiding this comment

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

This also makes me wonder if we were ever handling failures during the build step. Aside from linting errors, I don't see a process.exit for build issues. Is that by design?

Choose a reason for hiding this comment

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

If skyux build fails outside of linting, the ProcessExitCode plugin calls process.exit.

I was really only concerned with returning a promise from buildPromise knowing that cli/e2e.js imports build, which wouldn't be passing the serve command. It definitely makes sense to make the signature the same (always returning a promise) regardless of the arguments.

tl;dr I'm going to push an update to always have build return a promise, but process.exit is handled in the webpack plugin.

Choose a reason for hiding this comment

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

Gotcha. That makes sense!

Copy link
Author

@Blackbaud-BobbyEarl Blackbaud-BobbyEarl Aug 21, 2017

Choose a reason for hiding this comment

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

Wonder if I should still reject the promise, even if it's linting that fails? I'm thinking so, such that the command always returns a promise regardless of what actually failed.

@@ -218,7 +177,7 @@ function e2e(argv, skyPagesConfig, webpack) {
return killServers(0);
}

spawnServer()
server.start()

Choose a reason for hiding this comment

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

So much cleaner; love it.

} else {

const url = 'https://github.com/blackbaud/skyux-template';
const branch = 'master';

Choose a reason for hiding this comment

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

I pointed the branch to builder-dev (a protected branch) so that we could adjust the template as needed without affecting what consumers are cloning when typing skyux new. Unsure how you feel about this.

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

(This is also helpful for when we have various versions of SKY UX that need to be tested during a Travis build.)

Copy link
Author

@Blackbaud-BobbyEarl Blackbaud-BobbyEarl Aug 21, 2017

Choose a reason for hiding this comment

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

Changing this wasn't intentional... chalking it up to me being ignorant when resolving merge conflicts.

Learning about it though, I'm torn. It seems nice for development for new features in builder that may require a change to the template. On the other hand, running builder's e2e tests is used to test that skyux new runs as intended for consumers, in which case they'd be using the master branch.

I'll change it back to builder-dev for the sake of this PR and we can talk more about it later.

Copy link
Member

@Blackbaud-SteveBrush Blackbaud-SteveBrush left a comment

Choose a reason for hiding this comment

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

This is non-blocking feedback (because the feature works fantastically), but the build promise chain could be simplified a bit since all of the various methods return promises already (removed all new Promise, resolve, reject, etc.):

// ...

function buildServe(argv, skyPagesConfig, webpack, isAot) {
  return server.start(skyPagesConfigUtil.getAppBase(skyPagesConfig))
    .then(port => {
      argv.assets = argv.assets || `https://localhost:${port}`;
      return buildCompiler(argv, skyPagesConfig, webpack, isAot)
        .then(stats => browser(argv, skyPagesConfig, stats, port));
    });
}

function buildCompiler(argv, skyPagesConfig, webpack, isAot) {
  // ...

  return runCompiler(webpack, config, isAot)
    .then(stats => {
      if (isAot) {
        cleanupAot();
      }

      return stats;
    });
}

function build(argv, skyPagesConfig, webpack) {
  // ...
  const name = argv.serve ? buildServe : buildCompiler;
  return name(argv, skyPagesConfig, webpack, isAot);
}

// ...

@Blackbaud-BobbyEarl
Copy link
Author

Any feedback before this gets merged in @Blackbaud-PaulCrowder?

@Blackbaud-BobbyEarl Blackbaud-BobbyEarl merged commit 37878bb into master Aug 23, 2017
@Blackbaud-BobbyEarl Blackbaud-BobbyEarl deleted the serve-build branch August 23, 2017 17:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants