Browse Source

chore: add json plugin

Gerald 9 years ago
parent
commit
29ec462293
3 changed files with 17 additions and 3 deletions
  1. 5 2
      gulpfile.js
  2. 0 1
      package.json
  3. 12 0
      scripts/json.js

+ 5 - 2
gulpfile.js

@@ -1,7 +1,6 @@
 const del = require('del');
 const gulp = require('gulp');
 const concat = require('gulp-concat');
-const replace = require('gulp-replace');
 const merge2 = require('merge2');
 const cssnano = require('gulp-cssnano');
 const gulpFilter = require('gulp-filter');
@@ -12,6 +11,7 @@ const definePack = require('define-commonjs/pack/gulp');
 const templateCache = require('./scripts/templateCache');
 const i18n = require('./scripts/i18n');
 const wrap = require('./scripts/wrap');
+const json = require('./scripts/json');
 const pkg = require('./package.json');
 const isProd = process.env.NODE_ENV === 'production';
 
@@ -126,7 +126,10 @@ gulp.task('js', [
 
 gulp.task('manifest', () => (
   gulp.src(paths.manifest, {base: 'src'})
-  .pipe(replace('__VERSION__', pkg.version))
+  .pipe(json(data => {
+    data.version = pkg.version;
+    return data;
+  }))
   .pipe(gulp.dest('dist'))
 ));
 

+ 0 - 1
package.json

@@ -20,7 +20,6 @@
     "gulp-cssnano": "^2.1.2",
     "gulp-eslint": "^2.0.0",
     "gulp-filter": "^4.0.0",
-    "gulp-replace": "^0.5.4",
     "gulp-svg-sprite": "^1.2.19",
     "gulp-uglify": "^1.5.3",
     "gulp-util": "^3.0.7",

+ 12 - 0
scripts/json.js

@@ -0,0 +1,12 @@
+const gutil = require('gulp-util');
+const through = require('through2');
+
+module.exports = function (handle) {
+  return through.obj(function (file, enc, cb) {
+    if (file.isNull()) return cb();
+    if (file.isStream()) return this.emit('error', new gutil.PluginError('VM-json', 'Stream is not supported.'));
+    handle = handle || (i => i);
+    file.contents = new Buffer(JSON.stringify(handle(JSON.parse(String(file.contents)))));
+    cb(null, file);
+  });
+};