Skip to content

Commit

Permalink
Merge pull request #8 from mejarc/7-gulp
Browse files Browse the repository at this point in the history
7 gulp
  • Loading branch information
mejarc authored Jul 3, 2018
2 parents 83ae27c + ef1ee5b commit f699299
Show file tree
Hide file tree
Showing 56 changed files with 169 additions and 20 deletions.
7 changes: 7 additions & 0 deletions .babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const presets = [
["@babel/env", {
},
useBuiltIns: "usage"]
];

module.exports = { presets };
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ module.exports = function (grunt) {
files: [{
expand: true,
src: ['*.{gif,jpg,png}'],
cwd: 'img/',
dest: 'img/'
cwd: 'src/img/',
dest: 'dist/img/'
}]
}
}
Expand Down
117 changes: 117 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
var gulp = require('gulp');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var useref = require('gulp-useref');
var del = require('del');
var babel = require('gulp-babel');
var uglify = require('gulp-uglify');

// var gutil = require('gulp-util');
var browserSync = require('browser-sync').create();
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var webpackConfig = require('./webpack.config.js');
var stream = require('webpack-stream');

var paths = {
styles: {
src: 'src/css/**/*.css',
dest: 'dist/css/'
},
scripts: {
src: 'src/js/**/*.js',
dest: 'dist/js/'
},
html: {
src: 'src/*.html',
dest: 'dist/'
},
images: {
src: 'src/img/**/*.jpg',
dest: 'dist/img/'
}
};

// add tasks from incumbent Gruntfile
require('gulp-grunt')(gulp, {
prefix: 'stage-1-'
});

gulp.task('default', [
'stage-1-default'
] );

// utility
function clean() {
return del(['dist']);
}

// concatentate CSS; copy to /dist/css; TODO: minify
function styles() {
return (gulp.src(paths.styles.src))
.pipe(concat('all.min.css'))
.pipe(gulp.dest(paths.styles.dest));
}

