2017-03-22 15:08:23 +01:00
|
|
|
import readline from 'readline';
|
|
|
|
import url from 'url';
|
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2014-10-04 02:26:05 +02:00
|
|
|
module.exports = function (grunt) {
|
|
|
|
// build, then zip and upload to s3
|
|
|
|
grunt.registerTask('release', [
|
2015-08-15 01:20:48 +02:00
|
|
|
'_release:confirmUpload',
|
2014-10-04 02:26:05 +02:00
|
|
|
'build',
|
2016-07-21 00:00:30 +02:00
|
|
|
'_release:loadS3Config',
|
|
|
|
'aws_s3:staging',
|
2015-08-15 01:20:48 +02:00
|
|
|
'_release:complete'
|
2014-10-04 02:26:05 +02:00
|
|
|
]);
|
|
|
|
|
2015-08-15 01:20:48 +02:00
|
|
|
grunt.registerTask('_release:confirmUpload', function () {
|
2016-07-21 00:00:30 +02:00
|
|
|
const rl = readline.createInterface({
|
2015-08-15 01:20:48 +02:00
|
|
|
input: process.stdin,
|
|
|
|
output: process.stdout
|
|
|
|
});
|
|
|
|
|
|
|
|
rl.on('close', this.async());
|
|
|
|
rl.question('Do you want to actually upload the files to s3 after building?, [N/y] ', function (resp) {
|
2016-07-21 00:00:30 +02:00
|
|
|
const debug = resp.toLowerCase().trim()[0] !== 'y';
|
|
|
|
|
|
|
|
grunt.config.set('aws_s3.staging.options.debug', debug);
|
|
|
|
|
2015-08-15 01:20:48 +02:00
|
|
|
rl.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-10-04 02:26:05 +02:00
|
|
|
// collect the key and secret from the .aws-config.json file, finish configuring the s3 task
|
2015-08-15 01:20:48 +02:00
|
|
|
grunt.registerTask('_release:loadS3Config', function () {
|
2016-07-21 00:00:30 +02:00
|
|
|
const config = grunt.file.readJSON('.aws-config.json');
|
|
|
|
|
|
|
|
grunt.config('aws_s3.options', {
|
|
|
|
accessKeyId: config.key,
|
|
|
|
secretAccessKey: config.secret,
|
2016-12-15 03:03:02 +01:00
|
|
|
bucket: config.bucket || grunt.config.get('aws_s3.options.bucket'),
|
2016-07-21 00:00:30 +02:00
|
|
|
region: config.region
|
2014-10-04 02:26:05 +02:00
|
|
|
});
|
|
|
|
});
|
2015-08-14 20:53:26 +02:00
|
|
|
|
2016-07-21 00:00:30 +02:00
|
|
|
grunt.registerTask('_release:complete', function () {
|
|
|
|
const config = grunt.config.get('aws_s3.staging.files');
|
2016-06-17 20:26:08 +02:00
|
|
|
|
2016-07-21 00:00:30 +02:00
|
|
|
grunt.log.ok('Builds uploaded');
|
2016-06-17 20:26:08 +02:00
|
|
|
|
2016-07-21 00:00:30 +02:00
|
|
|
fs.readdirSync('./target').forEach((file) => {
|
|
|
|
if (path.extname(file) !== '.txt') {
|
2016-12-13 18:44:27 +01:00
|
|
|
const link = url.format({
|
2016-07-21 00:00:30 +02:00
|
|
|
protocol: 'https',
|
|
|
|
hostname: 'download.elastic.co',
|
|
|
|
pathname: config[0].dest + file
|
|
|
|
});
|
2016-06-17 20:26:08 +02:00
|
|
|
|
2016-07-21 00:00:30 +02:00
|
|
|
grunt.log.writeln(link);
|
|
|
|
}
|
2016-05-19 20:16:11 +02:00
|
|
|
});
|
2015-08-14 20:53:26 +02:00
|
|
|
});
|
2015-08-01 01:33:01 +02:00
|
|
|
};
|