UNPKG

1.38 kBJavaScriptView Raw
1var publishRelease = require('publish-release');
2var through = require('through2');
3var gutil = require('gulp-util');
4
5var PluginError = gutil.PluginError;
6var PLUGIN_NAME = 'gulp-github-release';
7
8module.exports = function(options) {
9 var files = [];
10
11 var stream = through.obj(function(file, encoding, next) {
12 files.push(file.path);
13 next();
14 }, function(callback) {
15 var _this = this;
16 var manifest = options.manifest;
17 var repo = manifest && manifest.repository && /git@github\.com:([\w-]+)\/([\w-]+)\.git/.exec(manifest.repository.url);
18
19 options = options || {};
20 options.token = options.token || process.env.GITHUB_TOKEN;
21 options.assets = files;
22 options.owner = options.owner || repo && repo[1] || undefined;
23 options.repo = options.repo || repo && repo[2] || undefined;
24 options.tag = options.tag || manifest && ('v' + manifest.version) || undefined;
25 options.name = options.name || options.tag;
26
27 var release = publishRelease(options, callback);
28
29 release.on('created-release', function() {
30 gutil.log('Release created successfully at https://github.com/' + options.owner + '/' + options.repo + '/releases/tag/' + options.tag);
31 });
32
33 release.on('upload-asset', function(name) {
34 gutil.log('Uploading asset ' + name);
35 });
36 });
37
38 // returning the file stream
39 stream.resume();
40 return stream;
41};