From 3930912f255f735efc238ce1b3928b35df836396 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sun, 25 Oct 2015 22:45:49 +0100 Subject: [PATCH] now working --- README.md | 22 +++++- index.js | 45 ++++++++++--- npm-debug.log | 41 ++++++++++++ package.json | 3 + ts/index.ts | 39 +++++++++-- ts/tsd.json | 3 + ts/typings/colors/colors.d.ts | 123 ++++++++++++++++++++++++++++++++++ ts/typings/tsd.d.ts | 1 + 8 files changed, 260 insertions(+), 17 deletions(-) create mode 100644 npm-debug.log create mode 100644 ts/typings/colors/colors.d.ts diff --git a/README.md b/README.md index 28b838d..f2f9c8f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,25 @@ # gulp-callfunction accepts call to execute in gulp pipeline. -## build status +### build status/Dependencies [![Build Status](https://travis-ci.org/pushrocks/gulp-callfunction.svg?branch=v0.0.2)](https://travis-ci.org/pushrocks/gulp-callfunction) +[![Dependency Status](https://david-dm.org/pushrocks/gulp-callfunction.svg)](https://david-dm.org/pushrocks/gulp-callfunction) + +### Usage +```javascript +var gulp = require("gulp"); +var gulpCallFunction = require("gulp-callfunction"); + +var myFunction = function () { + console.log("Hello World!") +} + +gulp.task('gulpTest',function() { + gulp.src('./mydir/*.something') + .pipe(gulpCallFunction(myFunction,'forEach')) + .pipe(gulp.dest(./build/)) +}); +``` + +>Note: The first argument of gulpCallFunction can also be an array of multiple functionnames. +>Note: the second argument can be empty (defaults to 'forEach') or 'atEnd' \ No newline at end of file diff --git a/index.js b/index.js index 7542385..da47ab9 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,38 @@ /// -var path, through; -through = require("through2"); -path = require("path"); -module.exports = function (jsonObject, type) { - if (type === void 0) { type = undefined; } - return through.obj(function (file, enc, cb) { - //tell gulp that we are complete - return cb(null, file); - }); +var through = require("through2"); +var path = require("path"); +var beautylog = require("beautylog"); +//important vars +var executionMode; //can be forEach or atEnd +var functionsToExecute; +var runFunctionNames = function () { + if (typeof functionsToExecute === "function") { + functionsToExecute(); + } + else if (Array.isArray(functionsToExecute)) { + for (var anyFunction in functionsToExecute) { + anyFunction(); + } + } + else { + beautylog.error('gulp-callfunction: something is strange with the given arguments'); + } +}; +var forEach = function (file, enc, cb) { + if (executionMode === 'forEach') { + runFunctionNames(); + } + //tell gulp that we are complete + return cb(null, file); +}; +var atEnd = function () { + if (executionMode === "atEnd") { + runFunctionNames(); + } +}; +module.exports = function (functionsToExecute, executionMode) { + if (executionMode === void 0) { executionMode = 'forEach'; } + this.functionsToExecute = functionsToExecute; + this.executionMode = executionMode; + return through.obj(forEach, atEnd); }; diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 0000000..61c971e --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,41 @@ +0 info it worked if it ends with ok +1 verbose cli [ '/usr/local/Cellar/node/4.1.0/bin/node', +1 verbose cli '/usr/local/bin/npm', +1 verbose cli 'version', +1 verbose cli 'patch' ] +2 info using npm@2.14.4 +3 info using node@v4.1.0 +4 info git [ 'status', '--porcelain' ] +5 verbose stack Error: Git working directory not clean. +5 verbose stack M README.md +5 verbose stack M index.js +5 verbose stack M package.json +5 verbose stack M ts/index.ts +5 verbose stack M ts/tsd.json +5 verbose stack A ts/typings/colors/colors.d.ts +5 verbose stack M ts/typings/tsd.d.ts +5 verbose stack at /usr/local/lib/node_modules/npm/lib/version.js:171:21 +5 verbose stack at ChildProcess.exithandler (child_process.js:194:7) +5 verbose stack at emitTwo (events.js:87:13) +5 verbose stack at ChildProcess.emit (events.js:172:7) +5 verbose stack at maybeClose (internal/child_process.js:817:16) +5 verbose stack at Socket. (internal/child_process.js:319:11) +5 verbose stack at emitOne (events.js:77:13) +5 verbose stack at Socket.emit (events.js:169:7) +5 verbose stack at Pipe._onclose (net.js:469:12) +6 verbose cwd /Users/philippkunz/GitHub/pushrocks/gulp-callfunction +7 error Darwin 15.0.0 +8 error argv "/usr/local/Cellar/node/4.1.0/bin/node" "/usr/local/bin/npm" "version" "patch" +9 error node v4.1.0 +10 error npm v2.14.4 +11 error Git working directory not clean. +11 error M README.md +11 error M index.js +11 error M package.json +11 error M ts/index.ts +11 error M ts/tsd.json +11 error A ts/typings/colors/colors.d.ts +11 error M ts/typings/tsd.d.ts +12 error If you need help, you may report this error at: +12 error +13 verbose exit [ 1, true ] diff --git a/package.json b/package.json index 5c0c7fa..a2267c3 100644 --- a/package.json +++ b/package.json @@ -27,5 +27,8 @@ "devDependencies": { "gulp": "^3.9.0", "gulp-typescript": "^2.9.2" + }, + "dependencies": { + "beautylog": "0.0.15" } } diff --git a/ts/index.ts b/ts/index.ts index 611b8c0..3e0a4ed 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,14 +1,39 @@ /// -var path, through; +var through = require("through2"); +var path = require("path"); +var beautylog = require("beautylog"); -through = require("through2"); -path = require("path"); +//important vars +var executionMode:string; //can be forEach or atEnd +var functionsToExecute; +var runFunctionNames = function () { + if (typeof functionsToExecute === "function" ) { + functionsToExecute(); + } else if (Array.isArray(functionsToExecute)) { + for (var anyFunction in functionsToExecute) { + anyFunction(); + } + } else { + beautylog.error('gulp-callfunction: something is strange with the given arguments'); + } +}; -module.exports = (jsonObject,type = undefined) => { - - return through.obj((file, enc, cb) => { +var forEach = function (file, enc, cb) { + if (executionMode === 'forEach') { + runFunctionNames(); + } //tell gulp that we are complete return cb(null, file); - }); +}; + +var atEnd = function() { + if (executionMode === "atEnd") { + runFunctionNames(); + } +}; +module.exports = function (functionsToExecute:any|any[],executionMode:string = 'forEach') { + this.functionsToExecute = functionsToExecute; + this.executionMode = executionMode; + return through.obj(forEach,atEnd); }; diff --git a/ts/tsd.json b/ts/tsd.json index 0764c2c..ed09359 100644 --- a/ts/tsd.json +++ b/ts/tsd.json @@ -7,6 +7,9 @@ "installed": { "node/node.d.ts": { "commit": "efa0c1196d7280640e624ac1e7fa604502e7bd63" + }, + "colors/colors.d.ts": { + "commit": "3191f6e0088eee07c4d8fd24e4d27a40a60d9eb9" } } } diff --git a/ts/typings/colors/colors.d.ts b/ts/typings/colors/colors.d.ts new file mode 100644 index 0000000..5aa2855 --- /dev/null +++ b/ts/typings/colors/colors.d.ts @@ -0,0 +1,123 @@ +// Type definitions for Colors.js 0.6.0-1 +// Project: https://github.com/Marak/colors.js +// Definitions by: Bart van der Schoor +// 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; +} diff --git a/ts/typings/tsd.d.ts b/ts/typings/tsd.d.ts index 4bd49f3..088fea2 100644 --- a/ts/typings/tsd.d.ts +++ b/ts/typings/tsd.d.ts @@ -1 +1,2 @@ /// +///