Example #1
0
 config.bundler.on('time', time => {
   gutil.log(gutil.colors.cyan('watchify'),
     're-bundled', 'after', gutil.colors.magenta(time > 1000 ? time / 1000 + ' s' : time + ' ms'))
 })
Example #2
0
function replace(opts) {
  var config = _.assign({
    cwd: undefined,
    module: undefined,
    refModuleList: [],
    replaceType: 'local',
    serve: false,
    release: false
  }, opts);
  
  config.base64Opts = config.base64Opts || {
    enable: false,
    exclude: [],
    size: 5000
  };

  if (!config.cwd || !config.module) {
    gutil.log(gutil.colors.red('传入参数有误 at replace!'));
    return;
  }
  var includeJson = {};
  config.replaceType = config.replaceType ? config.replaceType : 'local';

  var modulePath = path.join(config.cwd, config.module);
  // 读取module-conf配置文件
  config.moduleConf = require(path.join(modulePath, 'module-conf'));
  appConf = require(path.join(config.cwd, 'app-conf'));
  comboConf = (typeof appConf.comboConf === 'object') && !_.isEmpty(appConf.comboConf) ? appConf.comboConf : {
    mode: 'client'
  };
  var resourcePrefix = null;
  var mapJson = null;
  var gMapJson = null;
  try {
    mapJson = JSON.parse(fs.readFileSync(path.join(modulePath, 'dist', 'map.json')).toString());
  } catch (e) {
    mapJson = null;
  }
  if (!config.serve) {
    try {
      gMapJson = JSON.parse(fs.readFileSync(path.join(Util.getAthenaPath(), 'cache', 'common', appConf.app + '_' + appConf.common + '.json')).toString());
    } catch (e) {
      gMapJson = null;
    }
  }

  if (!_.isEmpty(mapJson)) {
    mapJSONCache[config.module] = mapJson;
  }
  if (!_.isEmpty(gMapJson)) {
    mapJSONCache[appConf.common] = gMapJson;
  }
  if (appConf && config.moduleConf) {
    var deployObj = appConf.deploy;
    resourcePrefix = {};
    for (var key in deployObj) {
      if (key === 'local') {
        resourcePrefix.local = deployObj.local ? (deployObj.local.fdPath ? deployObj.local.fdPath : '/') : '/';
      } else {
        resourcePrefix[key] = '//' + Util.urlJoin(deployObj[key].domain, deployObj[key].fdPath);
      }
    }
  }
  if (config.release) {
    resourcePrefix['release-mode'] = comboConf.server.onlineDomain;
    config.replaceType = 'release-mode';
  }
  var stream = through2.obj(function (file, encoding, callback) {
    if (file.isNull() || file.isStream()) {
      return callback(null, file);
    }
    if (file.isBuffer()) {
      var extname = path.extname(file.path);
      var basename = path.basename(file.path);
      var fileContents = file.contents.toString();
      includeJson[basename] = [];
      if (Util.regexps.js.test(extname)) {
        file.contents = new Buffer(processJs(basename, fileContents, resourcePrefix[config.replaceType], config, includeJson));
      } else if (Util.regexps.css.test(extname)) {
        file.contents = new Buffer(processCss(basename, fileContents, resourcePrefix[config.replaceType], config, includeJson));
      } else if (Util.regexps.tpl.test(extname)) {
        file.contents = new Buffer(processHtml(basename, fileContents, resourcePrefix[config.replaceType], config, includeJson));
      }
      this.push(file);
      callback();
    }
  }, function (callback) {
    var mapJsonInclude = mapJson.include;
    if (mapJsonInclude && (typeof mapJsonInclude === 'object')) {
      for (var i in mapJsonInclude) {
        var pageInclude = includeJson[i];
        if (pageInclude && pageInclude.sort) {
          mapJsonInclude[i].images = pageInclude;
        }
        var mapJsonIncludeCss = mapJsonInclude[i].css;
        if (mapJsonIncludeCss && mapJsonIncludeCss.forEach) {
          mapJsonIncludeCss.map(function (item) {
            var name = item.name;
            if (includeJson[name] && includeJson[name].sort) {
              item.images = includeJson[name];
            }
            return item;
          });
        }
        var mapJsonIncludeJs = mapJsonInclude[i].js;
        if (mapJsonIncludeJs && mapJsonIncludeJs.forEach) {
          mapJsonIncludeJs.map(function (item) {
            var name = item.name;
            if (includeJson[name] && includeJson[name].sort) {
              item.images = includeJson[name];
            }
            return item;
          });
        }
      }
      var dest = path.join(modulePath, 'dist');
      if (!fs.existsSync(dest)) {
        fs.mkdirSync(dest);
      }
      fs.writeFileSync(path.join(dest, 'map.json'), JSON.stringify(mapJson, null, 2));
    }
    callback();
  });

  return stream;
}
Example #3
0
gulp.task('hello', 'Example Task', () => {
  gutil.log(gutil.colors.green('Example Task Starting...'))

  gutil.log(gutil.colors.green('Example Task Ending...'))
})
Example #4
0
 .on('change', function (event) {        // Log the change to the console.
     gutil.log(gutil.colors.blue('File ' + event.path + ' was ' + event.type + ', test task started.'));
 });
