Exemple #1
0
  //新文件名(md5)
  function reversion(cb) {

    var RevOptions = {
      fileNameManifest: 'manifest.json',
      dontRenameFile: ['.html', '.php'],
      dontUpdateReference: ['.html'],
      includeFilesInManifest: ['.css', '.js', '.html', 'htm'],
      transformFilename: function (file, hash) {
        var ext = path.extname(file.path);

        // if(ext === '.html'){
        //     return path.basename(file.path, ext) + ext;
        // }

        return path.basename(file.path, ext) + '.' + hash.substr(0, 8) + ext;
      }
    };

    if (config['reversion']) {
      return gulp.src(['./tmp/**/*'])
        .pipe(RevAll.revision(RevOptions))
        .pipe(gulp.dest(paths.tmp.dir))
        .pipe(revDel({
          exclude: /(.html|.htm)$/
        }))
        .pipe(RevAll.manifestFile())
        .pipe(gulp.dest(paths.tmp.dir));
    } else {
      cb();
    }
  }
Exemple #2
0
gulp.task("dist:manifest", () => {
  let paths = [
    // Cachebust our CSS files and the source maps for them.
    path.join(distPath, "css", "*.css"),
    path.join(distPath, "css", "*.map"),

    // Cachebust our Font files.
    path.join(distPath, "fonts", "*"),

    // Cachebust our JS files and the source maps for them.
    path.join(distPath, "js", "*.js"),
    path.join(distPath, "js", "*.map"),

    // Cachebust our Image files.
    path.join(distPath, "images", "*"),
  ];

  let m = new manifest({ fileNameManifest: "manifest.json" });
  return gulp.src(paths, { base: distPath })
              .pipe(m.revision())
              .pipe(gulp.dest(distPath))
              .pipe(manifestClean({ verbose: false }))
              .pipe(m.manifestFile())
              .pipe(gulp.dest(distPath));
});
Exemple #3
0
Gulp.task('rev', ['styles'], function() {
    return Gulp.src(['.build/css/index.css'])
        .pipe(revAll.revision())
        .pipe(Gulp.dest('.build'))
        .pipe(revAll.manifestFile())
        .pipe(Gulp.dest('.build'));
});
Exemple #4
0
gulp.task('rev', ['browserify', 'styles'], function() {
  return gulp.src(['static/js/index.js', 'static/js/index.min.js', 'static/css/index.css', 'static/js/vendor.min.js'])
    .pipe(revAll.revision())
    .pipe(gulp.dest('static'))
    .pipe(revAll.manifestFile())
    .pipe(gulp.dest('static'));
});
Exemple #5
0
gulp.task('rev', function() {
  var revAll = new RevAll();
  return gulp.src('public/**')
    .pipe(revAll.revision())
    .pipe(gulp.dest('public'))
    .pipe(revAll.manifestFile())
    .pipe(gulp.dest('public'));
});
Exemple #6
0
gulp.task('rev', ['css-min', 'js-min'], function () {
    var revAll = new RevAll({dontRenameFile: [/^\/fonts/g, /^\/img/g]});
    return gulp.src([paths.dist + '/**'])
        .pipe(gulp.dest(paths.dist))
        .pipe(revAll.revision())
        .pipe(gulp.dest(paths.dist))
        .pipe(revAll.manifestFile())
        .pipe(gulp.dest(paths.dist));
});
Exemple #7
0
 //执行js,css rev到相应路径
 function() {
     var revAll = new RevAll({
         dontRenameFile: ['images/'],
         fileNameManifest:'asset-manifest.json'
     });
     gulp.src([config.publicPath.cssMin + '*.+(css|map)',config.publicPath.jsMin + '*.+(js|map)'])
         .pipe(revAll.revision())
         .pipe(gulp.dest(config.publicPath.min))
         .pipe(revAll.manifestFile())
         .pipe(gulp.dest(config.publicPath.min));
 }
