Slide 1

Slide 1 text

MODERN WEB APPLICATION DEVELOPMENT WORKFLOW

Slide 2

Slide 2 text

FIRST, LET’S LOOK AT THE PAST

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

THROW A BUNCH OF HTML FILES

Slide 5

Slide 5 text

THROW A BUNCH OF HTML FILES ADD A COUPLE OF CSS FILES

Slide 6

Slide 6 text

THROW A BUNCH OF HTML FILES ADD A COUPLE OF CSS FILES PUT SOME JAVASCRIPT IN ALL THIS

Slide 7

Slide 7 text

THROW A BUNCH OF HTML FILES ADD A COUPLE OF CSS FILES PUT SOME JAVASCRIPT IN ALL THIS AND CALL IT A DAY...

Slide 8

Slide 8 text

COME BACK 6 MONTHS LATER AND TRY TO REMEMBER HOW TO MAINTAIN YOUR CODE

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Node.js ≠ Server-side JavaScript

Slide 13

Slide 13 text

Node.js stand alone JavaScript runtime

Slide 14

Slide 14 text

Node.js stand alone JavaScript runtime using v8, Chrome’s JavaScript engine

Slide 15

Slide 15 text

Node.js stand alone JavaScript applications

Slide 16

Slide 16 text

Node.js stand alone JavaScript applications created by JavaScript developers

Slide 17

Slide 17 text

Node.js stand alone JavaScript applications created by JavaScript developers for JavaScript developers

Slide 18

Slide 18 text

BRAND NEW WORLD

Slide 19

Slide 19 text

JAVASCRIPT DEVELOPMENT TOOLS

Slide 20

Slide 20 text

JAVASCRIPT DEVELOPMENT WORKFLOW

Slide 21

Slide 21 text

A GOOD DEVELOPMENT WORKFLOW -HELPS YOU GET STARTED

Slide 22

Slide 22 text

A GOOD DEVELOPMENT WORKFLOW -HELPS YOU GET STARTED -MAINTAINS YOUR DEPENDENCIES

Slide 23

Slide 23 text

A GOOD DEVELOPMENT WORKFLOW -HELPS YOU GET STARTED -MAINTAINS YOUR DEPENDENCIES -ENFORCES BEST PRACTICES

Slide 24

Slide 24 text

A GOOD DEVELOPMENT WORKFLOW -HELPS YOU GET STARTED -MAINTAINS YOUR DEPENDENCIES -ENFORCES BEST PRACTICES -PREPARES YOUR TOOLS

Slide 25

Slide 25 text

A GOOD DEVELOPMENT WORKFLOW -HELPS YOU GET STARTED -MAINTAINS YOUR DEPENDENCIES -ENFORCES BEST PRACTICES -PREPARES YOUR TOOLS -FIGHTS REGRESSIONS

Slide 26

Slide 26 text

A GOOD DEVELOPMENT WORKFLOW -HELPS YOU GET STARTED -MAINTAINS YOUR DEPENDENCIES -ENFORCES BEST PRACTICES -PREPARES YOUR TOOLS -FIGHTS REGRESSIONS -EASES THE RELEASE PROCESS

Slide 27

Slide 27 text

HOW TO GET STARTED?

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

YEOMAN Born in 2012 Various contributors (Employees from Google, Twitter, etc)

Slide 30

Slide 30 text

YEOMAN scaffolding - structure - compilation - static analysis - dependencies management - development tools - unit testing

Slide 31

Slide 31 text

YEOMAN download > npm install -g yo “-g” global install

Slide 32

Slide 32 text

YEOMAN Various generators: ○ Angular ○ Ember ○ Backbone And all the other popular frameworks...

Slide 33

Slide 33 text

YEOMAN angular.js generator > npm install -g generator-angular

Slide 34

Slide 34 text

YEOMAN create an Angular project > yo angular

Slide 35

Slide 35 text

Select some dependencies

Slide 36

Slide 36 text

Choose some options

Slide 37

Slide 37 text

It creates the project

Slide 38

Slide 38 text

It downloads half of the internet

Slide 39

Slide 39 text

It uses some dark magic

Slide 40

Slide 40 text

Enjoy the view, Yeoman takes care of everything…

Slide 41

Slide 41 text

What does the result look like?

Slide 42

Slide 42 text

STRUCTURE

Slide 43

Slide 43 text

CONTENT

Slide 44

Slide 44 text

DEPENDENCIES

Slide 45

Slide 45 text

DEV TOOLS

Slide 46

Slide 46 text

IT’S MAGIC! and it will be your job to maintain it...

Slide 47

Slide 47 text

HAPPY?

Slide 48

Slide 48 text

