UNPKG

3.15 kBTypeScriptView Raw
1declare namespace taskr {
2 export interface Instance {
3 /**
4 * Start a Task by its name; may also pass initial values.
5 * Can return anything the Task is designed to.
6 */
7 start(task: string, options?: object),
8
9 /**
10 * Run a group of tasks simultaneously. Cascading is disabled
11 */
12 parallel(tasks: Array<string>, options?: object): IterableIterator<any>,
13
14 /**
15 * Run a group of tasks sequentially. Cascading is enabled
16 */
17 serial(tasks: Array<string>, options?: object): IterableIterator<any>
18
19 /**
20 * Perform local plugin
21 */
22 plugin(name: string, options: any, plugin?: (files: any, options?: any) => Iterator<any>)
23 }
24
25 export interface Utils {
26 /**
27 * Print to console with timestamp and alert coloring
28 */
29 alert(...msg: Array<string>): void,
30
31 /**
32 * Alias for `Bluebird.coroutine`.
33 */
34 coroutine(generator: GeneratorFunction),
35
36 /**
37 * Print to console with timestamp and error coloring.
38 */
39 error(...msg: Array<string>): void,
40
41 /**
42 * Get all filepaths that match the glob pattern constraints.
43 */
44 expand(globs: string | Array<string>, options?: object)
45
46 /**
47 * Find a complete filepath from a given path, or optional directory.
48 */
49 find(filename: string, dir: string)
50
51 /**
52 * Print to console with timestamp and normal coloring.
53 */
54 log(...msg: Array<string>): void
55
56 /**
57 * Alias for `Bluebird.promisify`.
58 */
59 promisify(fn: Function): Function
60
61 /**
62 * Get a file's contents. Ignores directory paths.
63 */
64 read(filepath: string, options?: object | string): IterableIterator<string |null | BufferSource>
65
66 /**
67 * Parse and prettify an Error's stack.
68 */
69 trace(stack: string): string
70
71 /**
72 * Write given data to a filepath. Will create directories as needed.
73 */
74 write(filepath: string, data: any , options?: object)
75 }
76
77 interface File {
78 dir: string,
79 base: string,
80 data: any
81 }
82
83 type InnerState = {
84 /**
85 * The Task's active files.
86 * Each object contains a dir and base key from its pathObject and
87 * maintains the file's Buffer contents as a data key.
88 */
89 files: Array<File>
90
91 /**
92 * The Task's glob patterns, from task.source(). Used to populate `task._.files`.
93 */
94 globs: Array<string>
95
96 /**
97 * The Task's last-known (aka, outdated) set of glob patterns. Used only for `taskr-watch`.
98 */
99 prevs: Array<string>
100 }
101
102 export interface Task extends Instance {
103 /**
104 * The directory wherein taskfile.js resides,
105 * now considered the root. Also accessible within plugins
106 */
107 root: string
108
109 /**
110 * The Task's internal state, populated by task.source().
111 * Also accessible within plugins.
112 */
113 _: InnerState
114
115 /**
116 * A collection of utility helpers to make life easy.
117 */
118 $: Utils
119
120 source(globs: Array<string> | string, options?: object)
121
122 /**
123 * Send output to certain destination(s)
124 */
125 target(dirs: Array<string> | string, options?: object)
126
127 /**
128 * Perform an inline plugin.
129 */
130 run(options: any, plugin?: (files: any, options?: any) => Iterator<any>)
131 }
132}