// transpile JS; concatentate; minify; copy to /dist/js
function scripts() {
return gulp.src(paths.scripts.src)
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(concat('all.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.scripts.dest));
}
// copy HTML to /dist; change script and CSS links
function html() {
return (gulp.src(paths.html.src))
.pipe(useref())
.pipe(gulp.dest(paths.html.dest));
}

// copy /img to /dist
function images() {
return (gulp.src(paths.images.src))
.pipe(gulp.dest(paths.images.dest));
}

exports.clean = clean;
exports.styles = styles;
exports.scripts = scripts;
exports.html = html;
exports.images = images;


gulp.task('useref', () => {
return gulp.src(paths.html.src)
.pipe(useref())
.pipe(uglify())
.pipe(gulp.dest(paths.html.dest))
});


gulp.task('browserSync', () => {
browserSync.init({
server: {
baseDir: 'src'
}
});
});

gulp.task('watch', ['browserSync'], () => {
gulp.watch('src/js/**/*.js', browserSync.reload);
gulp.watch('src/*.html', browserSync.reload);
gulp.watch('src/css/**/*.css', browserSync.reload);
});

gulp.task('webpack', [], () => {
return gulp.src(path.ALL)
.pipe(sourcemaps.init())
.pipe(stream(webpackConfig))
.pipe(uglify()) // minification
.pipe(sourcemaps.write())
.pipe(gulp.dest(path.DEST_BUILD))
});
26 changes: 23 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
{
"name": "mws-restaurant-stage-2",
"version": "0.1.0",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/mejarc/mws-restaurant-stage-2.git"
},
"devDependencies": {
"grunt": "~0.4.5",
"@babel/core": "^7.0.0-beta.51",
"@babel/preset-env": "^7.0.0-beta.51",
"babel-cli": "^7.0.0-beta.3",
"babel-preset-env": "^1.7.0",
"browser-sync": "^2.24.5",
"del": "^3.0.0",
"grunt": "^1.0.3",
"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-copy": "~0.8.0",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-uglify": "~0.5.0",
"grunt-mkdir": "~0.1.2",
"grunt-resize-crop": "0.0.1"
"grunt-resize-crop": "0.0.1",
"gulp": "^3.9.1",
"gulp-babel": "^8.0.0-beta.2",
"gulp-concat": "^2.6.1",
"gulp-grunt": "^0.5.5",
"gulp-sourcemaps": "^2.6.4",
"gulp-uglify": "^3.0.0",
"gulp-useref": "^3.1.5",
"gulp-util": "^3.0.8",
"webpack": "^4.13.0",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.4",
"webpack-stream": "^4.0.3"
},
"dependencies": {
"grunt-responsive-images": "^0.1.6"
"grunt-responsive-images": "^0.1.6",
"idb": "^2.1.3"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added src/img/1-small.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/1-thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/10-small.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/10-thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/2-small.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/2-thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/3-small.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/3-thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/4-small.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/4-thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/4.jpg
Binary file added src/img/5-small.jpg
Binary file added src/img/5-thumb.jpg
Binary file added src/img/5.jpg
Binary file added src/img/6-small.jpg
Binary file added src/img/6-thumb.jpg
Binary file added src/img/6.jpg
Binary file added src/img/7-small.jpg
Binary file added src/img/7-thumb.jpg
Binary file added src/img/7.jpg
Binary file added src/img/8-small.jpg
Binary file added src/img/8-thumb.jpg
Binary file added src/img/8.jpg
Binary file added src/img/9-small.jpg
Binary file added src/img/9-thumb.jpg
Binary file added src/img/9.jpg
5 changes: 4 additions & 1 deletion index.html → src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<html lang="en-US">

<head>
<!-- build:css css/all.min.css -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/styles.css">
<!-- endbuild -->
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
<title>Restaurant Reviews</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
Expand Down Expand Up @@ -34,9 +36,10 @@ <h3>Filter Results</h3>
<ul id="restaurants-list" aria-live="polite"></ul>
</section>
</main>

<!-- build:js js/all.min.js -->
<script src="js/dbhelper.js"></script>
<script src="js/main.js"></script>
<!-- endbuild -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAfh5xX0Unam8EcjtyvjS0a0_P3xv20SKs&libraries=places&callback=initMap"></script>


Expand Down
4 changes: 2 additions & 2 deletions js/dbhelper.js → src/js/dbhelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DBHelper {
*/
static get DATABASE_URL() {
const port = 8000 // Change this to your server port
return `http://localhost:${port}/data/restaurants.json`;
return `http://localhost:${port}/src/data/restaurants.json`;
}

/**
Expand Down Expand Up @@ -150,7 +150,7 @@ class DBHelper {
* Restaurant image URL.
*/
static imageUrlForRestaurant(restaurant) {
return (`/img/${restaurant.photograph}`);
return (`src/img/${restaurant.photograph}`);
}

/**
Expand Down
Empty file added src/js/idb-scripts.js
Empty file.
4 changes: 2 additions & 2 deletions js/main.js → src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ createRestaurantImages = (restaurant) => {
*/
const picture = document.createElement('picture');
picture.innerHTML = `
<source media="(min-width: 585px)" srcset="img/${restaurant.id}-thumb.jpg">
<source media="(max-width: 584px") srcset="img/${restaurant.id}-small.jpg">
<source media="(min-width: 585px)" srcset="src/img/${restaurant.id}-thumb.jpg">
<source media="(max-width: 584px") srcset="src/img/${restaurant.id}-small.jpg">
`;
picture.append(image);
return picture;
Expand Down
4 changes: 2 additions & 2 deletions js/restaurant_info.js → src/js/restaurant_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ createRestaurantImages = (restaurant) => {

const picture = document.createElement('picture');
picture.innerHTML = `
<source media="(max-width: 500px)" srcset="img/${restaurant.id}-thumb.jpg">
<source media="(min-width: 501px) and (max-width: 600px") srcset="img/${restaurant.id}-small.jpg">
<source media="(max-width: 500px)" srcset="src/img/${restaurant.id}-thumb.jpg">
<source media="(min-width: 501px) and (max-width: 600px") srcset="src/img/${restaurant.id}-small.jpg">
`;
picture.append(image);
return picture;
Expand Down
6 changes: 4 additions & 2 deletions js/sw.js → src/js/sw.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import idb from 'idb';

var contentCache = [
'/',
'../index.html',
Expand All @@ -7,8 +9,8 @@ var contentCache = [
'./dbhelper.js',
'../favicon.ico',
'../favicon-16x16.png',
'../css/styles.css',
'../css/normalize.css',
'./css/styles.css',
'./css/normalize.css',
'../data/restaurants.json'
];
var staticCacheName = 'stage-1-restaurants';
Expand Down
12 changes: 6 additions & 6 deletions restaurant.html → src/restaurant.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<html lang="en-US">

<head>
<!-- Normalize.css for better cross-browser consistency -->
<link rel="stylesheet" href="css/normalize.css">
<!-- Main CSS file -->
<link rel="stylesheet" href="css/styles.css">
<!-- build:css css/all.min.css -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/styles.css">
<!-- endbuild -->
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
<title>Restaurant Info</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
Expand Down Expand Up @@ -57,10 +57,10 @@ <h2 id="restaurant-name"></h2>
</footer>
<!-- End footer -->

<!-- Beginning scripts -->
<!-- Database helpers -->
<!-- build:js js/all.min.js -->
<script src="js/dbhelper.js"></script>
<script src="js/restaurant_info.js"></script>
<!-- endbuild -->
<!-- Google Maps -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAfh5xX0Unam8EcjtyvjS0a0_P3xv20SKs&libraries=places&callback=initMap"></script>
<!-- End scripts -->
Expand Down

0 comments on commit f699299

Please sign in to comment.