Thierry Lau “Build your own Yeoman generator” this afternoon at 2pm

Slide 49

Slide 49 text

BUT HOW DOES IT WORK?

Slide 50

Slide 50 text

YEOMAN HAS FRIENDS

Slide 51

Slide 51 text

BOWER

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

GRUNT

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

GULP

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

AND OTHERS

Slide 58

Slide 58 text

DEPENDENCIES MANAGEMENT

Slide 59

Slide 59 text

BOWER

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

BOWER Package manager for the web Born in 2012 Created by Twitter and other contributors over time

Slide 62

Slide 62 text

BOWER Download > npm install -g bower

Slide 63

Slide 63 text

Find a package: bower search

Slide 64

Slide 64 text

Find more information: bower info

Slide 65

Slide 65 text

BOWER Add a specific dependency > bower install jquery#1.10.2 --save install jquery and save this new dependency

Slide 66

Slide 66 text

BOWER runtime dependencies in bower.json

Slide 67

Slide 67 text

DEPENDENCIES

Slide 68

Slide 68 text

LOCATION

Slide 69

Slide 69 text

BOWER Add all your dependencies > bower install

Slide 70

Slide 70 text

See your dependencies: bower list

Slide 71

Slide 71 text

BOWER Package management always comes with its set of problems:

Slide 72

Slide 72 text

BOWER Package management always comes with its set of problems: - how can I create a new package?

Slide 73

Slide 73 text

BOWER Package management always comes with its set of problems: - how can I create a new package? - how can I host a bower repository?

Slide 74

Slide 74 text

BOWER Package management always comes with its set of problems: - how can I create a new package? - how can I host a bower repository? - what kind of exotic tools will I have to use?

Slide 75

Slide 75 text

Create a bower package: bower init

Slide 76

Slide 76 text

BOWER Host a bower repository

Slide 77

Slide 77 text

BOWER Host a bower repository > git init

Slide 78

Slide 78 text

BOWER Host a bower repository > git init > git add .

Slide 79

Slide 79 text

BOWER Host a bower repository > git init > git add . > git commit -m “Initial commit.”

Slide 80

Slide 80 text

BOWER Host a bower repository > git init > git add . > git commit -m “Initial commit.” > git remote add origin …

Slide 81

Slide 81 text

BOWER Host a bower repository > git init > git add . > git commit -m “Initial commit.” > git remote add origin … > git push origin master

Slide 82

Slide 82 text

BOWER Host a bower repository SVN support has been added with bower 1.3 for those who care….

Slide 83

Slide 83 text

BOWER Use bower with Git > bower install https://myrepository.git

Slide 84

Slide 84 text

BOWER Host multiple versions > git tag -a 1.4 -m 'version 1.4' > bower install https://myrepository.git#1.4

Slide 85

Slide 85 text

BOWER Host multiple versions Use semantic versioning to easily let your consumers handle API breakages

Slide 86

Slide 86 text

BOWER Download > bower install jquery > bower install git://github.com/jquery/jquery.git

Slide 87

Slide 87 text

BOWER Download > bower install jquery > bower install git://github.com/jquery/jquery.git How do this work?

Slide 88

Slide 88 text

BOWER Registry https://github.com/bower/registry A simple web server listing Git repository URLs

Slide 89

Slide 89 text

BOWER Register > bower register myrepository https://…git > bower install myrepository

Slide 90

Slide 90 text

BUILD

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

GRUNT GULP

Slide 93

Slide 93 text

CONFIGURATION GULP CODE GRUNT

Slide 94

Slide 94 text

EQUALLY POWERFUL

Slide 95

Slide 95 text

GRUNT is a bit older so its ECOSYSTEM is more mature

Slide 96

Slide 96 text

Grunt and Gulp development tools dependencies in package.json >npm install

Slide 97

Slide 97 text

DEV TOOLS

Slide 98

Slide 98 text

GRUNT

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

GRUNT configuration over code grunt.initConfig({ lint: { src: 'src/<%= pkg.name %>.js' }, concat: { src: [ '' , '.js>' ], dest: '<%= pkg.name %>.js' } });

Slide 101

Slide 101 text

GRUNT Configuration in Gruntfile.js

Slide 102

Slide 102 text

GRUNT Global install before Grunt 0.4 Updating Grunt cannot break existing projects anymore

Slide 103

Slide 103 text

GRUNT gruntfile.js structure 3 parts: -Task loading -Task configuration -Task registration

Slide 104

Slide 104 text

GRUNT An example: Static code analysis with JSHINT

Slide 105

Slide 105 text

GRUNT

Slide 106

Slide 106 text

HOW DO YOU USE IT? >grunt >grunt jshint:all

Slide 107

Slide 107 text

