Top Banner
AMBIENT INTELLIGENCE tech days 2015 # mstechdays techdays.microsoft.fr
35

Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

Jul 16, 2015

Download

Technology

jonathan donner
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

AMBIENT INTELLIGENCE

tech days•

2015

#mstechdays techdays.microsoft.fr

Page 2: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

Grunt / Bower / Yeoman ou comment automatiser le développement d'un projet web SPA

Maxime LUCECEO @ Touchify

[email protected]

@TouchifyApp

Page 3: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdaysComment automatiser le développement d'un projet web SPA

Page 4: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Gestion des dépendances

Compilation / Minification / Tests / Linting

Développement

Tâches récurrentes d’un projet web

Comment automatiser le développement d'un projet web SPA

Page 5: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Node.JS

Scripts simples mais puissant

Projet web donc javascript !

Outils d’automatisation

Comment automatiser le développement d'un projet web SPA

Page 6: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Bower ?

Grunt ?

Yeoman ?

Outils d’automatisation

Comment automatiser le développement d'un projet web SPA

Page 7: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdaysComment automatiser le développement d'un projet web SPA

Page 8: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Gestionnaire de librairies JS / CSS

Utilisé pour installer et mettre à jour les librairies

Assure l’intégrité des versions

Définition

Comment automatiser le développement d'un projet web SPA

Page 9: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Registre de librairies JS / CSS

Enregistre les versions dans un fichier bower.json

Arbre de dépendances plat

Comment ça marche ?

Comment automatiser le développement d'un projet web SPA

Page 10: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

Bower

# install bower

$ npm install –g bower

# install a package

$ bower install jquery --save

#install from github

$ bower install user/repo --save-dev

# install from url

$ bower install http://path.to/script.js

Page 11: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Bower

Comment automatiser le développement d'un projet web SPA

Page 12: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdaysComment automatiser le développement d'un projet web SPA

Page 13: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Gestionnaire de tâches Node.JS

Automatise les tâches récurrentes

Enormément de tâches dans NPM

Définition

Comment automatiser le développement d'un projet web SPA

Page 14: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Configuration dans un fichier Gruntfile.js

Tâches dans NPM ou en local

Simple !!

Comment ça marche ?

Comment automatiser le développement d'un projet web SPA

Page 15: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

Grunt CLI

# install grunt globally

$ npm install –g grunt-cli

# install grunt locally

$ npm install grunt --save-dev

# install a task

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

# run a task

$ grunt concat:dist

Page 16: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

Gruntfile.js

module.exports = function (grunt) {

grunt.initConfig({

// task config

concat: {

dist: {

src: "app/*.js",

dest: "dist/app.js"

}

}

});

// load task

grunt.loadNpmTasks("grunt-contrib-concat");

// alias task

grunt.registerTask("build", ["concat:dist"]);

};

Page 17: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Grunt

Comment automatiser le développement d'un projet web SPA

Page 18: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdaysComment automatiser le développement d'un projet web SPA

Page 19: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Gestionnaire de template de projets

Simplifie la création de projet et d’éléments

Force l’utilisation de bonnes pratiques

Définition

Comment automatiser le développement d'un projet web SPA

Page 20: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Générateurs dans NPM

Utilise Bower pour gérer les dépendances

Utilise Grunt pour gérer les tâches de compilation

Comment ça marche ?

Comment automatiser le développement d'un projet web SPA

Page 21: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

Yeoman

# install yeoman

$ npm install –g yo

# install generator

$ npm install –g generator-backbone

# run generator

$ yo backbone

# run sub generator

$ yo backbone:model user

Page 22: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Yeoman

Comment automatiser le développement d'un projet web SPA

Page 23: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdaysComment automatiser le développement d'un projet web SPA

Page 24: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

Create a simple Grunt Task

module.exports = function (grunt) {

grunt.registerTask("myCustomTask", function () {

// read package.json to get version

var pkg = grunt.file.readJSON("package.json");

// get the version.js content

var content = grunt.file.read("version.js");

// replace the tag {{version}} by the package’s version

content = content.replace("{{version}}", pkg.version);

// write the new content into version.js

grunt.file.write("version.js", content);

});

};

Page 25: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

Create a multi Grunt Task

module.exports = function (grunt) {

grunt.registerMultiTask("myVersionTask", function () {

var pkg = grunt.file.readJSON("package.json");

// loop over configured files

this.files.forEach(function (file) {

// loop over src / dest match

file.src.forEach(function (src) {

var content = grunt.file.read(src);

content = content.replace("{{version}}", pkg.version);

grunt.file.write("version.js", file.dest);

});

});

});

};

Page 26: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

Create a multi Grunt Task

module.exports = function (grunt) {

grunt.initConfig({

// task config

myVersionTask: {

dist: {

src: "app/**/*.js",

dest: "dist/"

}

}

});

// load task from local directory

grunt.loadTasks("tasks");

// alias task

grunt.registerTask("build", ["myVersionTask:dist"]);

};

Page 27: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Grunt avancé

Comment automatiser le développement d'un projet web SPA

Page 28: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdaysComment automatiser le développement d'un projet web SPA

Page 29: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

Create a Template

• app/• templates/

• …

• index.js

• model/• templates/

• …

• index.js

Page 30: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

Create a Template

var yeoman = require("yeoman-generator");

var CustomGenerator = yeoman.generators.Base.extend({

constructor: function () { },

prompting: function () { },

writing: {

git: function () { },

bower: function () { },

gruntfile: function () { },

index: function () { },

mainjs: function () { },

},

install: function () { },

});

module.exports = CustomGenerator;

Page 31: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

Create a Template

// prompting

var prompts = [{

type: "text",

name: "title",

message: "Title of the application"

}];

this.prompt(prompts, function (answers) {

this.title = answers.title;

});

// writing

this.fs.copy(this.templatePath("gitattributes"), this.destinationPath(".gitattributes"));

this.fs.copyTpl(this.templatePath("_gruntfile.js"), this.destinationPath("Gruntfile.js"), { arg1: "value1" });

// installing

this.installDependencies({ skipInstall: this.options["skip-install"] });

Page 32: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Yeoman avancé

Comment automatiser le développement d'un projet web SPA

Page 33: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA
Page 34: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

tech.days 2015#mstechdays

Slides : http://fr.slideshare.net/Touchify/grunt-bower-yeoman-ou-comment-automatiser-un-projet-web-spa

Démo :https://github.com/spatools/techdays2015

Documentations :http://bower.io http://gruntjs.com http://yeoman.io

Liens

Comment automatiser le développement d'un projet web SPA

Page 35: Grunt / Bower / Yeoman ou comment automatiser le développement d’un projet web SPA

© 2015 Microsoft Corporation. All rights reserved.

tech days•

2015

#mstechdays techdays.microsoft.fr