mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 00:07:07 +00:00
[broccoli-plugin] Introduce types (#29888)
This commit is contained in:
committed by
Sheetal Nandi
parent
3c33ad3938
commit
1e07d02f5d
@@ -0,0 +1,46 @@
|
||||
import Plugin = require('broccoli-plugin');
|
||||
|
||||
declare function copySync(src: string, dest: string): void;
|
||||
declare function setTimeout(callback: () => void, duration: number): void;
|
||||
|
||||
class SlowItDown extends Plugin {
|
||||
constructor(private readonly waitInMS: number) {
|
||||
super([], {
|
||||
annotation: `${waitInMS} ms`,
|
||||
needsCache: false
|
||||
});
|
||||
}
|
||||
|
||||
async build() {
|
||||
await new Promise(resolve => setTimeout(resolve, this.waitInMS));
|
||||
}
|
||||
}
|
||||
|
||||
class FileCopier extends Plugin {
|
||||
constructor(inputNodes: Plugin.BroccoliNode[]) {
|
||||
super(inputNodes, {
|
||||
name: 'CopyFiles',
|
||||
persistentOutput: true
|
||||
});
|
||||
}
|
||||
|
||||
build() {
|
||||
for (const input of this.inputPaths) {
|
||||
copySync(input, this.outputPath);
|
||||
}
|
||||
}
|
||||
|
||||
getCallbackObject() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
new FileCopier([
|
||||
new SlowItDown(5000),
|
||||
'src',
|
||||
'assets'
|
||||
]);
|
||||
|
||||
new Plugin(); // $ExpectError
|
||||
new Plugin([{}]); // $ExpectError
|
||||
new Plugin([], { foo: 'bar' }); // $ExpectError
|
||||
Vendored
+78
@@ -0,0 +1,78 @@
|
||||
// Type definitions for broccoli-plugin 1.3
|
||||
// Project: https://github.com/broccolijs/broccoli-plugin
|
||||
// Definitions by: Dan Freeman <https://github.com/dfreeman>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
export = BroccoliPlugin;
|
||||
|
||||
declare namespace BroccoliPlugin {
|
||||
type BroccoliNode = BroccoliPlugin | string;
|
||||
|
||||
interface BroccoliPluginOptions {
|
||||
/**
|
||||
* The name of this plugin. Defaults to `this.constructor.name`.
|
||||
*/
|
||||
name?: string;
|
||||
|
||||
/**
|
||||
* A descriptive annotation. Useful for debugging, to tell multiple
|
||||
* instances of the same plugin apart.
|
||||
*/
|
||||
annotation?: string;
|
||||
|
||||
/**
|
||||
* If `true`, the output directory is not automatically emptied between
|
||||
* builds. Defaults to `false`.
|
||||
*/
|
||||
persistentOutput?: boolean;
|
||||
|
||||
/**
|
||||
* If `true`, a cache directory is created automatically and the path is
|
||||
* set at `cachePath`. If `false`, a cache directory is not created and
|
||||
* `this.cachePath` is `undefined`. Defaults to `true`.
|
||||
*/
|
||||
needsCache?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
declare class BroccoliPlugin {
|
||||
constructor(inputNodes: BroccoliPlugin.BroccoliNode[], options?: BroccoliPlugin.BroccoliPluginOptions);
|
||||
|
||||
/**
|
||||
* An array of paths on disk corresponding to each node in `inputNodes`.
|
||||
* Your plugin will read files from these paths.
|
||||
*/
|
||||
readonly inputPaths: ReadonlyArray<string>;
|
||||
|
||||
/**
|
||||
* The path on disk corresponding to this plugin instance (this node).
|
||||
* Your plugin will write files to this path. This directory is emptied by
|
||||
* Broccoli before each build, unless the `persistentOutput` options is
|
||||
* `true`.
|
||||
*/
|
||||
readonly outputPath: string;
|
||||
|
||||
/**
|
||||
* The path on disk to an auxiliary cache directory. Use this to store
|
||||
* files that you want preserved between builds. This directory will
|
||||
* only be deleted when Broccoli exits. If a cache directory is not
|
||||
* needed, set `needsCache` to false when calling `broccoli-plugin`
|
||||
* constructor.
|
||||
*/
|
||||
readonly cachePath?: string;
|
||||
|
||||
/**
|
||||
* Override this method in your subclass. It will be called on each
|
||||
* (re-)build. All paths stay the same between builds.
|
||||
* To perform asynchronous work, return a promise.
|
||||
*/
|
||||
build(): void | Promise<any>;
|
||||
|
||||
/**
|
||||
* Advanced usage only.
|
||||
* Return the object on which Broccoli will call `obj.build()`. Called
|
||||
* once after instantiation. By default, returns `this`.
|
||||
*/
|
||||
getCallbackObject(): { build(): void | Promise<any> };
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"broccoli-plugin-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user