Example #5
0
function errorHandler (err) {
  util.log(util.colors.red('Error'), err.message);
  this.end();
}
Example #6
0
 end: function(filepath) {
     var taskTime = process.hrtime(startTime);
     var prettyTime = prettyHrtime(taskTime);
     gutil.log('Bundled', gutil.colors.green(filepath), 'in', gutil.colors.magenta(prettyTime));
 }
Example #7
0
 data.stats.warnings.forEach(w => {
   gutil.log(gutil.colors.yellow("WebPack Warning:"), w);
 });
Example #8
0
 .on('log', function(data) {
   gutil.log('bower', gutil.colors.cyan(data.id), data.message);
 });
Example #9
0
 gulp.task(name, function (cb) {
     gutil.log(gutil.colors.cyan('Running task: ') + gutil.colors.magenta(name));
     return require(filePath)(angus, gulp)(cb);
 });
Example #10
0
 server.listen(conf.devServer.port, 'localhost', () => {
   gutil.log(gutil.colors.gray('-------------------------------------------'));
   gutil.log('WebpackDevServer:', gutil.colors.magenta(`http://localhost:${conf.devServer.port}`));
   gutil.log(gutil.colors.gray('-------------------------------------------'));
   done();
 });
Example #11
0
 .pipe(eslint.formatEach('stylish', function(msg) {
   errorsFound = true;
   gutil.log(gutil.colors.red(msg));
 }))
Example #12
0
module.exports = function(options) {

  var defaults = {

    /**
     *
     * BASIC DEFAULTS
     *
     **/

    host: 'localhost',
    port: 8000,
    fallback: false,
    https: false,
    open: false,

    /**
     *
     * MIDDLEWARE DEFAULTS
     *
     * NOTE:
     *  All middleware should defaults should have the 'enable'
     *  property if you want to support shorthand syntax like:
     *
     *    webserver({
     *      livereload: true
     *    });
     *
     */

    // Middleware: Livereload
    livereload: {
      enable: false,
      port: 35729,
      filter: function (filename) {
        if (filename.match(/node_modules/)) {
          return false;
        } else { return true; }
      }
    },

    // Middleware: Directory listing
    // For possible options, see:
    //  https://github.com/expressjs/serve-index
    directoryListing: {
      enable: false,
      path: './',
      options: undefined
    },

    // Middleware: Proxy
    // For possible options, see:
    //  https://github.com/andrewrk/connect-proxy
    proxies: []

  };

  // Deep extend user provided options over the all of the defaults
  // Allow shorthand syntax, using the enable property as a flag
  var config = enableMiddlewareShorthand(defaults, options, [
    'directoryListing',
    'livereload'
  ]);

  if (typeof config.open === 'string' && config.open.length > 0) {
    // ensure leading slash
    config.open = (config.open.indexOf('/') !== 0 ? '/' : '') + config.open;
  }

  var app = connect();

  var openInBrowser = function() {
    if (config.open === false) return;
    open('http' + (config.https ? 's' : '') + '://' + config.host + ':' + config.port + (typeof config.open === 'string' ? config.open : ''));
  };

  var lrServer;

  if (config.livereload.enable) {

    app.use(connectLivereload({
      port: config.livereload.port
    }));

    if (config.https) {
      if (config.https.pfx) {
        lrServer = tinyLr({
          pfx: fs.readFileSync(config.https.pfx),
          passphrase: config.https.passphrase
        });
      }
      else {
        lrServer = tinyLr({
          key: fs.readFileSync(config.https.key || __dirname + '/../ssl/dev-key.pem'),
          cert: fs.readFileSync(config.https.cert || __dirname + '/../ssl/dev-cert.pem')
        });
      }
    } else {
      lrServer = tinyLr();
    }

    lrServer.listen(config.livereload.port, config.host);

  }

  if (config.directoryListing.enable) {
    app.use(serveIndex(path.resolve(config.directoryListing.path), config.directoryListing.options));
  }

  // Proxy requests
  for (var i = 0, len = config.proxies.length; i < len; i++) {
    var proxyoptions = url.parse(config.proxies[i].target);
    if (config.proxies[i].hasOwnProperty('options')) {
      extend(proxyoptions, config.proxies[i].options);
    }
    app.use(config.proxies[i].source, proxy(proxyoptions));
  }


  var files = [];

  // Create server
  var stream = through.obj(function(file, enc, callback) {

    app.use(serveStatic(file.path));

    if (config.livereload.enable) {
      var watchOptions = {
        ignoreDotFiles: true,
        filter: config.livereload.filter
      };
      watch.watchTree(file.path, watchOptions, function (filename) {
        lrServer.changed({
          body: {
            files: filename
          }
        });

      });
    }

    this.push(file);
    callback();
  })
  .on('data', function(f){files.push(f);})
  .on('end', function(){
    if (config.fallback) {
      files.forEach(function(file){
        var fallbackFile = file.path + '/' + config.fallback;
        if (fs.existsSync(fallbackFile)) {
          app.use(function(req, res) {
            res.setHeader('Content-Type', 'text/html; charset=UTF-8');
            fs.createReadStream(fallbackFile).pipe(res);
          });
        }
      });
    }
  });

  var webserver;

  if (config.https) {
    var opts; 

    if (config.https.pfx) {
      opts = {
        pfx: fs.readFileSync(config.https.pfx),
        passphrase: config.https.passphrase
      };
    } else {
      opts = {
        key: fs.readFileSync(config.https.key || __dirname + '/../ssl/dev-key.pem'),
        cert: fs.readFileSync(config.https.cert || __dirname + '/../ssl/dev-cert.pem')
      };
    }
    webserver = https.createServer(opts, app).listen(config.port, config.host, openInBrowser);
  } else {
    webserver = http.createServer(app).listen(config.port, config.host, openInBrowser);
  }

  gutil.log('Webserver started at', gutil.colors.cyan('http' + (config.https ? 's' : '') + '://' + config.host + ':' + config.port));

  stream.on('kill', function() {

    webserver.close();

    if (config.livereload.enable) {
      lrServer.close();
    }

  });

  return stream;

};
Example #13
0
var changeEvent = function(evt) {
  gutil.log('File', gutil.colors.cyan(evt.path.replace(new RegExp('/.*(?=/' + basePaths.src + ')/'), '')), 'was', gutil.colors.magenta(evt.type));
};
Example #14
0
		b.on("log", function(e) {
			gutil.log("Bundling Successful: " + gutil.colors.gray(e));
			nginx.build();
		});