gulp.task("revision", function(){
    if (process.env.BUILD_NUMBER) {    
        var revAll = new RevAll({transformFilename: transformFilename});
        return gulp.src(CONFIG.DESTINATIONS.TARGET_REV)
            .pipe(revAll.revision())
            .pipe(revNapkin({force:true}))
            .pipe(gulp.dest(CONFIG.DESTINATIONS.TARGET))
            .pipe(revAll.manifestFile())
            //     .pipe(revDel({ dest: CONFIG.DESTINATIONS.TARGET, force: true }))
            .pipe(gulp.dest(CONFIG.DESTINATIONS.TARGET))
    }
})
Exemple #9
0
gulp.task('rev', () => {
  return gulp
    .src('public/**/*')
    .pipe(
      rev.revision({
        dontRenameFile: ['.html', '.json', '.xml'],
        dontUpdateReference: ['.html', '.json', '.xml'],
      }),
    )
    .pipe(gulp.dest('public'))
    .pipe(rev.manifestFile())
    .pipe(gulp.dest('public'));
});
Exemple #10
0
gulp.task('rev', function() {
  var revAll = new RevAll();

  return gulp.src([
      'build/stylesheets/application.css',
      'build/javascripts/application.js',
      'build/images/**/*'
    ], { base: path.join(process.cwd(), 'build') })
    .pipe(revAll.revision())
    .pipe(gulp.dest('build'))
    .pipe(revAll.manifestFile())
    .pipe(gulp.dest('build'));
});
Exemple #11
0
gulp.task('rev', function () {
    var revAll = new RevAll({
        dontRenameFile: [/bootstrap\/.+/gi],
        replacer: function (fragment, replaceRegExp, newReference, referencedFile) {
            fragment.contents = fragment.contents.replace(replaceRegExp, function (matched, $1, $2, $3, $4) {
                return ($1 + newReference + $3 + $4).replace(/(\/|\.)scss(\/)?/g, '$1css$2');
            });
        }
    });
    return gulp.src('src/**')
        .pipe(revAll.revision())
        .pipe(gulp.dest(app.build))
        .pipe(revAll.manifestFile())
        .pipe(gulp.dest(app.build));
});
Exemple #12
0
gulp.task('rev', function(cb) {
    del(['build','_release'], function() {
        console.log(chalk.red('[清理] 删除旧有build文件夹'))
    });
    var revAll = new RevAll({
        prefix: projectConfigFile.staticUrl, //自动增加url路径
        dontRenameFile: [/^\/favicon.ico$/g, '.html','.json'],
    });
    // var ignoredFiles = {
    //     sprites:paths.dist.
    // }
    gulp.src(paths.dist.src + '/**')
        .pipe(revAll.revision())
        .pipe(gulp.dest(paths.dist.release))
        .pipe(revAll.manifestFile())
        .pipe(gulp.dest(paths.dist.build)).on('end',cb)
});
  gulp.task('revall', function() {
    if (!isProduction) {
      return;
    }

    var path = require('path');
    var RevAll = require('gulp-rev-all');
    var revAllAssets = new RevAll({
      // Since we only run this in production mode, add some extra logging
      debug: true,
      dontGlobal: [
        /favicon\.ico/g,
        'manifest.json'
      ],
      dontRenameFile: [
        /^(.+)\.html$/g
      ],
      // Increase the hashlength from 5 to 20 to avoid collisions
      hashLength: 20,
      // We can't have dots in our filenames, other wise we get a InvalidCrossOriginRequest response
      transformFilename: function(file, hash) {
        var extension = path.extname(file.path);
        // filename-6546259a4f83fd81debc.extension
        return path.basename(file.path, extension) + '-' + hash.substr(0, 20) + extension;
      }
    });

    return gulp.src([
        paths.src.assetsPublic,
        paths.src.mainTemplates.bcoursesEmbeddedPublic,
        paths.src.mainTemplates.indexPublic
      ])
      .pipe(revAllAssets.revision())
      .pipe(gulp.dest('public/'))
      // Will add a manifest file at public/rev-manifest.json for debugging purposes
      .pipe(revAllAssets.manifestFile())
      .pipe(gulp.dest('public/')
    );

    // Keep the following lines for debugging purposes
    // This puts out a manifest file with the links to all the resources
    // e.g. "fonts/FontAwesome.otf": "/fonts/FontAwesome.4f97a8a6.otf",
    // .pipe(revall.manifest())
    // .pipe(gulp.dest('public/assets/'));
  });
