-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (64 loc) · 2.73 KB
/
index.js
File metadata and controls
69 lines (64 loc) · 2.73 KB
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
var through = require('through2');
var vinyl = require('vinyl-fs');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var path = require('path');
var gulp = require('gulp');
const fs = require('fs');
const unzip = require('gulp-unzip');
var GITHUB_URL = 'https://cdn.rawgit.com/WebSeed/node-canvas-aws-lambda-example/master/dist/lamdba.zip';
const dependencyDirectory = path.resolve(__dirname, 'dependencies');
var DEPENDENCY_LOCATION = path.resolve(dependencyDirectory, 'lambda-node-canvas-dependency');
var https = require('https');
const DOWNLOAD_ZIP_LOCATION = dependencyDirectory+path.sep+'lambda-node-canvas-dependency.zip';
//ami-60b6c60a
module.exports = function (opts) {
opts = opts || {};
if(!opts.runtime) {
console.error(new PluginError('aws-lambda-node-canvas', 'runtime is mandatory'));
return;
}
if(opts.runtime !== 'nodejs' && opts.runtime!=='nodejs4.3'){
console.error(new PluginError('aws-lambda-node-canvas', 'runtime should either be nodejs or nodejs4.3'));
return;
}
if(opts.runtime !== 'nodejs') {
DEPENDENCY_LOCATION = path.resolve(dependencyDirectory, 'lambda-node-canvas-dependency-4.3');
}
var addNodeCanvasDependencyPath = function(originalStream, endCallback) {
console.log(DEPENDENCY_LOCATION);
gulp.src(DEPENDENCY_LOCATION + path.sep+'**'+path.sep+'*', { dot : true})
.pipe(through.obj(function(file, encoding, cb){
originalStream.push(file);
cb();
}))
.on('finish', function() {
console.log('finish')
endCallback();
});
};
var pass = through.obj(function(file, encoding, callback) {
callback(null, file);
},function(callback) {
var self = this;
if((!fs.existsSync(DEPENDENCY_LOCATION))){
var fileStream = fs.createWriteStream(DOWNLOAD_ZIP_LOCATION);
console.log('Dependency not available, Downloading dependency file '+GITHUB_URL);
https.get(GITHUB_URL, function(response) {
response.pipe(fileStream)
fileStream.on('finish', function() {
console.log('Download Complete');
gulp.src(DOWNLOAD_ZIP_LOCATION , { dot : true })
.pipe(unzip({ keepEmpty : true }))
.pipe(gulp.dest(DEPENDENCY_LOCATION))
.on('finish', function() {
addNodeCanvasDependencyPath(self, callback);
})
})
});
}else {
addNodeCanvasDependencyPath(self, callback);
}
});
return pass;
};