Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.0.7 #1

Merged
merged 1 commit into from
Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": [
"es2015"
],
"plugins": [
"add-module-exports"
]
}
6 changes: 6 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends: eslint:recommended
parserOptions:
ecmaVersion: 6
sourceType: module
env:
node: true
15 changes: 4 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
.DS_Store
logs
*.log
pids
*.pid
*.seed
lib-cov
coverage
.lock-wscript
npm-debug.log*
node_modules
/coverage/
/lib/
/node_modules/
/npm-debug.log
8 changes: 0 additions & 8 deletions .jscs.json

This file was deleted.

5 changes: 0 additions & 5 deletions .jshintrc

This file was deleted.

7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/coverage/
/src/
/.babelrc
/.editorconfig
/.eslintrc.yml
/.gitignore
/.travis.yml
25 changes: 18 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
language: node_js
node_js:
- "stable"
- "5.0"
- "4.0"
- "6"
- "4"
- "0.12"
- "0.10"
after_script:
after_success:
- npm run coveralls
branches:
only:
- master
before_deploy:
- npm run build
deploy:
provider: npm
api_key:
secure: iZZgNpXKoBt+O/xjmh9bhoxKV0Yth8LuxpDCE0ULD4kGlx/yMyGsSllLu1RHPKJKu4e/hB4svq9Qk8SJLH+q7drld1JzwkT9YPgYNKx4YyHzvi79sI7S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gIoc/1I18pUDHbXtzJL+dVEfk/zjrtGnZ7Ag1wJX6pGaNhndhTTIaFhAaDUojQAkeee5WmUTTgTHmjPjiCryXiKfbLhdXL3c3lXD4EnbBP5Gzv2Yu4YQMTVg1OcDi4zduussmN0uf+Ahm9dNIKkvrcTvAwPJ1tOqnbGH6SX75Zs=
skip_cleanup: true
on:
repo: akim-mcmath/gulp-transform
node: "4"
tags: true
after_deploy:
- npm run unbuild
18 changes: 0 additions & 18 deletions CHANGELOG.md

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Copyright © 2016 Akim McMath. Licensed under the [MIT License][License link
[NPM link]: https://npmjs.org/package/gulp-transform
[Version badge]: https://img.shields.io/npm/v/gulp-transform.svg?style=flat-square
[License badge]: https://img.shields.io/npm/l/gulp-transform.svg?style=flat-square
[License link]: LICENSE.txt
[License link]: LICENSE
[Build badge]: https://img.shields.io/travis/akim-mcmath/gulp-transform/master.svg?style=flat-square
[Build link]: https://travis-ci.org/akim-mcmath/gulp-transform
[Coverage badge]: https://img.shields.io/coveralls/akim-mcmath/gulp-transform/master.svg?style=flat-square&service=github
Expand Down
96 changes: 0 additions & 96 deletions index.js

This file was deleted.

50 changes: 24 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
{
"name": "gulp-transform",
"version": "1.0.6",
"description": "Gulp plugin for performing arbitrary transformations on the contents of files.",
"main": "index.js",
"files": [
"index.js",
"LICENSE.txt",
"README.md"
],
"version": "1.0.7",
"description": "Perform arbitrary transformations on files",
"main": "lib/index.js",
"scripts": {
"test": "npm run jshint && npm run jscs && npm run mocha",
"jshint": "jshint . --exclude-path .gitignore",
"jscs": "jscs .",
"mocha": "istanbul cover _mocha",
"build": "npm run unbuild && babel src -d lib",
"unbuild": "rimraf lib",
"test:lint": "eslint src",
"test:unit": "istanbul cover _mocha",
"test:report": "npm run test:unit && open coverage/lcov-report/index.html",
"test": "npm run test:lint && npm run test:unit",
"coverage": "npm test && open ./coverage/lcov-report/index.html",
"clean": "rm -rf ./node_modules ./coverage",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"preversion": "npm run test"
"coveralls": "cat coverage/lcov.info | coveralls"
},
"engines": {
"node": ">=0.10"
Expand All @@ -40,23 +35,26 @@
},
"homepage": "https://github.com/akim-mcmath/gulp-transform#readme",
"peerDependencies": {
"gulp": "^3.0.0"
"gulp": "3.x"
},
"dependencies": {
"gulp-util": "^3.0.7"
"gulp-util": "^3.0.7",
"lodash": "^4.13.1"
},
"devDependencies": {
"babel-cli": "^6.9.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.9.0",
"babel-register": "^6.9.0",
"chai": "^3.5.0",
"cheerio": "^0.20.0",
"coveralls": "^2.11.6",
"coffee-script": "^1.10.0",
"coveralls": "^2.11.9",
"eslint": "^2.11.1",
"event-stream": "^3.3.2",
"gulp": "^3.9.1",
"istanbul": "^0.4.2",
"jscs": "^2.9.0",
"jshint": "^2.9.1",
"mocha": "^2.4.5",
"rimraf": "^2.5.1",
"sinon": "^1.17.3",
"istanbul": "1.0.0-alpha.2",
"mocha": "^2.5.3",
"rimraf": "^2.5.2",
"sinon": "^1.17.4",
"sinon-chai": "^2.8.0"
}
}
5 changes: 5 additions & 0 deletions src/err.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {PluginError} from 'gulp-util';

export function err(msg) {
throw new PluginError('gulp-transform', msg);
}
27 changes: 27 additions & 0 deletions src/file-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {Transform} from 'stream';
import {transform} from './transform';

export class FileStream extends Transform {

constructor(transformFn, file, options) {
super();

this.fn = transformFn;
this.file = file;
this.opts = options;
this.data = [];
}

_transform(chunk, encoding, next) {
this.data.push(chunk);
next();
}

_flush(done) {
let contents = Buffer.concat(this.data);
this.push(transform(this.fn, contents, this.file, this.opts));

done();
}

}
18 changes: 18 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {isNil, isFunction, isObject} from 'lodash';
import {PluginStream} from './plugin-stream';
import {err} from './err';

export default function gulpTransform(transformFn, options) {
if (isNil(transformFn)) {
err('transformFn must be defined');

} else if (!isFunction(transformFn)) {
err('transformFn must be a function');

} else if (!isNil(options) && !isObject(options)) {
err('options must be an object');

} else {
return new PluginStream(transformFn, options);
}
}
28 changes: 28 additions & 0 deletions src/plugin-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {Transform} from 'stream';
import {FileStream} from './file-stream';
import {transform} from './transform';

export class PluginStream extends Transform {

constructor(transformFn, options={}) {
super({objectMode: true});

this.fn = transformFn;
this.opts = options;
}

_transform(file, encoding, next) {
let {fn, opts} = this;

if (file.isBuffer()) {
file.contents = transform(fn, file.contents, file, opts);
}

if (file.isStream()) {
file.contents = file.contents.pipe(new FileStream(fn, file, opts));
}

next(null, file);
}

}
11 changes: 11 additions & 0 deletions src/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {isBuffer, isString} from 'lodash';
import {err} from './err';

export function transform(fn, contents, file, opts) {
let encoded = opts.encoding ? contents.toString(opts.encoding) : contents;
let transformed = fn.call(opts.thisArg, encoded, file);

return isBuffer(transformed) ? transformed :
isString(transformed) ? new Buffer(transformed) :
err('transformFn must return a string or a Buffer');
}
10 changes: 0 additions & 10 deletions test/config/paths.js

This file was deleted.