Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
charlybrown03 committed Feb 19, 2017
0 parents commit 364f677
Show file tree
Hide file tree
Showing 46 changed files with 697 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [ "es2015" ]
}
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{js,json,scss,css,hbs}]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENV=dev
24 changes: 24 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"installedESLint": true,
"extends": "standard",
"env": {
"browser": true,
"node": true
},
"parser": "babel-eslint",
"plugins": [
"standard",
"promise"
],
"globals": {
"$": true,
"_": true,
"App": true,
"Backbone": true,
"Marionette": true,
"Radio": true,
"alert": true,
"localStorage": true,
"moment": true
}
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
.env
node_modules/
public/
npm-debug.log
70 changes: 70 additions & 0 deletions gulp/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import dotenv from 'dotenv'

dotenv.config({ silent: true })

let isDevelopment = (process.env.ENV && process.env.ENV !== 'production')

let config = {

environment: isDevelopment ? 'development' : 'production',
development: isDevelopment,

browsersync: {
port: 9000,
uiport: 9001
},

browserify: {
app: 'main.js',
vendor: 'vendor.js'
},

// fonts: {
// src: [
// 'src/resources/fonts/**/*',
// 'node_modules/font-awesome/fonts/**/*'
// ],
// dest: 'public/fonts'
// },

gzip: {
src: 'public/**/*.{html,xml,json,css,js,js.map,css.map}',
dest: 'public/',
options: {}
},

html: {
src: 'src/**/*.html',
dest: 'public',
cachebust: 'public/**/*.html'
},

images: {
src: 'src/resources/images/**/*',
dest: 'public/img'
},

sass: {
src: 'src/resources/styles',
dest: 'public/css',
glob: 'src/resources/styles/**/*.scss',
includePaths: [
'node_modules/normalize-scss/sass',
'node_modules'
]
},

scripts: {
src: 'src',
dest: 'public/js',
glob: 'src/**/*.js'
},

paths: {
src: 'src',
dest: 'public'
}

}

export default config
37 changes: 37 additions & 0 deletions gulp/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import gulp from 'gulp'

import fs from 'fs'

import gulpPlugins from 'gulp-load-plugins'
import config from './config/'

// Import gulp tasks
let tasks = []
let plugins = gulpPlugins()

let wrap = function (task, ...done) {
return task.bind(this, gulp, plugins, config, ...done)
}

fs.readdirSync(`${process.cwd()}/gulp/tasks/`).forEach(task => {
let taskName = task.replace('.js', '')
tasks[taskName] = require('./tasks/' + task).default
})

// Task assignment
gulp.task('browserify:app', wrap(tasks.browserify, config.browserify.app))
gulp.task('browserify:vendor', wrap(tasks.browserify, config.browserify.vendor))
gulp.task('browsersync', wrap(tasks.browsersync))
gulp.task('build', [ 'clean' ], wrap(tasks.build))
gulp.task('cachebust', wrap(tasks.cachebust))
gulp.task('clean', wrap(tasks.clean))
// gulp.task('copy:fonts', wrap(tasks.fonts))
gulp.task('copy:html', wrap(tasks.html))
gulp.task('copy:images', wrap(tasks.images))
gulp.task('default', wrap(tasks.default))
gulp.task('development', [ 'build' ], wrap(tasks.development))
gulp.task('eslint', wrap(tasks.eslint))
gulp.task('gzip', wrap(tasks.gzip))
gulp.task('production', [ 'build' ], wrap(tasks.production))
gulp.task('sass', wrap(tasks.sass))
gulp.task('watch', [ 'browsersync' ], wrap(tasks.watch))
57 changes: 57 additions & 0 deletions gulp/tasks/browserify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import browserify from 'browserify'

import babelify from 'babelify'
import envify from 'envify'
import hbsfy from 'hbsfy'
import watchify from 'watchify'

import browserSync from 'browser-sync'
import buffer from 'vinyl-buffer'
import source from 'vinyl-source-stream'

import errorHandler from '../utils/errorHandler'
import bundleLogger from '../utils/bundleLogger'

let browserifyTask = (gulp, plugins, config, file, done) => {
let bundler = browserify({
entries: [ `${config.scripts.src}/${file}` ],
debug: config.development
})

if (config.development) {
bundler = watchify(bundler)
bundler.on('update', rebundle)
}

const transforms = [
{ name: babelify, options: {} },
{ name: hbsfy, options: {} },
{ name: envify, options: {} }
]

transforms.forEach(transform => {
bundler.transform(transform.name, transform.options)
})

function rebundle () {
bundleLogger.start(file)
const stream = bundler.bundle()

return stream
.on('error', errorHandler.bind(this))
.on('end', bundleLogger.end.bind(this, file))
.pipe(source(file))
.pipe(plugins.if(config.development, buffer()))
.pipe(plugins.if(config.development, plugins.sourcemaps.init({ loadMaps: true })))
.pipe(plugins.if(!config.development, plugins.streamify(plugins.uglify({
compress: { drop_console: true }
}))))
.pipe(plugins.if(config.development, plugins.sourcemaps.write('./')))
.pipe(gulp.dest(config.scripts.dest))
.pipe(browserSync.stream())
}

return rebundle()
}

