Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
cf8182b86a | |||
c708f964ec | |||
f9c4fb9887 | |||
c6c352f587 | |||
3930912f25 | |||
b6a6c62962 | |||
e43c627307 |
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
node_modules/
|
||||
.settings/
|
||||
.idea/
|
||||
|
||||
ts/*.js
|
||||
ts/*.js.map
|
25
README.md
Normal file
25
README.md
Normal file
@ -0,0 +1,25 @@
|
||||
# gulp-callfunction
|
||||
accepts call to execute in gulp pipeline.
|
||||
|
||||
### build status/Dependencies
|
||||
[](https://travis-ci.org/pushrocks/gulp-callfunction)
|
||||
[](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'
|
47
index.js
Normal file
47
index.js
Normal file
@ -0,0 +1,47 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var through = require("through2");
|
||||
var path = require("path");
|
||||
var beautylog = require("beautylog");
|
||||
//important vars
|
||||
var gulpCallFunction = {
|
||||
executionMode: 'forEach',
|
||||
functionsToExecute: undefined,
|
||||
logBool: false
|
||||
};
|
||||
var runFunctionNames = function () {
|
||||
if (typeof gulpCallFunction.functionsToExecute == "function") {
|
||||
gulpCallFunction.functionsToExecute();
|
||||
}
|
||||
else if (Array.isArray(gulpCallFunction.functionsToExecute)) {
|
||||
for (var anyFunction in gulpCallFunction.functionsToExecute) {
|
||||
anyFunction();
|
||||
}
|
||||
}
|
||||
else {
|
||||
beautylog.error('gulp-callfunction: something is strange with the given arguments');
|
||||
}
|
||||
};
|
||||
var forEach = function (file, enc, cb) {
|
||||
if (gulpCallFunction.logBool)
|
||||
beautylog.log(gulpCallFunction.executionMode);
|
||||
if (gulpCallFunction.executionMode === 'forEach') {
|
||||
if (gulpCallFunction.logBool)
|
||||
beautylog.log('is forEach');
|
||||
runFunctionNames();
|
||||
}
|
||||
//tell gulp that we are complete
|
||||
return cb(null, file);
|
||||
};
|
||||
var atEnd = function () {
|
||||
if (gulpCallFunction.executionMode == "atEnd") {
|
||||
runFunctionNames();
|
||||
}
|
||||
};
|
||||
module.exports = function (functionsToExecute, executionMode, logBool) {
|
||||
if (executionMode === void 0) { executionMode = 'forEach'; }
|
||||
if (logBool === void 0) { logBool = false; }
|
||||
gulpCallFunction.functionsToExecute = functionsToExecute;
|
||||
gulpCallFunction.executionMode = executionMode;
|
||||
gulpCallFunction.logBool = logBool;
|
||||
return through.obj(forEach, atEnd);
|
||||
};
|
17
package.json
17
package.json
@ -1,10 +1,13 @@
|
||||
{
|
||||
"name": "gulp-callfunction",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.4",
|
||||
"description": "accepts a function call as parameter to execute in gulp pipeline",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "cd ts/compile && gulp"
|
||||
"test": "(cd ts/compile && node compile.js) && (node test.js)",
|
||||
"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)",
|
||||
"startdev": "(git checkout master && git pull origin master)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -20,5 +23,13 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/pushrocks/gulp-callfunction/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pushrocks/gulp-callfunction"
|
||||
"homepage": "https://github.com/pushrocks/gulp-callfunction",
|
||||
"devDependencies": {
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-typescript": "^2.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"beautylog": "0.0.15",
|
||||
"through2": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
12
test.js
Normal file
12
test.js
Normal file
@ -0,0 +1,12 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var gulp = require("gulp");
|
||||
var gulpCallFunction = require("./index.js");
|
||||
var myFunction = function () {
|
||||
console.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']);
|
2
test/README.md
Normal file
2
test/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
#Test
|
||||
This directory contains files for testing
|
2
test/result/test.md
Normal file
2
test/result/test.md
Normal file
@ -0,0 +1,2 @@
|
||||
# Test.md
|
||||
This is a test file for the test.js gulp pipeline
|
2
test/test.md
Normal file
2
test/test.md
Normal file
@ -0,0 +1,2 @@
|
||||
# Test.md
|
||||
This is a test file for the test.js gulp pipeline
|
@ -11,6 +11,16 @@ gulp.task('compileTS', function() {
|
||||
return stream;
|
||||
});
|
||||
|
||||
gulp.task('default',['compileTS'], function() {
|
||||
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']);
|
54
ts/index.ts
54
ts/index.ts
@ -1,14 +1,46 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var path, through;
|
||||
var through = require("through2");
|
||||
var path = require("path");
|
||||
var beautylog = require("beautylog");
|
||||
|
||||
through = require("through2");
|
||||
path = require("path");
|
||||
|
||||
module.exports = (jsonObject,type = undefined) => {
|
||||
|
||||
|
||||
return through.obj((file, enc, cb) => {
|
||||
//tell gulp that we are complete
|
||||
return cb(null, file);
|
||||
});
|
||||
//important vars
|
||||
var gulpCallFunction = {
|
||||
executionMode: 'forEach', //can be forEach or atEnd
|
||||
functionsToExecute: undefined,
|
||||
logBool: false
|
||||
};
|
||||
|
||||
var runFunctionNames = function () {
|
||||
if (typeof gulpCallFunction.functionsToExecute == "function" ) {
|
||||
gulpCallFunction.functionsToExecute();
|
||||
} else if (Array.isArray(gulpCallFunction.functionsToExecute)) {
|
||||
for (var anyFunction in gulpCallFunction.functionsToExecute) {
|
||||
anyFunction();
|
||||
}
|
||||
} else {
|
||||
beautylog.error('gulp-callfunction: something is strange with the given arguments');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var forEach = function (file, enc, cb) {
|
||||
if (gulpCallFunction.logBool) beautylog.log(gulpCallFunction.executionMode);
|
||||
if (gulpCallFunction.executionMode === 'forEach') {
|
||||
if(gulpCallFunction.logBool) beautylog.log('is forEach');
|
||||
runFunctionNames();
|
||||
}
|
||||
//tell gulp that we are complete
|
||||
return cb(null, file);
|
||||
};
|
||||
|
||||
var atEnd = function() {
|
||||
if (gulpCallFunction.executionMode == "atEnd") {
|
||||
runFunctionNames();
|
||||
}
|
||||
};
|
||||
module.exports = function (functionsToExecute:any|any[],executionMode:string = 'forEach', logBool = false) {
|
||||
gulpCallFunction.functionsToExecute = functionsToExecute;
|
||||
gulpCallFunction.executionMode = executionMode;
|
||||
gulpCallFunction.logBool = logBool;
|
||||
return through.obj(forEach,atEnd);
|
||||
};
|
||||
|
14
ts/test.ts
Normal file
14
ts/test.ts
Normal file
@ -0,0 +1,14 @@
|
||||
/// <reference path="typings/tsd.d.ts" />
|
||||
var gulp = require("gulp");
|
||||
var gulpCallFunction = require("./index.js");
|
||||
|
||||
var myFunction = function () {
|
||||
console.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']);
|
@ -7,6 +7,9 @@
|
||||
"installed": {
|
||||
"node/node.d.ts": {
|
||||
"commit": "efa0c1196d7280640e624ac1e7fa604502e7bd63"
|
||||
},
|
||||
"colors/colors.d.ts": {
|
||||
"commit": "3191f6e0088eee07c4d8fd24e4d27a40a60d9eb9"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
123
ts/typings/colors/colors.d.ts
vendored
Normal file
123
ts/typings/colors/colors.d.ts
vendored
Normal file
@ -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 <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;
|
||||
}
|
1
ts/typings/tsd.d.ts
vendored
1
ts/typings/tsd.d.ts
vendored
@ -1 +1,2 @@
|
||||
/// <reference path="node/node.d.ts" />
|
||||
/// <reference path="colors/colors.d.ts" />
|
||||
|
Reference in New Issue
Block a user