diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-03-27 21:01:33 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-03-27 21:01:33 +0100 |
commit | cc97a4dd2a967e1c2273bd5f4c5f49a5bf2e2585 (patch) | |
tree | 92c5d88706a6ffc654d1b133618d357890e7096b /node_modules/gulp-json-transform/index.js | |
parent | 3771b4d6b67b34c130f3a9a1a15f42deefdb2eda (diff) |
remove node_modules
Diffstat (limited to 'node_modules/gulp-json-transform/index.js')
-rw-r--r-- | node_modules/gulp-json-transform/index.js | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/node_modules/gulp-json-transform/index.js b/node_modules/gulp-json-transform/index.js deleted file mode 100644 index a42f4239c..000000000 --- a/node_modules/gulp-json-transform/index.js +++ /dev/null @@ -1,59 +0,0 @@ -var Promise = require('promise'); -var through = require('through2'); -var gutil = require('gulp-util'); -var PluginError = gutil.PluginError; - -const PLUGIN_NAME = 'gulp-json-transform'; - -function jsonPromiseParse(rawStr) { - return new Promise(function(resolve, reject) { - var json; - try { - json = JSON.parse(rawStr); - } catch (e) { - return reject(new Error('Invalid JSON: ' + e.message)); - } - resolve(json); - }); -} - -module.exports = function(transformFn, jsonSpace) { - if (!transformFn) { - throw new PluginError(PLUGIN_NAME, 'Missing transform function!'); - } - - return through.obj(function(file, enc, cb) { - var self = this; - - if (file.isStream()) { - return self.emit('error', new PluginError(PLUGIN_NAME, 'Streaming not supported')); - } - - if (file.isBuffer()) { - var fileContent = file.contents.toString(enc); - - jsonPromiseParse(fileContent) - .then(function(data){ - return transformFn(data, { - path: file.path, - relative: file.relative, - base: file.base - }); - }) - .then(function(output) { - var isString = (typeof output === 'string'); - file.contents = new Buffer(isString ? output : JSON.stringify(output, null, jsonSpace)); - self.push(file); - cb(); - }) - .catch(function(e) { - gutil.log(PLUGIN_NAME + ':', gutil.colors.red(e.message)); - self.emit('error', new PluginError(PLUGIN_NAME, e)); - self.emit('end'); - }); - - } - - }); - -}; |