forked from hybe/aws-autotranscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
110 lines (92 loc) · 3 KB
/
gulpfile.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var del = require('del'),
gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
runSequence = require('run-sequence'),
gulpNSP = require('gulp-nsp'),
mocha = require('gulp-mocha'),
install = require('gulp-install'),
lambda = require('gulp-awslambda'),
zip = require('gulp-zip'),
lambdaenv = require('./lambdaenv.json'),
package = require('./package.json');
/* Configurations. Note that most of the configuration is stored in
the task context. These are mainly for repeating configuration items */
var buildname = package.name + '_' + package.version;
buildname = buildname.replace(/[^A-Za-z0-9_-]/g,'_');
/* Bump version number for package.json */
// TODO Provide means for appending a patch id based on git commit id or md5 hash
gulp.task('bump', function() {
// Fetch whether we're bumping major, minor or patch; default to minor
var env = $.util.env,
type = (env.major) ? 'major' : (env.patch) ? 'patch' : 'minor';
gulp.src(['./package.json'])
.pipe($.bump({ type: type }))
.pipe(gulp.dest('./node_modules'));
});
gulp.task('build-cleantmp', function() {
return del('temp');
});
gulp.task('build-copysrcfiles', function() {
return gulp.src(['src/*.js'])
.pipe(gulp.dest('temp'));
});
gulp.task('build-copynodemodules', function() {
return gulp.src('./package.json')
.pipe(gulp.dest('temp'))
.pipe(install({production: true}));
});
gulp.task('build-ziptemp', function() {
return gulp.src('temp/**/*')
.pipe(zip(buildname + '.zip'))
.pipe(gulp.dest('.'));
});
gulp.task('buildzip', function() {
return runSequence('build-copysrcfiles', 'build-copynodemodules', 'build-ziptemp');
});
gulp.task('deployzip', function() {
var lambdaparams = {
'FunctionName' : buildname,
'Description' : package.description,
'Role' : lambdaenv.Role
};
var lambdaoptions = {
'region': lambdaenv.Region
};
return gulp.src(buildname + '.zip')
.pipe(lambda(lambdaparams, lambdaoptions));
});
gulp.task('deploy', function() {
return runSequence(
'build-copysrcfiles',
'build-copynodemodules',
'build-ziptemp',
'deployzip',
'build-cleantmp'
);
});
gulp.task('test-run', function() {
process.env.NODE_ENV = 'test';
$.util.log('Running tests (mocha)');
gulp.src(['tests/test*.js'])
.pipe(mocha());
});
//To check your package.json
gulp.task('test-nsp', function (cb) {
gulpNSP('./package.json', cb);
});
gulp.task('clean', function(cb) {
return del([
'dist',
// here we use a globbing pattern to match everything inside the `mobile` folder
'temp'
], cb);
});
// NOTE: Running also build to avoid running against old code
gulp.task('test', function() {
return runSequence('check', 'test-nsp');
});
// NOTE: Running also build to avoid running against old code
gulp.task('check', function() {
return runSequence('test-run');
});
gulp.task('default', ['build', 'test']);