From 75db78a9a1be9370ea9763103d4415476722d69f Mon Sep 17 00:00:00 2001 From: Austin Pray Date: Sun, 23 Nov 2014 00:16:07 -0600 Subject: [PATCH] Remove disparity between dev and prod gulp tasks removes `gulp dev` in favor of `gulp` adds `gulp --rev` to produce revved asset manifest adds `gulp --tasks` to the readme removes postinstall script removes bower dep --- README.md | 4 ++-- gulpfile.js | 45 ++++++++++++++------------------------------- lib/assets.php | 16 ++++++---------- package.json | 9 +++------ 4 files changed, 25 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 93eafff..1ed30df 100644 --- a/README.md +++ b/README.md @@ -74,10 +74,10 @@ When completed, you'll be able to run the various Gulp commands provided from th ### Available Gulp commands -* `gulp dev` — Compile LESS to CSS, concatenate and validate JS +* `gulp` — Compile LESS to CSS, concatenate and validate JS * `gulp watch` — Compile assets when file changes are made -* `gulp build` — Create minified assets that are used on non-development environments * `gulp images` — Lossless compression of PNG, JPEG, GIF and SVG images +* `gulp --tasks` - Lists all the available tasks and what they do ## Documentation diff --git a/gulpfile.js b/gulpfile.js index 5891138..90598b1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,7 +1,6 @@ /*global $:true*/ var gulp = require('gulp'); - -var $ = require('gulp-load-plugins')(); +var $ = require('gulp-load-plugins')(); var build = { src: 'assets/', @@ -21,7 +20,7 @@ var paths = { editorStyle: build.src + 'styles/editor-style.less' }; -gulp.task('styles:dev', function() { +gulp.task('styles', function() { return gulp.src(paths.styles) .pipe($.plumber()) .pipe($.sourcemaps.init()) @@ -29,21 +28,9 @@ gulp.task('styles:dev', function() { console.warn(err.message); }) .pipe($.autoprefixer('last 2 versions', 'ie 8', 'ie 9', 'android 2.3', 'android 4', 'opera 12')) + .pipe($.minifyCss()) .pipe($.sourcemaps.write()) .pipe($.rename('main.css')) - .pipe(gulp.dest(build.dist + 'styles')) - .pipe($.livereload({ auto: false })); -}); - -gulp.task('styles:build', function() { - return gulp.src(paths.styles) - .pipe($.plumber()) - .pipe($.less()).on('error', function(err) { - console.warn(err.message); - }) - .pipe($.autoprefixer('last 2 versions', 'ie 9', 'android 2.3', 'android 4', 'opera 12')) - .pipe($.rename('main.css')) - .pipe($.minifyCss()) .pipe(gulp.dest(build.dist + 'styles')); }); @@ -65,15 +52,7 @@ gulp.task('jshint', function() { .pipe($.jshint.reporter('fail')); }); -gulp.task('scripts:dev', ['jshint'], function() { - return gulp.src(require('main-bower-files')().concat(paths.scripts)) - .pipe($.filter('**/*.js')) - .pipe($.concat('scripts.js')) - .pipe(gulp.dest(build.dist + 'scripts')) - .pipe($.livereload({ auto: false })); -}); - -gulp.task('scripts:build', ['jshint'], function() { +gulp.task('scripts', ['jshint'], function() { return gulp.src(require('main-bower-files')().concat(paths.scripts)) .pipe($.filter('**/*.js')) .pipe($.concat('scripts.js')) @@ -110,7 +89,7 @@ gulp.task('images', function() { }); gulp.task('version', function() { - return gulp.src([build.dist + 'styles/main.css', build.dist + 'js/scripts.js'], { base: build.dist }) + return gulp.src([build.dist + 'styles/main.css', build.dist + 'scripts/scripts.js'], { base: build.dist }) .pipe(gulp.dest(build.dist)) .pipe($.rev()) .pipe(gulp.dest(build.dist)) @@ -125,13 +104,17 @@ gulp.task('clean', function() { gulp.task('watch', function() { $.livereload.listen(); - gulp.watch([build.src + 'styles/**/*', 'bower.json'], ['styles:dev']); - gulp.watch([build.src + 'scripts/**/*', 'bower.json'], ['jshint', 'scripts:dev']); + gulp.watch([build.src + 'styles/**/*', 'bower.json'], ['styles']); + gulp.watch([build.src + 'scripts/**/*', 'bower.json'], ['jshint', 'scripts']); gulp.watch('**/*.php').on('change', function(file) { $.livereload.changed(file.path); }); }); -gulp.task('default', ['styles:dev', 'styles:editorStyle', 'jshint', 'scripts:dev', 'copy:fonts', 'images']); -gulp.task('dev', ['default']); -gulp.task('build', ['styles:build', 'styles:editorStyle', 'scripts:build', 'copy:fonts', 'copy:jquery', 'copy:modernizr', 'images', 'version']); +gulp.task('build', ['styles', 'styles:editorStyle', 'scripts', 'copy:fonts', 'copy:jquery', 'copy:modernizr', 'images'], function () { + gulp.start('version'); +}); + +gulp.task('default', ['clean'], function () { + gulp.start('build'); +}); diff --git a/lib/assets.php b/lib/assets.php index 67b7952..c668ed2 100644 --- a/lib/assets.php +++ b/lib/assets.php @@ -14,9 +14,9 @@ * - An ID has been defined in config.php * - You're not logged in as an administrator */ -function roots_asset_path($filename_dev, $filename) { +function roots_asset_path($filename) { if (WP_ENV === 'development') { - return get_template_directory_uri() . '/dist/' . $filename_dev; + return get_template_directory_uri() . '/dist/' . $filename; } $manifest_path = get_template_directory() . '/dist/rev-manifest.json'; @@ -33,7 +33,7 @@ function roots_asset_path($filename_dev, $filename) { } function roots_assets() { - wp_enqueue_style('roots_css', roots_asset_path('styles/main.css', 'styles/main.css'), false, null); + wp_enqueue_style('roots_css', roots_asset_path('styles/main.css'), false, null); /** * jQuery is loaded using the same method from HTML5 Boilerplate: @@ -43,11 +43,7 @@ function roots_assets() { if (!is_admin() && current_theme_supports('jquery-cdn')) { wp_deregister_script('jquery'); - if (WP_ENV === 'development') { - wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js', array(), null, true); - } else { - wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js', array(), null, true); - } + wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js', array(), null, true); add_filter('script_loader_src', 'roots_jquery_local_fallback', 10, 2); } @@ -56,9 +52,9 @@ function roots_assets() { wp_enqueue_script('comment-reply'); } - wp_enqueue_script('modernizr', roots_asset_path('scripts/modernizr.js', 'scripts/modernizr.js'), array(), null, true); + wp_enqueue_script(roots_asset_path('scripts/modernizr.js'), array(), null, true); wp_enqueue_script('jquery'); - wp_enqueue_script('roots_js', roots_asset_path('scripts/scripts.js', 'scripts/scripts.js'), array(), null, true); + wp_enqueue_script('roots_js', roots_asset_path('scripts/scripts.js'), array(), null, true); } add_action('wp_enqueue_scripts', 'roots_assets', 100); diff --git a/package.json b/package.json index d4f9e78..60ef200 100644 --- a/package.json +++ b/package.json @@ -16,15 +16,12 @@ "url": "http://opensource.org/licenses/MIT" } ], - "scripts": { - "postinstall": "node node_modules/bower/bin/bower install && gulp dev" - }, + "scripts": {}, "engines": { "node": ">= 0.10.0" }, "devDependencies": { - "bower": ">=1.3.9", - "gulp": "^3.8.7", + "gulp": "^3.8.10", "gulp-autoprefixer": "^0.0.7", "gulp-clean": "^0.3.1", "gulp-concat": "^2.3.4", @@ -42,8 +39,8 @@ "gulp-sourcemaps": "^1.1.1", "gulp-uglify": "^0.3.1", "imagemin-pngcrush": "^1.0.0", - "jshint-stylish": "^0.4.0", "jquery": "1.11.1", + "jshint-stylish": "^0.4.0", "lodash": "^2.4.1", "main-bower-files": "^1.0.1" }