export default browserifyTask
20 changes: 20 additions & 0 deletions gulp/tasks/browsersync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import browserSync from 'browser-sync'
import historyFallback from 'connect-history-api-fallback'

let browserSyncTask = (gulp, plugins, config) => {
browserSync.init({
server: {
baseDir: config.paths.dest,
middleware: [ historyFallback() ]
},
open: false,
notify: false,
xip: true,
port: config.browsersync.port,
ui: {
port: config.browsersync.uiport
}
})
}

export default browserSyncTask
15 changes: 15 additions & 0 deletions gulp/tasks/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import runSequence from 'run-sequence'

let buildTask = (gulp, plugins, config, done) => {
runSequence([
// 'copy:fonts',
'copy:images',
'copy:html',
'sass'
], [
'browserify:vendor',
'browserify:app'
], done)
}

export default buildTask
10 changes: 10 additions & 0 deletions gulp/tasks/cachebust.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import browserSync from 'browser-sync'

let cacheBustTask = (gulp, plugins, config) => {
return gulp.src(config.html.cachebust)
.pipe(plugins.cacheBust())
.pipe(gulp.dest(config.html.dest))
.pipe(browserSync.stream())
}

export default cacheBustTask
7 changes: 7 additions & 0 deletions gulp/tasks/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import del from 'del'

let cleanTask = (gulp, plugins, config) => {
return del.sync(`${config.paths.dest}/**/*`)
}

export default cleanTask
8 changes: 8 additions & 0 deletions gulp/tasks/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import runSequence from 'run-sequence'

let defaultTask = (gulp, plugins, config, done) => {
plugins.util.log(`${plugins.util.colors.yellow('Starting', config.environment, 'build!')}`)
runSequence(`${config.environment}`, done)
}

export default defaultTask
7 changes: 7 additions & 0 deletions gulp/tasks/development.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import runSequence from 'run-sequence'

let developmentTask = (gulp, plugins, config, done) => {
runSequence('watch')
}

export default developmentTask
8 changes: 8 additions & 0 deletions gulp/tasks/eslint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let eslintTask = (gulp, plugins, config) => {
return gulp.src(config.scripts.glob)
.pipe(plugins.eslint())
.pipe(plugins.eslint.format())
.pipe(plugins.eslint.failAfterError())
}

export default eslintTask
10 changes: 10 additions & 0 deletions gulp/tasks/fonts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import browserSync from 'browser-sync'

let fontsTask = (gulp, plugins, config) => {
return gulp.src(config.fonts.src)
.pipe(plugins.changed(config.fonts.dest))
.pipe(gulp.dest(config.fonts.dest))
.pipe(browserSync.stream())
}

export default fontsTask
7 changes: 7 additions & 0 deletions gulp/tasks/gzip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let gzipTask = (gulp, plugins, config) => {
return gulp.src(config.gzip.src)
.pipe(plugins.gzip(config.gzip.options))
.pipe(gulp.dest(config.gzip.dest))
}

export default gzipTask
10 changes: 10 additions & 0 deletions gulp/tasks/html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import browserSync from 'browser-sync'

let htmlTask = (gulp, plugins, config) => {
return gulp.src(config.html.src)
.pipe(plugins.changed(config.html.dest))
.pipe(gulp.dest(config.html.dest))
.pipe(browserSync.stream())
}

export default htmlTask
11 changes: 11 additions & 0 deletions gulp/tasks/images.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import browserSync from 'browser-sync'

let imagesTask = (gulp, plugins, config) => {
return gulp.src(config.images.src)
.pipe(plugins.changed(config.images.dest))
.pipe(plugins.if(!config.development, plugins.imagemin()))
.pipe(gulp.dest(config.images.dest))
.pipe(browserSync.stream())
}

export default imagesTask
7 changes: 7 additions & 0 deletions gulp/tasks/production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import runSequence from 'run-sequence'

let productionTask = (gulp, plugins, config, done) => {
runSequence('gzip', 'cachebust', done)
}

export default productionTask
23 changes: 23 additions & 0 deletions gulp/tasks/sass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import browserSync from 'browser-sync'

import errorHandler from '../utils/errorHandler'

let sassTask = (gulp, plugins, config) => {
return gulp.src(config.sass.glob)
.pipe(plugins.if(config.development, plugins.sourcemaps.init()))
.pipe(plugins.sassGlob())
.pipe(plugins.sass({
sourceComments: config.development,
outputStyle: config.development ? 'nested' : 'compressed',
includePaths: config.sass.includePaths
}))
.on('error', errorHandler)
.pipe(plugins.autoprefixer({
browsers: [ 'last 2 versions', '> 1%', 'ie 8' ]
}))
.pipe(plugins.if(config.development, plugins.sourcemaps.write('./')))
.pipe(gulp.dest(config.sass.dest))
.pipe(browserSync.stream())
}

export default sassTask
9 changes: 9 additions & 0 deletions gulp/tasks/watch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let watchTask = (gulp, plugins, config) => {
// gulp.watch(config.fonts.src, [ 'copy:fonts' ])
gulp.watch(config.html.src, [ 'copy:html' ])
gulp.watch(config.images.src, [ 'copy:images' ])
gulp.watch(config.sass.glob, [ 'sass' ])
// gulp.watch(config.scripts.glob, [ 'eslint' ])
}

export default watchTask
Loading

0 comments on commit 364f677

Please sign in to comment.