Permalink
Browse files

ES6 support and gulpfile refactor

  • Loading branch information...
lorenzoganni committed Jan 5, 2017
1 parent 90f0b1f commit c2870494eda3ae04d3645c465432aef84f923b64
Showing with 58 additions and 51 deletions.
  1. +3 −0 .babelrc
  2. +52 −51 gulpfile.js → gulpfile.babel.js
  3. +3 −0 package.json
View
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
@@ -1,34 +1,46 @@
var gulp = require('gulp'),
argv = require('yargs').argv,
gulpif = require('gulp-if'),
pug = require('gulp-pug'),
sass = require('gulp-sass'),
compass = require('compass-importer'),
sassInlineImage = require('sass-inline-image'),
fontAwesome = require('node-font-awesome'),
merge = require('merge-stream'),
rename = require("gulp-rename"),
zip = require('gulp-zip'),
uglifycss = require('gulp-uglifycss'),
concat = require('gulp-concat'),
concatFilenames = require('gulp-concat-filenames'),
server = require('gulp-express'),
bro = require('gulp-bro'),
uglifyify = require('uglifyify');
import gulp from 'gulp';
import argv from 'yargs';
import gulpif from 'gulp-if';
import pug from 'gulp-pug';
import sass from 'gulp-sass';
import compass from 'compass-importer';
import sassInlineImage from 'sass-inline-image';
import fontAwesome from 'node-font-awesome';
import merge from 'merge-stream';
import rename from 'gulp-rename';
import zip from 'gulp-zip';
import uglifycss from 'gulp-uglifycss';
import concat from 'gulp-concat';
import concatFilenames from 'gulp-concat-filenames';
import server from 'gulp-express';
import bro from 'gulp-bro';
import babelify from 'babelify';
import uglifyify from 'uglifyify';
// use 'dist' folder for production output, dest otherwise
var dest = argv.production ? 'dist' : 'build';
const dest = argv.production ? 'dist' : 'build';
// tasks to be executed during build
const tasks = [
'styles',
'scripts',
'samplesList',
'samplesFolder',
'samplesZip',
'templates',
'fonts'
];
// pug templates
gulp.task('templates', function() {
return gulp.src('src/templates/index.pug')
gulp.task('templates', () => {
gulp.src('src/templates/index.pug')
.pipe(pug().on('error', console.error.bind(console)))
.pipe(gulp.dest(dest));
});
// compile sass using compass
gulp.task('styles', function() {
var sassStream = gulp.src('src/sass/main.sass')
gulp.task('styles', () => {
let sassStream = gulp.src('src/sass/main.sass')
.pipe(sass(
{
importer: compass,
@@ -38,28 +50,29 @@ gulp.task('styles', function() {
}
).on('error', sass.logError));
var codeMirror = gulp.src('node_modules/codemirror/lib/codemirror.css');
var codeMirrorLint = gulp.src('node_modules/codemirror/addon/lint/lint.css');
let codeMirror = gulp.src('node_modules/codemirror/lib/codemirror.css');
let codeMirrorLint = gulp.src('node_modules/codemirror/addon/lint/lint.css');
return merge(sassStream, codeMirrorLint, codeMirror)
merge(sassStream, codeMirrorLint, codeMirror)
.pipe(concat('app.css'))
.pipe(rename('style.min.css'))
.pipe(gulpif(argv.production, uglifycss({ 'uglyComments': true })))
.pipe(gulp.dest(dest + '/src'));
});
// font awesome
gulp.task('fonts', function() {
return gulp.src(fontAwesome.fonts)
gulp.task('fonts', () => {
gulp.src(fontAwesome.fonts)
.pipe(gulp.dest(dest + '/fonts'));
});
// produce uglified app js code
gulp.task('scripts', function() {
return gulp.src('src/js/index.js')
gulp.task('scripts', () => {
gulp.src('src/js/index.js')
.pipe(
bro({
transform: [
babelify.configure( { presets: ['es2015'] } ),
argv.production ? [ 'uglifyify', { global: true } ] : ''
]
})
@@ -69,11 +82,10 @@ gulp.task('scripts', function() {
});
// create list of samples file names
function fileNameFormatter(filename) {
return filename.split('.')[0];
}
gulp.task('samplesList', function () {
return gulp.src('samples/*.json')
let fileNameFormatter = filename => filename.split('.')[0];
gulp.task('samplesList', () => {
gulp.src('samples/*.json')
.pipe(concatFilenames('list.txt', {
root: 'samples/',
template: fileNameFormatter
@@ -82,31 +94,20 @@ gulp.task('samplesList', function () {
});
// copy samples folder
gulp.task('samplesFolder', function () {
return gulp.src('samples/**/*')
gulp.task('samplesFolder', () => {
gulp.src('samples/**/*')
.pipe(gulp.dest(dest + '/samples'));
});
// generate samples ZIP
gulp.task('samplesZip', () => {
return gulp.src('samples/*')
.pipe(zip('samples.zip'))
.pipe(gulp.dest(dest));
gulp.src('samples/*')
.pipe(zip('samples.zip'))
.pipe(gulp.dest(dest));
});
// tasks to be executed during build
var tasks = [
'styles',
'scripts',
'samplesList',
'samplesFolder',
'samplesZip',
'templates',
'fonts'
];
// default task
gulp.task('default', tasks, function() {
gulp.task('default', tasks, () => {
// in development start server and watchers
if (!argv.production) {
View
@@ -9,6 +9,9 @@
},
"license": "MIT",
"devDependencies": {
"babel-core": "^6.21.0",
"babel-preset-es2015": "^6.18.0",
"babelify": "^7.3.0",
"compass-importer": "^0.4.1",
"express": "^4.14.0",
"gulp": "^3.9.1",

0 comments on commit c287049

Please sign in to comment.