step up your game step up your game bring your projects
play

Step up your game Step up your game & bring your projects to - PowerPoint PPT Presentation

Step up your game Step up your game & bring your projects to the bring your projects to the Next Level Next Level bit.ly/goto-amstd Olivier Combe Olivier Combe @ocombe github.com/ocombe Front end dev @ 1. Setup your project 2. Write


  1. Step up your game Step up your game & bring your projects to the bring your projects to the Next Level Next Level bit.ly/goto-amstd

  2. Olivier Combe Olivier Combe @ocombe github.com/ocombe Front end dev @

  3. 1. Setup your project 2. Write code 3. Test (unit) Ideal Ideal 4. Build Continuous project project 5. Test (e2e) Integration work fl ow work fl ow 6. Commit 7. Tests Continuous 8. Deploy Delivery

  4. Setup your Setup your project project

  5. Opinions matter Opinions matter A few things to decide: A few things to decide: Application structure group by type Style guide group by feature/module JSCS (code style linter) Code conventions how to name things how to write code

  6. Sca ff olding Tools Sca ff olding Tools Use generators Let you decide what to include Quality depends on the generator used 2 main competitors: Yeoman Slush Alternative: use seeds/skeleton apps Yeoman generator: Gulp Angular

  7. Build tools Build tools One of the most important choice to make 4 main competitors: Grunt Gulp Brunch Broccoli

  8. Grunt Grunt The largest ecosystem (~4400 plugins) Task runner, not really a build tool Con fi guration over code

  9. module.exports = function(grunt) { // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { build: { src: 'src/<%= pkg.name %>.js', dest: 'build/<%= pkg.name %>.min.js' } } }); // Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-uglify'); // Default task(s). grunt.registerTask('default', ['uglify']); };

  10. Gulp Gulp The challenger Large ecosystem (~1530 plugins) Stream-based build system Code over con fi guration Easy to customize (it's just js!)

  11. var gulp = require('gulp'); var uglify = require('gulp-uglify'); gulp.task('compress', function() { return gulp.src('lib/*.js') .pipe(uglify()) .pipe(gulp.dest('dist')); });

  12. Brunch Brunch One of the fi rst ones In memory fi le-based build system Incremental rebuilds Simpli fi cation over customization Very opinionated

  13. exports.config = files: javascripts: joinTo: 'javascripts/app.js': /^app/

  14. Broccoli Broccoli New kid on the block (still in beta) Not a vegetable, more like a tree File-based build system with caching Customization over simpli fi cation Very fl exible (too much?)

  15. var uglifyJavaScript = require('broccoli-uglify-js' var pickFiles = require('broccoli-static-compiler' // create tree for files in the app folder var app = 'app' app = pickFiles(app, { srcDir: '/', destDir: 'appkit' // move under appkit namespace }) appJs = uglifyJavaScript(app, { // mangle: false, // compress: false }); // export the js tree module.exports = appJs;

  16. Assets managers Assets managers Bundle your libs as static assets Support AMD, CommonJS & ES6 modules Extendable with plugins 3 main competitors: Browserify Webpack JSPM + SystemJS

  17. Browserify Browserify Built to bring node into the browser Opinionated (there is a browser-way-ify) Easy to use If you follow the conventions CLI tool Con fi g goes into package.json Functionalities are split between plugins & transforms browserify -t es6ify main.js | exorcist bundle.js.map > bundle.js

  18. Webpack Webpack Built to help the user load all of his assets Pretty fl exible More like a build tool (con fi g fi le + CLI) Requires some work before you can start Add new functionalities with loaders & plugins

  19. module.exports = { context: __dirname + '/app', entry: './index.js', output: { path: __dirname + '/app', filename: 'bundle.js' }, module: { loaders: [{ test: /\.js$/, loader: 'babel', exclude: /node_modules/ }] } };

  20. JSPM + SystemJS JSPM + SystemJS Built to help the user load all of his assets Install assets from anywhere with JSPM Load them in the browser with SystemJS No build step (except for production) Add new functionalities with plugin loaders

  21. con fi g.js System.config({ // or 'traceur' or 'typescript' transpiler: 'babel' // or traceurOptions or typescriptOptions babelOptions: {} }); index.html <!doctype html> <script src="jspm_packages/system.js"></script> <script src="config.js"></script> <script> System.import('lib/main'); </script>

  22. bootstrap.js import _ from 'lodash-node/modern/lang/isEqual' import $ from 'jquery'; export function bootstrap() { // bootstrap code here } main.js import {bootstrap} from './bootstrap' bootstrap();

  23. Code Code

  24. (Pre|Post) processors (Pre|Post) processors Take your code and transform it Give you access to new features Handle annoying processes for you Alert you if necessary

  25. New language features New language features With a simple pre-processor: Co ff eeScript Babel (ES2015/JSX) Traceur (AtScript) TypeScript Why? Modularity (modules, imports) Clarity (classes, let/const) Economy (arrow functions, classes) And more (types, annotations, ...)

  26. Other tools Other tools Ng annotate : Handles angular dependency injection annotations for you var MyController = function($scope, greeter) { // ... } MyController.$inject = ['$scope', 'greeter'];

  27. CSS Processors CSS Processors Languages improvements SASS LESS Stylus Why? Clarity (indentation, variables) Economy (variables, mixins) Modularity (includes, extends) Optimizations And more (plugins, syntax check...)

  28. Other tools (2) Other tools (2) Auto pre fi xer : ​ Handles css browser pre fi xes for you Remove unused css rules: Uncss PurifyCSS

  29. Auto reload Auto reload Watch your fi les Reload the browser when needed Inject fi les when possible Many tools: Browser sync (node) Livereload (app) Fb fl o (browser extension)

  30. Debug Debug Sourcemaps Chrome extensions: Batarang Ng-inspector

  31. Test Test

  32. “ When you fail, fail fast, and not silently

  33. Linting tools Linting tools Static code analysis tools Detect errors & potential problems Choose which rules to apply or write new ones 3 main competitors: JSLint JSHint ESLint A comparison of JS linting tools

  34. “ Testing is not wasting time, it's compensating your fl aws and betting on the long term

  35. Unit tests Unit tests Test individual units of code Run fast Focus on small/stable testable parts (services, ...) Test driven development

  36. Unit tests (2) Unit tests (2) Test runners: Karma Mocha Test frameworks: QUnit Jasmine Mocha (+ Chai + Sinon) Jasmine vs. Mocha, Chai, and Sinon

  37. E2E Tests E2E Tests Test your app in a real browser Take time to run Focus on critical paths Test in multiple browsers ( BrowserStack / Sauce labs ) Test runner: Protractor (+ Jasmine)

  38. CSS Testing CSS Testing Test visual regressions 2 libs based on resemble.js: PhantomCSS (requires a full CasperJS setup) BacktopJS Testing with PhantomCSS / Testing with BacktopJS

  39. Deploy Deploy

  40. Changelog Changelog Make it easier to see notable changes between versions Because your memory isn't unbeatable and you might not be around forever Because reading git commits doesn't tell everything 2 libs: Conventional changelog Github changelog generator Keep a changelog

  41. Documentation Documentation Comment your code with ngDoc /** * * @ngdoc directive * @name awesomeElement * @module myModule * @restrict E * @description * This is a directive! * **/ Extract your doc with dgeni Or use readme.io

  42. Continuous integration Continuous integration Automate tasks on commit: tests build deploy Many solutions: TravisCI (free for open source) Jenkins (free & open source, host it yourself) CircleCI (free for 1 concurrent build) Codeship (free for 1 concurrent build)

  43. Thank you! Thank you!

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend