Interface IGrunt

The main Grunt module.

{@link http://gruntjs.com/api/grunt}

Hierarchy

Index

Call signatures

Properties

Methods

Call signatures

(prop: string, value: any): any

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.

Parameters

  • prop: string
  • value: any

Returns

any

(prop: string): any

Parameters

  • prop: string

Returns

any

Properties

public config: ConfigModule

public event: EventModule

public fail: FailModule

public file: FileModule

public log: LogModule

public option: OptionModule

public package: NodePackage

The current Grunt package.json metadata, as an object.

public task: TaskModule

public template: TemplateModule

public util: UtilModule

public version: string

The current Grunt version, as a string. This is just a shortcut to the grunt.package.version property.

Methods

public escape(propString: string): string

Escape '.' dots in the given propString. This should be used for property names that contain dots.

Parameters

  • propString: string

Returns

string

public fatal(error: string, errorCode?: ErrorCode)

Display a warning and abort Grunt immediately.

Parameters

  • error: string
  • errorCode?: ErrorCode optional

public fatal(error: Error, errorCode?: ErrorCode)

Parameters

  • error: Error
  • errorCode?: ErrorCode optional

public get(prop: string): T

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.

note

Although this accepts a generic type, you may still get the wrong typed value.

Parameters

  • prop: string

Returns

T

public get(): ConfigModule

Returns

ConfigModule

public getRaw(prop: 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.

Parameters

  • prop: string

Returns

T

public init(config: IProjectConfig)

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.

Parameters

public initConfig(config: IProjectConfig)

An alias

see

grunt.config.ConfigModule.init

Parameters

public loadNpmTasks(pluginName: string)

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.

Parameters

  • pluginName: string

public loadTasks(tasksPath: string)

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.

Parameters

  • tasksPath: string

public process(value: string): T

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.

Parameters

  • value: string

Returns

T

public registerMultiTask(taskName: string, taskFunction: Function)

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[])

Parameters

  • taskName: string
  • taskFunction: Function

public registerMultiTask(taskName: string, taskDescription: string, taskFunction: Function)

Parameters

  • taskName: string
  • taskDescription: string
  • taskFunction: Function

public registerTask(taskName: string, taskList: Array<string>)

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.

Parameters

  • taskName: string
  • taskList: Array<string>

public registerTask(taskName: string, description: string, taskFunction: Function)

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.ITask, args: any[])

Parameters

  • taskName: string
  • description: string
  • taskFunction: Function

public requires(prop: string, andProps?: Array<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.

Parameters

  • prop: string
  • andProps?: Array<string> optional

public requires(prop: Array<string>, andProps?: Array<string[]>)

Parameters

  • prop: Array<string>
  • andProps?: Array<string[]> optional

public set(prop: string, value: T): T

Set a value into the project's Grunt configuration.

note

any specified <% %> template strings will only be processed when config data is retrieved.

Parameters

  • prop: string
  • value: T

Returns

T

public warn(error: string, errorCode?: ErrorCode)

Display a warning and abort Grunt immediately. Grunt will continue processing tasks if the --force command-line option was specified.

Parameters

  • error: string
  • errorCode?: ErrorCode optional

public warn(error: Error, errorCode?: ErrorCode)

Parameters

  • error: Error
  • errorCode?: ErrorCode optional