Example #15
0
   .on('error', function(err) {
     gutil.log(gutil.colors.red('Uglify error: ') + err.message);
     this.emit('end');
 })
Example #16
0
 stream.on('end', function() {
     gutil.log(gutil.colors.green('✔') + ' Bundled scripts for ' + gutil.colors.cyan(device));
 });
Example #17
0
 start: function(filepath) {
     startTime = process.hrtime();
     gutil.log('Bundling', gutil.colors.green(filepath) + '...');
 },
Example #18
0
	return generateDocs().then(function() {
		gutil.log('Docs for', gutil.colors.cyan(docVersion), 'generated!');
	});
Example #19
0
 data.stats.errors.forEach(e => {
   gutil.log(gutil.colors.red("WebPack Error:"), e);
 });
Example #20
0
 stream.on('end',function(){
     var msg = msgFunc;
     gutil.log(gutil.colors.green(msg.title),": ", gutil.colors.magenta(count+" file"+(count == 1 ? " ":"s ")),
         msg.str);
 });
Example #21
0
 data.stats.assets.forEach(a => {
   gutil.log(
     " *", gutil.colors.green(a.name),
     gutil.colors.cyan(humanizeSize(a.size))
   );
 });
Example #22
0
	logMsg: function(msg) {
		gutil.log(gutil.colors.cyan(msg));
	},
Example #23
0
 .on('error', function(err) {
   gutil.beep();
   gutil.log(gutil.colors.red(err));
 })
Example #24
0
	logErr: function(err) {
		gutil.log(gutil.colors.red(err));
	}
Example #25
0
module.exports = function(page) {
  gulp.src('src/page/' + page + '/assets/**')
    .pipe(gulp.dest('build/page/' + page + '/assets/'));
  gutil.log(gutil.colors.green('Copy assets: build/page/' + page + '/assets'));
};
Example #26
0
 .pipe(plumber(function(error){
     gutil.log(gutil.colors.red(error.message)); //Красит ошибку в красный цвет
     this.emit('end');
 }))
Example #27
0
 return function(err) {
   gutil.log(gutil.colors.red('[' + title + ']'), err.toString());
   this.emit('end');
 };
Example #28
0
 .on('error', function(err) {
   gutil.log(gutil.colors.red('Browserify bundle error: ') + err);
   this.emit('end');
 })
 .pipe(plumber(function(error) {
      gutil.log(gutil.colors.red(error.message));
      gutil.beep();
      this.emit('end');
  }))
Example #30
0
 start: function() {
   startTime = process.hrtime();
   gutil.log('Running', gutil.colors.green("'bundle'") + '...');
 },