From ba9abec8939816c11f6f6d9be1d6416765167205 Mon Sep 17 00:00:00 2001 From: Jeff May Date: Sat, 26 Oct 2013 13:44:23 -0400 Subject: [PATCH 1/5] Updated grunt declarations to match 0.4.x documentation. Had to weaken some return types for TypeScript (left comments). Conflicts: gruntjs/gruntjs.d.ts --- gruntjs/gruntjs-tests.ts | 2 +- gruntjs/gruntjs.d.ts | 1262 ++++++++++++++++++++++++++++++++------ 2 files changed, 1064 insertions(+), 200 deletions(-) diff --git a/gruntjs/gruntjs-tests.ts b/gruntjs/gruntjs-tests.ts index abd1c90edd..5017451f18 100644 --- a/gruntjs/gruntjs-tests.ts +++ b/gruntjs/gruntjs-tests.ts @@ -4,7 +4,7 @@ // http://gruntjs.com/getting-started#an-example-gruntfile // exports should work same as module.exports -exports = function (grunt) { +exports = (grunt: IGrunt) => { // Project configuration. grunt.initConfig({ diff --git a/gruntjs/gruntjs.d.ts b/gruntjs/gruntjs.d.ts index 463721da92..92da410e37 100644 --- a/gruntjs/gruntjs.d.ts +++ b/gruntjs/gruntjs.d.ts @@ -1,220 +1,1084 @@ -// Type definitions for Grunt JS -// Project: http://gruntjs.com/ -// Definitions by: Basarat Ali Syed -// Definitions: https://github.com/borisyankov/DefinitelyTyped +/// +/** + * {@link http://github.com/marak/colors.js/} + */ +declare module colors { -//////////////// -/// To add plugins update the IGruntConfig using open ended interface syntax -//////////////// -interface IGruntConfig { - pkg?: any; + interface String { + yellow: string; + cyan: string; + white: string; + magenta: string; + green: string; + red: string; + grey: string; + blue: string; + } } -//////////////// -/// Sample grunt plugin definition: -/// uglify : https://github.com/gruntjs/grunt-contrib-uglify -//////////////// -interface IGruntUglifyConfig { - mangle?: boolean; - compress?: boolean; - beautify?: boolean; - report?: any; // false / 'min' / 'gzip' - sourceMap?: any; // String / Function - sourceMapRoot?: string; - sourceMapIn?: string; - sourceMappingURL?: any; // String / Function - sourceMapPrefix?: number; - wrap?: string; - exportAll?: boolean; - preserveComments?: any; // boolean / string / function - banner?: string; -} -interface IGruntConfig { - uglify?: { - options?: IGruntUglifyConfig; - build?: { - src: string; - dest: string; - }; +declare module node { - }; + /** + * {@link http://npmjs.org/doc/json.html} + */ + interface NodePackage { + name: string + version: string + description?: string + keywords?: string[] + homepage?: string + } } +/** + * {@link http://github.com/isaacs/minimatch} + */ +declare module minimatch { + /** + * A minimal matching utility options. + * + * This is the matching library used internally by npm. + * Eventually, it will replace the C binding in node-glob. + * It works by converting glob expressions into JavaScript RegExp objects. + */ + interface IMinimatchOptions { + /* + All options are false by default. + */ + /** + * Dump a ton of stuff to stderr. + */ + debug?: boolean -//////////////// -// Main Grunt object -// http://gruntjs.com/api/grunt -//////////////// -interface IGrunt { - // Config - config: IGruntConfigObject; - initConfig(config?: IGruntConfig): void; + /** + * Do not expand {a,b} and {1..3} brace sets. + */ + nobrace?: boolean + /** + * Disable ** matching against multiple folder names. + */ + noglobstar?: boolean - // Tasks - task: any; - // Creating - registerTask: Function; - registerMultiTask: Function; - renameTask: Function; - // Loading - loadTasks: Function; - loadNpmTasks: Function; + /** + * Allow patterns to match filenames starting with a period, + * even if the pattern does not explicitly have a period in that spot. + */ + // Note that by default, a/**\/b will not match a/.d/b, unless dot is set. + dot?: boolean - // Errors - warn: Function; - fatal: Function; + /** + * Disable "extglob" style patterns like +(a|b). + */ + noext?: boolean - // Misc: - package: any; - version: any; + /** + * Perform a case-insensitive match. + */ + nocase?: boolean - // File - file: IGruntFileObject; + /** + * When a match is not found by minimatch.match, return a list containing the pattern itself. + * When set, an empty list is returned if there are no matches. + */ + nonull?: boolean - // Event - event: any; - // Fail - fail: any; - // Log - log: any; - // Options - option: any; - // Template - template: any; - // Util - util: any; + /** + * If set, then patterns without slashes will be matched against the basename of the path if it contains slashes. + * For example, a?b would match the path /xyz/123/acb, but not /xyz/acb/123. + */ + matchBase?: boolean + + /** + * Suppress the behavior of treating # at the start of a pattern as a comment. + */ + nocomment?: boolean + + /** + * Suppress the behavior of treating a leading ! character as negation. + */ + nonegate?: boolean + + /** + * Returns from negate expressions the same as if they were not negated. (Ie, true on a hit, false on a miss.) + */ + flipNegate?: boolean + } } -//////////////// -/// Grunt Config object -/// http://gruntjs.com/api/grunt.config#accessing-config-data -//////////////// -interface IGruntConfigObject { - (...param: any[]): any; - init: (config?: IGruntConfig) => void; - get: Function; - process: Function; - getRaw: Function; - set: Function; - escape: (propString: string) => void; - requires: Function; +/* GRUNT CONFIGURATION + *********************/ + +declare module grunt { + + module config { + + /** + * {@link http://gruntjs.com/sample-gruntfile} + */ + interface IProjectConfig extends IConfigOptionFormat { + pkg: string + } + + /** + * @see IProjectConfig + */ + interface IConfigOptionFormat { + [plugin: string]: IConfigPluginFormat + } + + /** + * A map of plugin task names to config objects. + */ + interface IConfigPluginFormat { + [task: string]: grunt.task.ITaskOptions + } + + /** + * {@link http://gruntjs.com/api/grunt.config} + */ + interface ConfigModule { + /** + * Get or set a value from the project's Grunt configuration. + * This method serves as an alias to other methods; + * if two arguments are passed, grunt.config.set is called, + * otherwise grunt.config.get is called. + */ + (prop: string, value: any): void + (prop: string): any + + /** + * Initialize a configuration object for the current project. + * The specified configObject is used by tasks and can be accessed using the grunt.config method. + * Nearly every project's Gruntfile will call this method. + */ + init(config: IProjectConfig): void + + /** + * Get a value from the project's Grunt configuration. + * If prop is specified, that property's value is returned, or null if that property is not defined. + * If prop isn't specified, a copy of the entire config object is returned. + * Templates strings will be recursively processed using the grunt.config.process method. + */ + get(prop: string): T + get(): ConfigModule + + /** + * Process a value, recursively expanding <% %> templates (via the grunt.template.process method) + * in the context of the Grunt config, as they are encountered. + * this method is called automatically by grunt.config.get but not by grunt.config.getRaw. + * + * If any retrieved value is entirely a single '<%= foo %>' or '<%= foo.bar %>' template string, + * and the specified foo or foo.bar property is a non-string (and not null or undefined) value, + * it will be expanded to the actual value. That, combined with grunt's task system automatically + * flattening arrays, can be extremely useful. + */ + process(value: string): T + + /** + * Get a raw value from the project's Grunt configuration, without processing <% %> template strings. + * If prop is specified, that property's value is returned, or null if that property is not defined. + * If prop isn't specified, a copy of the entire config object is returned. + */ + getRaw(prop: string): T + + /** + * Set a value into the project's Grunt configuration. + * @note any specified <% %> template strings will only be processed when config data is retrieved. + */ + set(prop: string, value: any): void + + /** + * Escape '.' dots in the given propString. This should be used for property names that contain dots. + */ + escape(propString: string): string + + /** + * Fail the current task if one or more required config properties is missing, null or undefined. + * One or more string or array config properties may be specified. + */ + requires(prop: string, ...andProps: string[]) + requires(prop: string[], ...andProps: string[][]) + } + } + + module event { + /** + * {@link http://github.com/hij1nx/EventEmitter2} + */ + interface EventModule { + + /** + * Adds a listener to the end of the listeners array for the specified event. + */ + addListener(event: string, listener: Function): void + on(event: string, listener: Function): void + + /** + * Adds a listener that will be fired when any event is emitted. + */ + onAny(listener: Function): void + + /** + * Removes the listener that will be fired when any event is emitted. + */ + offAny(listener: Function): void + + /** + * Adds a one time listener for the event. + * The listener is invoked only the first time the event is fired, after which it is removed. + */ + once(event: string, listener: Function): void + + /** + * Adds a listener that will execute n times for the event before being removed. + * The listener is invoked only the first time the event is fired, after which it is removed. + */ + many(event: string, timesToListen: number, listener: Function): void + + /** + * Remove a listener from the listener array for the specified event. + * Caution: changes array indices in the listener array behind the listener. + */ + removeListener(event: string, listener: Function): void + off(event: string, listener: Function): void + + /** + * Removes all listeners, or those of the specified event. + */ + removeAllListeners(event: string): void + + /** + * By default EventEmitters will print a warning if more than 10 listeners are added to it. + * This is a useful default which helps finding memory leaks. Obviously not all Emitters + * should be limited to 10. This function allows that to be increased. + * + * Set to zero for unlimited. + */ + setMaxListener(n: number): void + + /** + * Returns an array of listeners for the specified event. + * This array can be manipulated, e.g. to remove listeners. + */ + listeners(event: string): Function[] + + /** + * Returns an array of listeners that are listening for any event that is specified. + * This array can be manipulated, e.g. to remove listeners. + */ + listenersAny() + + /** + * Execute each of the listeners that may be listening for the specified event name + * in order with the list of arguments. + */ + emit(event: string, ...args: any[]) + } + } + + module fail { + + enum ErrorCode { + NoError = 0, + Fatal = 1, + MissingGruntfile = 2, + Task = 3, + Template = 4, + Autocomplete = 5, + Warning = 6, + } + + interface FailModule { + + /** + * Display a warning and abort Grunt immediately. + * Grunt will continue processing tasks if the --force command-line option was specified. + */ + warn(error: string, errorCode?: ErrorCode): void + warn(error: Error, errorCode?: ErrorCode): void + + /** + * Display a warning and abort Grunt immediately. + */ + fatal(error: string, errorCode?: ErrorCode): void + fatal(error: Error, errorCode?: ErrorCode): void + } + } + + module file { + + /** + * {@link http://gruntjs.com/api/grunt.file#grunt.file.defaultencoding} + */ + interface IFileEncodedOption { + encoding: string + } + + /** + * {@link http://gruntjs.com/api/grunt.file#grunt.file.copy} + * + * @see IFileWriteBufferOption + * @see IFileWriteStringOption + */ + interface IFileWriteOptions { + /** + * These optional globbing patterns will be matched against the filepath + * (not the filename) using grunt.file.isMatch. If any specified globbing + * pattern matches, the file won't be processed via the `process` function. + * If `true` is specified, processing will be prevented. + */ + // noProcess?: string[] + // noProcess?: boolean + noProcess?: any + } + + /** + * @see IFileWriteOptions + */ + interface IFileWriteBufferOption extends grunt.file.IFileWriteOptions { + /** + * The source file contents and file path are passed into this function, + * whose return value will be used as the destination file's contents. If + * this function returns `false`, the file copy will be aborted. + */ + process?: (buffer: NodeBuffer) => boolean + } + + /** + * @see IFileWriteOptions + */ + interface IFileWriteStringOption extends grunt.file.IFileWriteOptions { + /** + * The source file contents and file path are passed into this function, + * whose return value will be used as the destination file's contents. If + * this function returns `false`, the file copy will be aborted. + */ + process?: (file: string) => boolean + } + + /** + * {@link http://gruntjs.com/api/grunt.file} + */ + interface FileModule { + + /** + * Set this property to change the default encoding used by all grunt.file methods. + * Defaults to 'utf8'. + * + * If you do have to change this value, it's recommended that you change + * it as early as possible inside your Gruntfile. + */ + defaultEncoding: string + + /** + * Read and return a file's contents. + * Returns a string, unless options.encoding is null in which case it returns a Buffer. + */ + read(filepath): string + read(filepath, options: IFileEncodedOption): NodeBuffer + + /** + * Read a file's contents, parsing the data as JSON and returning the result. + * @see FileModule.read for a list of supported options. + */ + readJSON(filepath): string + readJSON(filepath, options: IFileEncodedOption): NodeBuffer + + /** + * Read a file's contents, parsing the data as YAML and returning the result. + * @see FileModule.read for a list of supported options. + */ + readYAML(filepath: string) + readYAML(filepath: string, options: IFileEncodedOption) + + /** + * Write the specified contents to a file, creating intermediate directories if necessary. + * Strings will be encoded using the specified character encoding, Buffers will be written to disk as-specified. + * + * @param contents If `contents` is a Buffer, encoding is ignored. + * @param options If an encoding is not specified, default to grunt.file.defaultEncoding. + */ + write(filepath: string, contents: NodeBuffer, options?: IFileEncodedOption): void + + /** + * Copy a source file to a destination path, creating intermediate directories if necessary. + */ + copy(srcpath: string, destpath: string) + copy(srcpath: string, destpath: string, options: IFileWriteStringOption) + copy(srcpath: string, destpath: string, options: IFileWriteBufferOption) + + /** + * Delete the specified filepath. Will delete files and folders recursively. + */ + delete(filepath: string, options?: { force?: boolean }) + + /** + * Works like mkdir -p. Create a directory along with any intermediate directories. + * If mode isn't specified, it defaults to 0777 & (~process.umask()). + */ + mkdir(dirpath: string, mode?: string) + + /** + * Recurse into a directory, executing callback for each file. + * + * Callback args: + * abspath - The full path to the current file, + * which is nothing more than the rootdir + subdir + filename arguments, joined. + * rootdir - The root director, as originally specified. + * subdir - The current file's directory, relative to rootdir. + * filename - The filename of the current file, without any directory parts. + */ + recurse( + rootdir: string, + callback: (abspath: string, rootdir: string, subdir: string, filename: string) => void + ) + + /** + * Return a unique array of all file or directory paths that match the given globbing pattern(s). + * This method accepts either comma separated globbing patterns or an array of globbing patterns. + * Paths matching patterns that begin with ! will be excluded from the returned array. + * Patterns are processed in order, so inclusion and exclusion order is significant. + * + * File paths are relative to the Gruntfile unless the current working directory is changed with + * grunt.file.setBase or the --base command-line option. + */ + expand(patterns: string[]): string[] + expand(options: IFilesConfig, patterns: string[]): string[] + + /** + * Returns an array of src-dest file mapping objects. + * For each source file matched by a specified pattern, join that file path to the specified dest. + * This file path may be flattened or renamed, depending on the options specified. + * + * @see FileModule.expand method documentation for an explanation of how the patterns + * and options arguments may be specified. + */ + expandMapping(patterns: string[], dest: string, options: IExpandedFilesConfig): IFilesMap + + /** + * Match one or more globbing patterns against one or more file paths. + * Returns a uniqued array of all file paths that match any of the specified globbing patterns. + * Both the patterns and filepaths argument can be a single string or array of strings. + * Paths matching patterns that begin with ! will be excluded from the returned array. + * Patterns are processed in order, so inclusion and exclusion order is significant. + */ + match(pattern: string, filepath: string): string[] + match(pattern: string, filepaths: string[]): string[] + match(patterns: string[], filepath: string): string[] + match(patterns: string[], filepaths: string[]): string[] + match(options: minimatch.IMinimatchOptions, pattern: string, filepath: string): string[] + match(options: minimatch.IMinimatchOptions, pattern: string, filepaths: string[]): string[] + match(options: minimatch.IMinimatchOptions, patterns: string[], filepath: string): string[] + match(options: minimatch.IMinimatchOptions, patterns: string[], filepaths: string[]): string[] + + /** + * This method contains the same signature and logic as the grunt.file.match method, + * but simply returns true if any files were matched, otherwise false. + * + * @see FileModule.match + */ + isMatch(pattern: string, filepath: string): boolean + isMatch(pattern: string, filepaths: string[]): boolean + isMatch(patterns: string[], filepath: string): boolean + isMatch(patterns: string[], filepaths: string[]): boolean + isMatch(options: minimatch.IMinimatchOptions, pattern: string, filepath: string): boolean + isMatch(options: minimatch.IMinimatchOptions, pattern: string, filepaths: string[]): boolean + isMatch(options: minimatch.IMinimatchOptions, patterns: string[], filepath: string): boolean + isMatch(options: minimatch.IMinimatchOptions, patterns: string[], filepaths: string[]): boolean + + + /* + * Like the Node.js path.join method, the methods below will + * join all arguments together and normalize the resulting path. + */ + + /** + * Does the given path exist? + */ + exists(path: string, ...append: string[]): boolean + + /** + * Is the given path a symbolic link? + */ + isLink(path: string, ...append: string[]): boolean + + /** + * Is the given path a symbolic link? + */ + isDir(path: string, ...append: string[]): boolean + + /** + * Is the given path a file? + */ + isFile(path: string, ...append: string[]): boolean + + /** + * Is a given file path absolute? + */ + isPathAbsolute(path: string, ...append: string[]): boolean + + /** + * Do all the specified paths refer to the same path? + */ + arePathsEquivalent(path: string, ...append: string[]): boolean + + /** + * Are all descendant path(s) contained within the specified ancestor path? + */ + doesPathContain(ancestorPath: string, decendantPaths: string[]): boolean + + /** + * Is a given file path the current working directory (CWD)? + */ + isPathCwd(path: string, ...append: string[]): boolean + + /** + * Change grunt's current working directory (CWD). + * By default, all file paths are relative to the Gruntfile. + * This works just like the --base command-line option. + */ + setBase(path: string, ...append: string[]): void + + // External libraries + // TODO: Create declarations + glob: any + minimatch: any + findup: any + } + + /** + * A convenience type. + * + * {@link http://gruntjs.com/configuring-tasks#files} + */ + interface IFilesArray extends Array {} + + /** + * {@link http://gruntjs.com/configuring-tasks#files} + */ + interface IFilesConfig extends minimatch.IMinimatchOptions { + + /** + * Pattern(s) to match, relative to the {@link IExpandedFilesConfig.cwd}. + */ + src: string[] + + /** + * Destination path prefix. + */ + dest?: string + + /** + * Process a dynamic src-dest file mapping, + * @see {@link http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically for more information. + */ + expand?: boolean // = false + + /** + * Either a valid fs.Stats method name: + * - isFile + * - isDirectory + * - isBlockDevice + * - isCharacterDevice + * - isSymbolicLink + * - isFIFO + * - isSocket + * + * or a function that is passed the matched src filepath and returns true or false. + * + * string + * (src: string) => boolean + */ + // filter?: string + // filter?: (src: string) => boolean + filter?: any + } + + /** + * These are valid for compact-format + */ + interface IExpandedFilesConfig extends IFilesConfig { + + /** + * Enables the following options + */ + expand: boolean // = true + + /** + * All {@link IExpandedFilesConfig.src} matches are relative to (but don't include) this path. + */ + cwd?: boolean + + /** + * Replace any existing extension with this value in generated {@link IExpandedFilesConfig.dest} paths. + */ + ext?: boolean + + /** + * Remove all path parts from generated {@link IExpandedFilesConfig.dest} paths. + */ + flatten?: boolean + + /** + * This function is called for each matched src file, (after extension renaming and flattening). + * The {@link IExpandedFilesConfig.dest} and matched {@link IExpandedFilesConfig.src} path are passed in, + * and this function must return a new dest value. + * If the same dest is returned more than once, each src which used it will be added to an array of sources for it. + */ + rename?: boolean + } + + /** + * @see {@link http://gruntjs.com/configuring-tasks#files-object-format} + */ + interface IFilesMap { + /** + * A map of sources to a destination. + */ + [dest: string]: string[] + } + } + + module log { + + /** + * Grunt output should look consistent, and maybe even pretty. + * As such, there is a plethora of logging methods, and a few useful patterns. + * All of the methods that actually log something are chainable. + */ + interface CommonLogging { + + /** + * Log the specified msg string, with no trailing newline. + */ + write(msg: string): T + + /** + * Log the specified msg string, with trailing newline. + */ + writeln(msg: string): T + + /** + * If msg string is omitted, logs ERROR in red, + * otherwise logs >> msg, with trailing newline. + */ + error(msg: string): T + + /** + * Log an error with grunt.log.error, wrapping text to 80 columns using grunt.log.wraptext. + */ + errorlns(msg: string): T + + /** + * If msg string is omitted, logs OK in green, otherwise logs >> msg, with trailing newline. + */ + ok(msg: string): T + + /** + * Log an ok message with grunt.log.ok, wrapping text to 80 columns using grunt.log.wraptext. + */ + oklns(msg: string): T + + /** + * Log the specified msg string in bold, with trailing newline. + */ + subhead(msg: string): T + + /** + * Log a list of obj properties (good for debugging flags). + */ + writeflags(obj: any): T + } + + /** + * @note all methods available under grunt.verbose work exactly like grunt.log methods, + * but only log if the --verbose command-line option was specified. + */ + interface VerboseLogModule extends CommonLogging { + or: NotVerboseLogModule + } + + /** + * @note all methods available under grunt.verbose work exactly like grunt.log methods, + * but only log if the --verbose command-line option was not specified. + */ + interface NotVerboseLogModule extends CommonLogging { + or: VerboseLogModule + } + + /** + * {@link http://gruntjs.com/api/grunt.log} + */ + interface LogModule extends CommonLogging { + verbose: VerboseLogModule + notverbose: NotVerboseLogModule + } + } + + module option { + + /** + * {@link http://gruntjs.com/api/grunt.option} + */ + interface OptionModule { + + /** + * Gets or sets an option. + * Boolean options can be negated by prepending no- onto the key. For example: + * + * grunt.option('staging', false); + * var isDev = grunt.option('no-staging'); + * assert(isDev === true) + */ + (key: string, value: T): void + (key: string): T + + /** + * Initialize grunt.option. + * If initObject is omitted option will be initialized to an empty object + * otherwise will be set to initObject. + */ + init(initObject?: any): void + + /** + * Returns the options as an array of command line parameters. + */ + flags: grunt.IFlag[] + } + + } + + module task { + + interface TaskFunction extends ITask { + (...args: any[]): boolean + } + + /** + * {@link http://gruntjs.com/api/grunt.task} + */ + interface CommonTaskModule { + + /** + * If a task list is specified, the new task will be an alias for one or more other tasks. + * Whenever this "alias task" is run, every specified task in taskList will be run, in the order specified. + * The taskList argument must be an array of tasks. + */ + registerTask(taskName: string, taskList: string[]): void + + /** + * If a description and taskFunction are passed, the specified function will be executed + * whenever the task is run. + * + * In addition, the specified description will be shown when grunt --help is run. + * Task-specific properties and methods are available inside the task function as properties + * of the this object. The task function can return false to indicate that the task has failed. + * + * @note taskFunction.apply(scope: grunt.task.IMultiTask, args: any[]) + */ + registerTask(taskName: string, description: string, taskFunction: TaskFunction): void + + /** + * Register a "multi task." A multi task is a task that implicitly iterates over all of its + * named sub-properties (AKA targets) if no target was specified. + * In addition to the default properties and methods, extra multi task-specific properties + * are available inside the task function as properties of the this object. + * + * @note taskFunction.apply(scope: grunt.task.IMultiTask, args: any[]) + */ + registerMultiTask(taskName: string, taskFunction: grunt.task.ITask): void + registerMultiTask(taskName: string, taskDescription: string, taskFunction: TaskFunction): void + } + + /** + * {@link http://gruntjs.com/api/grunt.task#queueing-tasks} + */ + interface TaskModule extends CommonTaskModule { + /** + * Enqueue one or more tasks. + * Every specified task in taskList will be run immediately after the current task completes, + * in the order specified. The task list can be an array of tasks or individual task arguments. + */ + run(tasks: string[]): void + run(task: string, ...thenTasks: string[]): void + + /** + * Empty the task queue completely. Unless additional tasks are enqueued, no more tasks will be run. + */ + clearQueue(): void + + /** + * Normalizes a task target configuration object into an array of src-dest file mappings. + * This method is used internally by the multi task system this.files / grunt.task.current.files property. + */ + normalizeMultiTaskFiles(data: grunt.config.IProjectConfig, targetname?: string): grunt.file.IFilesMap + } + + interface AsyncResultCatcher { + /** + * Either false or an Error object may be passed to the done function + * to instruct Grunt that the task has failed. + */ + done(success: boolean): void; + done(error: Error): void; + done(result: any): void; + } + + /** + * @link http://gruntjs.com/inside-tasks + * + * Grunt version 0.4.x + */ + interface ITask { + + /** + * If a task is asynchronous, this method must be invoked to instruct Grunt to wait. + * It returns a handle to a "done" function that should be called when the task has completed. + * + * // Tell Grunt this task is asynchronous. + * var done = this.async(); + * // Your async code. + * setTimeout(function() { + * // Let's simulate an error, sometimes. + * var success = Math.random() > 0.5; + * // All done! + * done(success); + * }, 1000); + */ + async(): AsyncResultCatcher + + /** + * If one task depends on the successful completion of another task (or tasks), + * this method can be used to force Grunt to abort if the other task didn't run, + * or if the other task failed. + * + * @param tasks an array of task names or individual task names, as arguments. + * @note that this won't actually run the specified task(s), + * it will just fail the current task if they haven't already run successfully. + */ + requires(tasks: string[]): void + requires(tasks: string, ...otherTasks: string[]): void + requires(tasks: string[], ...otherTasks: string[][]): void + + /** + * Fail the current task if one or more required config properties is missing. + * One or more string or array config properties may be specified. + * this.requiresConfig(prop [, prop [, ...]]) + */ + requiresConfig(prop: string, ...andProps: string[]) + + /** + * The name of the task, as defined in grunt.registerTask. + * For example, if a "sample" task was run as grunt sample or grunt sample:foo, + * inside the task function, this.name would be "sample". + */ + name: string + + /** + * The name of the task, including any colon-separated arguments or flags specified on the command-line. + * For example, if a "sample" task was run as grunt sample:foo, + * inside the task function, this.nameArgs would be "sample:foo". + */ + nameArgs: string + + /** + * An array of arguments passed to the task. + * For example, if a "sample" task was run as grunt sample:foo:bar, + * inside the task function, this.args would be ["foo", "bar"]. + */ + args: string[] + + /** + * An object generated from the arguments passed to the task. + * For example, if a "sample" task was run as grunt sample:foo:bar, + * inside the task function, this.flags would be {foo: true, bar: true}. + */ + flags: grunt.IFlag[] + + /** + * The number of grunt.log.error calls that occurred during this task. + * This can be used to fail a task if errors were logged during the task. + */ + errorCount: number + + /** + * Returns an options object. + * Properties of the optional defaultsObj argument will be overridden by any task-level options + * object properties, which will be further overridden in multi tasks by any target-level + * options object properties. + */ + // options(defaultsObj: T): ITaskOptions + // options(defaultsObj: T): T + options(defaultsObj: any): any + } + + /** + * {@link http://gruntjs.com/inside-tasks#inside-multi-tasks} + */ + interface IMultiTask extends ITask { + /** + * In a multi task, this property contains the name of the target currently being iterated over. + * For example, if a "sample" multi task was run as grunt sample:foo with the config data + * {sample: {foo: "bar"}}, inside the task function, this.target would be "foo". + */ + target: string + + /** + * In a multi task, all files specified using any Grunt-supported file formats and options, + * globbing patterns or dynamic mappings will automatically be normalized into a single format: + * the Files Array file format. + * + * What this means is that tasks don't need to contain a ton of boilerplate for explicitly + * handling custom file formats, globbing patterns, mapping source files to destination files + * or filtering out files or directories. A task user can just specify files per the Configuring + * tasks guide, and Grunt will handle all the details. + * + * Your task should iterate over the this.files array, utilizing the src and dest properties of + * each object in that array. The this.files property will always be an array. + * The src property will also always be an array, in case your task cares about multiple source + * files per destination file. + * + * @note it's possible that nonexistent files might be included in src values, + * so you may want to explicitly test that source files exist before using them. + */ + files: grunt.file.IFilesArray + + /** + * In a multi task, all src files files specified via any file format are reduced to a single array. + * If your task is "read only" and doesn't care about destination filepaths, + * use this array instead of this.files. + */ + filesSrc: string[] + + /** + * In a multi task, this is the actual data stored in the Grunt config object for the given target. + * For example, if a "sample" multi task was run as grunt sample:foo with the config data + * {sample: {foo: "bar"}}, inside the task function, this.data would be "bar". + * + * @note It is recommended that this.options this.files and this.filesSrc are used instead of this.data, + * as their values are normalized. + */ + data: any + } + + /** + * {@link http://gruntjs.com/configuring-tasks} + * + * A TaskConfig can be either be a full config or a compacted files config. + * @see ITaskCompactOptions + */ + interface ITaskOptions { + + options?: any + + // files?: grunt.file.IFilesArray + // files?: grunt.file.IFilesMap + files?: any + } + + /** + * @see ITaskOptions + */ + interface ITaskCompactOptions extends grunt.task.ITaskOptions, grunt.file.IFilesConfig {} + } + + module template { + + interface TemplateModule { + // TODO + } + } + + module util { + + interface UtilModule { + // TODO + } + } + + /* + * Common interfaces + */ + + interface IFlag { + [flag: string]: boolean + } + + /* + * Grunt module mixins. + */ + + interface IConfigComponents extends grunt.config.ConfigModule { + /** + * An alias + * @see grunt.config.ConfigModule.init + */ + initConfig(config: grunt.config.IProjectConfig): void + } + + interface ITaskComponents extends grunt.task.CommonTaskModule { + + /** + * The currently running task or multitask. + * @see IMultiTask for when to cast + */ + current: grunt.task.ITask + + /** + * Load task-related files from the specified directory, relative to the Gruntfile. + * This method can be used to load task-related files from a local Grunt plugin by + * specifying the path to that plugin's "tasks" subdirectory. + */ + loadTasks(tasksPath: string): void + + /** + * Load tasks from the specified Grunt plugin. + * This plugin must be installed locally via npm, and must be relative to the Gruntfile. + * Grunt plugins can be created by using the grunt-init gruntplugin template: grunt init:gruntplugin. + */ + loadNpmTasks(pluginName: string): void + } } -//////////////// -// Grunt File object -// http://gruntjs.com/api/grunt.file -//////////////// -interface IGruntFileObjectOptionsSimple { - encoding?: string; +/* GRUNT MODULE + **************/ + +/** + * The main Grunt module. + * + * {@link http://gruntjs.com/api/grunt} + */ +interface IGrunt extends grunt.IConfigComponents, grunt.fail.FailModule, grunt.ITaskComponents { + + config: grunt.config.ConfigModule + + event: grunt.event.EventModule + + fail: grunt.fail.FailModule + + file: grunt.file.FileModule + + log: grunt.log.LogModule + + option: grunt.option.OptionModule + + task: grunt.task.TaskModule + + template: grunt.template.TemplateModule + + util: grunt.util.UtilModule + + /** + * The current Grunt package.json metadata, as an object. + */ + package: node.NodePackage + + /** + * The current Grunt version, as a string. This is just a shortcut to the grunt.package.version property. + */ + version: string } -interface IGruntFileObjectOptions extends IGruntFileObjectOptionsSimple { - process?: Function; - noProcess?: any; -} -interface IGruntFileObject { - - // Character encoding - defaultEncoding: string; - - // Reading and writing - read(filepath: string, options?: IGruntFileObjectOptionsSimple): string; - readJSON(filepath: string, options?: IGruntFileObjectOptionsSimple): any; - readYAML(filepath: string, options?: IGruntFileObjectOptionsSimple): any; - write(filepath: string, contents: any, options?: IGruntFileObjectOptionsSimple): void; - copy(srcpath: string, destpath: string, options?: IGruntFileObjectOptions): void; - delete(filepath: string, options?: { force?: boolean; }): void; - - // Directories - mkdir(dirpath: string, mode?: number): void; - recurse(rootdir: string, callback: (abspath: string, rootdir: string, subdir: string, filename: string) => void): void; - - // Globbing patterns - expand(...patterns: string[]): string[]; - expand(options: Object, ...patterns: string[]): string[]; - expandMapping(patterns: string[], dest: string, options?: Object): any[]; - - match(patterns: string[], filepaths: string[]): string[]; - match(patterns: string[], filepaths: string): string[]; - match(patterns: string, filepaths: string[]): string[]; - match(patterns: string, filepaths: string): string[]; - match(options: Object, patterns: string[], filepaths: string[]): string[]; - match(options: Object, patterns: string[], filepaths: string): string[]; - match(options: Object, patterns: string, filepaths: string[]): string[]; - match(options: Object, patterns: string, filepaths: string): string[]; - - isMatch(patterns: string[], filepaths: string[]): boolean; - isMatch(patterns: string[], filepaths: string): boolean; - isMatch(patterns: string, filepaths: string[]): boolean; - isMatch(patterns: string, filepaths: string): boolean; - isMatch(options: Object, patterns: string[], filepaths: string[]): boolean; - isMatch(options: Object, patterns: string[], filepaths: string): boolean; - isMatch(options: Object, patterns: string, filepaths: string[]): boolean; - isMatch(options: Object, patterns: string, filepaths: string): boolean; - - // file types - exists(...paths: string[]): boolean; - isLink(...paths: string[]): boolean; - isDir(...paths: string[]): boolean; - isFile(...paths: string[]): boolean; - - // paths - isPathAbsolute(...paths: string[]): boolean; - arePathsEquivalent(...paths: string[]): boolean; - doesPathContain(ancestorPath: string, ...descendantPaths: string[]): boolean; - isPathCwd(...paths: string[]): boolean; - isPathInCwd(...paths: string[]): boolean; - setBase(...paths: string[]): void; - - // External libraries - glob: any; - minimatch: any; - findup: any; -} - -//////////////// -// 'this' when executing within a task -// http://gruntjs.com/api/inside-tasks -//////////////// -interface IGruntTaskThis { - async(): (err:any) => void; - requires(...taskNames: string[]): void; - requiresConfig(...props: string[]): void; - name: string; - nameArgs: string; - args: string[]; - flags: any; - errorCount: number; - options(defaults?: Object): any; -} - -//////////////// -// 'this' when executing within a multitask -// http://gruntjs.com/api/inside-tasks -//////////////// -interface IGruntMultiTaskThis extends IGruntTaskThis { - target: string; - files: IGruntFileArray[]; - filesSrc: string[]; - data: any; -} - -//////////////// -// Files array format -// http://gruntjs.com/configuring-tasks#files-array-format -//////////////// -interface IGruntFileArray { - src: string[]; - dest: string; - nonull?: boolean; - filter?: any; -} - -//////////////// -/// Globally called export function module.exports -//////////////// - -declare var exports: (grunt: IGrunt) => void; From 85ec704f8dba9b0ffca2e3f9f4b6622ef567233d Mon Sep 17 00:00:00 2001 From: Jeff May Date: Sun, 27 Oct 2013 22:49:24 -0400 Subject: [PATCH 2/5] Updated for contribution guidelines. Conflicts: README.md --- README.md | 2 +- gruntjs/gruntjs.d.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 143754d982..5b2e26e789 100755 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ List of Definitions * [GoJS](http://gojs.net/) (by [Barbara Duckworth](https://github.com/barbara42)) * [Greasemonkey](http://www.greasespot.net/) (by [Kota Saito](https://github.com/kotas)) * [GreenSock Animation Platform (GSAP)](http://www.greensock.com/get-started-js/) (by [Robert S.](https://github.com/codeBelt)) -* [Grunt JS](http://gruntjs.com/) (by [Basarat Ali Syed](https://github.com/basarat)) +* [Grunt JS](http://gruntjs.com/) (by [Jeff May](https://github.com/jeffmay) and [Basarat Ali Syed](https://github.com/basarat)) * [Google API Client](https://code.google.com/p/google-api-javascript-client/) (by [Frank M](https://github.com/sgtfrankieboy)) * [Google App Engine Channel API](https://developers.google.com/appengine/docs/java/channel/javascript) (by [vvakame](https://github.com/vvakame)) * [GoogleMaps](https://developers.google.com/maps/) (by [Esben Nepper](https://github.com/eNepper)) diff --git a/gruntjs/gruntjs.d.ts b/gruntjs/gruntjs.d.ts index 92da410e37..f191173e16 100644 --- a/gruntjs/gruntjs.d.ts +++ b/gruntjs/gruntjs.d.ts @@ -1,3 +1,8 @@ +// Type definitions for Grunt 0.4.x +// Project: http://gruntjs.com +// Definitions by: Jeff May +// Definitions: https://github.com/jeffmay/DefinitelyTyped + /// /** From 112ff52ba16f89ebd5811aa272ac8075afb416cf Mon Sep 17 00:00:00 2001 From: Jeff May Date: Sun, 27 Oct 2013 22:58:37 -0400 Subject: [PATCH 3/5] Switched to generic MultiTask for structured configuration. --- gruntjs/gruntjs.d.ts | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/gruntjs/gruntjs.d.ts b/gruntjs/gruntjs.d.ts index f191173e16..04b730ce78 100644 --- a/gruntjs/gruntjs.d.ts +++ b/gruntjs/gruntjs.d.ts @@ -8,18 +8,15 @@ /** * {@link http://github.com/marak/colors.js/} */ -declare module colors { - - interface String { - yellow: string; - cyan: string; - white: string; - magenta: string; - green: string; - red: string; - grey: string; - blue: string; - } +interface String { + yellow: string; + cyan: string; + white: string; + magenta: string; + green: string; + red: string; + grey: string; + blue: string; } declare module node { @@ -924,7 +921,7 @@ declare module grunt { /** * {@link http://gruntjs.com/inside-tasks#inside-multi-tasks} */ - interface IMultiTask extends ITask { + interface IMultiTask extends ITask { /** * In a multi task, this property contains the name of the target currently being iterated over. * For example, if a "sample" multi task was run as grunt sample:foo with the config data @@ -967,7 +964,7 @@ declare module grunt { * @note It is recommended that this.options this.files and this.filesSrc are used instead of this.data, * as their values are normalized. */ - data: any + data: T } /** @@ -1031,7 +1028,7 @@ declare module grunt { * The currently running task or multitask. * @see IMultiTask for when to cast */ - current: grunt.task.ITask + current: grunt.task.ITask /** * Load task-related files from the specified directory, relative to the Gruntfile. From 56f5ab0ad8fa7195a88ca1531e6942963545c756 Mon Sep 17 00:00:00 2001 From: Jeff May Date: Mon, 28 Oct 2013 00:42:59 -0400 Subject: [PATCH 4/5] Added Template and Util modules. --- gruntjs/gruntjs-tests.ts | 12 +++ gruntjs/gruntjs.d.ts | 212 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 222 insertions(+), 2 deletions(-) diff --git a/gruntjs/gruntjs-tests.ts b/gruntjs/gruntjs-tests.ts index 5017451f18..9097fa7df1 100644 --- a/gruntjs/gruntjs-tests.ts +++ b/gruntjs/gruntjs-tests.ts @@ -26,4 +26,16 @@ exports = (grunt: IGrunt) => { // Default task(s). grunt.registerTask('default', ['uglify']); + + // util methods + var testOneArg = (a: number) => a * 2; + var asyncedOneArg = grunt.util.callbackify(testOneArg); + asyncedOneArg(1, (result: number) => { + console.log(result); + }); + var testTwoArgs = (a: number, b: string) => "it works with " + a + " " + b; + var asyncedTwoArgs = grunt.util.callbackify(testTwoArgs); + asyncedTwoArgs(2, "values", (result: string) => { + console.log(result); + }); }; \ No newline at end of file diff --git a/gruntjs/gruntjs.d.ts b/gruntjs/gruntjs.d.ts index 04b730ce78..a113244a5d 100644 --- a/gruntjs/gruntjs.d.ts +++ b/gruntjs/gruntjs.d.ts @@ -991,14 +991,222 @@ declare module grunt { module template { interface TemplateModule { - // TODO + + /** + * Process a Lo-Dash template string. + * + * The template argument will be processed recursively until there are no more templates to process. + * + * The default data object is the entire config object, but if options.data is set, that object will + * be used instead. The default template delimiters are <% %> but if options.delimiters is set to a + * custom delimiter name, those template delimiters will be used instead. + * + * Inside templates, the grunt object is exposed so that you can do things like: + * <%= grunt.template.today('yyyy') %> + * + * @note if the data object already has a grunt property, the grunt API will not be accessible in templates. + */ + process(template: string): (options: any) => string + process(template: string, options: any): string + + /** + * Set the Lo-Dash template delimiters to a predefined set in case you grunt.util._.template + * needs to be called manually. + * + * The config delimiters <% %> are included by default. + */ + setDelimiters(name: string): void + + /** + * Add a named set of Lo-Dash template delimiters. + * + * You probably won't need to use this method, because the built-in delimiters should be sufficient, + * but you could always add {% %} or [% %] style delimiters. + */ + addDelimiters(name: string, opener: string, closer: string): void + + /** + * {@link http://github.com/felixge/node-dateformat} + * + * @note if you don't include the mask argument, dateFormat.masks.default is used + */ + date(date?: Date, format?: string): string + date(date?: number, format?: string): string + date(date?: string, format?: string): string + + /** + * {@link http://github.com/felixge/node-dateformat} + * + * @note if you don't include the mask argument, dateFormat.masks.default is used + */ + today(format?: string) } } module util { + /** + * {@link http://gruntjs.com/api/grunt.util} + */ interface UtilModule { - // TODO + + /** + * Return the "kind" of a value. Like typeof but returns the internal [Class](Class/) value. + * Possible results are "number", "string", "boolean", "function", "regexp", "array", "date", + * "error", "null", "undefined" and the catch-all "object". + */ + kindOf(value: any): string + + /** + * Return a new Error instance (that can be thrown) with the appropriate message. + * If an Error object is specified instead of message that object will be returned. + * Also, if an Error object is specified for origError and Grunt was run with the --debug 9 option, + * the original Error stack will be dumped. + */ + error(message: string, origError?: Error) + + /** + * The linefeed character, normalized for the current operating system. + * (\r\n on Windows, \n otherwise) + */ + linefeed: string + + /** + * Given a string, return a new string with all the linefeeds normalized for the current operating system. + * (\r\n on Windows, \n otherwise) + */ + normalizelf(str: string): string + + /** + * Recurse through nested objects and arrays, executing callbackFunction for each non-object value. + * If continueFunction returns false, a given object or value will be skipped. + */ + recurse(object: any, callbackFunction: (value: any) => void, continueFunction: (objOrValue: any) => boolean): void + + /** + * Return string str repeated n times. + */ + repeat(n: number, str: string): string + + /** + * Given str of "a/b", If n is 1, return "a" otherwise "b". + * You can specify a custom separator if '/' doesn't work for you. + */ + pluralize(n: number, str: string, separator?: string): string + + /** + * Spawn a child process, keeping track of its stdout, stderr and exit code. + * The method returns a reference to the spawned child. + * When the child exits, the done function is called. + * + * @param done a function with arguments: + * error - If the exit code was non-zero and a fallback wasn't specified, + * an Error object, otherwise null. + * result - The result object is an + * code - The numeric exit code. + */ + spawn(options: ISpawnOptions, done: (error: Error, result: ISpawnResult, code: number) => void): ISpawnedChild + + /** + * Given an array or array-like object, return an array. + * Great for converting arguments objects into arrays. + */ + toArray(arrayLikeObject: any): T[] + + /** + * Normalizes both "returns a value" and "passes result to a callback" functions to always + * pass a result to the specified callback. If the original function returns a value, + * that value will now be passed to the callback, which is specified as the last argument, + * after all other predefined arguments. If the original function passed a value to a callback, + * it will continue to do so. + */ + callbackify(syncOrAsyncFunction: () => R): + (callback: (result: R) => void) => void + callbackify(syncOrAsyncFunction: (a: A) => R): + (a: A, callback: (result: R) => void) => void + callbackify(syncOrAsyncFunction: (a: A, b: B) => R): + (a: A, b: B, callback: (result: R) => void) => void + callbackify(syncOrAsyncFunction: (a: A, b: B, c: C) => R): + (a: A, b: B, c: C, callback: (result: R) => void) => void + callbackify(syncOrAsyncFunction: (a: A, b: B, c: C, d: D) => R): + (a: A, b: B, c: C, d: D, callback: (result: R) => void) => void + + // Internal libraries + namespace: any + task: any + } + + /** + * {@link http://gruntjs.com/api/grunt.util#grunt.util.spawn} + */ + interface ISpawnOptions { + + /** + * The command to execute. It should be in the system path. + */ + cmd: string + + /** + * If specified, the same grunt bin that is currently running will be + * spawned as the child command, instead of the "cmd" option. + * Defaults to false. + */ + grunt?: boolean + + /** + * An array of arguments to pass to the command. + */ + args?: string[] + + /** + * Additional options for the Node.js child_process spawn method. + */ + opts?: ISpawnOptions + + /** + * If this value is set and an error occurs, it will be used as the value + * and null will be passed as the error value. + */ + fallback?: any + } + + /** + * @note When result is coerced to a string, the value is stdout if the exit code + * was zero, the fallback if the exit code was non-zero and a fallback was + * specified, or stderr if the exit code was non-zero and a fallback was + * not specified. + */ + interface ISpawnResult { + stdout: string + stderr: string + code: number + } + + /** + * {@link http://github.com/snbartell/node-spawn} + */ + interface ISpawnedChild { + /** + * Start the cmd with the options provided. + */ + start(): void + + /** + * Convenience function. Overrides options. restarts to 0. + * Runs command exactly once no matter the options passed into the constructor. + */ + once(): void + + /** + * Convenience function. Overrides options.restarts to -1. + * Runs command indefinitely no matter the options passed into the constructor. + */ + forever(): void + + /** + * Shut down the child and don't let it restart. + */ + kill(): void } } From 05b6a0a1cae09a74fa0daec8135f6bc327ac8851 Mon Sep 17 00:00:00 2001 From: Jeff May Date: Tue, 29 Oct 2013 09:51:11 -0400 Subject: [PATCH 5/5] Fixed implicitAny bugs. --- gruntjs/gruntjs.d.ts | 68 +++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/gruntjs/gruntjs.d.ts b/gruntjs/gruntjs.d.ts index a113244a5d..0b3d6ee2eb 100644 --- a/gruntjs/gruntjs.d.ts +++ b/gruntjs/gruntjs.d.ts @@ -149,7 +149,7 @@ declare module grunt { * if two arguments are passed, grunt.config.set is called, * otherwise grunt.config.get is called. */ - (prop: string, value: any): void + (prop: string, value: any): any (prop: string): any /** @@ -164,6 +164,8 @@ declare module grunt { * If prop is specified, that property's value is returned, or null if that property is not defined. * If prop isn't specified, a copy of the entire config object is returned. * Templates strings will be recursively processed using the grunt.config.process method. + * + * @note Although this accepts a generic type, you may still get the wrong typed value. */ get(prop: string): T get(): ConfigModule @@ -191,7 +193,7 @@ declare module grunt { * Set a value into the project's Grunt configuration. * @note any specified <% %> template strings will only be processed when config data is retrieved. */ - set(prop: string, value: any): void + set(prop: string, value: T): T /** * Escape '.' dots in the given propString. This should be used for property names that contain dots. @@ -202,8 +204,8 @@ declare module grunt { * Fail the current task if one or more required config properties is missing, null or undefined. * One or more string or array config properties may be specified. */ - requires(prop: string, ...andProps: string[]) - requires(prop: string[], ...andProps: string[][]) + requires(prop: string, ...andProps: string[]): void + requires(prop: string[], ...andProps: string[][]): void } } @@ -216,42 +218,42 @@ declare module grunt { /** * Adds a listener to the end of the listeners array for the specified event. */ - addListener(event: string, listener: Function): void - on(event: string, listener: Function): void + addListener(event: string, listener: Function): EventModule + on(event: string, listener: Function): EventModule /** * Adds a listener that will be fired when any event is emitted. */ - onAny(listener: Function): void + onAny(listener: Function): EventModule /** * Removes the listener that will be fired when any event is emitted. */ - offAny(listener: Function): void + offAny(listener: Function): EventModule /** * Adds a one time listener for the event. * The listener is invoked only the first time the event is fired, after which it is removed. */ - once(event: string, listener: Function): void + once(event: string, listener: Function): EventModule /** * Adds a listener that will execute n times for the event before being removed. * The listener is invoked only the first time the event is fired, after which it is removed. */ - many(event: string, timesToListen: number, listener: Function): void + many(event: string, timesToListen: number, listener: Function): EventModule /** * Remove a listener from the listener array for the specified event. * Caution: changes array indices in the listener array behind the listener. */ - removeListener(event: string, listener: Function): void - off(event: string, listener: Function): void + removeListener(event: string, listener: Function): EventModule + off(event: string, listener: Function): EventModule /** * Removes all listeners, or those of the specified event. */ - removeAllListeners(event: string): void + removeAllListeners(event: string): EventModule /** * By default EventEmitters will print a warning if more than 10 listeners are added to it. @@ -272,13 +274,13 @@ declare module grunt { * Returns an array of listeners that are listening for any event that is specified. * This array can be manipulated, e.g. to remove listeners. */ - listenersAny() + listenersAny(): Function[] /** * Execute each of the listeners that may be listening for the specified event name * in order with the list of arguments. */ - emit(event: string, ...args: any[]) + emit(event: string, ...args: any[]): any } } @@ -380,22 +382,22 @@ declare module grunt { * Read and return a file's contents. * Returns a string, unless options.encoding is null in which case it returns a Buffer. */ - read(filepath): string - read(filepath, options: IFileEncodedOption): NodeBuffer + read(filepath: string): string + read(filepath: string, options: IFileEncodedOption): NodeBuffer /** * Read a file's contents, parsing the data as JSON and returning the result. * @see FileModule.read for a list of supported options. */ - readJSON(filepath): string - readJSON(filepath, options: IFileEncodedOption): NodeBuffer + readJSON(filepath: string): any + readJSON(filepath: string, options: IFileEncodedOption): NodeBuffer /** * Read a file's contents, parsing the data as YAML and returning the result. * @see FileModule.read for a list of supported options. */ - readYAML(filepath: string) - readYAML(filepath: string, options: IFileEncodedOption) + readYAML(filepath: string): any + readYAML(filepath: string, options: IFileEncodedOption): NodeBuffer /** * Write the specified contents to a file, creating intermediate directories if necessary. @@ -409,20 +411,22 @@ declare module grunt { /** * Copy a source file to a destination path, creating intermediate directories if necessary. */ - copy(srcpath: string, destpath: string) - copy(srcpath: string, destpath: string, options: IFileWriteStringOption) - copy(srcpath: string, destpath: string, options: IFileWriteBufferOption) + copy(srcpath: string, destpath: string): void + copy(srcpath: string, destpath: string, options: IFileWriteStringOption): void + copy(srcpath: string, destpath: string, options: IFileWriteBufferOption): void /** * Delete the specified filepath. Will delete files and folders recursively. + * + * @return true if the files could be deleted, otherwise false. */ - delete(filepath: string, options?: { force?: boolean }) + delete(filepath: string, options?: { force?: boolean }): boolean /** * Works like mkdir -p. Create a directory along with any intermediate directories. * If mode isn't specified, it defaults to 0777 & (~process.umask()). */ - mkdir(dirpath: string, mode?: string) + mkdir(dirpath: string, mode?: string): void /** * Recurse into a directory, executing callback for each file. @@ -437,7 +441,7 @@ declare module grunt { recurse( rootdir: string, callback: (abspath: string, rootdir: string, subdir: string, filename: string) => void - ) + ): void /** * Return a unique array of all file or directory paths that match the given globbing pattern(s). @@ -871,7 +875,7 @@ declare module grunt { * One or more string or array config properties may be specified. * this.requiresConfig(prop [, prop [, ...]]) */ - requiresConfig(prop: string, ...andProps: string[]) + requiresConfig(prop: string, ...andProps: string[]): void /** * The name of the task, as defined in grunt.registerTask. @@ -1026,6 +1030,7 @@ declare module grunt { addDelimiters(name: string, opener: string, closer: string): void /** + * Format a date using the dateformat library. * {@link http://github.com/felixge/node-dateformat} * * @note if you don't include the mask argument, dateFormat.masks.default is used @@ -1035,11 +1040,12 @@ declare module grunt { date(date?: string, format?: string): string /** + * Format today's date using the dateformat library using the current date and time. * {@link http://github.com/felixge/node-dateformat} * * @note if you don't include the mask argument, dateFormat.masks.default is used */ - today(format?: string) + today(format?: string): string } } @@ -1063,7 +1069,9 @@ declare module grunt { * Also, if an Error object is specified for origError and Grunt was run with the --debug 9 option, * the original Error stack will be dumped. */ - error(message: string, origError?: Error) + error(message: string, origError?: Error): Error + error(error: Error, origError?: Error): Error + error(error: any, origError?: Error): Error /** * The linefeed character, normalized for the current operating system.