├── README.md ├── gulp-asset-rev ├── .gitignore ├── README.md ├── dest │ ├── styles │ │ └── test.css │ └── test.html ├── gulpfile.js ├── index.js ├── package.json └── test │ ├── images │ ├── bg.png │ └── test.png │ ├── scripts │ └── test.js │ ├── styles │ └── test.css │ └── test.html ├── gulp-content-includer ├── .gitignore ├── README.md ├── content.html ├── footer.html ├── gulpfile.js ├── header.html ├── inc │ ├── meta.html │ └── subinc │ │ └── meta.html ├── index.html ├── index.js └── package.json ├── gulp-make-css-url-version ├── README.md ├── index.js └── package.json ├── gulp-minify-inline-scripts ├── README.md ├── index.js └── package.json ├── gulp-require-tpl2js ├── .gitignore ├── README.md ├── gulpfile.js ├── index.js ├── package.json ├── test.bak.tpl └── test.tpl ├── gulp-rev-files ├── .gitignore ├── README.md ├── dest │ ├── images │ │ ├── bg-2769acd3.png │ │ └── test-25cf2b4e.png │ ├── scripts │ │ └── test-8ced4e61.js │ ├── styles │ │ └── test-dd42597b.css │ └── test-375782d0.html ├── gulpfile.js ├── index.js ├── package.json └── test │ ├── images │ ├── bg.png │ └── test.png │ ├── scripts │ └── test.js │ ├── styles │ └── test.css │ └── test.html └── gulp-utf8-convert ├── .gitignore ├── README.md ├── gulpfile.js ├── index.js ├── package.json └── test.txt /README.md: -------------------------------------------------------------------------------- 1 | gulp_plugin 2 | =========== 3 | 4 | plugins for gulp.js 5 | 6 | ###gulp-minify-inline-scripts 7 | 8 | minify inline scripts in html file 9 | 10 | ###gulp-make-css-url-version 11 | 12 | replace version for images in css files 13 | 14 | ###gulp-utf8-convert 15 | 16 | convert file encoding to utf8 17 | 18 | ###gulp-require-tpl2js 19 | 20 | convert tpl files content to js for requirejs 21 | 22 | ###gulp-content-includer 23 | 24 | include files 25 | 26 | ###gulp-asset-rev 27 | 28 | replace asset's filename by adding file hash 29 | -------------------------------------------------------------------------------- /gulp-asset-rev/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /gulp-asset-rev/README.md: -------------------------------------------------------------------------------- 1 | ## gulp-asset-rev 2 | 3 | a plugin for gulp.js to replace file's name by adding content hash 4 | 5 | ## Installation 6 | 7 | ```bash 8 | npm install gulp-asset-rev 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | var gulp = require('gulp'); 15 | var assetRev = require('gulp-asset-rev'); 16 | 17 | gulp.task('rev',function() { 18 | gulp.src("./test/test.html") 19 | .pipe(assetRev()) 20 | .pipe(gulp.dest('./')); 21 | }); 22 | ``` 23 | 24 | ## Options 25 | 26 | ### hashLen: length of hash version string 27 | Type: `Number` default: 7 28 | 29 | ### verConnecter: version connect char 30 | Type: `String` default: '-' 31 | 32 | ### rootPath: it should be assigned when the asset's path is an absolute path 33 | Type: `String` default: "" 34 | 35 | ### verStr: use custom version string 36 | Type: `String` 37 | 38 | ## Example 39 | 40 | ```js 41 | var gulp = require('gulp'); 42 | var assetRev = require('./index.js'); 43 | 44 | gulp.task('rev',['revCss'],function() { 45 | gulp.src("./test/test.html") 46 | .pipe(assetRev()) 47 | .pipe(gulp.dest('./dest')); 48 | }); 49 | 50 | gulp.task('revCss',function () { 51 | return gulp.src('./test/styles/test.css') 52 | .pipe(assetRev()) 53 | .pipe(gulp.dest('./dest/styles/')) 54 | }); 55 | gulp.task('default',['rev']); 56 | ``` 57 | 58 | ### before: test.css 59 | ```css 60 | body{background:url('../images/bg.png')} 61 | ``` 62 | 63 | ### after: test.css 64 | ```css 65 | body{background:url("../images/bg_2769acd.png"} 66 | ``` 67 | ### before: test.html 68 | ```html 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 |
77 | 78 |
79 | 80 | 81 | 82 | ``` 83 | ### after: test.html 84 | 85 | ```html 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
94 | 95 |
96 | 97 | 98 | 99 | ``` 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /gulp-asset-rev/dest/styles/test.css: -------------------------------------------------------------------------------- 1 | body{background:url("../images/bg.png?d=20153022") no-repeat} 2 | -------------------------------------------------------------------------------- /gulp-asset-rev/dest/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /gulp-asset-rev/gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var assetRev = require('./index.js'); 3 | 4 | gulp.task('rev', ['revCss'], function () { 5 | gulp.src("./test/test.html") 6 | .pipe(assetRev()) 7 | .pipe(gulp.dest('./dest')); 8 | }); 9 | 10 | gulp.task('revCss', function () { 11 | return gulp.src('./test/styles/test.css') 12 | .pipe(assetRev({ verStr: "?d=20153022" })) 13 | .pipe(gulp.dest('./dest/styles/')) 14 | }); 15 | 16 | gulp.task('default', ['rev']); 17 | -------------------------------------------------------------------------------- /gulp-asset-rev/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var path = require('path'); 4 | var fs = require('fs'); 5 | var crypto = require('crypto'); 6 | 7 | var gutil = require('gulp-util'); 8 | var through = require('through2'); 9 | 10 | var PLUGIN_NAME = 'gulp-asset-rev'; 11 | 12 | var ASSET_REG = { 13 | "SCRIPT": /(]+src=)['"]([^'"]+)["']/ig, 14 | "STYLESHEET": /(]+href=)['"]([^'"]+)["']/ig, 15 | "IMAGE": /(]+src=)['"]([^'"]+)["']/ig, 16 | "BACKGROUND": /(url\()(?!data:|about:)([^)]*)/ig 17 | }; 18 | 19 | var createHash = function (file, len) { 20 | return crypto.createHash('md5').update(file).digest('hex').substr(0, len); 21 | }; 22 | 23 | module.exports = function (options) { 24 | return through.obj(function (file, enc, cb) { 25 | 26 | options = options || {}; 27 | 28 | if (file.isNull()) { 29 | this.push(file); 30 | return cb(); 31 | } 32 | 33 | if (file.isStream()) { 34 | this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported')); 35 | return cb(); 36 | } 37 | 38 | var content = file.contents.toString(); 39 | 40 | var filePath = path.dirname(file.path); 41 | 42 | for (var type in ASSET_REG) { 43 | if (type === "BACKGROUND" && !/\.(css|scss|less)$/.test(file.path)) { 44 | 45 | } else { 46 | content = content.replace(ASSET_REG[type], function (str, tag, src) { 47 | src = src.replace(/\?[\s\S]+$/, '').replace(/(^['"]|['"]$)/g, ''); 48 | 49 | if (!/\.[^\.]+$/.test(src)) { 50 | return str; 51 | } 52 | if (options.verStr) { 53 | src += options.verStr; 54 | return tag + '"' + src + '"'; 55 | } 56 | 57 | // remote resource 58 | if (/^https?:\/\//.test(src)) { 59 | return str; 60 | } 61 | 62 | var assetPath = path.join(filePath, src); 63 | 64 | if (src.indexOf('/') == 0) { 65 | if (options.resolvePath && typeof options.resolvePath === "function") { 66 | assetPath = options.resolvePath(src); 67 | } else { 68 | assetPath = (options.rootPath || "") + src; 69 | } 70 | } 71 | 72 | if (fs.existsSync(assetPath)) { 73 | 74 | var buf = fs.readFileSync(assetPath); 75 | 76 | var md5 = createHash(buf, options.hashLen || 7); 77 | 78 | var verStr = (options.verConnecter || "-") + md5; 79 | 80 | src = src.replace(verStr, '').replace(/(\.[^\.]+)$/, verStr + "$1"); 81 | } else { 82 | return str; 83 | } 84 | 85 | return tag + '"' + src + '"'; 86 | }); 87 | } 88 | } 89 | 90 | file.contents = new Buffer(content); 91 | this.push(file); 92 | cb(); 93 | }); 94 | }; 95 | 96 | -------------------------------------------------------------------------------- /gulp-asset-rev/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-asset-rev", 3 | "version": "0.0.14", 4 | "description": "replace asset's filename by adding file hash", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/hellopao/gulp_plugin" 9 | }, 10 | "author": { 11 | "name": "qinjia", 12 | "email": "qinjia@outlook.com" 13 | }, 14 | "engines": { 15 | "node": ">=0.12.0" 16 | }, 17 | "files": [ 18 | "index.js" 19 | ], 20 | "keywords": [ 21 | "gulpplugin", 22 | "asset version", 23 | "md5" 24 | ], 25 | "dependencies": { 26 | "gulp": "^3.8.11", 27 | "gulp-util": "^3.0.0", 28 | "through2": "^0.6.1" 29 | }, 30 | "homepage": "https://github.com/hellopao/gulp_plugin", 31 | "_id": "gulp-asset-rev@0.0.14", 32 | "_from": "gulp-asset-rev@" 33 | } 34 | -------------------------------------------------------------------------------- /gulp-asset-rev/test/images/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellopao/gulp_plugin/66fd1b0f8e9f97ef22d6fe0a5483223fa34f390c/gulp-asset-rev/test/images/bg.png -------------------------------------------------------------------------------- /gulp-asset-rev/test/images/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellopao/gulp_plugin/66fd1b0f8e9f97ef22d6fe0a5483223fa34f390c/gulp-asset-rev/test/images/test.png -------------------------------------------------------------------------------- /gulp-asset-rev/test/scripts/test.js: -------------------------------------------------------------------------------- 1 | console.log("hello world"); 2 | -------------------------------------------------------------------------------- /gulp-asset-rev/test/styles/test.css: -------------------------------------------------------------------------------- 1 | body{background:url('../images/bg.png?d=20153022') no-repeat} 2 | -------------------------------------------------------------------------------- /gulp-asset-rev/test/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /gulp-content-includer/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /gulp-content-includer/README.md: -------------------------------------------------------------------------------- 1 | ## gulp-content-includer 2 | 3 | a plugin for gulp.js to include files 4 | 5 | ## Installation 6 | 7 | ```bash 8 | npm install gulp-utf8-convert 9 | ``` 10 | 11 | ## Options 12 | 13 | ### includerReg: RegExp of the include expression 14 | Type: `RegExp` 15 | 16 | ### baseSrc: basedir of the source 17 | Type: `String` 18 | 19 | ### deepConcat concat content recursive 20 | Type: `Boolean` default : false 21 | 22 | ## Usage 23 | 24 | ```js 25 | var gulp = require('gulp'); 26 | var contentInclude = require('gulp-content-includer'); 27 | 28 | gulp.task('concat',function() { 29 | gulp.src("./content.html") 30 | .pipe(contentInclude({ 31 | includerReg://g 32 | })) 33 | .pipe(gulp.dest('./')); 34 | }); 35 | ``` 36 | -------------------------------------------------------------------------------- /gulp-content-includer/content.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
    4 |
  • 5 | test 6 |
  • 7 |
  • 8 | test 9 |
  • 10 |
  • 11 | test 12 |
  • 13 |
  • 14 | test 15 |
  • 16 |
  • 17 | test 18 |
  • 19 |
  • 20 | test 21 |
  • 22 |
  • 23 | test 24 |
  • 25 |
26 |
27 | 28 | -------------------------------------------------------------------------------- /gulp-content-includer/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gulp-content-includer/gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var contentIncluder = require('./'); 3 | var rename = require('gulp-rename'); 4 | 5 | gulp.task('concat',function() { 6 | gulp.src("./content.html") 7 | .pipe(contentIncluder({ 8 | includerReg://g, 9 | deepConcat: true, 10 | baseSrc: './' 11 | })) 12 | .pipe(rename('index.html')) 13 | .pipe(gulp.dest('./')); 14 | }); 15 | -------------------------------------------------------------------------------- /gulp-content-includer/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /gulp-content-includer/inc/meta.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /gulp-content-includer/inc/subinc/meta.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /gulp-content-includer/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 |
    12 |
  • 13 | test 14 |
  • 15 |
  • 16 | test 17 |
  • 18 |
  • 19 | test 20 |
  • 21 |
  • 22 | test 23 |
  • 24 |
  • 25 | test 26 |
  • 27 |
  • 28 | test 29 |
  • 30 |
  • 31 | test 32 |
  • 33 |
34 |
35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /gulp-content-includer/index.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var util = require('util'); 3 | var fs = require('fs'); 4 | 5 | var gutil = require('gulp-util'); 6 | var through = require('through2'); 7 | 8 | var PLUGIN_NAME = 'gulp-content-includer'; 9 | 10 | module.exports = function(options) { 11 | return through.obj(function(file, enc, cb) { 12 | var self = this; 13 | 14 | options = options || {}; 15 | 16 | var showLog = options.showLog; 17 | 18 | if (file.isNull()) { 19 | this.push(file); 20 | return cb(); 21 | } 22 | 23 | if (file.isStream()) { 24 | this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported')); 25 | return cb(); 26 | } 27 | 28 | var includerReg = options.includerReg; 29 | 30 | if (!util.isRegExp(includerReg)) { 31 | gutil.log(gutil.colors.red('[ERROR] includerReg is required')); 32 | this.push(file); 33 | return cb(); 34 | } 35 | 36 | var content = file.contents.toString(); 37 | 38 | var replaceContent = function (content,dir){ 39 | content = content.replace(includerReg, function(str, src) { 40 | if (/^[\\\/]/.test(src)) { 41 | if (options.resolvePath && typeof options.resolvePath === "function") { 42 | src = options.resolvePath(src); 43 | } else { 44 | src = path.join(options.baseSrc || "",src); 45 | } 46 | } else { 47 | src = path.join(path.dirname(dir),src); 48 | } 49 | 50 | try { 51 | var fileContent = fs.readFileSync(src,'utf8'); 52 | 53 | if (options.deepConcat && includerReg.test(fileContent)) { 54 | return replaceContent(fileContent,src); 55 | } 56 | return fileContent; 57 | } catch (err) { 58 | gutil.log(gutil.colors.red('[ERROR] the file %s required by %s is not exsist'),src,dir); 59 | return str; 60 | } 61 | 62 | }); 63 | return content; 64 | } 65 | 66 | content = replaceContent(content,file.path); 67 | 68 | file.contents = new Buffer(content); 69 | this.push(file); 70 | cb(); 71 | }); 72 | }; 73 | -------------------------------------------------------------------------------- /gulp-content-includer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-content-includer", 3 | "version": "0.0.7", 4 | "description": "include files", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/hellopao/gulp_plugin" 9 | }, 10 | "author": { 11 | "name": "qinjia", 12 | "email": "qinjia@outlook.com" 13 | }, 14 | "engines": { 15 | "node": ">=0.10.0" 16 | }, 17 | "files": [ 18 | "index.js" 19 | ], 20 | "keywords": [ 21 | "gulpplugin", 22 | "content includer", 23 | "include files" 24 | ], 25 | "dependencies": { 26 | "gulp-util": "^3.0.0", 27 | "through2": "^0.6.1" 28 | }, 29 | "homepage": "https://github.com/hellopao/gulp_plugin", 30 | "_id": "gulp-content-includer@0.0.7", 31 | "_from": "gulp-content-includer@" 32 | } 33 | -------------------------------------------------------------------------------- /gulp-make-css-url-version/README.md: -------------------------------------------------------------------------------- 1 | ## gulp-make-css-url-version 2 | 3 | a plugin for gulp.js to replace version for images in css files,the version should be file's md5 or time stamp; 4 | 5 | ## Installation 6 | 7 | ```bash 8 | npm install gulp-make-css-url-version 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | var makeUrlVer = require('gulp-make-css-url-version'); 15 | 16 | gulp.task('stylesheets', function() { 17 | gulp.src('css/*.css') 18 | .pipe(makeUrlVer()) 19 | .pipe(gulp.dest('dist')) 20 | }); 21 | ``` 22 | 23 | ## Options 24 | 25 | useDate :make version with time stamp 26 | 27 | ```js 28 | var makeUrlVer = require('gulp-make-css-url-version'); 29 | 30 | gulp.task('stylesheets', function() { 31 | gulp.src('css/*.css') 32 | .pipe(makeUrlVer({useDate:true})) 33 | .pipe(gulp.dest('dist')) 34 | }); 35 | ``` 36 | 37 | assetsDir: specify the public directory for correct MD5 calculation in some specific cases 38 | 39 | ```js 40 | var makeUrlVer = require('gulp-make-css-url-version'); 41 | 42 | gulp.task('stylesheets', function() { 43 | gulp.src('css/*.css') 44 | .pipe(makeUrlVer({ 45 | assetsDir: __dirname + '/public' 46 | })) 47 | .pipe(gulp.dest('dist')) 48 | }); 49 | ``` 50 | 51 | ## Example 52 | 53 | ### before: index.css 54 | 55 | ```css 56 | /* loading */ 57 | .i-loading{width:32px;height:32px;background:url(../images/loading.gif) no-repeat;} 58 | ``` 59 | 60 | ### after: index.css 61 | 62 | ```css 63 | /* loading */ 64 | .i-loading{width:32px;height:32px;background:url(../images/loading.gif?v=Je0sUcMH0mhJPWdZdpHzXg%3D%3D) no-repeat} 65 | 66 | ``` 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /gulp-make-css-url-version/index.js: -------------------------------------------------------------------------------- 1 | 2 | var path = require('path'); 3 | var crypto = require('crypto'); 4 | var fs = require('fs'); 5 | 6 | var gutil = require('gulp-util'); 7 | var through = require('through2'); 8 | var Q = require('q'); 9 | 10 | var PLUGIN_NAME = 'gulp-make-css-url-version'; 11 | 12 | var getMD5 = function (data) { 13 | var hash = crypto.createHash("md5"); 14 | hash.update(data); 15 | var md5Base64 = hash.digest("base64"); 16 | return md5Base64; 17 | }; 18 | 19 | var formatDate = function (format, date) { 20 | date = date || new Date(); 21 | var o = { 22 | "M+": date.getMonth() + 1, 23 | "d+": date.getDate(), 24 | "h+": date.getHours(), 25 | "m+": date.getMinutes(), 26 | "s+": date.getSeconds(), 27 | "q+": Math.floor((date.getMonth() + 3) / 3), 28 | "S": date.getMilliseconds() 29 | }; 30 | format = format.replace(/y{4}/, date.getFullYear()).replace(/y{2}/, date.getFullYear().toString().substring(2)); 31 | 32 | for (var k in o) { 33 | var reg = new RegExp(k); 34 | format = format.replace(reg, match); 35 | } 36 | function match(m) { 37 | return m.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length); 38 | } 39 | return format; 40 | }; 41 | 42 | module.exports = function (options) { 43 | return through.obj(function (file, enc, cb) { 44 | options = options || {}; 45 | var self = this; 46 | 47 | var fileName = file.path.split(path.sep).pop(); 48 | 49 | if (file.isNull()) { 50 | this.push(file); 51 | return cb(); 52 | } 53 | 54 | if (file.isStream()) { 55 | this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported')); 56 | return cb(); 57 | } 58 | 59 | //css file only 60 | if (!/^\.css?$/.test(path.extname(file.path))) { 61 | gutil.log(gutil.colors.red('[WARN] file ' + fileName + ' is not a css file')); 62 | this.push(file); 63 | return cb(); 64 | } 65 | 66 | var html = file.contents.toString(); 67 | 68 | var promises = []; 69 | 70 | html = html.replace(/url\("?([^\)"]+)"?\)/g, function (str, url) { 71 | 72 | url = url.replace(/\?[\s\S]*$/, "").trim(); 73 | url = url.replace(/['"]*/g, ""); 74 | 75 | if (url.indexOf("base64,") > -1 || url.indexOf("about:blank") > -1 || url.indexOf("http://") > -1 || url === '/') { 76 | return str; 77 | } 78 | 79 | var format = options.format || "yyyy-MM-dd"; 80 | 81 | //use date as the version 82 | if (options.useDate) { 83 | return "url(" + url + "?v=" + formatDate(format, new Date()) + ")"; 84 | } 85 | 86 | //use md5 87 | var safeUrl = url.replace(/#[\s\S]*$/,''); 88 | var imageFilePath; 89 | if (options.assetsDir) { 90 | imageFilePath = path.join(options.assetsDir, safeUrl); 91 | } else { 92 | imageFilePath = path.resolve(path.dirname(file.path), safeUrl); 93 | } 94 | 95 | var tempKey = Math.random().toString(); 96 | var readFile = Q.denodeify(fs.readFile); 97 | 98 | var promise = readFile(imageFilePath) 99 | .then(function (data) { 100 | //gutil.log('replacing image ' + imageFilePath + ' version in css file: ' + file.path); 101 | var verStr = data ? encodeURIComponent(getMD5(data.toString())) : formatDate(format); 102 | return { 103 | key: tempKey, 104 | value: "url(" + url + "?v=" + verStr + ")" 105 | }; 106 | }, function (e) { 107 | gutil.log(e); 108 | return { 109 | key: tempKey, 110 | value: "url(" + url + "?v=" + formatDate(format) + ")" 111 | }; 112 | }); 113 | 114 | promises.push(promise); 115 | 116 | return tempKey; 117 | }); 118 | 119 | if (options.useDate) { 120 | file.contents = new Buffer(html); 121 | self.push(file); 122 | cb(); 123 | return; 124 | } 125 | 126 | Q.all(promises).then(function (mathces) { 127 | 128 | mathces.forEach(function (match) { 129 | html = html.replace(match.key, match.value); 130 | }); 131 | 132 | file.contents = new Buffer(html); 133 | self.push(file); 134 | cb(); 135 | }); 136 | 137 | }); 138 | }; 139 | -------------------------------------------------------------------------------- /gulp-make-css-url-version/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-make-css-url-version", 3 | "version": "0.0.12", 4 | "description": "replace version for images in css files", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/hellopao/gulp_plugin" 9 | }, 10 | "author": { 11 | "name": "qinjia", 12 | "email": "qinjia@outlook.com" 13 | }, 14 | "engines": { 15 | "node": ">=0.10.0" 16 | }, 17 | "files": [ 18 | "index.js" 19 | ], 20 | "keywords": [ 21 | "gulpplugin", 22 | "image version", 23 | "css" 24 | ], 25 | "dependencies": { 26 | "gulp-util": "^3.0.0", 27 | "through2": "^0.6.1", 28 | "q":"^1.0.1" 29 | }, 30 | "license": "MIT", 31 | "homepage": "https://github.com/hellopao/gulp_plugin", 32 | "_id": "gulp-make-css-url-version@0.0.12", 33 | "_from": "gulp-make-css-url-version@" 34 | } 35 | -------------------------------------------------------------------------------- /gulp-minify-inline-scripts/README.md: -------------------------------------------------------------------------------- 1 | ## gulp-minify-inline-scripts 2 | 3 | a plugin for gulp.js to minify inline scripts in html files 4 | 5 | ## Installation 6 | 7 | ```bash 8 | npm install gulp-minify-inline-scripts 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | var minifyInline = require('gulp-minify-inline-scripts'); 15 | 16 | gulp.task('minify', function() { 17 | gulp.src('html/*.html') 18 | .pipe(minifyInline()) 19 | .pipe(gulp.dest('dist')) 20 | }); 21 | ``` 22 | 23 | ## Example 24 | 25 | ### before: index.html 26 | 27 | ```html 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 48 | 49 | 50 | ``` 51 | 52 | ### after:index.html 53 | 54 | ```html 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | ``` 67 | -------------------------------------------------------------------------------- /gulp-minify-inline-scripts/index.js: -------------------------------------------------------------------------------- 1 | 2 | var path = require('path'); 3 | 4 | var gutil = require('gulp-util'); 5 | var uglify = require('uglify-js'); 6 | var through = require('through2'); 7 | 8 | var PLUGIN_NAME = 'gulp-minify-inline-scripts'; 9 | 10 | module.exports = function (options) { 11 | return through.obj(function (file, enc, cb) { 12 | var self = this; 13 | 14 | if (file.isNull()) { 15 | this.push(file); 16 | return cb(); 17 | } 18 | 19 | if (file.isStream()) { 20 | this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported')); 21 | return cb(); 22 | } 23 | 24 | var fileName = file.path.split(path.sep).pop(); 25 | 26 | //html file only 27 | if (!/^\.html?$/.test(path.extname(file.path))) { 28 | gutil.log(gutil.colors.red('[WARN] file ' + fileName + ' is not a html file')); 29 | this.push(file); 30 | return cb(); 31 | } 32 | 33 | gutil.log("uglify inline scripts in html file: " + file.path); 34 | 35 | var html = file.contents.toString('utf8'); 36 | var reg = /(]*?\b(type=['"]text\/template['"]|src=["']))[^>]*?>)([\s\S]*?)<\/script>/g; 37 | 38 | 39 | html = html.replace(reg, function (str, tagStart,attr, script) { 40 | try { 41 | var result = uglify.minify(script, { fromString: true }); 42 | return tagStart + result.code + ''; 43 | } catch (e) { 44 | self.emit('error', new gutil.PluginError(PLUGIN_NAME, 'uglify inline scripts error: ' + (e && e.stack))); 45 | } 46 | }); 47 | 48 | 49 | file.contents = new Buffer(html); 50 | this.push(file); 51 | cb(); 52 | }); 53 | }; 54 | -------------------------------------------------------------------------------- /gulp-minify-inline-scripts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-minify-inline-scripts", 3 | "version": "0.0.6", 4 | "description": "minify inline scripts in html files", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/hellopao/gulp_plugin" 9 | }, 10 | "author": { 11 | "name": "qinjia", 12 | "email": "qinjia@outlook.com" 13 | }, 14 | "engines": { 15 | "node": ">=0.10.0" 16 | }, 17 | "files": [ 18 | "index.js" 19 | ], 20 | "keywords": [ 21 | "gulpplugin", 22 | "inline scripts", 23 | "uglify", 24 | "minify" 25 | ], 26 | "dependencies": { 27 | "gulp-util": "^3.0.0", 28 | "through2": "^0.6.1", 29 | "uglify-js":"^2.4.15" 30 | }, 31 | "license": "MIT", 32 | "homepage": "https://github.com/hellopao/gulp_plugin", 33 | "_id": "gulp-minify-inline-scripts@0.0.6", 34 | "_from": "gulp-minify-inline-scripts@" 35 | } 36 | -------------------------------------------------------------------------------- /gulp-require-tpl2js/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /gulp-require-tpl2js/README.md: -------------------------------------------------------------------------------- 1 | ## gulp-require-tpl2js 2 | 3 | convert tpl files content to js for requirejs 4 | 5 | ## Installation 6 | 7 | ```bash 8 | npm install gulp-require-tpl2js 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | var gulp = require('gulp'); 15 | var tpl2js = require('gulp-require-tpl2js') 16 | 17 | gulp.task('convert',function() { 18 | gulp.src("./test.tpl") 19 | .pipe(tpl2js()) 20 | .pipe(gulp.dest('./')); 21 | }); 22 | ``` 23 | 24 | -------------------------------------------------------------------------------- /gulp-require-tpl2js/gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require ('gulp'); 2 | var tpl2js = require('./'); 3 | var rename = require('gulp-rename'); 4 | 5 | gulp.task('convert',function () { 6 | gulp.src('./test.tpl') 7 | .pipe(tpl2js()) 8 | .pipe(rename('./test.bak.tpl')) 9 | .pipe(gulp.dest('./')); 10 | }); 11 | 12 | -------------------------------------------------------------------------------- /gulp-require-tpl2js/index.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | 3 | var gutil = require('gulp-util'); 4 | var through = require('through2'); 5 | 6 | var PLUGIN_NAME = 'gulp-require-tpl2js'; 7 | 8 | module.exports = function(options) { 9 | return through.obj(function(file, enc, cb) { 10 | var self = this; 11 | 12 | options = options || {}; 13 | 14 | if (file.isNull()) { 15 | this.push(file); 16 | return cb(); 17 | } 18 | 19 | if (file.isStream()) { 20 | this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported')); 21 | return cb(); 22 | } 23 | 24 | var defaultExtNames = [".html",".tpl"]; 25 | var fileExtname = path.extname(file.path); 26 | 27 | if (defaultExtNames.indexOf(fileExtname) > -1 || (options.extname && options.extname.replace(/^\.?/,'.') === fileExtname)) { 28 | try { 29 | var tpl = file.contents.toString(); 30 | var lines = tpl.replace(/^\s*$/gm,'').split(/\r?\n/); 31 | 32 | for (var i = 0; i < lines.length; i++) { 33 | lines[i] = lines[i].replace(/'/g,'\\\'').replace(/^(\s*)/g,'\t$1\'').replace(/(\s)*$/,'\'$1'); 34 | } 35 | 36 | tpl = ';define(function(){\r\n\t return ' + '[\r\n\t' + lines.join(",\r\n\t") + '\r\n\t].join("");\r\n});'; 37 | } catch (err) { 38 | 39 | } 40 | 41 | file.contents = new Buffer(tpl); 42 | } 43 | 44 | 45 | this.push(file); 46 | cb(); 47 | }); 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /gulp-require-tpl2js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-require-tpl2js", 3 | "version": "0.0.4", 4 | "description": "convert tpl file content to js for requirejs", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/hellopao/gulp_plugin" 9 | }, 10 | "author": { 11 | "name": "qinjia", 12 | "email": "qinjia@outlook.com" 13 | }, 14 | "engines": { 15 | "node": ">=0.10.0" 16 | }, 17 | "files": [ 18 | "index.js" 19 | ], 20 | "keywords": [ 21 | "gulpplugin", 22 | "tpl2js", 23 | "requirejs tpl" 24 | ], 25 | "dependencies": { 26 | "gulp-util": "^3.0.0", 27 | "through2": "^0.6.1" 28 | }, 29 | "license": "MIT", 30 | "homepage": "https://github.com/hellopao/gulp_plugin", 31 | "_id": "gulp-require-tpl2js@0.0.4", 32 | "_from": "gulp-require-tpl2js@" 33 | } 34 | -------------------------------------------------------------------------------- /gulp-require-tpl2js/test.bak.tpl: -------------------------------------------------------------------------------- 1 | ;define(function(){ 2 | return [ 3 | '' 29 | ].join(""); 30 | }); -------------------------------------------------------------------------------- /gulp-require-tpl2js/test.tpl: -------------------------------------------------------------------------------- 1 | 27 | -------------------------------------------------------------------------------- /gulp-rev-files/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /gulp-rev-files/README.md: -------------------------------------------------------------------------------- 1 | ## gulp-rev-flies 2 | 3 | a plugin for gulp.js to replace file's name by adding content hash 4 | 5 | ## Installation 6 | 7 | ```bash 8 | npm install gulp-rev-flies 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | var gulp = require('gulp'); 15 | var rev = require('gulp-rev-flies'); 16 | 17 | gulp.task('rev',function() { 18 | gulp.src("./test/test.html") 19 | .pipe(rev()) 20 | .pipe(gulp.dest('./')); 21 | }); 22 | ``` 23 | 24 | ## Options 25 | 26 | ### hashLen: length of hash version string 27 | Type: `Number` default: 7 28 | 29 | ### verConnecter: version connect char 30 | Type: `String` default: '-' 31 | 32 | ## Example 33 | 34 | ```js 35 | 36 | var gulp = require('gulp'); 37 | var rev = require('./index'); 38 | 39 | gulp.task('default',function(){ 40 | return gulp.src('./test/**/*.*') 41 | .pipe(rev()) 42 | .pipe(gulp.dest('./dest/')) 43 | }) 44 | ``` 45 | -------------------------------------------------------------------------------- /gulp-rev-files/dest/images/bg-2769acd3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellopao/gulp_plugin/66fd1b0f8e9f97ef22d6fe0a5483223fa34f390c/gulp-rev-files/dest/images/bg-2769acd3.png -------------------------------------------------------------------------------- /gulp-rev-files/dest/images/test-25cf2b4e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellopao/gulp_plugin/66fd1b0f8e9f97ef22d6fe0a5483223fa34f390c/gulp-rev-files/dest/images/test-25cf2b4e.png -------------------------------------------------------------------------------- /gulp-rev-files/dest/scripts/test-8ced4e61.js: -------------------------------------------------------------------------------- 1 | console.log("hello world"); 2 | -------------------------------------------------------------------------------- /gulp-rev-files/dest/styles/test-dd42597b.css: -------------------------------------------------------------------------------- 1 | body{background:url('../images/bg.png?d=20153022') no-repeat} 2 | -------------------------------------------------------------------------------- /gulp-rev-files/dest/test-375782d0.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /gulp-rev-files/gulpfile.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var gulp = require('gulp'); 4 | var rev = require('./index'); 5 | 6 | gulp.task('default',function(){ 7 | return gulp.src('./test/**/*.*') 8 | .pipe(rev()) 9 | .pipe(gulp.dest('./dest/')) 10 | }) -------------------------------------------------------------------------------- /gulp-rev-files/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var crypto = require('crypto'); 4 | 5 | var gutil = require('gulp-util'); 6 | var through = require('through2'); 7 | 8 | var PLUGIN_NAME = 'gulp-rev-files'; 9 | 10 | var createHash = function (file,len) { 11 | return crypto.createHash('md5').update(file).digest('hex').substr(0,len); 12 | }; 13 | 14 | module.exports = function(options) { 15 | return through.obj(function(file, enc, cb) { 16 | 17 | options = options || {}; 18 | 19 | if (file.isNull()) { 20 | this.push(file); 21 | return cb(); 22 | } 23 | 24 | if (file.isStream()) { 25 | this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported')); 26 | return cb(); 27 | } 28 | 29 | if (!(typeof options.filter === "function" && options.filter(file.path))) { 30 | var hash = createHash(file.contents,options.hashLen || 7); 31 | 32 | file.path = file.path.replace(/(\.[^\.]+)$/,(options.verConnecter || "-") + hash + "$1"); 33 | } 34 | 35 | this.push(file); 36 | cb(); 37 | }); 38 | }; 39 | 40 | -------------------------------------------------------------------------------- /gulp-rev-files/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-rev-files", 3 | "version": "0.0.3", 4 | "description": "replace filename by adding file hash", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/hellopao/gulp_plugin" 9 | }, 10 | "author": { 11 | "name": "qinjia", 12 | "email": "qinjia@outlook.com" 13 | }, 14 | "engines": { 15 | "node": ">=0.12.0" 16 | }, 17 | "files": [ 18 | "index.js" 19 | ], 20 | "keywords": [ 21 | "gulpplugin", 22 | "file version", 23 | "md5" 24 | ], 25 | "dependencies": { 26 | "gulp-util": "^3.0.0", 27 | "through2": "^0.6.1" 28 | }, 29 | "homepage": "https://github.com/hellopao/gulp_plugin", 30 | "_id": "gulp-rev-files@0.0.3", 31 | "_from": "gulp-rev-files@" 32 | } 33 | -------------------------------------------------------------------------------- /gulp-rev-files/test/images/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellopao/gulp_plugin/66fd1b0f8e9f97ef22d6fe0a5483223fa34f390c/gulp-rev-files/test/images/bg.png -------------------------------------------------------------------------------- /gulp-rev-files/test/images/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellopao/gulp_plugin/66fd1b0f8e9f97ef22d6fe0a5483223fa34f390c/gulp-rev-files/test/images/test.png -------------------------------------------------------------------------------- /gulp-rev-files/test/scripts/test.js: -------------------------------------------------------------------------------- 1 | console.log("hello world"); 2 | -------------------------------------------------------------------------------- /gulp-rev-files/test/styles/test.css: -------------------------------------------------------------------------------- 1 | body{background:url('../images/bg.png?d=20153022') no-repeat} 2 | -------------------------------------------------------------------------------- /gulp-rev-files/test/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /gulp-utf8-convert/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /gulp-utf8-convert/README.md: -------------------------------------------------------------------------------- 1 | ## gulp-utf8-convert 2 | 3 | a plugin for gulp.js to convert file encoding to utf8 4 | 5 | ## Installation 6 | 7 | ```bash 8 | npm install gulp-utf8-convert 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | var gulp = require('gulp'); 15 | var utf8Convert = require('gulp-utf8-convert'); 16 | 17 | gulp.task('convert',function() { 18 | gulp.src("./test.txt") 19 | .pipe(utf8Convert({ 20 | encNotMatchHandle:function (file) { 21 | //notify 22 | } 23 | })) 24 | .pipe(gulp.dest('./')); 25 | }); 26 | ``` 27 | -------------------------------------------------------------------------------- /gulp-utf8-convert/gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var utf8Convert = require('./'); 3 | 4 | gulp.task('convert',function() { 5 | gulp.src("./test.txt") 6 | .pipe(utf8Convert({ 7 | encNotMatchHandle:function (file) { 8 | //send mail 9 | console.log(file + " 编码不正确,请事主速速认领并修改!"); 10 | } 11 | })) 12 | .pipe(gulp.dest('./')); 13 | }) 14 | -------------------------------------------------------------------------------- /gulp-utf8-convert/index.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | 3 | var gutil = require('gulp-util'); 4 | var through = require('through2'); 5 | var isUtf8 = require('is-utf8'); 6 | var iconv = require('iconv-lite'); 7 | var jschardet = require('jschardet'); 8 | 9 | var PLUGIN_NAME = 'gulp-utf8-convert'; 10 | 11 | module.exports = function(options) { 12 | return through.obj(function(file, enc, cb) { 13 | var self = this; 14 | 15 | options = options || {}; 16 | 17 | if (file.isNull()) { 18 | this.push(file); 19 | return cb(); 20 | } 21 | 22 | if (file.isStream()) { 23 | this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported')); 24 | return cb(); 25 | } 26 | 27 | var fileName = file.path.split(path.sep).pop(); 28 | 29 | //todo use text file detect 30 | var isTextFile = /^\.(js|ts|coffee|css|less|sass|html?|tpl|txt|xml|json|ejs|jade)$/.test(path.extname(fileName)); 31 | 32 | if (isTextFile && !isUtf8(file.contents)) { 33 | try { 34 | var encInfo = jschardet.detect(file.contents); 35 | gutil.log(gutil.colors.red('[WARN] file ' + fileName + ' is not encoded in utf-8, it may be encoded in ' + encInfo.encoding)); 36 | 37 | //notify 38 | options.encNotMatchHandle && options.encNotMatchHandle(file.path); 39 | 40 | var content = iconv.decode(file.contents,encInfo.encoding); 41 | file.contents = iconv.encode(content,"utf8"); 42 | } catch(e) { 43 | gutil.log('convert encoding to utf8 failed : ' + e); 44 | } 45 | } 46 | 47 | this.push(file); 48 | cb(); 49 | }); 50 | }; 51 | 52 | -------------------------------------------------------------------------------- /gulp-utf8-convert/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-utf8-convert", 3 | "version": "0.0.7", 4 | "description": "convert file encoding to utf8", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/hellopao/gulp_plugin" 9 | }, 10 | "author": { 11 | "name": "qinjia", 12 | "email": "qinjia@outlook.com" 13 | }, 14 | "engines": { 15 | "node": ">=0.10.0" 16 | }, 17 | "files": [ 18 | "index.js" 19 | ], 20 | "keywords": [ 21 | "gulpplugin", 22 | "file encoding", 23 | "utf8 convert" 24 | ], 25 | "dependencies": { 26 | "gulp-util": "^3.0.0", 27 | "through2": "^0.6.1", 28 | "is-utf8":"^0.2.0", 29 | "iconv-lite":"^0.4.4", 30 | "jschardet":"^1.0.0" 31 | }, 32 | "license": "MIT", 33 | "homepage": "https://github.com/hellopao/gulp_plugin", 34 | "_id": "gulp-utf8-convert@0.0.7", 35 | "_from": "gulp-utf8-convert@" 36 | } 37 | -------------------------------------------------------------------------------- /gulp-utf8-convert/test.txt: -------------------------------------------------------------------------------- 1 | 一地在要工,上是中国同,和的有人我,主产不为这,民了发以经 --------------------------------------------------------------------------------