diff --git a/.babel.config.js b/.babel.config.js new file mode 100644 index 000000000..453ffa842 --- /dev/null +++ b/.babel.config.js @@ -0,0 +1,7 @@ +const presets = [ + ["@babel/env", { + }, +useBuiltIns: "usage"] +]; + +module.exports = { presets }; \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 94acadf6c..b822f7c8f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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/' }] } } diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 000000000..84744cf93 --- /dev/null +++ b/gulpfile.js @@ -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)) +}); \ No newline at end of file diff --git a/package.json b/package.json index fdd436673..28214ae90 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/css/normalize.css b/src/css/normalize.css similarity index 100% rename from css/normalize.css rename to src/css/normalize.css diff --git a/css/styles.css b/src/css/styles.css similarity index 100% rename from css/styles.css rename to src/css/styles.css diff --git a/data/restaurants.json b/src/data/restaurants.json similarity index 100% rename from data/restaurants.json rename to src/data/restaurants.json diff --git a/favicon-16x16.png b/src/favicon-16x16.png similarity index 100% rename from favicon-16x16.png rename to src/favicon-16x16.png diff --git a/favicon.ico b/src/favicon.ico similarity index 100% rename from favicon.ico rename to src/favicon.ico diff --git a/img/1.jpg b/src/img.1/1.jpg similarity index 100% rename from img/1.jpg rename to src/img.1/1.jpg diff --git a/img/10.jpg b/src/img.1/10.jpg similarity index 100% rename from img/10.jpg rename to src/img.1/10.jpg diff --git a/img/2.jpg b/src/img.1/2.jpg similarity index 100% rename from img/2.jpg rename to src/img.1/2.jpg diff --git a/img/3.jpg b/src/img.1/3.jpg similarity index 100% rename from img/3.jpg rename to src/img.1/3.jpg diff --git a/img/4.jpg b/src/img.1/4.jpg similarity index 100% rename from img/4.jpg rename to src/img.1/4.jpg diff --git a/img/5.jpg b/src/img.1/5.jpg similarity index 100% rename from img/5.jpg rename to src/img.1/5.jpg diff --git a/img/6.jpg b/src/img.1/6.jpg similarity index 100% rename from img/6.jpg rename to src/img.1/6.jpg diff --git a/img/7.jpg b/src/img.1/7.jpg similarity index 100% rename from img/7.jpg rename to src/img.1/7.jpg diff --git a/img/8.jpg b/src/img.1/8.jpg similarity index 100% rename from img/8.jpg rename to src/img.1/8.jpg diff --git a/img/9.jpg b/src/img.1/9.jpg similarity index 100% rename from img/9.jpg rename to src/img.1/9.jpg diff --git a/src/img/1-small.jpg b/src/img/1-small.jpg new file mode 100644 index 000000000..359e6d52f Binary files /dev/null and b/src/img/1-small.jpg differ diff --git a/src/img/1-thumb.jpg b/src/img/1-thumb.jpg new file mode 100644 index 000000000..fee43ce95 Binary files /dev/null and b/src/img/1-thumb.jpg differ diff --git a/src/img/1.jpg b/src/img/1.jpg new file mode 100755 index 000000000..3a9c23963 Binary files /dev/null and b/src/img/1.jpg differ diff --git a/src/img/10-small.jpg b/src/img/10-small.jpg new file mode 100644 index 000000000..2eeb45cc2 Binary files /dev/null and b/src/img/10-small.jpg differ diff --git a/src/img/10-thumb.jpg b/src/img/10-thumb.jpg new file mode 100644 index 000000000..985f0431d Binary files /dev/null and b/src/img/10-thumb.jpg differ diff --git a/src/img/10.jpg b/src/img/10.jpg new file mode 100755 index 000000000..d0289ef64 Binary files /dev/null and b/src/img/10.jpg differ diff --git a/src/img/2-small.jpg b/src/img/2-small.jpg new file mode 100644 index 000000000..6f9c7b252 Binary files /dev/null and b/src/img/2-small.jpg differ diff --git a/src/img/2-thumb.jpg b/src/img/2-thumb.jpg new file mode 100644 index 000000000..69c394710 Binary files /dev/null and b/src/img/2-thumb.jpg differ diff --git a/src/img/2.jpg b/src/img/2.jpg new file mode 100755 index 000000000..810b30260 Binary files /dev/null and b/src/img/2.jpg differ diff --git a/src/img/3-small.jpg b/src/img/3-small.jpg new file mode 100644 index 000000000..08c164465 Binary files /dev/null and b/src/img/3-small.jpg differ diff --git a/src/img/3-thumb.jpg b/src/img/3-thumb.jpg new file mode 100644 index 000000000..b4e0fcccc Binary files /dev/null and b/src/img/3-thumb.jpg differ diff --git a/src/img/3.jpg b/src/img/3.jpg new file mode 100755 index 000000000..581540fde Binary files /dev/null and b/src/img/3.jpg differ diff --git a/src/img/4-small.jpg b/src/img/4-small.jpg new file mode 100644 index 000000000..971772cf7 Binary files /dev/null and b/src/img/4-small.jpg differ diff --git a/src/img/4-thumb.jpg b/src/img/4-thumb.jpg new file mode 100644 index 000000000..c47ab8034 Binary files /dev/null and b/src/img/4-thumb.jpg differ diff --git a/src/img/4.jpg b/src/img/4.jpg new file mode 100755 index 000000000..e870025a7 Binary files /dev/null and b/src/img/4.jpg differ diff --git a/src/img/5-small.jpg b/src/img/5-small.jpg new file mode 100644 index 000000000..40085bb6e Binary files /dev/null and b/src/img/5-small.jpg differ diff --git a/src/img/5-thumb.jpg b/src/img/5-thumb.jpg new file mode 100644 index 000000000..3cc0defb8 Binary files /dev/null and b/src/img/5-thumb.jpg differ diff --git a/src/img/5.jpg b/src/img/5.jpg new file mode 100755 index 000000000..1409faf98 Binary files /dev/null and b/src/img/5.jpg differ diff --git a/src/img/6-small.jpg b/src/img/6-small.jpg new file mode 100644 index 000000000..faedf9603 Binary files /dev/null and b/src/img/6-small.jpg differ diff --git a/src/img/6-thumb.jpg b/src/img/6-thumb.jpg new file mode 100644 index 000000000..8b1953517 Binary files /dev/null and b/src/img/6-thumb.jpg differ diff --git a/src/img/6.jpg b/src/img/6.jpg new file mode 100755 index 000000000..6f6dbc995 Binary files /dev/null and b/src/img/6.jpg differ diff --git a/src/img/7-small.jpg b/src/img/7-small.jpg new file mode 100644 index 000000000..c8aea07f2 Binary files /dev/null and b/src/img/7-small.jpg differ diff --git a/src/img/7-thumb.jpg b/src/img/7-thumb.jpg new file mode 100644 index 000000000..d6d743e6a Binary files /dev/null and b/src/img/7-thumb.jpg differ diff --git a/src/img/7.jpg b/src/img/7.jpg new file mode 100755 index 000000000..c37a719dc Binary files /dev/null and b/src/img/7.jpg differ diff --git a/src/img/8-small.jpg b/src/img/8-small.jpg new file mode 100644 index 000000000..44972496d Binary files /dev/null and b/src/img/8-small.jpg differ diff --git a/src/img/8-thumb.jpg b/src/img/8-thumb.jpg new file mode 100644 index 000000000..16c5d4d0e Binary files /dev/null and b/src/img/8-thumb.jpg differ diff --git a/src/img/8.jpg b/src/img/8.jpg new file mode 100755 index 000000000..0fa0c1511 Binary files /dev/null and b/src/img/8.jpg differ diff --git a/src/img/9-small.jpg b/src/img/9-small.jpg new file mode 100644 index 000000000..eeca69223 Binary files /dev/null and b/src/img/9-small.jpg differ diff --git a/src/img/9-thumb.jpg b/src/img/9-thumb.jpg new file mode 100644 index 000000000..73a3ed843 Binary files /dev/null and b/src/img/9-thumb.jpg differ diff --git a/src/img/9.jpg b/src/img/9.jpg new file mode 100755 index 000000000..39ea1c029 Binary files /dev/null and b/src/img/9.jpg differ diff --git a/index.html b/src/index.html similarity index 93% rename from index.html rename to src/index.html index f352ad30a..737573b7b 100644 --- a/index.html +++ b/src/index.html @@ -2,8 +2,10 @@ + + Restaurant Reviews @@ -34,9 +36,10 @@

