Developers Meetup


Automate Everything

Amir Souchami



About me


30 Years of life

15 Years of Web Development

6 Years of hardcore FED

3 Years with Grunt.js

3 Grunt plugins contributions


Agenda


1. Automation?

2. Whats in it for you?

3. How? - Tools!

4. Grunt vs. Gulp

5. Grunt Examples

6. What is Automate Everything?

Automation


The technique of making a manual process, or a system 
operate automatically




We aspire to


1. Eliminates repetitive work

2. Reduces human error

2. Reduces human error

1. Eliminates repetitive work

 

Productivity

Focus

Plan

Architect

We need a good tool


 


Grunt vs Gulp


 

Grunt

Gulp

Mature
New & Shiny
Awesome Docs
Good Docs
Thousands of plugins
Hundreds of plugins
Fast
Faster!
Configurations Driven
Code Driven

Install Grunt.js


Create a package.json in your project dir

npm init

Install Grunt CLI Globaly

npm install -g grunt-cli

Install Grunt in project dir

npm install grunt --save-dev

Grunt Workflow


1. Extend grunt with a plugin 
(e.g. concat)

2. Define the task and its targets in your Gruntfile.js 
(concat all js file in a dir)

3. Run the task from the command line


Which Plugins?


Watch
Sass / Less / CoffeeScript / Jade
Live Reload
JSHint / Lint
Concat files
Optimize Images
Minify (JS, CSS, HTML)
Gzip
Upload to S3 / FTP 
Deploy to AWS
 Jasmine / Mocha / Selenium
Page Speed insights

And a lot more: http://gruntjs.com/plugins

Concat step 1



Start by installing:


npm install grunt-contrib-concat --save-dev

Concat step 2.1


Define Gruntfile.js in your project root dir

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
     
     // ---------------------------------------
     // your automation configuration goes here
     // ---------------------------------------
  });

  // ----------------------------
  // Load your grunt plugins here
  // ----------------------------
  

};


Concat step 2.2


Define the concat task target
module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    concat: {
      myProject: {
        src: 'src/*.js',
        dest: 'build/main.js'
      }
    }
  });

  // Load the plugin that provides the "concat" task.
  grunt.loadNpmTasks('grunt-contrib-concat');

  // Default task(s).
  grunt.registerTask('default', ['concat']);

};

Concat step 3


Run the task with one of the following commands:

grunt

grunt [task]

grunt [task]:[target]


Example:
grunt concat:myProject 

Minify with Uglify.js


npm install grunt-contrib-uglify --save-dev

  // Put the task config in your Gruntfile.js inside initConfig
  uglify: {
    myProject: {
      src: 'build/main.js',
      dest: 'build/main.min.js'
    }
  }
    
  // Dont forget to Load the plugin that provides the "Uglify" task
  grunt.loadNpmTasks('grunt-contrib-uglify');


Run the command line:  "grunt uglify:myProject"




Continuous development

AKA, Watch & React to changes automatically



Continuous development 


npm install grunt-contrib-watch --save-dev
module.exports = function(grunt) {
  grunt.initConfig({
    watch: {
       myProject: {
         files: ['src/*.js'],
         tasks: ['concat', 'uglify'] // or: concat:myProject, uglify:myProject       }
    },
    concat: {
      myProject: {
        src: 'src/*.js',
        dest: 'build/main.js'
      }
    }
    // uglify...
  });

  // Load all the plugin:
  grunt.loadNpmTasks('grunt-contrib-watch'); // also load uglify and concat 
};
Run the command line:  grunt watch:myProject

Gulp Example

Watch, Concatenate & Minify JS

Gulpfile.js
// Include gulp
var gulp = require('gulp'),
    watch = require('gulp-watch'); // require all libs that you need (uglify, concat, etc..)

// Watch Files For Changes
gulp.task('watch', function() {
    gulp.watch('src/*.js', ['scripts']);
});

// Concatenate & Minify JS
gulp.task('scripts', function() {
    return gulp.src('src/*.js')
        .pipe(concat('main.js'))
        .pipe(gulp.dest('build'))
        .pipe(rename('main.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('build'));
});

gulp.task('default', ['lint', 'sass', 'scripts', 'watch']); // Default Task
Run: gulp or gulp watch

Continuous development 


Demo Scenario 1

Watch SCSS
Compile to CSS
Live reload changes in browser



Continuous development 


Demo Scenario 2

Watch JS files
Concat into main.js
Run 200 unit tests with Karma

Continuous Delivery


Development

Integration

Deployment

Automate Everything


Conclusions


Choose a good automation tool 

Eliminate repetitive work 

Work Continuously 

Focus on creating great apps

Automate Everything you need



 

We're looking for talented developers like

YOU! 

Contact: amir@supersonicads.com

Automate Everything

By amirsouchami

Automate Everything

  • 1,391