Exemple #14
0
gulp.task("dist:manifest", () => {
  let paths = [
    // Cachebust our CSS files and the source maps for them.
    path.join(distPath, "css", "*.css"),
    path.join(distPath, "css", "*.map"),

    // Cachebust our Font files.
    path.join(distPath, "fonts", "*"),
    path.join(distPath, "webfonts", "*"),

    // Cachebust our JS files and the source maps for them.
    path.join(distPath, "js", "*.js"),
    path.join(distPath, "js", "*.map"),

    // Cachebust our vendored JS files and the source maps for them.
    path.join(distPath, "js", "vendor", "*.js"),
    path.join(distPath, "js", "vendor", "*.map"),

    // Cachebust our Image files.
    path.join(distPath, "images", "*"),
  ];

  return gulp.src(paths, { base: distPath })
    .pipe(manifest.revision({
      fileNameManifest: "manifest.json",
      includeFilesInManifest: [
        ".css",
        ".map",
        ".woff",
        ".woff2",
        ".svg",
        ".eot",
        ".ttf",
        ".otf",
        ".png",
        ".jpg",
        ".ico",
        ".js",
      ],
    }))
    .pipe(gulp.dest(distPath))
    .pipe(manifestClean({ verbose: false }))
    .pipe(manifest.manifestFile())
    .pipe(gulp.dest(distPath));
});
Exemple #15
0
gulp.task("publish",["clean"],function(){
	var _indexCopy=0
	var revAll=new RevAll({ 
		dontRenameFile: ['.html'],
		hashLength: 8,
		transformPath: function (rev, source, path) { 
			var _index=(++_indexCopy)%cdn.length
            return rev.replace('../', cdn[_index]);
        }
	})
	
	gulp.src("dest/**")
		.pipe(revAll.revision())
		.pipe(gulp.dest("publish"))
		.pipe(revAll.manifestFile())
		.pipe(gulp.dest("publish"))
	console.log("发布完成,可以上线!")
})
  gulp.task('cachebust',function() {

    var rev = new RevAll({
      dontGlobal: [/__reports__\/.*/], //fixme: not ignoring report assets?
      dontRenameFile: [/\.html$/],
      dontUpdateReference: [/\.html$/]
    });

    return gulp.src([cfg.destDir+'/**'])
      .pipe(gulp.dest(cfg.destDir))
      .pipe(rev.revision())
      .pipe(gulp.dest(cfg.destDir))
      .pipe(revdel())
      .pipe(rev.manifestFile())
      .pipe(gulp.dest(cfg.destDir))
    ;

  });
    //新文件名(md5)
    function reversion(cb) {
        var revAll = new RevAll({
            fileNameManifest: 'manifest.json',
            dontRenameFile: ['.html', '.php']
        });

        if (config['reversion']) {
            return gulp.src(['./tmp/**/*'])
                .pipe(revAll.revision())
                .pipe(gulp.dest(paths.tmp.dir))
                .pipe(revDel({
                    exclude: /(.html|.htm)$/
                }))
                .pipe(revAll.manifestFile())
                .pipe(gulp.dest(paths.tmp.dir));
        } else {
            cb();
        }
    }
