Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Add --watch flag to serve command #23

Closed
raphaelokon opened this issue Jan 6, 2017 · 3 comments
Closed

Add --watch flag to serve command #23

raphaelokon opened this issue Jan 6, 2017 · 3 comments

Comments

@raphaelokon
Copy link
Contributor

This is a must-have for all PatternLab power users, so that they can specify their own paths to watch

@bmuenzenmeyer
Copy link
Member

thinking about this a bit more - I think we actually are in luck of sorts.

most/all of the watches that come with editions are defined from the paths object found on the patternlab-config.json object anyways. what this means is that we can, with reasonable confidence, watch those paths and file types internally as a black box for users - under normal circumstances they have no need to alter the watch. we don't need to supply an array of globs to watch if we use the paths object and blackbox the watches against them!

take this snippet from the edition-node-gulp gulpfile.js

  var patternWatches = [
    resolvePath(paths().source.patterns) + '/**/*.json',
    resolvePath(paths().source.patterns) + '/**/*.md',
    resolvePath(paths().source.data) + '/*.json',
    resolvePath(paths().source.fonts) + '/*',
    resolvePath(paths().source.images) + '/*',
    resolvePath(paths().source.meta) + '/*',
    resolvePath(paths().source.annotations) + '/*'
  ].concat(getTemplateWatches());

  gulp.watch(patternWatches, { awaitWriteFinish: true }).on('change', gulp.series(build, reload));

all this really equates to is "hey PL, build again when something you care about and already use changes"

the css is one place where, in my mind, we can optimize things by directly injecting via BS. again from the gulpfile:

  gulp.watch(resolvePath(paths().source.css) + '/**/*.css', { awaitWriteFinish: true }).on('change', gulp.series('pl-copy:css', reloadCSS));
  gulp.watch(resolvePath(paths().source.styleguide) + '/**/*.*', { awaitWriteFinish: true }).on('change', gulp.series('pl-copy:styleguide', 'pl-copy:styleguide-css', reloadCSS));

we can do that on behalf of users too I think.

anyone that wants to do something with their asset pipeline still can, knowing that once changes hit our watched directories, PL takes over if need be

we might need to be careful about this snippet, however, which supports watching whichever template extensions a user has engines for

// watch task utility functions
function getSupportedTemplateExtensions() {
  var engines = require('./node_modules/patternlab-node/core/lib/pattern_engines');
  return engines.getSupportedFileExtensions();
}
function getTemplateWatches() {
  return getSupportedTemplateExtensions().map(function (dotExtension) {
    return resolvePath(paths().source.patterns) + '/**/*' + dotExtension;
  });
}

I think this can likely be internalized too

I will open a different issue discussing remaining browsersync server options to consider.

@raphaelokon
Copy link
Contributor Author

Thanks … this sounds great and mitigates a lot of boilerplate

@raphaelokon raphaelokon changed the title Add --watch flag to serve command Add --watch flag to build command Jan 17, 2017
@raphaelokon raphaelokon changed the title Add --watch flag to build command Add --watch flag to serve command Feb 2, 2017
@raphaelokon raphaelokon added this to Backlog in CLI Development Feb 2, 2017
@raphaelokon raphaelokon moved this from Backlog to Development in CLI Development Feb 2, 2017
@raphaelokon
Copy link
Contributor Author

Fixed via c696a6a

@raphaelokon raphaelokon moved this from Development to Done in CLI Development Mar 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

No branches or pull requests

2 participants