UNPKG

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