From 3802b15cb369437176ff9894d670dd82eff55c8c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 23 Aug 2016 17:07:05 -0700 Subject: [PATCH 1/4] Added declarations and tests for 'gulp-file-include'. --- gulp-file-include/index-tests.ts | 40 ++++++++++++++++++++++++++++++++ gulp-file-include/index.d.ts | 37 +++++++++++++++++++++++++++++ gulp-file-include/tsconfig.json | 19 +++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 gulp-file-include/index-tests.ts create mode 100644 gulp-file-include/index.d.ts create mode 100644 gulp-file-include/tsconfig.json diff --git a/gulp-file-include/index-tests.ts b/gulp-file-include/index-tests.ts new file mode 100644 index 0000000000..1d0d995236 --- /dev/null +++ b/gulp-file-include/index-tests.ts @@ -0,0 +1,40 @@ +import gulp = require("gulp"); +import fileinclude = require("gulp-file-include"); + +function testA() { + fileinclude({ + prefix: "@@", + basepath: "/home/" + }) +} + +function testB() { + gulp.task("fileinclude", function () { + gulp.src(["index.html"]) + .pipe(fileinclude({ + prefix: "@@", + basepath: "@file" + })) + .pipe(gulp.dest("./")); + }); +} + +function testC() { + gulp.task("fileinclude", function () { + gulp.src(["index.html"]) + .pipe(fileinclude({ + filters: { + markdown: (x) => "nope" + } + })) + .pipe(gulp.dest("./")); + }); +} + +function testD() { + fileinclude({ + context: { + arr: ["test1", "test2"] + } + }); +} \ No newline at end of file diff --git a/gulp-file-include/index.d.ts b/gulp-file-include/index.d.ts new file mode 100644 index 0000000000..546225cd03 --- /dev/null +++ b/gulp-file-include/index.d.ts @@ -0,0 +1,37 @@ +// Type definitions for gulp-file-include 0.14.0 +// Project: https://github.com/coderhaoxin/gulp-file-include +// Definitions by: Daniel Rosenwasser +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare function fileinclude(): NodeJS.ReadWriteStream; +declare namespace fileinclude { + export interface Options { + /** default: "@@" */ + prefix?: string; + /** default: "" */ + suffix?: string; + /** + * Can be "@file" or "@root" or some base path. + * default: "@file" + */ + basepath?: "@file" | "@root" | string; + /** + * Filters basically look like functions that get passed into '@@include'. + * When one of these functions is called, something of that name is looked + * up in this object and called to get the contents of that include. + */ + filters?: { [filter: string]: (arg: any) => string }; + /** + * Effectively a context for variables used in 'if' statements. + */ + context?: { [contextVarName: string]: any }; + /** + * default: false + */ + indent?: boolean; + } +} + +export = fileinclude; \ No newline at end of file diff --git a/gulp-file-include/tsconfig.json b/gulp-file-include/tsconfig.json new file mode 100644 index 0000000000..82b98c8f9f --- /dev/null +++ b/gulp-file-include/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "gulp-file-include-tests.ts" + ] +} \ No newline at end of file From 1992f41ea91236f1803eaebc2302f25f59648eec Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 20 Sep 2016 15:51:05 -0400 Subject: [PATCH 2/4] Rename index-tests.ts to gulp-file-include-tests.ts --- .../{index-tests.ts => gulp-file-include-tests.ts} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename gulp-file-include/{index-tests.ts => gulp-file-include-tests.ts} (99%) diff --git a/gulp-file-include/index-tests.ts b/gulp-file-include/gulp-file-include-tests.ts similarity index 99% rename from gulp-file-include/index-tests.ts rename to gulp-file-include/gulp-file-include-tests.ts index 1d0d995236..bd6b6bc810 100644 --- a/gulp-file-include/index-tests.ts +++ b/gulp-file-include/gulp-file-include-tests.ts @@ -37,4 +37,4 @@ function testD() { arr: ["test1", "test2"] } }); -} \ No newline at end of file +} From e3bd4325009600d69dbedc869a7e4116bf771841 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sat, 24 Sep 2016 08:51:03 -0400 Subject: [PATCH 3/4] Fixed up existing signature; added string parameter overload. --- gulp-file-include/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gulp-file-include/index.d.ts b/gulp-file-include/index.d.ts index 546225cd03..9b3acb7d89 100644 --- a/gulp-file-include/index.d.ts +++ b/gulp-file-include/index.d.ts @@ -5,7 +5,8 @@ /// -declare function fileinclude(): NodeJS.ReadWriteStream; +declare function fileinclude(prefix: string): NodeJS.ReadWriteStream; +declare function fileinclude(opts: fileinclude.Options): NodeJS.ReadWriteStream; declare namespace fileinclude { export interface Options { /** default: "@@" */ From 69ecd6bb8b85de86408180ccc41614be6a6448a2 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sat, 24 Sep 2016 08:51:55 -0400 Subject: [PATCH 4/4] Added test for string-accepting overload. --- gulp-file-include/gulp-file-include-tests.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gulp-file-include/gulp-file-include-tests.ts b/gulp-file-include/gulp-file-include-tests.ts index bd6b6bc810..624d13a3fa 100644 --- a/gulp-file-include/gulp-file-include-tests.ts +++ b/gulp-file-include/gulp-file-include-tests.ts @@ -38,3 +38,7 @@ function testD() { } }); } + +function testE() { + fileinclude('@@'); +} \ No newline at end of file