Exemple #18
0
gulp.task('rev', ['build'], function () {
  var revAllConfig = {
    dontRenameFile: [/.*vendor\/revolution\/.*/ig, 'signup.html', '.php'],
    dontUpdateReference: [/.*vendor\/revolution\/.*/ig],
    dontSearchFile: [/js\/vendor\/*/ig, '.pdf', '.png', '.jpg']
  };

  return gulp.src('./dist/**/*')
    .pipe(RevAll.revision(revAllConfig))
    .pipe(gulp.dest('.rev'))

    // add manifest file
    .pipe(RevAll.manifestFile(revAllConfig))
    .pipe(gulp.dest('.rev'))

    // add version file
    .pipe(RevAll.versionFile(revAllConfig))
    .pipe(gulp.dest('.rev'));
});
gulp.task('final', ['vet', 'styles', 'compile', 'merge'], function() {
    var onlyHtml = filter(['*.html']);

    var rev = new Rev({
        transformFilename: function(file, hash) {
            return 'assets/' + hash + path.extname(file.path);
        },

        dontRenameFile: [/^\/favicon.ico$/g, /^\/index.html/g]
    });

    return gulp.src(['build/inter/*'])
        .pipe(onlyHtml)
            .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(onlyHtml.restore())
        .pipe(rev.revision())
        .pipe(gulp.dest('build/final'))
        .pipe(rev.manifestFile())
        .pipe(gulp.dest('build'));
});
Exemple #20
0
gulp.task('cache-bust', function(done) {
  var revAll = new RevAll({ prefix: cdnHostStr, dontRenameFile: ['.html','db.json'] });
  var stream = gulp.src('build/**')
    .pipe(revAll.revision())
    .pipe(gulp.dest('build'))
    .pipe(revAll.manifestFile())
    .pipe(gulp.dest('build'));

  stream.on('end', function() {
    var manifest = require('./build/rev-manifest.json');
    var arr = [];
    for(var origFileName in manifest) {
      if(origFileName != manifest[origFileName]) { // For all files busted/renamed
        arr.push('./build/' + origFileName);       // Add the original filename to the list
      }
    }
    del(arr, done);     // Delete all originals files the were not busted/renamed
  });
  stream.on('error', done);
});
Exemple #21
0
function compile(_packageUtils, _config, argv) {
	if (argv.p && argv.p !== 'readme-docs') {
		log.info('skip readme compilation');
		return;
	}

	packageUtils = _packageUtils;
	config = _config;
	var revAll = new RevAll({
		fileNameManifest: 'readmes-rev-manifest.json',
		dontRenameFile: [readmeMappingFileName],
		debug: config().devMode
	});
	var readmePackagePath = packageUtils.findBrowserPackagePath('@dr/readme');

	return gulp.src([docPath.replace(/\\/g, '/') + '/**/*.*'], {base: srcDir})
		.pipe(compileMarkdown())
		.pipe(revAll.revision())
		.pipe(replaceReference())
		.pipe(through.obj(function(file, enc, next) {
			var ext = Path.extname(file.path);
			if (ext === '.md') {
				file.path = file.path.substring(0, file.path.lastIndexOf('.')) + '.html';
				log.debug('rename to html: ' + file.path);
			}
			next(null, file);
		}))
		.pipe(gulp.dest(config().staticDir + '/' + distDir))
		.pipe(revAll.manifestFile())
		.pipe(mergeWithExistingMani(readmePackagePath))
		.pipe(gulp.dest(config().destDir))
		.pipe(removeUselessManifestData())
		.pipe(gulp.dest(readmePackagePath + '/dist'))
		.on('end', function() {
			buildUtils.writeTimestamp('readme');
		})
		.on('error', function(err) {
			log.error(err);
			throw new Error(err.stack);
		});
}
gulp.task('uglify', function () {
  var jsFilter = filter('**/*.js');
  var cssFilter = filter('**/*.css');
  var revAll = new rev({

    //不重命名文件
    dontRenameFile: ['.html'],

    //无需关联处理文件
    dontGlobal: [/^\/favicon.ico$/, '.bat', '.txt', '.xml'],

    //该项配置只影响绝对路径的资源
    prefix: ''
  });
  var assets = useref.assets();
  return gulp.src('client/main.html')
    //合并html里面的js/css
    .pipe(assets)
    .pipe(assets.restore())
    .pipe(useref())

    //压缩css
    .pipe(cssFilter)
    .pipe(csso())
    .pipe(cssFilter.restore())

    //压缩js
    .pipe(jsFilter)
    .pipe(ngAnnotate())
    .pipe(uglify())
    .pipe(jsFilter.restore())


    //加MD5后缀
    .pipe(revAll.revision())
    //输出
    .pipe(gulp.dest('dist'))
    //生成映射json文件
    .pipe(revAll.manifestFile())
    .pipe(gulp.dest('dist'));
});
gulp.task("rev-all", function(){
    var revAll  = new RevAll({
        dontGlobal: [/^\/favicons\/favicon\.ico$/g, /^\/sounds\/(.+)\.mp3/g],
        dontRenameFile: [/^\/.+\.html/g, /^\/robots\.txt/g, /^\/img\/ks\.jpg/g],
        referenceToRegexs: referenceToRegexs,
        transformPath: function (rev, source, path) {
            if( source.match(/main/) ) {
                return rev;
            }

            return rev.replace('/js/app/', '');
        }
    });

    return gulp.src(['dist/**', '!dist/bower_components/**'])
        .pipe(revAll.revision())
        .pipe(revDel())
        .pipe(gulp.dest('dist'))
        .pipe(revAll.manifestFile())
        .pipe(gulp.dest('dist'));
});
Exemple #24
0
gulp.task('useref', ['less'], function () {
  var assets = $.useref.assets();
  var revAll = new RevAll({
    dontRenameFile: ['.html'] ,
    prefix: '/',
    transformFilename: function (file, hash) {
      var ext = path.extname(file.path);
      return hash.substr(0, 8) + '.'  + path.basename(file.path, ext) + ext;
    }
  });
  return gulp.src(app.src + 'index.html')
    .pipe(assets)
    .pipe($.if('*.js', $.uglify()))
    .pipe($.if('*.css', $.csso()))
    .pipe(assets.restore())
    .pipe($.useref())
    .pipe(revAll.revision())
    .pipe($.if('*.js', gulp.dest(app.dist)))
    .pipe($.if('*.css', gulp.dest(app.dist)))
    .pipe(revAll.manifestFile())
    .pipe(gulp.dest(app.tmp));
});
Exemple #25
0
        return function ()
        {
            // var scssOpts = {outputStyle: options.isDevelopment ? 'compact' : 'compressed'};

            return gulp.src(options.src + '/*.*')
                .pipe(RevAll.revision({
                    fileNameManifest: "css-assets.json",
                    transformFilename: function (file, hash) {
                        var ext = path.extname(file.path);
                        return path.basename(file.path, ext) + '-' + hash.substr(0, 8) + ext;
                    }
                }))
                .pipe(gulp.dest(options.dst))
                .pipe(RevAll.manifestFile())
                .pipe(revDelRedundant({dest: options.dst, force: true}))
                .pipe(gulp.dest(options.manifestPath))
                .pipe($.notify(function (file) {
                    var options = {hour: 'numeric', minute: 'numeric', second: 'numeric'};
                    return "Compiled " + file.relative + ' ' + (new Date()).toLocaleString("ru", options);
                        // " (" + options.chList + ")";
                }))
                ;
        }
Exemple #26
0
    //新文件名(md5)
    function reversion(cb) {
        var revAll = new RevAll({
            fileNameManifest: 'manifest.json',
            dontRenameFile: ['.html', '.php']
        });

        if (config['reversion']) {
            gulp.src(paths.tmp.dirAll)
                .pipe(revAll.revision())
                .pipe(gulp.dest(paths.tmp.dir))
                .pipe(revDel({
                    exclude: /(.html|.htm)$/
                }))
                .pipe(revAll.manifestFile())
                .pipe(gulp.dest(paths.tmp.dir))
                .on('end', function () {
                    console.log('reversion success.');
                    log('reversion success.');
                    cb && cb();
                })
        } else {
            cb && cb();
        }
    }
gulp.task('md5-all', function () {
  var files = {
    js: [
      './components/**/*.js',
      './modules/**/*.js'
    ],
    html: [
      './components/**/*.html',
      './modules/**/*.html'
    ],
    css: [
      './css/**/*.css'
    ]
  };
  var jsFilter = filter(files.js, {restore: true}),
    htmlFilter = filter(files.html, {restore: true}),
    cssFilter = filter(files.css, {restore: true});

  var revAll = new RevAll({
    debug: !true,
    replacer: function (fragment, replaceRegExp, newReference, referencedFile) {
      //这里修正了gulp-rev-all的替换规则,目的是不替换跟文件名同名的变量
      if (newReference.indexOf('/') === -1) {
        fragment.contents = fragment.contents.replace(replaceRegExp, '$1' + '$2' + '$3$4');
      } else {
        fragment.contents = fragment.contents.replace(replaceRegExp, '$1' + newReference + '$3$4');
      }
    }
  });

  return gulp.src([
      './components/**',
      './modules/**',
      './css/**',
      'index.html'
    ])
    .pipe(htmlFilter)
    .pipe(minifyHTML())
    .pipe(useref())
    .pipe(htmlFilter.restore)

    .pipe(jsFilter)
    .pipe(uglify({
      mangle: false
    }))
    .pipe(jsFilter.restore)

    //css
    .pipe(cssFilter)
    .pipe(minifyCSS())
    .pipe(csso())
    .pipe(cssFilter.restore)
    //
    .pipe(revAll.revision())

    .pipe(gulp.dest(paths.output))

    .pipe(revAll.manifestFile())
    .pipe(gulp.dest('./rev'))
    ;
});