2015-04-09 23:26:08 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
2015-04-16 15:20:06 -07:00
|
|
|
var paths,
|
|
|
|
|
gulp = require('gulp'),
|
|
|
|
|
convertBytes = function(bytes) {
|
|
|
|
|
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
|
|
|
|
if (bytes == 0) return '0 Byte';
|
|
|
|
|
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
|
|
|
|
|
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
|
|
|
|
|
};
|
2015-04-14 15:30:05 -07:00
|
|
|
|
|
|
|
|
// if we call `up` or `update`, we just need to run through projs and update all NPM deps
|
|
|
|
|
if (process.argv.slice(2).join(',').match(/(update|up|--update|-up)/)) {
|
|
|
|
|
gulp.task('default', function() {
|
|
|
|
|
paths = ['./', 'platforms/common', 'assets/common', 'engines/common/nucleus'];
|
|
|
|
|
|
|
|
|
|
var exec = require('child_process').exec, child;
|
|
|
|
|
paths.forEach(function(path) {
|
|
|
|
|
console.log("Updating JS dependencies in: " + path);
|
|
|
|
|
child = exec('cd ' + path + ' && npm update --save --save-dev',
|
|
|
|
|
function(error, stdout, stderr) {
|
|
|
|
|
if (stdout) { console.log('Completed `' + path + '`:', "\n", stdout); }
|
|
|
|
|
if (stderr) { console.log('Error `' + path + '`:' + stderr); }
|
|
|
|
|
if (error !== null) { console.log('Exec error `' + path + '`:' + error); }
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-04-16 15:20:06 -07:00
|
|
|
|
2015-04-14 15:30:05 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var argv = require('yargs').argv,
|
2015-04-09 23:26:08 -07:00
|
|
|
gutil = require('gulp-util'),
|
|
|
|
|
gulpif = require('gulp-if'),
|
|
|
|
|
uglify = require('gulp-uglify'),
|
|
|
|
|
buffer = require('vinyl-buffer'),
|
|
|
|
|
source = require('vinyl-source-stream'),
|
|
|
|
|
merge = require('merge-stream'),
|
|
|
|
|
sourcemaps = require('gulp-sourcemaps'),
|
|
|
|
|
browserify = require('browserify'),
|
|
|
|
|
watchify = require('watchify'),
|
2015-04-13 14:49:27 -07:00
|
|
|
jsonminify = require('gulp-jsonminify'),
|
2015-04-09 23:26:08 -07:00
|
|
|
sass = require('gulp-ruby-sass'),
|
|
|
|
|
|
|
|
|
|
prod = !!(argv.p || argv.prod || argv.production),
|
2015-04-15 14:39:55 -07:00
|
|
|
watchType = (argv.css && argv.js) ? 'all' : (argv.css ? 'css' : (argv.js ? 'js' : 'all')),
|
2015-04-09 23:26:08 -07:00
|
|
|
watch = false;
|
|
|
|
|
|
2015-04-14 15:30:05 -07:00
|
|
|
paths = {
|
2015-04-09 23:26:08 -07:00
|
|
|
js: [
|
|
|
|
|
{ // admin
|
|
|
|
|
in: './platforms/common/application/main.js',
|
|
|
|
|
out: './platforms/common/js/main.js'
|
|
|
|
|
},
|
|
|
|
|
{ // frontend
|
|
|
|
|
in: './assets/common/application/main.js',
|
|
|
|
|
out: './assets/common/js/main.js'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
css: [
|
|
|
|
|
{ // admin
|
|
|
|
|
in: './platforms/common/scss/admin.scss',
|
|
|
|
|
out: './platforms/common/css-compiled/admin.css',
|
|
|
|
|
load: './engines/common/nucleus/scss'
|
|
|
|
|
},
|
|
|
|
|
{ // admin - joomla
|
|
|
|
|
in: './platforms/joomla/com_gantry5/admin/scss/joomla-admin.scss',
|
|
|
|
|
out: './platforms/joomla/com_gantry5/admin/css-compiled/joomla-admin.css',
|
|
|
|
|
load: './engines/common/nucleus/scss'
|
|
|
|
|
},
|
2015-05-26 19:20:52 +02:00
|
|
|
{ // admin - wordpress
|
2015-05-26 19:31:24 +02:00
|
|
|
in: './platforms/wordpress/gantry5/scss/wordpress-admin.scss',
|
|
|
|
|
out: './platforms/wordpress/gantry5/css-compiled/wordpress-admin.css',
|
2015-05-26 19:20:52 +02:00
|
|
|
load: './engines/common/nucleus/scss'
|
|
|
|
|
},
|
2015-04-09 23:26:08 -07:00
|
|
|
{ // nucleus
|
|
|
|
|
in: './engines/common/nucleus/scss/nucleus.scss',
|
|
|
|
|
out: './engines/common/nucleus/css-compiled/nucleus.css'
|
2015-04-27 14:26:22 -07:00
|
|
|
},
|
|
|
|
|
{ // nucleus - joomla
|
|
|
|
|
in: './engines/joomla/nucleus/scss/joomla.scss',
|
|
|
|
|
out: './engines/joomla/nucleus/css-compiled/joomla.css',
|
|
|
|
|
load: './engines/common/nucleus/scss'
|
2015-04-09 23:26:08 -07:00
|
|
|
}
|
2015-04-13 14:49:27 -07:00
|
|
|
],
|
|
|
|
|
minify: [
|
|
|
|
|
{ // google fonts
|
|
|
|
|
in: './platforms/common/js/google-fonts.json',
|
|
|
|
|
out: './platforms/common/js/google-fonts.json'
|
2015-04-15 17:27:12 -07:00
|
|
|
},
|
|
|
|
|
{ // matchMedia polyfill
|
|
|
|
|
in: './assets/common/js/matchmedia.polyfill.js',
|
|
|
|
|
out: './assets/common/js/matchmedia.polyfill.js'
|
2015-04-13 14:49:27 -07:00
|
|
|
}
|
2015-04-09 23:26:08 -07:00
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
|
2015-04-10 12:50:16 -07:00
|
|
|
// -- DO NOT EDIT BELOW --
|
|
|
|
|
|
2015-04-09 23:26:08 -07:00
|
|
|
var compileCSS = function(app) {
|
|
|
|
|
var _in = app.in,
|
|
|
|
|
_out = app.out.split(/[\\/]/).pop(),
|
|
|
|
|
_load = app.load || false,
|
|
|
|
|
_dest = app.out.substring(0, app.out.lastIndexOf('/')),
|
2015-04-10 11:05:03 -07:00
|
|
|
_maps = '../' + app.in.substring(0, app.in.lastIndexOf('/')).split(/[\\/]/).pop();
|
2015-04-09 23:26:08 -07:00
|
|
|
|
|
|
|
|
gutil.log(gutil.colors.blue('*'), 'Compiling', _in);
|
|
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
|
container: _out,
|
|
|
|
|
sourcemap: !prod,
|
|
|
|
|
loadPath: _load,
|
2015-04-10 12:40:36 -07:00
|
|
|
style: prod ? 'compact' : 'expanded',
|
2015-04-09 23:26:08 -07:00
|
|
|
lineNumbers: !prod,
|
|
|
|
|
trace: !prod
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return sass(_in, options)
|
|
|
|
|
.on('end', function() {
|
|
|
|
|
gutil.log(gutil.colors.green('√'), 'Saved ' + _in);
|
|
|
|
|
})
|
|
|
|
|
.on('error', gutil.log)
|
2015-04-10 11:05:03 -07:00
|
|
|
.pipe(gulpif(!prod, sourcemaps.write('.', { sourceRoot: _maps })))
|
2015-04-09 23:26:08 -07:00
|
|
|
.pipe(gulp.dest(_dest));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var compileJS = function(app, watching) {
|
|
|
|
|
var _in = app.in,
|
|
|
|
|
_out = app.out.split(/[\\/]/).pop(),
|
|
|
|
|
_dest = app.out.substring(0, app.out.lastIndexOf('/')),
|
|
|
|
|
_maps = './' + app.in.substring(0, app.in.lastIndexOf('/')).split(/[\\/]/).pop();
|
|
|
|
|
|
|
|
|
|
if (!watching) {
|
|
|
|
|
gutil.log(gutil.colors.blue('*'), 'Compiling', _in);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bundle = browserify({
|
|
|
|
|
entries: [_in],
|
|
|
|
|
debug: !prod,
|
2015-04-16 15:20:06 -07:00
|
|
|
watch: watching,
|
2015-04-09 23:26:08 -07:00
|
|
|
|
|
|
|
|
cache: {},
|
|
|
|
|
packageCache: {},
|
2015-04-11 23:26:56 -07:00
|
|
|
fullPaths: false
|
2015-04-09 23:26:08 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (watching) {
|
|
|
|
|
bundle = watchify(bundle);
|
2015-04-16 15:20:06 -07:00
|
|
|
bundle.on('log', function(msg) {
|
|
|
|
|
var bytes = msg.match(/^(\d{1,})\s/)[1];
|
|
|
|
|
msg = msg.replace(/^\d{1,}\sbytes/, convertBytes(bytes));
|
|
|
|
|
gutil.log(gutil.colors.green('√'), 'Done, ', msg, '...');
|
|
|
|
|
});
|
2015-04-10 11:50:28 -07:00
|
|
|
bundle.on('update', function(files) {
|
2015-04-09 23:26:08 -07:00
|
|
|
gutil.log(gutil.colors.red('>'), 'Change detected in', files.join(', '), '...');
|
2015-04-16 15:20:06 -07:00
|
|
|
return bundleShare(bundle, _in, _out, _maps, _dest);
|
2015-04-09 23:26:08 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bundleShare(bundle, _in, _out, _maps, _dest);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var bundleShare = function(bundle, _in, _out, _maps, _dest) {
|
|
|
|
|
return bundle.bundle()
|
2015-04-16 15:20:06 -07:00
|
|
|
.on('error', function(error){
|
|
|
|
|
gutil.log('Browserify', '' + error);
|
|
|
|
|
})
|
2015-04-09 23:26:08 -07:00
|
|
|
.on('end', function() {
|
|
|
|
|
gutil.log(gutil.colors.green('√'), 'Saved ' + _in);
|
|
|
|
|
})
|
|
|
|
|
.pipe(source(_out))
|
|
|
|
|
.pipe(buffer())
|
|
|
|
|
// sourcemaps start
|
|
|
|
|
.pipe(gulpif(!prod, sourcemaps.init({ loadMaps: true })))
|
|
|
|
|
.pipe(gulpif(prod, uglify()))
|
2015-05-03 13:28:37 -07:00
|
|
|
.pipe(gulpif(!prod, sourcemaps.write('.')))
|
2015-04-09 23:26:08 -07:00
|
|
|
// sourcemaps end
|
|
|
|
|
.pipe(gulp.dest(_dest));
|
|
|
|
|
};
|
|
|
|
|
|
2015-04-13 14:49:27 -07:00
|
|
|
var minifyJS = function() {
|
|
|
|
|
var streams = [];
|
|
|
|
|
paths.minify.forEach(function(app) {
|
|
|
|
|
var _file = app.in.substring(app.in.lastIndexOf('/')).split(/[\\/]/).pop(),
|
|
|
|
|
_dest = app.out.substring(0, app.out.lastIndexOf('/')),
|
|
|
|
|
_ext = _file.split('.').pop();
|
|
|
|
|
|
|
|
|
|
gutil.log(gutil.colors.blue('*'), 'Minifying', app.in);
|
|
|
|
|
|
|
|
|
|
streams.push(gulp.src(app.in)
|
|
|
|
|
.on('end', function() {
|
|
|
|
|
gutil.log(gutil.colors.green('√'), 'Saved ' + app.in);
|
|
|
|
|
})
|
|
|
|
|
.on('error', gutil.log)
|
|
|
|
|
.pipe(gulpif(_ext == 'json', jsonminify(), uglify()))
|
|
|
|
|
.pipe(gulp.dest(_dest)));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return merge(streams);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gulp.task('minify', function() {
|
|
|
|
|
if (!prod) { return; }
|
|
|
|
|
|
|
|
|
|
return minifyJS();
|
|
|
|
|
});
|
|
|
|
|
|
2015-04-10 11:50:28 -07:00
|
|
|
gulp.task('watchify', function() {
|
2015-04-15 14:39:55 -07:00
|
|
|
if (watchType != 'js' && watchType != 'all') { return; }
|
2015-04-09 23:26:08 -07:00
|
|
|
watch = true;
|
|
|
|
|
|
|
|
|
|
// watch js
|
|
|
|
|
paths.js.forEach(function(app) {
|
|
|
|
|
var _path = app.in.substring(0, app.in.lastIndexOf('/'));
|
|
|
|
|
return compileJS(app, true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('js', function() {
|
|
|
|
|
var streams = [];
|
|
|
|
|
paths.js.forEach(function(app) {
|
|
|
|
|
streams.push(compileJS(app));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return merge(streams);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('css', function(done) {
|
|
|
|
|
var streams = [];
|
|
|
|
|
paths.css.forEach(function(app) {
|
|
|
|
|
streams.push(compileCSS(app, done));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return merge(streams);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
gulp.task('watch', ['watchify'], function() {
|
2015-04-15 14:39:55 -07:00
|
|
|
if (watchType != 'css' && watchType != 'all') { return; }
|
|
|
|
|
|
2015-04-09 23:26:08 -07:00
|
|
|
// watch css
|
|
|
|
|
paths.css.forEach(function(app) {
|
|
|
|
|
var _path = app.in.substring(0, app.in.lastIndexOf('/'));
|
|
|
|
|
gulp.watch(_path + '/**/*.scss', function(event) {
|
|
|
|
|
gutil.log(gutil.colors.red('>'), 'File', event.path, 'was', event.type);
|
|
|
|
|
return compileCSS(app);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-04-13 14:49:27 -07:00
|
|
|
gulp.task('all', ['css', 'js', 'minify']);
|
2015-04-09 23:26:08 -07:00
|
|
|
gulp.task('default', ['all']);
|