Example #1
0
App.prototype.watch = function(glob, opts, fn) {
  if (Array.isArray(opts) || typeof opts === 'function') {
    fn = opts; opts = null;
  }
  if (!Array.isArray(fn)) return vfs.watch(glob, opts, fn);
  return vfs.watch(glob, opts, function () {
    this.start.apply(this, fn);
  }.bind(this));
};
Example #2
0
Assemble.prototype.watch = function(glob, options, fn) {
  if (typeof options === 'function' || Array.isArray(options)) {
    fn = options;
    options = null;
  }

  // Tasks to watch
  if (Array.isArray(fn)) {
    return fs.watch(glob, options, function() {
      this.start.apply(this, fn);
    }.bind(this));
  }
  return fs.watch(glob, options, fn);
};
Example #3
0
Gulp.prototype.watch = function(glob, opt, fn) {
  if (typeof opt === 'function' || Array.isArray(opt)) {
    fn = opt;
    opt = null;
  }

  // array of tasks given
  if (Array.isArray(fn)) {
    return vfs.watch(glob, opt, function() {
      this.start.apply(this, fn);
    }.bind(this));
  }

  return vfs.watch(glob, opt, fn);
};
Example #4
0
IonicServeTask.prototype._start = function(ionic) {
  var self = this;

  var app = connect();

  if(this.runLivereload) {
    vfs.watch('www/**/*', {
    }, function(f) {
      self._changed(f.path);
    });

    server = tinylr();
    server.listen(this.liveReloadPort, function(err) {
      if(err) {
        ionic.fail('Unable to start server:', err);
      } else {
        console.log('Running live reload server at', ('http://0.0.0.0:' + self.liveReloadPort).info.bold);
        if(self.launchBrowser) {
          open('http://localhost:' + self.port);
        }
      }
    });

    app.use(require('connect-livereload')({
      port: this.liveReloadPort
    }))
  }

  app.use(connect.static('www'))
    .listen(this.port);
  
  console.log('Running dev server at', ('http://0.0.0.0:' + this.port).info.bold);
};
Example #5
0
IonicServeTask.prototype._start = function(ionic) {
  var self = this;
  var app = connect();

  if (!fs.existsSync( path.resolve('www') )) {
    return ionic.fail('"www" directory cannot be found. Make sure the working directory is an Ionic project.');
  }

  if(this.watchSass) {
    var childProcess = spawn('gulp', ['watch']);

    childProcess.stdout.on('data', function (data) {
      process.stdout.write(data);
    });

    childProcess.stderr.on('data', function (data) {
      if(data) {
        process.stderr.write(data.toString().yellow);
      }
    });
  }

  if(this.runLivereload) {
    vfs.watch('www/**/*', {
    }, function(f) {
      self._changed(f.path);
    });

    server = tinylr();
    server.listen(this.liveReloadPort, function(err) {
      if(err) {
        return ionic.fail('Unable to start live reload server:', err);
      } else {
        console.log('Running live reload server:'.green.bold, (self.host(self.liveReloadPort).bold) );
        if(self.launchBrowser) {
          open( self.host(self.port) );
        }
      }
    });

    app.use(require('connect-livereload')({
      port: this.liveReloadPort
    }));
  }

  app.use(connect.static('www'))
    .listen(this.port);

  console.log('Running dev server:'.green.bold, ( this.host(this.port) ).bold);

  process.stdin.on('readable', function() {
    var chunk = process.stdin.read();
    if (chunk !== null && /exit|quit|close|stop/gi.test(chunk)) {
      process.exit();
    }
  });
};
Example #6
0
IonicServeTask.prototype._start = function(ionic) {
  var self = this;
  var app = connect();

  if (!fs.existsSync( path.resolve('www') )) {
    return ionic.fail('"www" directory cannot be found. Make sure the working directory is an Ionic project.');
  }

  if(this.runLivereload) {
    vfs.watch('www/**/*', {
    }, function(f) {
      self._changed(f.path);
    });

    server = tinylr();
    server.listen(this.liveReloadPort, function(err) {
      if(err) {
        return ionic.fail('Unable to start live reload server:', err);
      } else {
        console.log('Running live reload server at', (self.host(self.liveReloadPort).info.bold) );
        if(self.launchBrowser) {
          open( self.host(self.port) );
        }
      }
    });

    app.use(require('connect-livereload')({
      port: this.liveReloadPort
    }));
  }

  app.use(connect.static('www'))
    .listen(this.port);

  console.log('Running dev server at', ( this.host(this.port) ).info.bold);
};
Example #7
0
IonicTask.prototype.start = function(ionic) {
  try {
    var self = this;
    var app = connect();

    if (!fs.existsSync( path.resolve(this.documentRoot) )) {
      return ionic.fail('"www" directory cannot be found. Please make sure the working directory is an Ionic project.');
    }

    // gulpStartupTasks should be an array of tasks set in the project config
    // watchSass is for backwards compatible sass: true project config
    if((this.gulpStartupTasks && this.gulpStartupTasks.length) || this.watchSass) {
      var spawn = require('cross-spawn').spawn;
      var tasks = this.gulpStartupTasks || ['sass','watch'];

      console.log('Gulp startup tasks:'.green.bold, tasks);
      var childProcess = spawn('gulp', tasks);

      childProcess.stdout.on('data', function (data) {
        process.stdout.write(data);
      });

      childProcess.stderr.on('data', function (data) {
        if(data) {
          process.stderr.write(data.toString().yellow);
        }
      });
    }

    if(this.runLivereload) {

      vfs.watch(self.watchPatterns, {},function(f) {
        self._changed(f.path);
      });

      self.liveReloadServer = self.host(self.liveReloadPort);

      var lrServer = tinylr();
      lrServer.listen(this.liveReloadPort, function(err) {
        if(err) {
          return ionic.fail('Unable to start live reload server:', err);
        } else {
          console.log('Running live reload server:'.green.bold, self.liveReloadServer );
          console.log('Watching :'.green.bold, self.watchPatterns);
          if(self.launchBrowser) {
            var open = require('open');
            open( self.host(self.port) );
          }
          self.printCommandTips();
        }
      });

      app.use(require('connect-livereload')({
        port: this.liveReloadPort
      }));
    }

    this.devServer = this.host(this.port);

    // Serve up the www folder by default
    var serve = serveStatic(this.documentRoot);

    // Create static server
    var server = http.createServer(function(req, res){
      var done = finalhandler(req, res);

      var platformUrl = getPlatformUrl(req);
      if(platformUrl) {
        var platformWWW = getPlatformWWW(req);

        if(self.isPlatformServe) {
          fs.readFile( path.resolve(path.join(platformWWW, platformUrl)), function (err, buf) {
            res.setHeader('Content-Type', 'application/javascript');
            if (err) {
              res.end('// mocked cordova.js response to prevent 404 errors during development');
              if(req.url == '/cordova.js') {
                self.serverLog(req, '(mocked)');
              } else {
                self.serverLog(req, '(Error ' + platformWWW + ')');
              }
            } else {
              self.serverLog(req, '(' + platformWWW + ')');
              res.end(buf);
            }
          });
        } else {
          self.serverLog(req, '(mocked)');
          res.setHeader('Content-Type', 'application/javascript');
          res.end('// mocked cordova.js response to prevent 404 errors during development');
        }
        return;
      }

      if(self.printConsoleLogs && req.url === '/__ionic-cli/console') {
        self.consoleLog(req);
        res.end('');
        return;
      }

      if(req.url.split('?')[0] === '/') {
        fs.readFile( path.resolve(self.contentSrc), 'utf8', function (err, buf) {
          res.setHeader('Content-Type', 'text/html');
          if (err) {
            self.serverLog(req, 'ERROR!');
            res.end(err.toString());
          } else {
            self.serverLog(req, '(' + self.contentSrc + ')');

            var html = injectGoToScript( buf.toString('utf8') );

            if(self.printConsoleLogs) {
              html = injectConsoleLogScript(html);
            }

            res.end(html);
          }
        });
        return;
      }

      // root www directory file
      self.serverLog(req);
      serve(req, res, done);
    });

    // Listen
    app.use(server);
    app.listen(this.port);

    console.log('Running dev server:'.green.bold, this.devServer);

  } catch(e) {
    var msg;
    if(e && (e + '').indexOf('EMFILE') > -1) {
      msg = (e + '\n').error.bold +
            'The watch process has exceed the default number of files to keep open.\n'.error.bold +
            'You can change the default with the following command:\n\n'.error.bold +
            '  ulimit -n 1000\n\n' +
            'In the command above, it\'s setting the default to watch a max of 1000 files.\n\n'.error.bold;

    } else {
      msg = ('server start error: ' + e).error.bold;
    }
    console.log(msg);
    process.exit(1);
  }
};
Example #8
0
    help: 'orientation of the sprite image (vertical|horizontal|binary-tree)'
  })
  .option('prefix', {
    help: 'prefix for the class name used in css (without .)'
  })
  .option('no-sort', {
    flag: true,
    help: 'disable sorting of layout'
  })
  .script('css-sprite')
  .parse();

