From a9cd4008341e73b6c32dbd71e2ba7c23aa0c861e Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Wed, 6 Aug 2014 12:08:19 +0000 Subject: [PATCH] Add a Gulp tasks for composer dependancies installation --- src/gulpfile.js | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/gulpfile.js b/src/gulpfile.js index 01412b45..3f5451cc 100644 --- a/src/gulpfile.js +++ b/src/gulpfile.js @@ -1,4 +1,6 @@ var fs = require('fs'), + https = require('https'), + exec = require('child_process').exec, eventStream = require('event-stream'), gulp = require('gulp'), uglify = require('gulp-uglify'), @@ -17,12 +19,13 @@ var config = { jsPath: 'mibew/js', chatStylesPath: 'mibew/styles/dialogs', pageStylesPath: 'mibew/styles/pages', - compiledTemplatesHeader: fs.readFileSync('tools/compiled_templates_header.txt') + compiledTemplatesHeader: fs.readFileSync('tools/compiled_templates_header.txt'), + getComposerUrl: 'https://getcomposer.org/installer' } // Checks all PHP files with PHP Code Sniffer. -gulp.task('phpcs', function() { +gulp.task('phpcs', ['composer-install-dev'], function() { return gulp.src([ config.mibewPath + '/**/*.php', '!' + config.phpVendorPath + '/**/*.*', @@ -35,6 +38,40 @@ gulp.task('phpcs', function() { })); }); +// 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('php', 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', ['get-composer'], function(callback) { + exec('php composer.phar install --no-dev', function(error, stdout, stderr) { + callback(error ? stderr : null); + }); +}); + +// Install all Composer dependencies +gulp.task('composer-install-dev', ['get-composer'], function(callback) { + exec('php composer.phar install', function(error, stdout, stderr) { + callback(error ? stderr : null); + }); +}); + // Compile all JavaScript files of the Mibew Core gulp.task('js', function() { return eventStream.merge(