From 8850b96dc9e4034150574e622595ede0ad03ffb3 Mon Sep 17 00:00:00 2001 From: Joe Skeen Date: Tue, 4 Aug 2015 17:43:57 -0600 Subject: [PATCH 1/3] Added definitions for gulp-load-plugins --- gulp-load-plugins/gulp-load-plugins-tests.ts | 53 ++++++++++++++++++++ gulp-load-plugins/gulp-load-plugins.d.ts | 42 ++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 gulp-load-plugins/gulp-load-plugins-tests.ts create mode 100644 gulp-load-plugins/gulp-load-plugins.d.ts diff --git a/gulp-load-plugins/gulp-load-plugins-tests.ts b/gulp-load-plugins/gulp-load-plugins-tests.ts new file mode 100644 index 000000000..b527fd6a3 --- /dev/null +++ b/gulp-load-plugins/gulp-load-plugins-tests.ts @@ -0,0 +1,53 @@ +/// +/// +/// +/// + +import gulp = require('gulp'); +import gulpConcat = require('gulp-concat'); +import gulpLoadPlugins = require('gulp-load-plugins'); + +interface GulpPlugins extends IGulpPlugins { + concat: typeof gulpConcat; +} + +var plugins = gulpLoadPlugins({ + pattern: ['gulp-*', 'gulp.*'], + config: 'package.json', + scope: ['dependencies', 'devDependencies', 'peerDependencies'], + replaceString: /^gulp(-|\.)/, + camelize: true, + lazy: true, + rename: {} +}); +plugins = gulpLoadPlugins(); + +gulp.task('taskName', () => { + gulp.src('*.*') + .pipe(plugins.concat('concatenated.js')) + .pipe(gulp.dest('output')); +}); + +/* + * From 0.8.0, you can pass in an object of mappings for renaming plugins. For example, + * imagine you want to load the gulp-ruby-sass plugin, but want to refer to it as just + * sass : + */ +plugins = gulpLoadPlugins({ + rename: { + 'gulp-ruby-sass': 'sass' + } +}); +/* + * gulp-load-plugins comes with npm scope support. The major difference is that scoped + * plugins are accessible through an object on plugins that represents the scope. For + * example, if the plugin is @myco/gulp-test-plugin then you can access the plugin as + * shown in the following example: + */ +interface GulpPlugins { + myco: { + testPlugin(): NodeJS.ReadWriteStream; + } +} + +plugins.myco.testPlugin(); diff --git a/gulp-load-plugins/gulp-load-plugins.d.ts b/gulp-load-plugins/gulp-load-plugins.d.ts new file mode 100644 index 000000000..a1aad053e --- /dev/null +++ b/gulp-load-plugins/gulp-load-plugins.d.ts @@ -0,0 +1,42 @@ +// Type definitions for gulp-load-plugins +// Project: https://github.com/jackfranklin/gulp-load-plugins +// Definitions by: Joe Skeen +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +/** Loads in any gulp plugins and attaches them to an object, freeing you up from having to manually require each gulp plugin. */ +declare module 'gulp-load-plugins' { + + interface IOptions { + /** the glob(s) to search for, default ['gulp-*', 'gulp.*'] */ + pattern?: string[]; + /** where to find the plugins, searched up from process.cwd(), default 'package.json' */ + config?: string; + /** which keys in the config to look within, default ['dependencies', 'devDependencies', 'peerDependencies'] */ + scope?: string[]; + /** what to remove from the name of the module when adding it to the context, default /^gulp(-|\.)/ */ + replaceString?: RegExp; + /** if true, transforms hyphenated plugin names to camel case, default true */ + camelize?: boolean; + /** whether the plugins should be lazy loaded on demand, default true */ + lazy?: boolean; + /** a mapping of plugins to rename, the key being the NPM name of the package, and the value being an alias you define */ + rename?: IPluginNameMappings; + } + + interface IPluginNameMappings { + [npmPackageName: string]: string + } + + /** Loads in any gulp plugins and attaches them to an object, freeing you up from having to manually require each gulp plugin. */ + function gulpLoadPlugins(options?: IOptions): IGulpPlugins; + + export = gulpLoadPlugins; +} + +/** + * Extend this interface to use Gulp plugins in your gulpfile.js + */ +interface IGulpPlugins { +} From 8f8e8c55bfa090cb9cf7efcf7b2ce191643cccfd Mon Sep 17 00:00:00 2001 From: Joe Skeen Date: Tue, 4 Aug 2015 17:48:06 -0600 Subject: [PATCH 2/3] fix comment --- gulp-load-plugins/gulp-load-plugins.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gulp-load-plugins/gulp-load-plugins.d.ts b/gulp-load-plugins/gulp-load-plugins.d.ts index a1aad053e..6b31993a9 100644 --- a/gulp-load-plugins/gulp-load-plugins.d.ts +++ b/gulp-load-plugins/gulp-load-plugins.d.ts @@ -1,6 +1,6 @@ // Type definitions for gulp-load-plugins // Project: https://github.com/jackfranklin/gulp-load-plugins -// Definitions by: Joe Skeen +// Definitions by: Joe Skeen // Definitions: https://github.com/borisyankov/DefinitelyTyped /// From bbf926bcf0868edcd6891f6798e4cd9da393af09 Mon Sep 17 00:00:00 2001 From: Joe Skeen Date: Wed, 5 Aug 2015 11:46:31 -0600 Subject: [PATCH 3/3] Utilize generics in plugin loading --- gulp-load-plugins/gulp-load-plugins-tests.ts | 6 +++--- gulp-load-plugins/gulp-load-plugins.d.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gulp-load-plugins/gulp-load-plugins-tests.ts b/gulp-load-plugins/gulp-load-plugins-tests.ts index b527fd6a3..f479be00c 100644 --- a/gulp-load-plugins/gulp-load-plugins-tests.ts +++ b/gulp-load-plugins/gulp-load-plugins-tests.ts @@ -11,7 +11,7 @@ interface GulpPlugins extends IGulpPlugins { concat: typeof gulpConcat; } -var plugins = gulpLoadPlugins({ +var plugins = gulpLoadPlugins({ pattern: ['gulp-*', 'gulp.*'], config: 'package.json', scope: ['dependencies', 'devDependencies', 'peerDependencies'], @@ -20,7 +20,7 @@ var plugins = gulpLoadPlugins({ lazy: true, rename: {} }); -plugins = gulpLoadPlugins(); +plugins = gulpLoadPlugins(); gulp.task('taskName', () => { gulp.src('*.*') @@ -33,7 +33,7 @@ gulp.task('taskName', () => { * imagine you want to load the gulp-ruby-sass plugin, but want to refer to it as just * sass : */ -plugins = gulpLoadPlugins({ +plugins = gulpLoadPlugins({ rename: { 'gulp-ruby-sass': 'sass' } diff --git a/gulp-load-plugins/gulp-load-plugins.d.ts b/gulp-load-plugins/gulp-load-plugins.d.ts index 6b31993a9..c8a11091d 100644 --- a/gulp-load-plugins/gulp-load-plugins.d.ts +++ b/gulp-load-plugins/gulp-load-plugins.d.ts @@ -30,7 +30,7 @@ declare module 'gulp-load-plugins' { } /** Loads in any gulp plugins and attaches them to an object, freeing you up from having to manually require each gulp plugin. */ - function gulpLoadPlugins(options?: IOptions): IGulpPlugins; + function gulpLoadPlugins(options?: IOptions): T; export = gulpLoadPlugins; }