-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgulpfile.js
More file actions
124 lines (101 loc) · 2.91 KB
/
gulpfile.js
File metadata and controls
124 lines (101 loc) · 2.91 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
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
111
112
113
114
115
116
117
118
119
120
121
122
'use strict';
var path = require('path');
var fs = require('fs');
var gulp = require('gulp');
var argv = require('yargs').default('environment', 'stage').argv;
var $ = require('gulp-load-plugins')();
var merge = require('merge-stream');
var runSequence = require('run-sequence');
var SRC_NAME = 'Quirkbot.zip';
var RELEASE_NAME = 'quirkbot-arduino-library';
var PACKAGE = JSON.parse(fs.readFileSync('package.json'));
var VERSION_FILENAME = `${RELEASE_NAME}-${PACKAGE.version}.zip`;
var LATEST_FILENAME = `${RELEASE_NAME}-latest.zip`;
/**
* Cleans all the generated files
*/
gulp.task('clean', function () {
return gulp.src([
LATEST_FILENAME,
RELEASE_NAME,
RELEASE_NAME + '-*.zip',
SRC_NAME
])
.pipe($.clean());
});
/**
* Gives a warning in case the current release you are building overwrites an
* existing release.
*/
gulp.task('check-release-overwrite', [], function () {
var file = fs.readFileSync(path.resolve('library.properties')).toString();
var lines = file.split('\n');
var settings = {};
lines.forEach(function (line) {
var parts = line.split('=');
if(parts.length === 2){
var key = parts[0];
var value = parts[1];
settings[key] = value;
}
});
if(settings.version == PACKAGE.version){
return gulp.src('')
.pipe($.prompt.confirm(`There is already a release with the version ${PACKAGE.version}. Do you want to overwrite it (Y)?\n (If you want to create a new release, answer (N) and updated the version in package.json first)`))
}
});
/**
* Bundles the source code into a versioned zip file
*/
gulp.task('bundle', ['check-release-overwrite','clean'], function (cb){
var exec = require('child_process').exec;
exec(
`sh build-release.sh ` +
`&& cp ${SRC_NAME} ${LATEST_FILENAME} `+
`&& cp ${SRC_NAME} ${VERSION_FILENAME}`,
(error, stdout, stderr) => {
console.log(stderr)
cb();
}
);
});
/**
* Generate the "platform" entry on the package index
*/
gulp.task('build', ['bundle'], function (cb) {
// Create generate the library properties file
var libraryProperties = fs.readFileSync('library.template.properties').toString()
.split('{{VERSION}}').join(PACKAGE.version)
// Save the new properties
fs.writeFileSync('library.properties',libraryProperties);
cb();
});
/**
* Builds and publish to s3
*/
gulp.task('s3', ['build'], function () {
var aws = JSON.parse(fs.readFileSync(path.join('aws-config', `${argv.environment}.json`)));
return gulp.src([
VERSION_FILENAME,
LATEST_FILENAME
])
.pipe($.s3(aws, {
uploadPath: 'downloads/'
}));
});
/**
* Deploys the release. Asks for confirmation if deploying to production
*/
gulp.task('confirm-deploy', [], function () {
if(argv.environment == 'production'){
return gulp.src('')
.pipe($.prompt.confirm('You are about to deploy TO PRODUCTION! Are you sure you want to continue)'))
.pipe($.prompt.confirm('Really sure?!'))
}
});
gulp.task('deploy', function (cb) {
runSequence(
'confirm-deploy',
's3',
cb);
});