-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jakefile.js
87 lines (77 loc) · 2.53 KB
/
Jakefile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
Filename: Jakefile
Date: 3/26/17
Author: Chris Mendez http://chrisjmendez.com
Description: DevOps tool aimed at simplifying two things:
- The packaging and publishing of AWS Lambda functions
- Streamline HTTP Requests to AWS API Gateway to test Lambda functions.
The task below titled "default" simply
* ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
require('dotenv').config({path: ''});
desc('Archive app and upload to S3.');
task('default', { async: true }, function() {
var config = {
//Name of this .zip file
app: process.env.APP,
//Name of your AWS S3 Bucket destination
bucket: process.env.BUCKET,
//Name of your AWS Client profile
profile: process.env.AWSCLI_PROFILE
}
//Start
init(config);
});
/*
Workflow
*/
function archive(config){
var task = jake.Task['app:archive'];
task.addListener("start", onStart.bind(null,"archive"))
//Once we're done archiving the app, let's upload it to AWS S3
task.addListener("complete", onComplete.bind(null, "archive", upload, config ), false)
task.addListener("error", onError);
task.invoke.apply(task, [config]);
}
function upload(config){
var task = jake.Task['app:upload'];
task.addListener("start", onStart.bind(null, "upload"))
//Once we're done uploading the files, reset the environment
task.addListener("complete", onComplete.bind(null, "upload", reset, config ), false);
task.addListener("error", onError);
task.invoke.apply(task, [config]);
}
function reset(config){
var task = jake.Task['app:reset'];
task.addListener("start", onStart.bind(null, "reset"))
//Once the process is complete, we're done.
task.addListener("complete", onComplete.bind(null, "reset", complete, null ), false)
task.addListener("error", onError);
task.invoke.apply(task, [config]);
}
function init(config){
console.log('Jake Start.');
if(config.app && config.bucket && config.profile){
archive(config);
} else {
var example = `
APP=name_of_zip_file
BUCKET=name_of_s3_bucket
AWSCLI_PROFILE=name_of_awscli_profile`
console.log("Please make sure you have a .env file that includes these variables: ", example)
}
}
/*
Event Handlers
*/
function onStart(callee){
console.log("Handler:", arguments.callee.name, ":", callee);
}
function onComplete(callee, callback, config){
console.log("Handler:", arguments.callee.name, ":", callee, ":", config);
callback(config)
}
function onError(e){
console.log("Reset Error:", e.message, e.code);
//If things go wrong, re-download the npm packages we deleted.
jake.Task['app:reset'].invoke();
}