GULP

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

GULP code over configuration gulp.src('src/main.mycss' ) .pipe(stylus()) .pipe(rename({ ext: 'css' })) .pipe(autoprefixer()) .pipe(cssmin()) .pipe(header( '/* All Right Reserved */' )) .pipe(gulp.dest( 'dist'))

Slide 110

Slide 110 text

GULP Configuration in Gulpfile.js

Slide 111

Slide 111 text

GULP gulpfile.js structure 3 parts: - task loading - task configuration - task registration

Slide 112

Slide 112 text

GULP

Slide 113

Slide 113 text

SOUNDS FAMILIAR?

Slide 114

Slide 114 text

GULP differences with Grunt node.js streams (asynchronous by nature) nice and simple api less IO operations

Slide 115

Slide 115 text

GULP Task define a task gulp.task('name', ['deps'], function(done) { return stream || promise|| done(); });

Slide 116

Slide 116 text

GULP Watch react to changes on the file system gulp.watch('src/**/*.js', ['test', 'compile']);

Slide 117

Slide 117 text

GULP Src create a stream from the file system gulp.src(['src/**/*.js', 'test/**/*.js' ])

Slide 118

Slide 118 text

GULP Dest create a stream to the file system gulp.src('src') .pipe(...) .pipe(gulp.dest( 'dist'));

Slide 119

Slide 119 text

GULP Start Start a task gulp.task('default', ['clean'], function(){ gulp.start('lint', 'min', 'concat'); });

Slide 120

Slide 120 text

GULP Execution computed using the dependencies concurrent execution with Orchestrator adopted by Grunt 1.0 too

Slide 121

Slide 121 text

BUILD TASKS

Slide 122

Slide 122 text

STATIC ANALYSIS grunt-contrib-jshint gulp-jshint Detect coding errors in your JavaScript files

Slide 123

Slide 123 text

STATIC ANALYSIS Various style of reports (checkstyle, html, etc) Configuration in .jshtinrc

Slide 124

Slide 124 text

COFFEESCRIPT grunt-contrib-coffee gulp-coffee Compile CoffeeScript source code to JavaScript

Slide 125

Slide 125 text

RESPONSIVE IMAGES grunt-responsive-images gulp-responsive-images Produce images at different sizes for responsive websites

Slide 126

Slide 126 text

COMPRESS IMAGES grunt-contrib-imagemin gulp-imagemin Compress and optimize images

Slide 127

Slide 127 text

MINIFICATION grunt-contrib-uglify gulp-uglify Reduce the size of JavaScript files

Slide 128

Slide 128 text

CSS TRIMMING grunt-uncss gulp-uncss-task Remove unused CSS rules

Slide 129

Slide 129 text

LIVE RELOAD grunt-contrib-watch gulp-livereload Reload automatically the web application if some files have been changed

Slide 130

Slide 130 text

init concat jshint min unit server endtoend watch WORKFLOW

Slide 131

Slide 131 text

SASS

Slide 132

Slide 132 text

No content

Slide 133

Slide 133 text

SASS - variables $font-stack: Helvetica, sans-serif; $primary-color: #333; body { font: 100% $font-stack; color: $primary-color; }

Slide 134

Slide 134 text

SASS - nesting nav { ul { margin: 0; padding: 0; list-style: none; } li { display: inline-block; } a { display: block; padding: 6px 12px; text-decoration: none; } }

Slide 135

Slide 135 text

SASS - import - partials // base.scss @import ‘reset’; body { font: 100% Helvetica, sans- serif; color: #333; } // _reset.scss html, body { margin: 0; padding: 0; }

Slide 136

Slide 136 text

SASS - mixins @mixin border-radius($radius) { -webkit-border-radius: $radius; -moz-border-radius: $radius; -ms-border-radius: $radius; border-radius: $radius; } .box { @include border-radius(10px); }

Slide 137

Slide 137 text

