This commit is contained in:
Philipp Kunz 2016-02-01 03:33:33 +01:00
parent c1f1500ffc
commit 27a97c1bde
18 changed files with 97 additions and 2309 deletions

3
.gitignore vendored
View File

@ -4,3 +4,6 @@ node_modules/
ts/*.js ts/*.js
ts/*.js.map ts/*.js.map
ts/typings/
test/result/

3
.npmignore Normal file
View File

@ -0,0 +1,3 @@
ts/
test/
node_modules/

View File

@ -1,15 +1,15 @@
# gulp-callfunction # gulp-function
accepts call to execute in gulp pipeline. accepts call to execute in gulp pipeline.
### build status/Dependencies ### build status/Dependencies
[![Build Status](https://travis-ci.org/pushrocks/gulp-callfunction.svg?branch=v0.0.2)](https://travis-ci.org/pushrocks/gulp-callfunction) [![Build Status](https://travis-ci.org/pushrocks/gulp-function.svg?branch=v0.0.2)](https://travis-ci.org/pushrocks/gulp-function)
[![Dependency Status](https://david-dm.org/pushrocks/gulp-callfunction.svg)](https://david-dm.org/pushrocks/gulp-callfunction) [![Dependency Status](https://david-dm.org/pushrocks/gulp-function.svg)](https://david-dm.org/pushrocks/gulp-function)
[![devDependency Status](https://david-dm.org/pushrocks/gulp-callfunction/dev-status.svg)](https://david-dm.org/pushrocks/gulp-callfunction#info=devDependencies) [![devDependency Status](https://david-dm.org/pushrocks/gulp-function/dev-status.svg)](https://david-dm.org/pushrocks/gulp-function#info=devDependencies)
### Usage ### Usage
```javascript ```javascript
var gulp = require("gulp"); var gulp = require("gulp");
var gulpCallFunction = require("gulp-callfunction"); var gulpFunction = require("gulp-function");
var myFunction = function () { var myFunction = function () {
console.log("Hello World!") console.log("Hello World!")
@ -17,10 +17,10 @@ var myFunction = function () {
gulp.task('gulpTest',function() { gulp.task('gulpTest',function() {
gulp.src('./mydir/*.something') gulp.src('./mydir/*.something')
.pipe(gulpCallFunction(myFunction,'forEach')) .pipe(gulpFunction(myFunction,'forEach'))
.pipe(gulp.dest("./build/")) .pipe(gulp.dest("./build/"))
}); });
``` ```
>Note: The first argument of gulpCallFunction can also be an array of multiple functionnames. >Note: The first argument of gulpFunction can also be an array of multiple functionnames.
>Note: the second argument can be empty (defaults to 'forEach') or 'atEnd' >Note: the second argument can be empty (defaults to 'forEach') or 'atEnd'

4
index.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
/// <reference path="ts/typings/main.d.ts" />
declare var through: any;
declare var path: any;
declare var beautylog: any;

View File

@ -1,25 +1,24 @@
/// <reference path="typings/tsd.d.ts" /> #!/usr/bin/env node
/// <reference path="typings/main.d.ts" />
var through = require("through2"); var through = require("through2");
var path = require("path"); var path = require("path");
var beautylog = require("beautylog")("os"); var beautylog = require("beautylog");
module.exports = function (functionsToExecute, executionMode, logBool) { module.exports = function (functionsToExecuteArg, executionModeArg, logBoolArg) {
if (executionMode === void 0) { executionMode = 'forEach'; } if (executionModeArg === void 0) { executionModeArg = 'forEach'; }
if (logBool === void 0) { logBool = false; } if (logBoolArg === void 0) { logBoolArg = false; }
//important vars //important vars
var gulpCallFunction = { var gulpFunction = {
executionMode: 'forEach', executionMode: executionModeArg,
functionsToExecute: undefined, functionsToExecute: functionsToExecuteArg,
logBool: false logBool: logBoolArg
}; };
gulpCallFunction.functionsToExecute = functionsToExecute;
gulpCallFunction.executionMode = executionMode;
gulpCallFunction.logBool = logBool;
var runFunctionNames = function () { var runFunctionNames = function () {
if (typeof gulpCallFunction.functionsToExecute == "function") { if (typeof gulpFunction.functionsToExecute == "function") {
gulpCallFunction.functionsToExecute(); gulpFunction.functionsToExecute();
} }
else if (Array.isArray(gulpCallFunction.functionsToExecute)) { else if (Array.isArray(gulpFunction.functionsToExecute)) {
for (var anyFunction in gulpCallFunction.functionsToExecute) { for (var anyFunction in gulpFunction.functionsToExecute) {
anyFunction(); anyFunction();
} }
} }
@ -28,10 +27,10 @@ module.exports = function (functionsToExecute, executionMode, logBool) {
} }
}; };
var forEach = function (file, enc, cb) { var forEach = function (file, enc, cb) {
if (gulpCallFunction.logBool) if (gulpFunction.logBool)
beautylog.log(gulpCallFunction.executionMode); beautylog.log(gulpFunction.executionMode);
if (gulpCallFunction.executionMode === 'forEach') { if (gulpFunction.executionMode === 'forEach') {
if (gulpCallFunction.logBool) if (gulpFunction.logBool)
beautylog.log('is forEach'); beautylog.log('is forEach');
runFunctionNames(); runFunctionNames();
} }
@ -39,7 +38,7 @@ module.exports = function (functionsToExecute, executionMode, logBool) {
return cb(null, file); return cb(null, file);
}; };
var atEnd = function (cb) { var atEnd = function (cb) {
if (gulpCallFunction.executionMode == "atEnd") { if (gulpFunction.executionMode == "atEnd") {
runFunctionNames(); runFunctionNames();
} }
cb(); cb();

View File

@ -1,17 +1,17 @@
{ {
"name": "gulp-callfunction", "name": "gulp-function",
"version": "0.0.10", "version": "0.0.10",
"description": "accepts a function call as parameter to execute in gulp pipeline", "description": "accepts a function call as parameter to execute in gulp pipeline",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "(cd ts/compile && node compile.js) && (node test.js)", "test": "(npmts)",
"reinstall": "(rm -r node_modules && npm install)", "reinstall": "(rm -r node_modules && npm install)",
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)", "release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
"startdev": "(git checkout master && git pull origin master)" "startdev": "(git checkout master && git pull origin master)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/pushrocks/gulp-callfunction.git" "url": "https://github.com/pushrocks/gulp-function.git"
}, },
"keywords": [ "keywords": [
"json", "json",
@ -21,15 +21,14 @@
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)", "author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/pushrocks/gulp-callfunction/issues" "url": "https://github.com/pushrocks/gulp-function/issues"
},
"homepage": "https://github.com/pushrocks/gulp-callfunction",
"devDependencies": {
"gulp": "^3.9.0",
"gulp-typescript": "^2.9.2"
}, },
"homepage": "https://github.com/pushrocks/gulp-function",
"dependencies": { "dependencies": {
"beautylog": "1.0.4", "beautylog": "2.0.4",
"through2": "^2.0.0" "through2": "2.0.0"
},
"devDependencies": {
"gulp": "^3.9.0"
} }
} }

13
test.js
View File

@ -1,13 +0,0 @@
/// <reference path="typings/tsd.d.ts" />
var gulp = require("gulp");
var gulpCallFunction = require("./index.js");
var beautylog = require("beautylog")("os");
var myFunction = function () {
beautylog.log("Hello World!");
};
gulp.task('default', function () {
gulp.src('./test/test.md')
.pipe(gulpCallFunction(myFunction, 'forEach'))
.pipe(gulp.dest("./test/result/"));
});
gulp.start.apply(gulp, ['default']);

View File

@ -1,2 +0,0 @@
# Test.md
This is a test file for the test.js gulp pipeline

17
test/test.js Normal file
View File

@ -0,0 +1,17 @@
/// <reference path="typings/main.d.ts" />
var gulp = require("gulp");
var gulpFunction = require("../index.js");
var beautylog = require("beautylog");
var myFunction = function () {
beautylog.log("Mocha Test successfull!");
};
describe("gulpFunction", function () {
it("should run through smoothly", function () {
gulp.task('default', function () {
gulp.src('./test/test.md')
.pipe(gulpFunction(myFunction, 'forEach'))
.pipe(gulp.dest("./test/result/"));
});
gulp.start.apply(gulp, ['default']);
});
});

View File

@ -1,26 +0,0 @@
// import gulp
var gulp = require("gulp"),
gulpTypescript = require("gulp-typescript");
gulp.task('compileTS', function() {
var stream = gulp.src('../index.ts')
.pipe(gulpTypescript({
out: "index.js"
}))
.pipe(gulp.dest("../../"));
return stream;
});
gulp.task('compileTestTS', function() {
var stream = gulp.src('../test.ts')
.pipe(gulpTypescript({
out: "test.js"
}))
.pipe(gulp.dest("../../"));
return stream;
});
gulp.task('default',['compileTS','compileTestTS'], function() {
console.log('Typescript compiled');
});
gulp.start.apply(gulp, ['default']);

View File

@ -1,2 +0,0 @@
nvm use v0.12.7
gulp

View File

@ -1,2 +0,0 @@
# How to compile.
Make sure gulp and gulp-taypescript from npm are available. Then run the gulpfile in this directory.

View File

@ -1,22 +1,22 @@
/// <reference path="typings/tsd.d.ts" /> /// <reference path="typings/main.d.ts" />
var through = require("through2"); var through = require("through2");
var path = require("path"); var path = require("path");
var beautylog = require("beautylog")("os"); var beautylog = require("beautylog");
module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach', logBoolArg = false) { module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:string = 'forEach', logBoolArg = false) {
//important vars //important vars
var gulpCallFunction = { var gulpFunction = {
executionMode: executionModeArg, //can be forEach or atEnd executionMode: executionModeArg, //can be forEach or atEnd
functionsToExecute: functionsToExecuteArg, functionsToExecute: functionsToExecuteArg,
logBool: logBoolArg logBool: logBoolArg
}; };
var runFunctionNames = function () { var runFunctionNames = function () {
if (typeof gulpCallFunction.functionsToExecute == "function" ) { if (typeof gulpFunction.functionsToExecute == "function" ) {
gulpCallFunction.functionsToExecute(); gulpFunction.functionsToExecute();
} else if (Array.isArray(gulpCallFunction.functionsToExecute)) { } else if (Array.isArray(gulpFunction.functionsToExecute)) {
for (var anyFunction in gulpCallFunction.functionsToExecute) { for (var anyFunction in gulpFunction.functionsToExecute) {
anyFunction(); anyFunction();
} }
} else { } else {
@ -26,9 +26,9 @@ module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:stri
var forEach = function (file, enc, cb) { var forEach = function (file, enc, cb) {
if (gulpCallFunction.logBool) beautylog.log(gulpCallFunction.executionMode); if (gulpFunction.logBool) beautylog.log(gulpFunction.executionMode);
if (gulpCallFunction.executionMode === 'forEach') { if (gulpFunction.executionMode === 'forEach') {
if(gulpCallFunction.logBool) beautylog.log('is forEach'); if(gulpFunction.logBool) beautylog.log('is forEach');
runFunctionNames(); runFunctionNames();
} }
//tell gulp that we are complete //tell gulp that we are complete
@ -36,7 +36,7 @@ module.exports = function (functionsToExecuteArg:any|any[],executionModeArg:stri
}; };
var atEnd = function(cb) { var atEnd = function(cb) {
if (gulpCallFunction.executionMode == "atEnd") { if (gulpFunction.executionMode == "atEnd") {
runFunctionNames(); runFunctionNames();
} }
cb(); cb();

View File

@ -1,15 +1,20 @@
/// <reference path="typings/tsd.d.ts" /> /// <reference path="typings/main.d.ts" />
var gulp = require("gulp"); var gulp = require("gulp");
var gulpCallFunction = require("./index.js"); var gulpFunction = require("../index.js");
var beautylog = require("beautylog")("os"); var beautylog = require("beautylog");
var myFunction = function () { var myFunction = function () {
beautylog.log("Hello World!"); beautylog.log("Mocha Test successfull!");
} };
gulp.task('default',function() { describe("gulpFunction",function(){
gulp.src('./test/test.md') it("should run through smoothly",function(){
.pipe(gulpCallFunction(myFunction,'forEach')) gulp.task('default',function() {
.pipe(gulp.dest("./test/result/")) gulp.src('./test/test.md')
.pipe(gulpFunction(myFunction,'forEach'))
.pipe(gulp.dest("./test/result/"))
});
gulp.start.apply(gulp, ['default']);
});
}); });
gulp.start.apply(gulp, ['default']);

7
ts/typings.json Normal file
View File

@ -0,0 +1,7 @@
{
"ambientDependencies": {
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts",
"mocha": "github:Bartvds/tsd-deftools/typings/DefinitelyTyped/mocha/mocha.d.ts",
"colors": "github:DefinitelyTyped/DefinitelyTyped/colors/colors.d.ts"
}
}

View File

@ -1,123 +0,0 @@
// Type definitions for Colors.js 0.6.0-1
// Project: https://github.com/Marak/colors.js
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module "colors" {
interface Color {
(text: string): string;
black: Color;
red: Color;
green: Color;
yellow: Color;
blue: Color;
magenta: Color;
cyan: Color;
white: Color;
gray: Color;
grey: Color;
bgBlack: Color;
bgRed: Color;
bgGreen: Color;
bgYellow: Color;
bgBlue: Color;
bgMagenta: Color;
bgCyan: Color;
bgWhite: Color;
reset: Color;
bold: Color;
dim: Color;
italic: Color;
underline: Color;
inverse: Color;
hidden: Color;
strikethrough: Color;
rainbow: Color;
zebra: Color;
america: Color;
trap: Color;
random: Color;
}
module e {
export function setTheme(theme:any): void;
export var black: Color;
export var red: Color;
export var green: Color;
export var yellow: Color;
export var blue: Color;
export var magenta: Color;
export var cyan: Color;
export var white: Color;
export var gray: Color;
export var grey: Color;
export var bgBlack: Color;
export var bgRed: Color;
export var bgGreen: Color;
export var bgYellow: Color;
export var bgBlue: Color;
export var bgMagenta: Color;
export var bgCyan: Color;
export var bgWhite: Color;
export var reset: Color;
export var bold: Color;
export var dim: Color;
export var italic: Color;
export var underline: Color;
export var inverse: Color;
export var hidden: Color;
export var strikethrough: Color;
export var rainbow: Color;
export var zebra: Color;
export var america: Color;
export var trap: Color;
export var random: Color;
}
export = e;
}
interface String {
black: string;
red: string;
green: string;
yellow: string;
blue: string;
magenta: string;
cyan: string;
white: string;
gray: string;
grey: string;
bgBlack: string;
bgRed: string;
bgGreen: string;
bgYellow: string;
bgBlue: string;
bgMagenta: string;
bgCyan: string;
bgWhite: string;
reset: string;
bold: string;
dim: string;
italic: string;
underline: string;
inverse: string;
hidden: string;
strikethrough: string;
rainbow: string;
zebra: string;
america: string;
trap: string;
random: string;
}

File diff suppressed because it is too large Load Diff

2
ts/typings/tsd.d.ts vendored
View File

@ -1,2 +0,0 @@
/// <reference path="node/node.d.ts" />
/// <reference path="colors/colors.d.ts" />