0
# Jake
1
2
Jake is a JavaScript build tool for Node.js that provides functionality similar to Make or Rake. It allows developers to define build tasks in JavaScript using a familiar task-based approach, with support for file dependencies, asynchronous operations, and command-line execution.
3
4
## Package Information
5
6
- **Package Name**: jake
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install jake` (global: `npm install -g jake`)
10
11
## Core Imports
12
13
```javascript
14
// Import the entire Jake API
15
const jake = require('jake');
16
17
// Or import specific functions (globals are also available)
18
const { task, desc, file, directory, namespace } = require('jake');
19
```
20
21
When using Jake as a build tool, the API functions are automatically available as globals in Jakefiles.
22
23
## Basic Usage
24
25
```javascript
26
// Define a simple task
27
desc('Default task');
28
task('default', function() {
29
console.log('Hello from Jake!');
30
});
31
32
// Define a task with prerequisites
33
desc('Build project');
34
task('build', ['clean', 'compile'], function() {
35
console.log('Building project...');
36
});
37
38
// Create a file task that checks modification times
39
file('dist/app.js', ['src/app.js'], function() {
40
// This only runs if src/app.js is newer than dist/app.js
41
jake.exec(['uglifyjs src/app.js -o dist/app.js'], function() {
42
complete();
43
});
44
}, { async: true });
45
46
// Create a directory task
47
directory('dist');
48
49
// Run Jake from command line: `jake build`
50
```
51
52
## Architecture
53
54
Jake is built around several key components:
55
56
- **Task System**: Core task definition and execution with prerequisite handling
57
- **File Tasks**: File-based tasks with automatic modification time checking
58
- **Rule System**: Pattern-based task generation for flexible build systems
59
- **Namespace System**: Hierarchical task organization to prevent naming conflicts
60
- **Execution Engine**: Asynchronous task execution with dependency resolution
61
- **Utility Functions**: Built-in file operations and shell command execution
62
63
## Capabilities
64
65
### Core Task System
66
67
Define and execute build tasks with prerequisites, asynchronous operations, and file dependency checking. The foundation of Jake's build automation.
68
69
```javascript { .api }
70
function task(name, prereqs, action, opts);
71
function file(name, prereqs, action, opts);
72
function directory(name);
73
function desc(description);
74
function complete(task, value);
75
function fail(err, code);
76
function series(...tasks);
77
function setTaskTimeout(timeout);
78
function setSeriesAutoPrefix(prefix);
79
```
80
81
[Core Task System](./core-tasks.md)
82
83
### Build Task Types
84
85
Specialized task types for common build operations including package creation, publishing, and test execution with built-in conventions.
86
87
```javascript { .api }
88
function packageTask(name, version, prereqs, definition);
89
function publishTask(name, prereqs, opts, definition);
90
function npmPublishTask(name, prereqs, opts, definition);
91
function testTask(name, prereqs, definition);
92
```
93
94
[Build Task Types](./build-tasks.md)
95
96
### Task Organization
97
98
Organize tasks hierarchically using namespaces and create dynamic tasks using pattern-based rules for scalable build systems.
99
100
```javascript { .api }
101
function namespace(name, closure);
102
function rule(pattern, source, prereqs, action, opts);
103
```
104
105
[Task Organization](./task-organization.md)
106
107
### Utility Functions
108
109
Built-in utilities for shell command execution and file operations, providing cross-platform build automation capabilities.
110
111
```javascript { .api }
112
function exec(cmds, opts, callback);
113
function createExec(cmds, opts, callback);
114
function uuid(length, radix);
115
function cpR(fromPath, toPath, opts);
116
function mkdirP(dir, mode);
117
function rmRf(path, options);
118
function isAbsolute(path);
119
function absolutize(path);
120
```
121
122
[Utility Functions](./utilities.md)
123
124
### Task Classes
125
126
Direct access to Jake's task class hierarchy for programmatic task creation and advanced build system development.
127
128
```javascript { .api }
129
class Task extends EventEmitter;
130
class FileTask extends Task;
131
class DirectoryTask extends FileTask;
132
class PackageTask;
133
class PublishTask;
134
class TestTask;
135
```
136
137
[Task Classes](./task-classes.md)
138
139
## Global Jake Object
140
141
The main Jake object provides access to all functionality and system state:
142
143
```javascript { .api }
144
interface Jake extends EventEmitter {
145
version: string;
146
errorCode: number;
147
logger: Logger;
148
exec: Function;
149
createExec: Function;
150
uuid: Function;
151
FileList: FileListConstructor;
152
Task: TaskConstructor;
153
FileTask: FileTaskConstructor;
154
DirectoryTask: DirectoryTaskConstructor;
155
PackageTask: PackageTaskConstructor;
156
PublishTask: PublishTaskConstructor;
157
TestTask: TestTaskConstructor;
158
Namespace: NamespaceConstructor;
159
Rule: RuleConstructor;
160
161
// File utilities
162
cpR: Function;
163
mkdirP: Function;
164
rmRf: Function;
165
isAbsolute: Function;
166
absolutize: Function;
167
168
// Task system
169
parseAllTasks(): void;
170
showAllTaskDescriptions(filter?: string): void;
171
run(...args: any[]): void;
172
setTaskTimeout(timeout: number): void;
173
setSeriesAutoPrefix(prefix: string): void;
174
175
// Namespaces
176
rootNamespace: RootNamespace;
177
defaultNamespace: RootNamespace;
178
currentNamespace: Namespace;
179
180
// Task management
181
currentTaskDescription: string | null;
182
createTask(type: string, ...args: any[]): Task;
183
loader: Loader;
184
program: Program;
185
186
// Internal properties
187
_invocationChain: Task[];
188
_taskTimeout: number;
189
_seriesAutoPrefix: string;
190
}
191
```