SASS - inheritance .message { border: 1px solid #ccc; padding: 10px; color: #333; } .success { @extend .message; border-color: green; } .error { @extend .message; border-color: red; }

Slide 138

Slide 138 text

SASS - operators .container { width: 100%; } article[role="main"] { float: left; width: 600px / 960px * 100%; }

Slide 139

Slide 139 text

SASS grunt-contrib-sass gulp-sass Compile SASS to CSS

Slide 140

Slide 140 text

TESTING

Slide 141

Slide 141 text

UNIT TESTS Frameworks: Jasmine, Mocha, QUnit describe("A suite", function() { it("contains spec with an expectation", function() { expect(true).toBe(true); }); });

Slide 142

Slide 142 text

RUNNING TESTS Runner: Karma // Gruntfile.js karma: { unit: { configFile: 'karma.conf.js' } }

Slide 143

Slide 143 text

module.exports = function(config) { config.set({ frameworks: [ 'jasmine'], singleRun: true, browsers: [ 'Chrome','Firefox','Safari'], files: [ '**/*.js' ], plugins: [ 'karma-jasmine' , 'karma-chrome-launcher' , 'karma-firefox-launcher' , 'karma-safari-launcher' ], exclude: [], reporters: [ 'progress'], colors: true, logLevel: config.LOG_INFO, captureTimeout: 60000 }); };

Slide 144

Slide 144 text

FUNCTIONAL TESTS PhantomJS & SlimerJS - headless browsers CasperJS - navigation scripting & testing utility

Slide 145

Slide 145 text

PHANTOMJS Headless WebKit scriptable with JavaScript console.log('Loading a web page'); var page = require('webpage').create(); var url = 'http://www.phantomjs.org/'; page.open(url, function (status) { //Page is loaded! phantom.exit(); });

Slide 146

Slide 146 text

TESTING Modern.ie - for the poor souls who have to support Windows XP and IE6 IE8

Slide 147

Slide 147 text

TESTING Code Coverage: Istanbul

Slide 148

Slide 148 text

TESTING Hudson/Jenkins integration? karma-junit-reporter (JUnit reports) karma-coverage (Cobertura reports) jshint (Checkstyle reports)

Slide 149

Slide 149 text

No content

Slide 150

Slide 150 text

KARMA + GRUNT/GULP Test your application on various devices

Slide 151

Slide 151 text

No content

Slide 152

Slide 152 text

No content

Slide 153

Slide 153 text

CHROME DEVTOOLS

Slide 154

Slide 154 text

F12 or Ctrl+Shift+i

Slide 155

Slide 155 text

ELEMENTS

Slide 156

Slide 156 text

No content

Slide 157

Slide 157 text

No content

Slide 158

Slide 158 text

No content

Slide 159

Slide 159 text

NETWORK

Slide 160

Slide 160 text

No content

Slide 161

Slide 161 text

No content

Slide 162

Slide 162 text

HAR HTTP Archive

Slide 163

Slide 163 text

No content

Slide 164

Slide 164 text

SOURCES

Slide 165

Slide 165 text

WORKSPACE

Slide 166

Slide 166 text

No content

Slide 167

Slide 167 text

SNIPPETS

Slide 168

Slide 168 text

No content

Slide 169

Slide 169 text

Chrome Devtools Options

Slide 170

Slide 170 text

No content

Slide 171

Slide 171 text

TIMELINE

Slide 172

Slide 172 text

No content

Slide 173

Slide 173 text

No content

Slide 174

Slide 174 text

No content

Slide 175

Slide 175 text

CHROME CANARY

Slide 176

Slide 176 text

No content

Slide 177

Slide 177 text

No content

Slide 178

Slide 178 text

No content

Slide 179

Slide 179 text

Custom events console.timeStamp

Slide 180

Slide 180 text

PERFORMANCES

Slide 181

Slide 181 text

MEMORY LEAKS

Slide 182

Slide 182 text

No content

Slide 183

Slide 183 text

No content

Slide 184

Slide 184 text

No content

Slide 185

Slide 185 text

Compare memory snapshots

Slide 186

Slide 186 text

No content

Slide 187

Slide 187 text

Think about browsers extensions

Slide 188

Slide 188 text

CPU PROFILING

Slide 189

Slide 189 text

No content

Slide 190

Slide 190 text

AUDITS

Slide 191

Slide 191 text

No content

Slide 192

Slide 192 text

Customize the Chrome Devtools

Slide 193

Slide 193 text

New panels

Slide 194

Slide 194 text

No content

Slide 195

Slide 195 text

No content

Slide 196

Slide 196 text

MOBILE FIRST

Slide 197

Slide 197 text

EMULATION

Slide 198

Slide 198 text

No content

Slide 199

Slide 199 text

REAL DEVICE

Slide 200

Slide 200 text

No content

Slide 201

Slide 201 text

No content

Slide 202

Slide 202 text

No content

Slide 203

Slide 203 text

No content

Slide 204

Slide 204 text

TO SUM UP

Slide 205

Slide 205 text

YEOMAN + BOWER + GRUNT/GULP and Chrome... = AWESOME

Slide 206

Slide 206 text

THANKS! Stéphane Bégaudeau Twitter: @sbegaudeau Google+: +stephane.begaudeau The research leading to these results has received funding from the European Union’s Seventh Framework Program (FP7/2007-2013) for CRYSTAL – Critical System Engineering Acceleration Joint Undertaking under grant agreement № 332830 and from specific national programs and/or funding authorities.