if (opts.watch) {
  if (opts['no-sort']) {
    opts.sort = false;
  }
  console.log('Watching for file changes ...');
  fs.watch(opts.src, function () {
    sprite.create(opts, function () {
      console.log('> Sprite created in ' + opts.out);
    });
  });
}
else {
  if (opts['no-sort']) {
    opts.sort = false;
  }

  sprite.create(opts);
}
Example #9
0
IonicTask.prototype.start = function(ionic) {
  try {
    var self = this;
    var app = connect();

    if (!fs.existsSync( path.resolve('www') )) {
      return ionic.fail('"www" directory cannot be found. Please make sure the working directory is an Ionic project.');
    }

    // gulpStartupTasks should be an array of tasks set in the project config
    // watchSass is for backwards compatible sass: true project config
    if((this.gulpStartupTasks && this.gulpStartupTasks.length) || this.watchSass) {
      var spawn = require('cross-spawn').spawn;
      var tasks = this.gulpStartupTasks || ['sass','watch'];

      console.log('Gulp startup tasks:'.green.bold, tasks);
      var childProcess = spawn('gulp', tasks);

      childProcess.stdout.on('data', function (data) {
        process.stdout.write(data);
      });

      childProcess.stderr.on('data', function (data) {
        if(data) {
          process.stderr.write(data.toString().yellow);
        }
      });
    }

    if(this.runLivereload) {

      vfs.watch(self.watchPatterns, {},function(f) {
        self._changed(f.path);
      });

      self.liveReloadServer = self.host(self.liveReloadPort);

      var lrServer = tinylr();
      lrServer.listen(this.liveReloadPort, function(err) {
        if(err) {
          return ionic.fail('Unable to start live reload server:', err);
        } else {
          console.log('Running live reload server:'.green.bold, self.liveReloadServer );
          console.log('Watching :'.green.bold, self.watchPatterns);
          if(self.launchLab) {
            var open = require('open');
            open( self.host(self.port) + IONIC_LAB_URL );
          } else if(self.launchBrowser) {
            var open = require('open');
            open( self.host(self.port) );
          }
          self.printCommandTips();
        }
      });

      app.use(require('connect-livereload')({
        port: this.liveReloadPort
      }));
    }

    if(this.useProxy) {

      for(var x=0; x<this.proxies.length; x++) {
        var proxy = this.proxies[x];

        app.use(proxy.path, proxyMiddleware(url.parse(proxy.proxyUrl)));
        console.log('Proxy added:'.green.bold, proxy.path + " => " + url.format(proxy.proxyUrl));
      }
    }


    this.devServer = this.host(this.port);

    // Serve up the www folder by default
    var serve = serveStatic('www');

    // Create static server
    var server = http.createServer(function(req, res){
      var done = finalhandler(req, res);

      var urlParsed = url.parse(req.url, true);
      var platformOverride = urlParsed.query && urlParsed.query.ionicplatform;

      var platformUrl = getPlatformUrl(req);
      if(platformUrl) {
        var platformWWW = getPlatformWWW(req);

        if(self.isPlatformServe) {
          fs.readFile( path.resolve(path.join(platformWWW, platformUrl)), function (err, buf) {
            res.setHeader('Content-Type', 'application/javascript');
            if (err) {
              res.end('// mocked cordova.js response to prevent 404 errors during development');
              if(req.url == '/cordova.js') {
                self.serverLog(req, '(mocked)');
              } else {
                self.serverLog(req, '(Error ' + platformWWW + ')');
              }
            } else {
              self.serverLog(req, '(' + platformWWW + ')');
              res.end(buf);
            }
          });
        } else {
          self.serverLog(req, '(mocked)');
          res.setHeader('Content-Type', 'application/javascript');
          res.end('// mocked cordova.js response to prevent 404 errors during development');
        }
        return;
      }

      if(self.printConsoleLogs && req.url === '/__ionic-cli/console') {
        self.consoleLog(req);
        res.end('');
        return;
      }

      if(req.url === IONIC_LAB_URL) {
        // Serve the lab page with the given object with template data
        var labServeFn = function(context) {
          fs.readFile(path.resolve(path.join(__dirname, 'assets/preview.html')), function(err, buf) {
            var html;
            if(err) {
              res.end('404');
            } else {
              html = buf.toString('utf8');
              html = html.replace('//INSERT_JSON_HERE', 'var BOOTSTRAP = ' + JSON.stringify(context || {}));
            }
            res.setHeader('Content-Type', 'text/html');
            res.end(html);
          });
        };

        // If the config.xml file exists, let's parse it for some nice features like
        // showing the name of the app in the title
        if(fs.existsSync('config.xml')) {
          fs.readFile(path.resolve('config.xml'), function(err, buf) {
            var xml = buf.toString('utf8');
            xml2js.parseString(xml, function (err, result) {
              labServeFn({
                appName: result.widget.name[0]
              });
            });
          });
        } else {
          labServeFn();
        }

        return;
      }

      if(req.url.split('?')[0] === '/') {
        fs.readFile( path.resolve(self.contentSrc), 'utf8', function (err, buf) {
          res.setHeader('Content-Type', 'text/html');
          if (err) {
            self.serverLog(req, 'ERROR!');
            res.end(err.toString());
          } else {
            self.serverLog(req, '(' + self.contentSrc + ')');

            var html = injectGoToScript( buf.toString('utf8') );

            if(self.printConsoleLogs) {
              html = injectConsoleLogScript(html);
            }

            if(platformOverride) {
              html = injectPlatformScript( html, platformOverride );
            }

            res.end(html);
          }
        });
        return;
      }

      // root www directory file
      self.serverLog(req);
      serve(req, res, done);
    });

    // Listen
    app.use(server);
    app.listen(this.port);

    console.log('Running dev server:'.green.bold, this.devServer);

  } catch(e) {
    var msg;
    if(e && (e + '').indexOf('EMFILE') > -1) {
      msg = (e + '\n').error.bold +
            'The watch process has exceed the default number of files to keep open.\n'.error.bold +
            'You can change the default with the following command:\n\n'.error.bold +
            '  ulimit -n 1000\n\n' +
            'In the command above, it\'s setting the default to watch a max of 1000 files.\n\n'.error.bold;

    } else {
      msg = ('server start error: ' + e).error.bold;
    }
    console.log(msg);
    process.exit(1);
  }
};
Example #10
0
 watch: function (globs, opt, cb) {
   return vfs.watch(globs, _.defaults(opt, defaultBrowserFsOpts), cb);
 }
Example #11
0
        .on('error', function onErrorFn (err) {
            if (require.main === module) { console.error(err); }
            events.emit('error', err);
        });
};

if (require.main === module) {
    //Run
    runner();

    //Output for unix interop
    events.on('error', function (e) {
        process.stderr.write(e);
    });
    events.on('report', function (r) {
        process.stdout.write(r);
    });
}

if (program.watch) {
    //Run runner if files changes
    vinylfs.watch(program.dir, runner);
}



module.exports = {
    run: runner,
    events: events
};