Added definitions for gulp-load-plugins

This commit is contained in:
Joe Skeen
2015-08-04 17:43:57 -06:00
parent 070e3a5e09
commit 8850b96dc9
2 changed files with 95 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
/// <reference path="../node/node" />
/// <reference path="../gulp/gulp" />
/// <reference path="../gulp-concat/gulp-concat" />
/// <reference path="gulp-load-plugins" />
import gulp = require('gulp');
import gulpConcat = require('gulp-concat');
import gulpLoadPlugins = require('gulp-load-plugins');
interface GulpPlugins extends IGulpPlugins {
concat: typeof gulpConcat;
}
var plugins = <GulpPlugins>gulpLoadPlugins({
pattern: ['gulp-*', 'gulp.*'],
config: 'package.json',
scope: ['dependencies', 'devDependencies', 'peerDependencies'],
replaceString: /^gulp(-|\.)/,
camelize: true,
lazy: true,
rename: {}
});
plugins = <GulpPlugins>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 = <GulpPlugins>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();

View File

@@ -0,0 +1,42 @@
// Type definitions for gulp-load-plugins
// Project: https://github.com/jackfranklin/gulp-load-plugins
// Definitions by: Joe Skeen <joeskeen@outlook.com>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
/** 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 {
}