diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
commit | abd94a7f5a50f43c797a11b53549ae48fff667c3 (patch) | |
tree | ab8ed457f65cdd72e13e0571d2975729428f1551 /node_modules/gulp-json-transform | |
parent | a0247c6a3fd6a09a41a7e35a3441324c4dcb58be (diff) | |
download | wallet-core-abd94a7f5a50f43c797a11b53549ae48fff667c3.tar.xz |
add node_modules to address #4364
Diffstat (limited to 'node_modules/gulp-json-transform')
-rw-r--r-- | node_modules/gulp-json-transform/.npmignore | 4 | ||||
-rw-r--r-- | node_modules/gulp-json-transform/.travis.yml | 3 | ||||
-rw-r--r-- | node_modules/gulp-json-transform/LICENSE | 22 | ||||
-rw-r--r-- | node_modules/gulp-json-transform/README.md | 68 | ||||
-rw-r--r-- | node_modules/gulp-json-transform/index.js | 59 | ||||
-rw-r--r-- | node_modules/gulp-json-transform/package.json | 98 | ||||
-rw-r--r-- | node_modules/gulp-json-transform/test/fixtures/input.json | 4 | ||||
-rw-r--r-- | node_modules/gulp-json-transform/test/main.js | 77 |
8 files changed, 335 insertions, 0 deletions
diff --git a/node_modules/gulp-json-transform/.npmignore b/node_modules/gulp-json-transform/.npmignore new file mode 100644 index 000000000..fbf7cad83 --- /dev/null +++ b/node_modules/gulp-json-transform/.npmignore @@ -0,0 +1,4 @@ +.DS_Store +node_modules/ +temp/ +npm-debug.log diff --git a/node_modules/gulp-json-transform/.travis.yml b/node_modules/gulp-json-transform/.travis.yml new file mode 100644 index 000000000..87f8cd91a --- /dev/null +++ b/node_modules/gulp-json-transform/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - "0.10"
\ No newline at end of file diff --git a/node_modules/gulp-json-transform/LICENSE b/node_modules/gulp-json-transform/LICENSE new file mode 100644 index 000000000..9c6ee41d9 --- /dev/null +++ b/node_modules/gulp-json-transform/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2014 Tom Haggie + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/node_modules/gulp-json-transform/README.md b/node_modules/gulp-json-transform/README.md new file mode 100644 index 000000000..fa71df3da --- /dev/null +++ b/node_modules/gulp-json-transform/README.md @@ -0,0 +1,68 @@ +gulp-json-transform +=================== +[![NPM Version](http://img.shields.io/npm/v/gulp-json-transform.svg?style=flat)](https://www.npmjs.com/package/gulp-json-transform) +[![Build Status](https://travis-ci.org/thaggie/gulp-json-transform.svg)](https://travis-ci.org/thaggie/gulp-json-transform) +[![Dependencies Status](https://david-dm.org/thaggie/gulp-json-transform.svg)](https://david-dm.org/thaggie/gulp-json-transform) + + +A [gulp](https://github.com/gulpjs/gulp) plugin to transform JSON files, pipe JSON files through it and transform them to other JSON files or other text based formats. + + +## Usage + + +First install `gulp-json-transform` as a development dependency: + +```shell +npm install gulp-json-transform --save-dev +``` + +Then, add it to your gulpfile.js: + +```javascript +var jsonTransform = require('gulp-json-transform'); +``` + +Then create a task that uses it: + +```javascript +gulp.task('do-something', function() { + gulp.src('./app/**/*.json') + .pipe(jsonTransform(function(data, file) { + return { + foobar: data.foo + file.relative + }; + })) + .pipe(gulp.dest('./dist/out/')); +}); +``` + +## API + +### jsonTransform(transformFn [, whiteSpace]) + +#### transformFn +Type: `function` + +A function that takes the JSON object and a file object (parameters path, base and relative are exposed) as the input parameters and should return either a string which is written raw to the file, a JSON object which is stringified or a Promise which resolves to a string or a JSON object. + +Example structure of the file object: +``` +{ + path: 'test/fixtures/input.json', + relative: 'input.json', + base: 'test/fixtures' +} +``` + +#### whiteSpace + +Type: `String` or `Number` +Default: `undefined` + +JSON.stringify's whitespace attribute for pretty-printing the resulting JSON. +See [MDN docs on JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) for more information. + +## License + +[MIT License](http://en.wikipedia.org/wiki/MIT_License) diff --git a/node_modules/gulp-json-transform/index.js b/node_modules/gulp-json-transform/index.js new file mode 100644 index 000000000..a42f4239c --- /dev/null +++ b/node_modules/gulp-json-transform/index.js @@ -0,0 +1,59 @@ +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'); + }); + + } + + }); + +}; diff --git a/node_modules/gulp-json-transform/package.json b/node_modules/gulp-json-transform/package.json new file mode 100644 index 000000000..c9e9faede --- /dev/null +++ b/node_modules/gulp-json-transform/package.json @@ -0,0 +1,98 @@ +{ + "_args": [ + [ + { + "raw": "gulp-json-transform@^0.4.2", + "scope": null, + "escapedName": "gulp-json-transform", + "name": "gulp-json-transform", + "rawSpec": "^0.4.2", + "spec": ">=0.4.2 <0.5.0", + "type": "range" + }, + "/home/dold/repos/taler/wallet-webex" + ] + ], + "_from": "gulp-json-transform@>=0.4.2 <0.5.0", + "_id": "gulp-json-transform@0.4.2", + "_inCache": true, + "_location": "/gulp-json-transform", + "_nodeVersion": "6.2.2", + "_npmOperationalInternal": { + "host": "packages-12-west.internal.npmjs.com", + "tmp": "tmp/gulp-json-transform-0.4.2.tgz_1468387824523_0.4617619593627751" + }, + "_npmUser": { + "name": "thaggie", + "email": "thaggie@gmail.com" + }, + "_npmVersion": "3.9.5", + "_phantomChildren": {}, + "_requested": { + "raw": "gulp-json-transform@^0.4.2", + "scope": null, + "escapedName": "gulp-json-transform", + "name": "gulp-json-transform", + "rawSpec": "^0.4.2", + "spec": ">=0.4.2 <0.5.0", + "type": "range" + }, + "_requiredBy": [ + "#DEV:/" + ], + "_resolved": "https://registry.npmjs.org/gulp-json-transform/-/gulp-json-transform-0.4.2.tgz", + "_shasum": "2245ed252fa309c97b8bdd9d1a19cdd149e32685", + "_shrinkwrap": null, + "_spec": "gulp-json-transform@^0.4.2", + "_where": "/home/dold/repos/taler/wallet-webex", + "author": { + "name": "Tom Haggie", + "url": "https://github.com/thaggie" + }, + "bugs": { + "url": "https://github.com/thaggie/gulp-json-transform/issues" + }, + "dependencies": { + "gulp-util": "^3.0.7", + "promise": "^7.1.1", + "through2": "^2.0.1" + }, + "description": "A gulp plugin to transform json files, pipe json files through it and transform them to other json files or other formats.", + "devDependencies": { + "jshint": "^2.9.2", + "mocha": "^2.5.3", + "should": "^9.0.2" + }, + "directories": {}, + "dist": { + "shasum": "2245ed252fa309c97b8bdd9d1a19cdd149e32685", + "tarball": "https://registry.npmjs.org/gulp-json-transform/-/gulp-json-transform-0.4.2.tgz" + }, + "gitHead": "c7ae1628910e4413650e894b004cae036cbba625", + "homepage": "https://github.com/thaggie/gulp-json-transform", + "keywords": [ + "gulp", + "plugin", + "transform", + "json" + ], + "license": "MIT", + "main": "./index.js", + "maintainers": [ + { + "name": "thaggie", + "email": "thaggie@gmail.com" + } + ], + "name": "gulp-json-transform", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/thaggie/gulp-json-transform.git" + }, + "scripts": { + "test": "mocha" + }, + "version": "0.4.2" +} diff --git a/node_modules/gulp-json-transform/test/fixtures/input.json b/node_modules/gulp-json-transform/test/fixtures/input.json new file mode 100644 index 000000000..fcd280901 --- /dev/null +++ b/node_modules/gulp-json-transform/test/fixtures/input.json @@ -0,0 +1,4 @@ +{ + "foo": "[foo]", + "bar": "[bar]" +}
\ No newline at end of file diff --git a/node_modules/gulp-json-transform/test/main.js b/node_modules/gulp-json-transform/test/main.js new file mode 100644 index 000000000..10f0dc5c9 --- /dev/null +++ b/node_modules/gulp-json-transform/test/main.js @@ -0,0 +1,77 @@ +'use strict'; + +var jsonTransform = require('../'); +var Promise = require('promise'); + +var should = require('should'); +require('mocha'); + +var gutil = require('gulp-util'); +var fs = require('fs'); +var path = require('path'); + +var jshint = require('jshint'); + +describe('gulp-json-transform', function () { + + var testTransform = function (inputFile, transformFn, expected) { + var inputJson = new gutil.File({ + path: 'test/fixtures/' + inputFile, + cwd: 'test/', + base: 'test/fixtures', + contents: fs.readFileSync('test/fixtures/' + inputFile) + }); + + return function (done) { + var stream = jsonTransform(transformFn); + + stream.on('error', function(err) { + should.exist(err); + done(err); + }); + + stream.on('data', function (newFile) { + should.exist(newFile); + should.exist(newFile.contents); + var newFilePath = path.resolve(newFile.path); + var expectedFilePath = path.resolve('test/fixtures/' + inputFile); + newFilePath.should.equal(expectedFilePath); + newFile.relative.should.equal(inputFile); + String(newFile.contents).should.equal(expected); + Buffer.isBuffer(newFile.contents).should.equal(true); + done(); + }); + + stream.write(inputJson); + stream.end(); + }; + }; + + it('should transform a json file to a json file', testTransform('input.json', function(data) { + return {foobar: data.foo + data.bar}; + }, '{"foobar":"[foo][bar]"}')); + + it('should transform a json file to a text file', testTransform('input.json', function(data) { + return data.foo + data.bar; + }, '[foo][bar]')); + + it('should accept the file as a parameter to the transform function', testTransform('input.json', function(data, file) { + var fileProps = ['path', 'relative', 'base']; + for (var fileProp in file) { + if (file.hasOwnProperty(fileProp)) { + var index = fileProps.indexOf(fileProp); + should.ok(index >= 0, 'file object has illegal property: ' + fileProp); + if (index >= 0) { + fileProps.splice(index, 1); + } + } + } + should.ok(fileProps.length === 0, 'file object is missing properties: ' + JSON.stringify(fileProps)); + + return file.relative + ' - ' + data.foo + data.bar; + }, 'input.json - [foo][bar]')); + + it('should accept promises', testTransform('input.json', function(data) { + return Promise.resolve(data.foo + data.bar); + }, '[foo][bar]')); +}); |