Filter Results

- + + diff --git a/js/dbhelper.js b/src/js/dbhelper.js similarity index 94% rename from js/dbhelper.js rename to src/js/dbhelper.js index 559426229..9802a94eb 100644 --- a/js/dbhelper.js +++ b/src/js/dbhelper.js @@ -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`; } /** @@ -150,7 +150,7 @@ class DBHelper { * Restaurant image URL. */ static imageUrlForRestaurant(restaurant) { - return (`/img/${restaurant.photograph}`); + return (`src/img/${restaurant.photograph}`); } /** diff --git a/src/js/idb-scripts.js b/src/js/idb-scripts.js new file mode 100644 index 000000000..e69de29bb diff --git a/js/main.js b/src/js/main.js similarity index 93% rename from js/main.js rename to src/js/main.js index 3e5ba0282..3479b813d 100644 --- a/js/main.js +++ b/src/js/main.js @@ -194,8 +194,8 @@ createRestaurantImages = (restaurant) => { */ const picture = document.createElement('picture'); picture.innerHTML = ` - - + + `; picture.append(image); return picture; diff --git a/js/restaurant_info.js b/src/js/restaurant_info.js similarity index 97% rename from js/restaurant_info.js rename to src/js/restaurant_info.js index a467f7164..139c04c67 100644 --- a/js/restaurant_info.js +++ b/src/js/restaurant_info.js @@ -56,8 +56,8 @@ createRestaurantImages = (restaurant) => { const picture = document.createElement('picture'); picture.innerHTML = ` - - + + `; picture.append(image); return picture; diff --git a/js/sw.js b/src/js/sw.js similarity index 96% rename from js/sw.js rename to src/js/sw.js index b11ed8490..dc7f5bc5b 100644 --- a/js/sw.js +++ b/src/js/sw.js @@ -1,3 +1,5 @@ +import idb from 'idb'; + var contentCache = [ '/', '../index.html', @@ -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'; diff --git a/restaurant.html b/src/restaurant.html similarity index 85% rename from restaurant.html rename to src/restaurant.html index 88ec74391..4dc5c75d1 100644 --- a/restaurant.html +++ b/src/restaurant.html @@ -2,10 +2,10 @@ - - - - + + + + Restaurant Info @@ -57,10 +57,10 @@

- - + +