From 8850b96dc9e4034150574e622595ede0ad03ffb3 Mon Sep 17 00:00:00 2001 From: Joe Skeen Date: Tue, 4 Aug 2015 17:43:57 -0600 Subject: [PATCH] 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 00000000000000..b527fd6a36d978 --- /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 00000000000000..a1aad053e89849 --- /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 { +}