forked from dmcdaniel12/mibew_slack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
93 lines (82 loc) · 2.7 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
var fs = require('fs'),
https = require('https'),
exec = require('child_process').exec,
eventStream = require('event-stream'),
gulp = require('gulp'),
chmod = require('gulp-chmod'),
zip = require('gulp-zip'),
tar = require('gulp-tar'),
gzip = require('gulp-gzip'),
rename = require('gulp-rename');
var config = {
getComposerUrl: 'https://getcomposer.org/installer',
phpBin: 'php -d "suhosin.executor.include.whitelist = phar"',
package: require('./composer.json')
}
// Cleans all built files
gulp.task('clean', function(callback) {
del([
'release',
], callback);
});
// Get and install PHP Composer
gulp.task('get-composer', function(callback) {
// Check if Composer already in place
if (fs.existsSync('./composer.phar')) {
callback(null);
return;
}
// Get installer from the internet
https.get(config.getComposerUrl, function(response) {
// Run PHP to install Composer
var php = exec(config.phpBin, function(error, stdout, stderr) {
callback(error ? stderr : null);
});
// Pass installer code to PHP via STDIN
response.pipe(php.stdin);
});
});
// Install Composer dependencies excluding development ones
gulp.task('composer-install', gulp.series('get-composer', function(callback) {
exec(config.phpBin + ' composer.phar install --no-dev', function(error, stdout, stderr) {
callback(error ? stderr : null);
});
}));
// Install all Composer dependencies
gulp.task('composer-install-dev', gulp.series('get-composer', function(callback) {
exec(config.phpBin + ' composer.phar install', function(error, stdout, stderr) {
callback(error ? stderr : null);
});
}));
gulp.task('prepare-release', function() {
var version = require('./package.json').version;
return eventStream.merge(
getSources()
.pipe(zip('slack-' + version + '.zip')),
getSources()
.pipe(tar('slack-' + version + '.tar'))
.pipe(gzip())
)
.pipe(chmod(0644))
.pipe(gulp.dest('release'));
});
// Builds and packs plugins sources
gulp.task('default', gulp.series('composer-install','prepare-release'));
/**
* Returns files stream with the plugin sources.
*
* @returns {Object} Stream with VinylFS files.
*/
var getSources = function() {
return gulp.src([
'Plugin.php',
'README.md',
'LICENSE',
'vendor/**/*.*'
],
{base: './'}
)
.pipe(rename(function(path) {
path.dirname = 'Mibew/Mibew/Plugin/Slack/' + path.dirname;
}));
}