1 | // Type definitions for jake
|
2 | // Project: https://github.com/mde/jake
|
3 | // Definitions by: Kon <http://phyzkit.net/>
|
4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
5 | // TypeScript Version: 2.2
|
6 |
|
7 | /// <reference types="node" />
|
8 |
|
9 | import { EventEmitter } from 'events';
|
10 |
|
11 | declare global {
|
12 | /**
|
13 | * Complets an asynchronous task, allowing Jake's execution to proceed to the next task
|
14 | * @param value A value to return from the task.
|
15 | */
|
16 | function complete(value?: any): void;
|
17 |
|
18 | /**
|
19 | * Creates a description for a Jake Task (or FileTask, DirectoryTask). When invoked, the description that iscreated will be associated with whatever Task is created next.
|
20 | * @param description The description for the Task
|
21 | */
|
22 | function desc(description:string): void;
|
23 |
|
24 | /**
|
25 | * Creates a Jake DirectoryTask. Can be used as a prerequisite for FileTasks, or for simply ensuring a directory exists for use with a Task's action.
|
26 | * @param name The name of the DiretoryTask
|
27 | */
|
28 | function directory(name:string): jake.DirectoryTask;
|
29 |
|
30 | /**
|
31 | * Causes Jake execution to abort with an error. Allows passing an optional error code, which will be used to set the exit-code of exiting process.
|
32 | * @param err The error to thow when aborting execution. If this argument is an Error object, it will simply be thrown. If a String, it will be used as the error-message. (If it is a multi-line String, the first line will be used as the Error message, and the remaining lines will be used as the error-stack.)
|
33 | */
|
34 | function fail(...err:string[]): void;
|
35 | function fail(...err:Error[]): void;
|
36 | function fail(...err:any[]): void;
|
37 |
|
38 | /**
|
39 | * Creates a Jake FileTask.
|
40 | * @name name The name of the Task
|
41 | * @param prereqs Prerequisites to be run before this task
|
42 | * @param action The action to perform for this task
|
43 | * @param opts Perform this task asynchronously. If you flag a task with this option, you must call the global `complete` method inside the task's action, for execution to proceed to the next task.
|
44 | */
|
45 | function file(name:string, prereqs?:string[], action?:(this: jake.FileTask)=>void, opts?:jake.FileTaskOptions): jake.FileTask;
|
46 |
|
47 | /**
|
48 | * Creates Jake FileTask from regex patterns
|
49 | * @name name/pattern of the Task
|
50 | * @param source calculated from the name pattern
|
51 | * @param prereqs Prerequisites to be run before this task
|
52 | * @param action The action to perform for this task
|
53 | * @param opts Perform this task asynchronously. If you flag a task with this option, you must call the global `complete` method inside the task's action, for execution to proceed to the next task.
|
54 | */
|
55 | function rule(pattern: RegExp, source: string | { (name: string): string; }, prereqs?: string[], action?: () => void, opts?: jake.TaskOptions): void;
|
56 |
|
57 | /**
|
58 | * Creates a namespace which allows logical grouping of tasks, and prevents name-collisions with task-names. Namespaces can be nested inside of other namespaces.
|
59 | * @param name The name of the namespace
|
60 | * @param scope The enclosing scope for the namespaced tasks
|
61 | */
|
62 | function namespace(name:string, scope:()=>void): void;
|
63 |
|
64 | /**
|
65 | * @param name The name of the Task
|
66 | * @param prereqs Prerequisites to be run before this task
|
67 | * @param action The action to perform for this task
|
68 | * @param opts
|
69 | */
|
70 | function task(name:string, prereqs?:string[], action?:(this: jake.Task, ...params:any[])=>any, opts?:jake.TaskOptions): jake.Task;
|
71 | function task(name:string, action?:(this: jake.Task, ...params:any[])=>any, opts?:jake.TaskOptions): jake.Task;
|
72 | function task(name:string, opts?:jake.TaskOptions, action?:(this: jake.Task, ...params:any[])=>any): jake.Task;
|
73 |
|
74 | /**
|
75 | * @param name The name of the NpmPublishTask
|
76 | * @param packageFiles The files to include in the package
|
77 | * @param definition A function that creates the package definition
|
78 | */
|
79 | function npmPublishTask(name:string, packageFiles:string[]): jake.NpmPublishTask;
|
80 | function npmPublishTask(name:string, definition?:()=>void): jake.NpmPublishTask;
|
81 |
|
82 |
|
83 | namespace jake{
|
84 |
|
85 | ////////////////////////////////////////////////////////////////////////////////////
|
86 | // File-utils //////////////////////////////////////////////////////////////////////
|
87 | ////////////////////////////////////////////////////////////////////////////////////
|
88 |
|
89 | interface UtilOptions{
|
90 | silent?: boolean | undefined;
|
91 | }
|
92 |
|
93 | /**
|
94 | * The jake.mkdirP utility recursively creates a set of nested directories. It will not throw an error if any of the directories already exists.
|
95 | * https://github.com/substack/node-mkdirp
|
96 | */
|
97 | export function mkdirP(name:string, mode?:string, f?:(er:Error, made:any)=>void): void;
|
98 | export function mkdirP(name:string, f?:(er:Error, made:any)=>void): void;
|
99 |
|
100 | /**
|
101 | * The jake.cpR utility does a recursive copy of a file or directory.
|
102 | * Note that this command can only copy files and directories; it does not perform globbing (so arguments like '*.txt' are not possible).
|
103 | * @param path the file/directory to copy,
|
104 | * @param destination the destination.
|
105 | */
|
106 | export function cpR(path:string, destination:string, opts?:UtilOptions, callback?:()=>void): void;
|
107 | export function cpR(path:string, destination:string, callback?:(err:Error)=>void): void;
|
108 |
|
109 | /**
|
110 | * The jake.readdirR utility gives you a recursive directory listing, giving you output somewhat similar to the Unix find command. It only works with a directory name, and does not perform filtering or globbing.
|
111 | * @return an array of filepaths for all files in the 'pkg' directory, and all its subdirectories.
|
112 | */
|
113 | export function readdirR(name:string, opts?:UtilOptions): string[];
|
114 |
|
115 | /**
|
116 | * The jake.rmRf utility recursively removes a directory and all its contents.
|
117 | */
|
118 | export function rmRf(name:string, opts?:UtilOptions): void;
|
119 |
|
120 | //////////////////////////////////////////////////////////////////////////////////////////////
|
121 | // Running shell-commands ////////////////////////////////////////////////////////////////////
|
122 | //////////////////////////////////////////////////////////////////////////////////////////////
|
123 |
|
124 | interface ExecOptions{
|
125 | /**
|
126 | * print to stdout, default false
|
127 | */
|
128 |
|
129 | printStdout?:boolean | undefined;
|
130 | /**
|
131 | * print to stderr, default false
|
132 | */
|
133 | printStderr?:boolean | undefined;
|
134 |
|
135 | /**
|
136 | * stop execution on error, default true
|
137 | */
|
138 | breakOnError?:boolean | undefined;
|
139 |
|
140 | /**
|
141 | *
|
142 | */
|
143 | windowsVerbatimArguments?: boolean | undefined
|
144 | }
|
145 | export function exec(cmds:string[], callback?:()=>void, opts?:ExecOptions):void;
|
146 |
|
147 |
|
148 | /**
|
149 | * @event cmdStart When a new command begins to run. Passes one arg, the command being run.
|
150 | * @event cmdEnd When a command finishes. Passes one arg, the command being run.
|
151 | * @event stdout When the stdout for the child-process recieves data. This streams the stdout data. Passes one arg, the chunk of data.
|
152 | * @event stderr When the stderr for the child-process recieves data. This streams the stderr data. Passes one arg, the chunk of data.
|
153 | * @event error When a shell-command
|
154 | */
|
155 | export interface Exec extends NodeJS.EventEmitter {
|
156 | append(cmd:string): void;
|
157 | run(): void;
|
158 | }
|
159 |
|
160 | export function createExec(cmds:string[], callback?:()=>void, opts?:ExecOptions ):Exec;
|
161 | export function createExec(cmds:string[], opts?:ExecOptions, callback?:()=>void):Exec;
|
162 | export function createExec(cmds:string, callback?:()=>void, opts?:ExecOptions ):Exec;
|
163 | export function createExec(cmds:string, opts?:ExecOptions, callback?:()=>void):Exec;
|
164 |
|
165 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
166 | // Logging and output ////////////////////////////////////////////////////////////////////////////////////////
|
167 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
168 |
|
169 | interface Logger{
|
170 | log(value:any): void;
|
171 | error(value:any): void;
|
172 | }
|
173 |
|
174 | export var logger: Logger;
|
175 |
|
176 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
177 | // program ////////////////////////////////////////////////////////////////////////////////////////////////////
|
178 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
179 |
|
180 | export var program: {
|
181 | opts: {
|
182 | [name:string]: any;
|
183 | quiet: boolean;
|
184 | };
|
185 | taskNames: string[];
|
186 | taskArgs: string[];
|
187 | envVars: { [key:string]: string; };
|
188 | };
|
189 |
|
190 |
|
191 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
192 | // Tasks /////////////////////////////////////////////////////////////////////////////////////////////////////
|
193 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
194 |
|
195 |
|
196 | export interface TaskOptions{
|
197 | /**
|
198 | * Perform this task asynchronously. If you flag a task with this option, you must call the global `complete` method inside the task's action, for execution to proceed to the next task.
|
199 | * @default false
|
200 | */
|
201 | async?: boolean | undefined;
|
202 |
|
203 | /**
|
204 | * number of parllel async tasks
|
205 | */
|
206 | parallelLimit?: number | undefined;
|
207 | }
|
208 |
|
209 | /**
|
210 | * A Jake Task
|
211 | *
|
212 | * @event complete
|
213 | */
|
214 | export class Task extends EventEmitter {
|
215 | /**
|
216 | * @name name The name of the Task
|
217 | * @param prereqs Prerequisites to be run before this task
|
218 | * @param action The action to perform for this task
|
219 | * @param opts Perform this task asynchronously. If you flag a task with this option, you must call the global `complete` method inside the task's action, for execution to proceed to the next task.
|
220 | */
|
221 | constructor(name:string, prereqs?:string[], action?:(this: Task)=>void, opts?:TaskOptions);
|
222 |
|
223 | /**
|
224 | * Runs prerequisites, then this task. If the task has already been run, will not run the task again.
|
225 | */
|
226 | invoke(): void;
|
227 |
|
228 | /**
|
229 | * Runs this task, without running any prerequisites. If the task has already been run, it will still run it again.
|
230 | */
|
231 | reenable(): void;
|
232 |
|
233 | addListener(event: string, listener: Function): this;
|
234 | on(event: string, listener: Function): this;
|
235 | once(event: string, listener: Function): this;
|
236 | removeListener(event: string, listener: Function): this;
|
237 | removeAllListeners(event?: string): this;
|
238 | setMaxListeners(n: number): this;
|
239 | getMaxListeners(): number;
|
240 | listeners(event: string): Function[];
|
241 | emit(event: string, ...args: any[]): boolean;
|
242 | listenerCount(type: string): number;
|
243 | complete(value?: any): void;
|
244 | value: any;
|
245 |
|
246 | name?: string | undefined;
|
247 | prereqs?: string[] | undefined;
|
248 | action?: ((...params: any[]) => any) | undefined;
|
249 | taskStatus?: string | undefined;
|
250 | async?: boolean | undefined;
|
251 | description?: string | undefined;
|
252 | fullName: string;
|
253 | }
|
254 |
|
255 | export class DirectoryTask extends FileTask {
|
256 | /**
|
257 | * @param name The name of the directory to create.
|
258 | */
|
259 | constructor(name:string);
|
260 | }
|
261 |
|
262 | export interface FileTaskOptions{
|
263 | /**
|
264 | * Perform this task asynchronously. If you flag a task with this option, you must call the global `complete` method inside the task's action, for execution to proceed to the next task.
|
265 | * @default false
|
266 | */
|
267 | async?: boolean | undefined;
|
268 | }
|
269 |
|
270 | export class FileTask extends Task{
|
271 | /**
|
272 | * @param name The name of the Task
|
273 | * @param prereqs Prerequisites to be run before this task
|
274 | * @param action The action to perform to create this file
|
275 | * @param opts Perform this task asynchronously. If you flag a task with this option, you must call the global `complete` method inside the task's action, for execution to proceed to the next task.
|
276 | */
|
277 | constructor(name:string, prereqs?:string[], action?:(this: FileTask)=>void, opts?:FileTaskOptions);
|
278 | }
|
279 |
|
280 | interface FileFilter{
|
281 | (filename:string): boolean;
|
282 | }
|
283 |
|
284 | export class FileList{
|
285 | constructor();
|
286 |
|
287 | /**
|
288 | * Includes file-patterns in the FileList. Should be called with one or more
|
289 | * pattern for finding file to include in the list. Arguments should be strings
|
290 | * for either a glob-pattern or a specific file-name, or an array of them
|
291 | */
|
292 | include(files:string[]): void;
|
293 | include(...files:string[]): void;
|
294 |
|
295 | /**
|
296 | * Indicates whether a particular file would be filtered out by the current
|
297 | * exclusion rules for this FileList.
|
298 | * @param name The filename to check
|
299 | * @return Whether or not the file should be excluded
|
300 | */
|
301 | shouldExclude(name:string): boolean;
|
302 |
|
303 | /**
|
304 | * Excludes file-patterns from the FileList. Should be called with one or more
|
305 | * pattern for finding file to include in the list. Arguments can be:
|
306 | * 1. Strings for either a glob-pattern or a specific file-name
|
307 | * 2. Regular expression literals
|
308 | * 3. Functions to be run on the filename that return a true/false
|
309 | */
|
310 | exclude(file:string[]): void;
|
311 | exclude(...file:string[]): void;
|
312 | exclude(file:RegExp[]): void;
|
313 | exclude(...file:RegExp[]): void;
|
314 | exclude(file:FileFilter[]): void;
|
315 | exclude(...file:FileFilter[]): void;
|
316 |
|
317 | /**
|
318 | * Populates the FileList from the include/exclude rules with a list of
|
319 | * actual files
|
320 | */
|
321 | resolve(): void;
|
322 |
|
323 | /**
|
324 | * Convert to a plain-jane array
|
325 | */
|
326 | toArray(): string[];
|
327 |
|
328 | /**
|
329 | * Get rid of any current exclusion rules
|
330 | */
|
331 | clearExclude(): void;
|
332 | }
|
333 |
|
334 | export class PackageTask{
|
335 | /**
|
336 | * Instantiating a PackageTask creates a number of Jake Tasks that make packaging and distributing your software easy.
|
337 | * @param name The name of the project
|
338 | * @param version The current project version (will be appended to the project-name in the package-archive
|
339 | * @param definition Defines the contents of the package, and format of the package-archive. Will be executed on the instantiated PackageTask (i.e., 'this', will be the PackageTask instance), to set the various instance-propertiess.
|
340 | */
|
341 | constructor(name:string, version:string, definition:()=>void);
|
342 |
|
343 | /**
|
344 | * Equivalent to the '-C' command for the `tar` and `jar` commands. ("Change to this directory before adding files.")
|
345 | */
|
346 | archiveChangeDir: string;
|
347 |
|
348 | /**
|
349 | * Specifies the files and directories to include in the package-archive. If unset, this will default to the main package directory -- i.e., name + version.
|
350 | */
|
351 | archiveContentDir: string;
|
352 |
|
353 | /**
|
354 | * The shell-command to use for creating jar archives.
|
355 | */
|
356 | jarCommand: string;
|
357 |
|
358 | /**
|
359 | * Can be set to point the `jar` utility at a manifest file to use in a .jar archive. If unset, one will be automatically created by the `jar` utility. This path should be relative to the root of the package directory (this.packageDir above, likely 'pkg')
|
360 | */
|
361 | manifestFile: string;
|
362 |
|
363 | /**
|
364 | * The name of the project
|
365 | */
|
366 | name: string;
|
367 |
|
368 | /**
|
369 | * If set to true, uses the `jar` utility to create a .jar archive of the pagckage
|
370 | */
|
371 | needJar: boolean;
|
372 |
|
373 | /**
|
374 | * If set to true, uses the `tar` utility to create a gzip .tgz archive of the pagckage
|
375 | */
|
376 | needTar: boolean;
|
377 |
|
378 | /**
|
379 | * If set to true, uses the `tar` utility to create a bzip2 .bz2 archive of the pagckage
|
380 | */
|
381 | needTarBz2: boolean;
|
382 |
|
383 | /**
|
384 | * If set to true, uses the `zip` utility to create a .zip archive of the pagckage
|
385 | */
|
386 | needZip: boolean;
|
387 |
|
388 | /**
|
389 | * The list of files and directories to include in the package-archive
|
390 | */
|
391 | packageFiles: FileList;
|
392 |
|
393 | /**
|
394 | * The shell-command to use for creating tar archives.
|
395 | */
|
396 | tarCommand: string;
|
397 |
|
398 | /**
|
399 | * The project version-string
|
400 | */
|
401 | version: string;
|
402 |
|
403 | /**
|
404 | * The shell-command to use for creating zip archives.
|
405 | */
|
406 | zipCommand: string;
|
407 |
|
408 | }
|
409 |
|
410 | export class TestTask{
|
411 | constructor(name:string, definition?:()=>void);
|
412 | }
|
413 |
|
414 | export class NpmPublishTask{
|
415 | constructor(name:string, packageFiles:string[]);
|
416 | constructor(name:string, definition?:()=>void);
|
417 | }
|
418 |
|
419 | export function addListener(event: string, listener: Function): NodeJS.EventEmitter;
|
420 | export function on(event: string, listener: Function): NodeJS.EventEmitter;
|
421 | export function once(event: string, listener: Function): NodeJS.EventEmitter;
|
422 | export function removeListener(event: string, listener: Function): NodeJS.EventEmitter;
|
423 | export function removeAllListener(event: string): NodeJS.EventEmitter;
|
424 | export function setMaxListeners(n: number): void;
|
425 | export function listeners(event: string): Function[];
|
426 | export function emit(event: string, ...args: any[]): boolean;
|
427 | }
|
428 | }
|