run.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import gulp from 'gulp';
  2. import browserSync from 'browser-sync';
  3. import historyApiFallback from 'connect-history-api-fallback/lib';
  4. import project from '../aurelia.json';
  5. import build from './build';
  6. import {CLIOptions} from 'aurelia-cli';
  7. function log(message) {
  8. console.log(message); //eslint-disable-line no-console
  9. }
  10. function onChange(path) {
  11. log(`File Changed: ${path}`);
  12. }
  13. function reload(done) {
  14. browserSync.reload();
  15. done();
  16. }
  17. let serve = gulp.series(
  18. build,
  19. done => {
  20. browserSync({
  21. online: false,
  22. open: false,
  23. port: 9000,
  24. logLevel: 'silent',
  25. server: {
  26. baseDir: ['.'],
  27. middleware: [historyApiFallback(), function(req, res, next) {
  28. res.setHeader('Access-Control-Allow-Origin', '*');
  29. next();
  30. }]
  31. }
  32. }, function(err, bs) {
  33. let urls = bs.options.get('urls').toJS();
  34. log(`Application Available At: ${urls.local}`);
  35. log(`BrowserSync Available At: ${urls.ui}`);
  36. done();
  37. });
  38. }
  39. );
  40. let refresh = gulp.series(
  41. build,
  42. reload
  43. );
  44. let watch = function() {
  45. gulp.watch(project.transpiler.source, refresh).on('change', onChange);
  46. gulp.watch(project.markupProcessor.source, refresh).on('change', onChange);
  47. gulp.watch(project.cssProcessor.source, refresh).on('change', onChange);
  48. };
  49. let run;
  50. if (CLIOptions.hasFlag('watch')) {
  51. run = gulp.series(
  52. serve,
  53. watch
  54. );
  55. } else {
  56. run = serve;
  57. }
  58. export default run;