SlideShare a Scribd company logo
1 of 21
Download to read offline
1
LESLES GÉNÉRATEURS DE CODEGÉNÉRATEURS DE CODE,,
POUR SEPOUR SE SIMPLIFIER LA VIESIMPLIFIER LA VIE AU QUOTIDIENAU QUOTIDIEN
2
@NICOESPEON@NICOESPEON
http://nicoespeon.com
3
QUELQUESQUELQUES USE CASESUSE CASES
Un nouveau projet en mode proto
On veut juste quelque chose qui marche rapidement et
nous permet de coder
Un nouveau projet selon des standards persos
Pour ré-utiliser nos outils / conventions (ex: freelances)
Création d’un nouveau fichier au quotidien
Quelles sont les conventions ? Est-ce-que je dois l’instancier
quelque part ?…
4 . 1
QU’EST-CE-QU’UNQU’EST-CE-QU’UN GÉNÉRATEUR DE CODEGÉNÉRATEUR DE CODE??
4 . 2
LE PRINCIPELE PRINCIPE
1. On lance une commande
2. On répond à quelques questions
3. TADAAA ! Les fichiers sont générés !
Éviter d'aller copier/coller un autre fichier « similaire » (lequel ?),
puis supprimer les lignes inutiles et déclarer tout ça où il faut
(sans se tromper ?)
4 . 3
GAIN DE TEMPSGAIN DE TEMPS AU SCAFFOLD D’UN PROJETAU SCAFFOLD D’UN PROJET
4 . 4
GAIN DE TEMPSGAIN DE TEMPS && MOINS D'ERREURSMOINS D'ERREURS AU QUOTIDIENAU QUOTIDIEN
5 . 1
EXEMPLE DE GÉNÉRATEUR JS #1 :EXEMPLE DE GÉNÉRATEUR JS #1 :
YEOMANYEOMAN
5 . 2
«« THE WEB'STHE WEB'S SCAFFOLDING TOOLSCAFFOLDING TOOL FOR MODERN WEBAPPSFOR MODERN WEBAPPS »»
Très populaire
Facile à installer / utiliser
Language agnostic (Web, Java, Python, C#, etc.)
De nombreux generators pour scaffold un projet
standard :
On peut créer et publier son propre générateur
yeoman.io/generators/
5 . 3
EN PRATIQUEEN PRATIQUE
npm install -g yo
npm install -g generator-webapp
Installer Yeoman
Installer un générateur
yo webappScaffold un projet
yo angular:controller MyNewControllerBootstrap un fichier
Getting started: http://yeoman.io/learning/index.html
6 . 1
EXEMPLE DE GÉNÉRATEUR JS #2 :EXEMPLE DE GÉNÉRATEUR JS #2 :
PLOPPLOP
6 . 2
KEZAKOKEZAKO PLOPPLOP ??
« Micro-generator framework that makes it easy for an entire
team to create files with a level of uniformity »
Le projet n’est pas forcément standard
Créer un générateur, le publier et le maintenir dans un
dépôt distinct n’a pas forcément de valeur ajoutée
Au quotidien, ce serait quand même bien pratique
Getting started: https://github.com/amwmedia/plop
6 . 3
EN PRATIQUEEN PRATIQUE
Dans le projet :
plopfile.js
des templates
module.exports = function (plop) {};
npm install -g plop
Installer Plop
6 . 4
POURQUOIPOURQUOI PLOPPLOP PLUTÔT QUEPLUTÔT QUE YEOMANYEOMAN ??
Léger, embarqué dans le projet =
maintenance plus simple
Simple à prendre en main, plus
facilement adopté car peu coûteux
6 . 5
DES USE CASESDES USE CASES DIFFÉRENTSDIFFÉRENTS
scaffold un nouveau projet
selon des standards
bootstrap de nouveaux
fichiers dans le cadre de
ce projet (standard)
PlopYeoman
bootstrap de nouveaux fichiers
selon les standards
personnalisés d'un projet
7
MERCI !MERCI ! DES QUESTIONS ?DES QUESTIONS ?
Pour découvrir plop plus en détail : http://bit.ly/22hX160
8 . 1
LES TEMPLATESLES TEMPLATES
C'est du !Handlebars
/**
* TODO - Describe what your model does.
*
* @class {{pascalCase name}}.Model
* @module {{pascalCase name}}
* @constructor
*/
import {Model} from "backbone";
export default Model.extend( {
initialize() {
// Executed on model initialization
}
} );
On a accès :
aux variables du prompt
aux / définishelpers partials
plop.addHelper( name, helper );
plop.addPartial( name, template );
Dans plopfile.js :
8 . 2
CRÉER UN GÉNÉRATEURCRÉER UN GÉNÉRATEUR
module.exports = function ( plop ) {
plop.setGenerator( "module", {
description: "create a new module",
prompts: [],
actions: []
} );
};
plop.setGenerator( name, config );
Création Utilisation
8 . 3
GÉNÉRATEURGÉNÉRATEUR −− PROMPTSPROMPTS
module.exports = function ( plop ) {
plop.setGenerator( "module", {
description: "create a new module",
prompts: [
{
type: "input",
name: "name",
message: "What is your module name?",
validate: function (value) {
if ((/.+/).test(value)) { return true; }
return "name is required";
}
}
],
// …
} );
};
C'est du !Inquirer
8 . 4
GÉNÉRATEURGÉNÉRATEUR −− ACTIONSACTIONS
module.exports = function ( plop ) {
plop.setGenerator( "module", {
description: "create a new module",
// …
actions: [
{
type: "add",
path: "modules/{{camelCase name}}.js",
templateFile: "templates/module.js"
}
]
} );
};
3 types d'actions :
add
modify
custom (fonction)
Strings parsées avec Handlebars
8 . 5
GÉNÉRATEURGÉNÉRATEUR −− ACTIONSACTIONS
actions: function( data ) {
var actions = [];
if( data.wantTacos ) {
actions.push( {
type: "add",
path: "folder/{{dashCase name}}.txt",
templateFile: "templates/tacos.txt"
} );
} else {
actions.push( {
type: "add",
path: "folder/{{dashCase name}}.txt",
templateFile: "templates/burritos.txt"
} );
}
return actions;
}
actions peut aussi être une
fonction qui :
prend les réponses de
prompts en paramètre
retourne le tableau des
actions à effectuer
Permet d'adapter les actions en
fonction des réponses données

More Related Content

What's hot

Gulp fiction, Builder, tester, livrer, sans tomber dans les poms - breizhcam...
Gulp fiction, Builder, tester, livrer, sans tomber dans les poms  - breizhcam...Gulp fiction, Builder, tester, livrer, sans tomber dans les poms  - breizhcam...
Gulp fiction, Builder, tester, livrer, sans tomber dans les poms - breizhcam...mbrechet
 
20081113 - Nantes Jug - Apache Maven
20081113 - Nantes Jug - Apache Maven20081113 - Nantes Jug - Apache Maven
20081113 - Nantes Jug - Apache MavenArnaud Héritier
 
4 asynch task_services_thread
4 asynch task_services_thread4 asynch task_services_thread
4 asynch task_services_threadSaber LAJILI
 
Intégration continue et déploiement continue avec Jenkins
Intégration continue et déploiement continue avec JenkinsIntégration continue et déploiement continue avec Jenkins
Intégration continue et déploiement continue avec JenkinsKokou Gaglo
 
20081023 - Paris Vi Master STL TA - Initiation Maven
20081023 - Paris Vi Master STL TA - Initiation Maven20081023 - Paris Vi Master STL TA - Initiation Maven
20081023 - Paris Vi Master STL TA - Initiation MavenArnaud Héritier
 
SonarQube Manuel Automatisation d'analyse ANT JENKINS/Hudson
SonarQube Manuel Automatisation d'analyse ANT JENKINS/HudsonSonarQube Manuel Automatisation d'analyse ANT JENKINS/Hudson
SonarQube Manuel Automatisation d'analyse ANT JENKINS/Hudsonxmacina
 
Apéro techno node.js + AngularJS @Omnilog 2014
Apéro techno node.js + AngularJS @Omnilog 2014Apéro techno node.js + AngularJS @Omnilog 2014
Apéro techno node.js + AngularJS @Omnilog 2014Yves-Emmanuel Jutard
 
Des poneys à Liberation.fr
Des poneys à Liberation.frDes poneys à Liberation.fr
Des poneys à Liberation.frliberation_dev
 
Intégration continue & Qualité logicielle
Intégration continue & Qualité logicielleIntégration continue & Qualité logicielle
Intégration continue & Qualité logicielleDavid Buros
 
Test flight et les outils de distribution continue par simone civetta de xebia
Test flight et les outils de distribution continue par simone civetta de xebiaTest flight et les outils de distribution continue par simone civetta de xebia
Test flight et les outils de distribution continue par simone civetta de xebiaCocoaHeads France
 
Installation et configuration d'openbravo
Installation et configuration d'openbravoInstallation et configuration d'openbravo
Installation et configuration d'openbravoSoumia Brabije
 
CocoaHeads Lyon - Mode Déconnecté dans une app iOS
CocoaHeads Lyon - Mode Déconnecté dans une app iOSCocoaHeads Lyon - Mode Déconnecté dans une app iOS
CocoaHeads Lyon - Mode Déconnecté dans une app iOSClaire Reynaud
 
Introduction à SBT
Introduction à SBTIntroduction à SBT
Introduction à SBTJean Detoeuf
 
20080311 - Paris Vi Master STL TA - Initiation Maven
20080311 - Paris Vi Master STL TA - Initiation Maven20080311 - Paris Vi Master STL TA - Initiation Maven
20080311 - Paris Vi Master STL TA - Initiation MavenArnaud Héritier
 
Jasmine : tests unitaires en JavaScript - Human Talks Grenoble 14.05.2013
Jasmine : tests unitaires en JavaScript - Human Talks Grenoble 14.05.2013Jasmine : tests unitaires en JavaScript - Human Talks Grenoble 14.05.2013
Jasmine : tests unitaires en JavaScript - Human Talks Grenoble 14.05.2013Xavier NOPRE
 
Du Docker dans notre workflow de dev
Du Docker dans notre workflow de devDu Docker dans notre workflow de dev
Du Docker dans notre workflow de devKodo Kojo
 
DevOps, freedom to get stuff done
DevOps, freedom to get stuff doneDevOps, freedom to get stuff done
DevOps, freedom to get stuff doneAhmed Bessifi
 
Présentation de Carthage par Simone Civetta
Présentation de Carthage par Simone CivettaPrésentation de Carthage par Simone Civetta
Présentation de Carthage par Simone CivettaCocoaHeads France
 
Déploiement PHP : de l'âge de pierre à nos jours.
Déploiement PHP : de l'âge de pierre à nos jours.Déploiement PHP : de l'âge de pierre à nos jours.
Déploiement PHP : de l'âge de pierre à nos jours.Amélie DUVERNET
 

What's hot (20)

Gulp fiction, Builder, tester, livrer, sans tomber dans les poms - breizhcam...
Gulp fiction, Builder, tester, livrer, sans tomber dans les poms  - breizhcam...Gulp fiction, Builder, tester, livrer, sans tomber dans les poms  - breizhcam...
Gulp fiction, Builder, tester, livrer, sans tomber dans les poms - breizhcam...
 
Multi-Threading Et Cocoa
Multi-Threading Et CocoaMulti-Threading Et Cocoa
Multi-Threading Et Cocoa
 
20081113 - Nantes Jug - Apache Maven
20081113 - Nantes Jug - Apache Maven20081113 - Nantes Jug - Apache Maven
20081113 - Nantes Jug - Apache Maven
 
4 asynch task_services_thread
4 asynch task_services_thread4 asynch task_services_thread
4 asynch task_services_thread
 
Intégration continue et déploiement continue avec Jenkins
Intégration continue et déploiement continue avec JenkinsIntégration continue et déploiement continue avec Jenkins
Intégration continue et déploiement continue avec Jenkins
 
20081023 - Paris Vi Master STL TA - Initiation Maven
20081023 - Paris Vi Master STL TA - Initiation Maven20081023 - Paris Vi Master STL TA - Initiation Maven
20081023 - Paris Vi Master STL TA - Initiation Maven
 
SonarQube Manuel Automatisation d'analyse ANT JENKINS/Hudson
SonarQube Manuel Automatisation d'analyse ANT JENKINS/HudsonSonarQube Manuel Automatisation d'analyse ANT JENKINS/Hudson
SonarQube Manuel Automatisation d'analyse ANT JENKINS/Hudson
 
Apéro techno node.js + AngularJS @Omnilog 2014
Apéro techno node.js + AngularJS @Omnilog 2014Apéro techno node.js + AngularJS @Omnilog 2014
Apéro techno node.js + AngularJS @Omnilog 2014
 
Des poneys à Liberation.fr
Des poneys à Liberation.frDes poneys à Liberation.fr
Des poneys à Liberation.fr
 
Intégration continue & Qualité logicielle
Intégration continue & Qualité logicielleIntégration continue & Qualité logicielle
Intégration continue & Qualité logicielle
 
Test flight et les outils de distribution continue par simone civetta de xebia
Test flight et les outils de distribution continue par simone civetta de xebiaTest flight et les outils de distribution continue par simone civetta de xebia
Test flight et les outils de distribution continue par simone civetta de xebia
 
Installation et configuration d'openbravo
Installation et configuration d'openbravoInstallation et configuration d'openbravo
Installation et configuration d'openbravo
 
CocoaHeads Lyon - Mode Déconnecté dans une app iOS
CocoaHeads Lyon - Mode Déconnecté dans une app iOSCocoaHeads Lyon - Mode Déconnecté dans une app iOS
CocoaHeads Lyon - Mode Déconnecté dans une app iOS
 
Introduction à SBT
Introduction à SBTIntroduction à SBT
Introduction à SBT
 
20080311 - Paris Vi Master STL TA - Initiation Maven
20080311 - Paris Vi Master STL TA - Initiation Maven20080311 - Paris Vi Master STL TA - Initiation Maven
20080311 - Paris Vi Master STL TA - Initiation Maven
 
Jasmine : tests unitaires en JavaScript - Human Talks Grenoble 14.05.2013
Jasmine : tests unitaires en JavaScript - Human Talks Grenoble 14.05.2013Jasmine : tests unitaires en JavaScript - Human Talks Grenoble 14.05.2013
Jasmine : tests unitaires en JavaScript - Human Talks Grenoble 14.05.2013
 
Du Docker dans notre workflow de dev
Du Docker dans notre workflow de devDu Docker dans notre workflow de dev
Du Docker dans notre workflow de dev
 
DevOps, freedom to get stuff done
DevOps, freedom to get stuff doneDevOps, freedom to get stuff done
DevOps, freedom to get stuff done
 
Présentation de Carthage par Simone Civetta
Présentation de Carthage par Simone CivettaPrésentation de Carthage par Simone Civetta
Présentation de Carthage par Simone Civetta
 
Déploiement PHP : de l'âge de pierre à nos jours.
Déploiement PHP : de l'âge de pierre à nos jours.Déploiement PHP : de l'âge de pierre à nos jours.
Déploiement PHP : de l'âge de pierre à nos jours.
 

Similar to Les générateurs de code, pour se simplifier la vie au quotidien

Spring Boot & Containers - Do's & Don'ts
Spring Boot & Containers - Do's & Don'tsSpring Boot & Containers - Do's & Don'ts
Spring Boot & Containers - Do's & Don'tsJulien Wittouck
 
Cours yeoman backbone box2d
Cours yeoman backbone box2dCours yeoman backbone box2d
Cours yeoman backbone box2dhugomallet
 
20090615 - Ch'ti JUG - Apache Maven
20090615 - Ch'ti JUG - Apache Maven20090615 - Ch'ti JUG - Apache Maven
20090615 - Ch'ti JUG - Apache MavenArnaud Héritier
 
Symfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiquesSymfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiquesNoel GUILBERT
 
Uni.sherbrooke 2015 créez la meilleur application grâce à gwt, gwtp et j...
Uni.sherbrooke 2015   créez la meilleur application grâce à gwt, gwtp et j...Uni.sherbrooke 2015   créez la meilleur application grâce à gwt, gwtp et j...
Uni.sherbrooke 2015 créez la meilleur application grâce à gwt, gwtp et j...Arcbees
 
Être productif avec JHipster - Devoxx France 2017
Être productif avec JHipster - Devoxx France 2017Être productif avec JHipster - Devoxx France 2017
Être productif avec JHipster - Devoxx France 2017Julien Dubois
 
Node.js, le pavé dans la mare
Node.js, le pavé dans la mareNode.js, le pavé dans la mare
Node.js, le pavé dans la mareValtech
 
Build automatique et distribution OTA avec Xcode 4.x et Jenkins
Build automatique et distribution OTA avec Xcode 4.x et JenkinsBuild automatique et distribution OTA avec Xcode 4.x et Jenkins
Build automatique et distribution OTA avec Xcode 4.x et JenkinsCocoaHeads France
 
StyleCop avec visual studio 2010
StyleCop avec visual studio 2010StyleCop avec visual studio 2010
StyleCop avec visual studio 2010Novencia Groupe
 
Aspect avec AspectJ
Aspect avec AspectJAspect avec AspectJ
Aspect avec AspectJsimeon
 
WordCamp Lyon 2015 - WordPress, Git et l'intégration continue
 WordCamp Lyon 2015 - WordPress, Git et l'intégration continue WordCamp Lyon 2015 - WordPress, Git et l'intégration continue
WordCamp Lyon 2015 - WordPress, Git et l'intégration continueStéphane HULARD
 
Spring Meetup Paris - Back to the basics of Spring (Boot)
Spring Meetup Paris - Back to the basics of Spring (Boot)Spring Meetup Paris - Back to the basics of Spring (Boot)
Spring Meetup Paris - Back to the basics of Spring (Boot)Eric SIBER
 
Chaine de production pipeline
Chaine de production   pipelineChaine de production   pipeline
Chaine de production pipelineNicolas wallerand
 
Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016
Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016
Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016Fabien Arcellier
 
Java scripting api
Java scripting apiJava scripting api
Java scripting apiFranck SIMON
 

Similar to Les générateurs de code, pour se simplifier la vie au quotidien (20)

Spring Boot & Containers - Do's & Don'ts
Spring Boot & Containers - Do's & Don'tsSpring Boot & Containers - Do's & Don'ts
Spring Boot & Containers - Do's & Don'ts
 
Cours yeoman backbone box2d
Cours yeoman backbone box2dCours yeoman backbone box2d
Cours yeoman backbone box2d
 
20090615 - Ch'ti JUG - Apache Maven
20090615 - Ch'ti JUG - Apache Maven20090615 - Ch'ti JUG - Apache Maven
20090615 - Ch'ti JUG - Apache Maven
 
Symfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiquesSymfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiques
 
Uni.sherbrooke 2015 créez la meilleur application grâce à gwt, gwtp et j...
Uni.sherbrooke 2015   créez la meilleur application grâce à gwt, gwtp et j...Uni.sherbrooke 2015   créez la meilleur application grâce à gwt, gwtp et j...
Uni.sherbrooke 2015 créez la meilleur application grâce à gwt, gwtp et j...
 
Kick starting OpenERP
Kick starting OpenERPKick starting OpenERP
Kick starting OpenERP
 
Être productif avec JHipster - Devoxx France 2017
Être productif avec JHipster - Devoxx France 2017Être productif avec JHipster - Devoxx France 2017
Être productif avec JHipster - Devoxx France 2017
 
Node.js, le pavé dans la mare
Node.js, le pavé dans la mareNode.js, le pavé dans la mare
Node.js, le pavé dans la mare
 
Build automatique et distribution OTA avec Xcode 4.x et Jenkins
Build automatique et distribution OTA avec Xcode 4.x et JenkinsBuild automatique et distribution OTA avec Xcode 4.x et Jenkins
Build automatique et distribution OTA avec Xcode 4.x et Jenkins
 
StyleCop avec visual studio 2010
StyleCop avec visual studio 2010StyleCop avec visual studio 2010
StyleCop avec visual studio 2010
 
Outils front-end
Outils front-endOutils front-end
Outils front-end
 
Présentation1
Présentation1Présentation1
Présentation1
 
Aspect avec AspectJ
Aspect avec AspectJAspect avec AspectJ
Aspect avec AspectJ
 
Tuto bada
Tuto badaTuto bada
Tuto bada
 
WordCamp Lyon 2015 - WordPress, Git et l'intégration continue
 WordCamp Lyon 2015 - WordPress, Git et l'intégration continue WordCamp Lyon 2015 - WordPress, Git et l'intégration continue
WordCamp Lyon 2015 - WordPress, Git et l'intégration continue
 
Spring Meetup Paris - Back to the basics of Spring (Boot)
Spring Meetup Paris - Back to the basics of Spring (Boot)Spring Meetup Paris - Back to the basics of Spring (Boot)
Spring Meetup Paris - Back to the basics of Spring (Boot)
 
Jenkins
JenkinsJenkins
Jenkins
 
Chaine de production pipeline
Chaine de production   pipelineChaine de production   pipeline
Chaine de production pipeline
 
Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016
Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016
Infra as Code, choisissez vous la pilule rouge ou la pilule bleue - Devoxx 2016
 
Java scripting api
Java scripting apiJava scripting api
Java scripting api
 

More from Nicolas Carlo

The Secrets of Hexagonal Architecture
The Secrets of Hexagonal ArchitectureThe Secrets of Hexagonal Architecture
The Secrets of Hexagonal ArchitectureNicolas Carlo
 
Hexagonal architecture & Elixir
Hexagonal architecture & ElixirHexagonal architecture & Elixir
Hexagonal architecture & ElixirNicolas Carlo
 
À la découverte des Observables - HumanTalks Paris 2017
À la découverte des Observables - HumanTalks Paris 2017À la découverte des Observables - HumanTalks Paris 2017
À la découverte des Observables - HumanTalks Paris 2017Nicolas Carlo
 
À la découverte des observables
À la découverte des observablesÀ la découverte des observables
À la découverte des observablesNicolas Carlo
 
Testing Marionette.js Behaviors
Testing Marionette.js BehaviorsTesting Marionette.js Behaviors
Testing Marionette.js BehaviorsNicolas Carlo
 
Chaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscoreChaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscoreNicolas Carlo
 
Kanban et Game Development avec Trello
Kanban et Game Development avec TrelloKanban et Game Development avec Trello
Kanban et Game Development avec TrelloNicolas Carlo
 
Tester ses Behaviors Marionette.js
Tester ses Behaviors Marionette.jsTester ses Behaviors Marionette.js
Tester ses Behaviors Marionette.jsNicolas Carlo
 
Chaining et composition de fonctions avec lodash / underscore
Chaining et composition de fonctions avec lodash / underscoreChaining et composition de fonctions avec lodash / underscore
Chaining et composition de fonctions avec lodash / underscoreNicolas Carlo
 
Comment organiser un gros projet backbone
Comment organiser un gros projet backboneComment organiser un gros projet backbone
Comment organiser un gros projet backboneNicolas Carlo
 

More from Nicolas Carlo (10)

The Secrets of Hexagonal Architecture
The Secrets of Hexagonal ArchitectureThe Secrets of Hexagonal Architecture
The Secrets of Hexagonal Architecture
 
Hexagonal architecture & Elixir
Hexagonal architecture & ElixirHexagonal architecture & Elixir
Hexagonal architecture & Elixir
 
À la découverte des Observables - HumanTalks Paris 2017
À la découverte des Observables - HumanTalks Paris 2017À la découverte des Observables - HumanTalks Paris 2017
À la découverte des Observables - HumanTalks Paris 2017
 
À la découverte des observables
À la découverte des observablesÀ la découverte des observables
À la découverte des observables
 
Testing Marionette.js Behaviors
Testing Marionette.js BehaviorsTesting Marionette.js Behaviors
Testing Marionette.js Behaviors
 
Chaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscoreChaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscore
 
Kanban et Game Development avec Trello
Kanban et Game Development avec TrelloKanban et Game Development avec Trello
Kanban et Game Development avec Trello
 
Tester ses Behaviors Marionette.js
Tester ses Behaviors Marionette.jsTester ses Behaviors Marionette.js
Tester ses Behaviors Marionette.js
 
Chaining et composition de fonctions avec lodash / underscore
Chaining et composition de fonctions avec lodash / underscoreChaining et composition de fonctions avec lodash / underscore
Chaining et composition de fonctions avec lodash / underscore
 
Comment organiser un gros projet backbone
Comment organiser un gros projet backboneComment organiser un gros projet backbone
Comment organiser un gros projet backbone
 

Les générateurs de code, pour se simplifier la vie au quotidien

  • 1. 1 LESLES GÉNÉRATEURS DE CODEGÉNÉRATEURS DE CODE,, POUR SEPOUR SE SIMPLIFIER LA VIESIMPLIFIER LA VIE AU QUOTIDIENAU QUOTIDIEN
  • 3. 3 QUELQUESQUELQUES USE CASESUSE CASES Un nouveau projet en mode proto On veut juste quelque chose qui marche rapidement et nous permet de coder Un nouveau projet selon des standards persos Pour ré-utiliser nos outils / conventions (ex: freelances) Création d’un nouveau fichier au quotidien Quelles sont les conventions ? Est-ce-que je dois l’instancier quelque part ?…
  • 4. 4 . 1 QU’EST-CE-QU’UNQU’EST-CE-QU’UN GÉNÉRATEUR DE CODEGÉNÉRATEUR DE CODE??
  • 5. 4 . 2 LE PRINCIPELE PRINCIPE 1. On lance une commande 2. On répond à quelques questions 3. TADAAA ! Les fichiers sont générés ! Éviter d'aller copier/coller un autre fichier « similaire » (lequel ?), puis supprimer les lignes inutiles et déclarer tout ça où il faut (sans se tromper ?)
  • 6. 4 . 3 GAIN DE TEMPSGAIN DE TEMPS AU SCAFFOLD D’UN PROJETAU SCAFFOLD D’UN PROJET
  • 7. 4 . 4 GAIN DE TEMPSGAIN DE TEMPS && MOINS D'ERREURSMOINS D'ERREURS AU QUOTIDIENAU QUOTIDIEN
  • 8. 5 . 1 EXEMPLE DE GÉNÉRATEUR JS #1 :EXEMPLE DE GÉNÉRATEUR JS #1 : YEOMANYEOMAN
  • 9. 5 . 2 «« THE WEB'STHE WEB'S SCAFFOLDING TOOLSCAFFOLDING TOOL FOR MODERN WEBAPPSFOR MODERN WEBAPPS »» Très populaire Facile à installer / utiliser Language agnostic (Web, Java, Python, C#, etc.) De nombreux generators pour scaffold un projet standard : On peut créer et publier son propre générateur yeoman.io/generators/
  • 10. 5 . 3 EN PRATIQUEEN PRATIQUE npm install -g yo npm install -g generator-webapp Installer Yeoman Installer un générateur yo webappScaffold un projet yo angular:controller MyNewControllerBootstrap un fichier Getting started: http://yeoman.io/learning/index.html
  • 11. 6 . 1 EXEMPLE DE GÉNÉRATEUR JS #2 :EXEMPLE DE GÉNÉRATEUR JS #2 : PLOPPLOP
  • 12. 6 . 2 KEZAKOKEZAKO PLOPPLOP ?? « Micro-generator framework that makes it easy for an entire team to create files with a level of uniformity » Le projet n’est pas forcément standard Créer un générateur, le publier et le maintenir dans un dépôt distinct n’a pas forcément de valeur ajoutée Au quotidien, ce serait quand même bien pratique Getting started: https://github.com/amwmedia/plop
  • 13. 6 . 3 EN PRATIQUEEN PRATIQUE Dans le projet : plopfile.js des templates module.exports = function (plop) {}; npm install -g plop Installer Plop
  • 14. 6 . 4 POURQUOIPOURQUOI PLOPPLOP PLUTÔT QUEPLUTÔT QUE YEOMANYEOMAN ?? Léger, embarqué dans le projet = maintenance plus simple Simple à prendre en main, plus facilement adopté car peu coûteux
  • 15. 6 . 5 DES USE CASESDES USE CASES DIFFÉRENTSDIFFÉRENTS scaffold un nouveau projet selon des standards bootstrap de nouveaux fichiers dans le cadre de ce projet (standard) PlopYeoman bootstrap de nouveaux fichiers selon les standards personnalisés d'un projet
  • 16. 7 MERCI !MERCI ! DES QUESTIONS ?DES QUESTIONS ? Pour découvrir plop plus en détail : http://bit.ly/22hX160
  • 17. 8 . 1 LES TEMPLATESLES TEMPLATES C'est du !Handlebars /** * TODO - Describe what your model does. * * @class {{pascalCase name}}.Model * @module {{pascalCase name}} * @constructor */ import {Model} from "backbone"; export default Model.extend( { initialize() { // Executed on model initialization } } ); On a accès : aux variables du prompt aux / définishelpers partials plop.addHelper( name, helper ); plop.addPartial( name, template ); Dans plopfile.js :
  • 18. 8 . 2 CRÉER UN GÉNÉRATEURCRÉER UN GÉNÉRATEUR module.exports = function ( plop ) { plop.setGenerator( "module", { description: "create a new module", prompts: [], actions: [] } ); }; plop.setGenerator( name, config ); Création Utilisation
  • 19. 8 . 3 GÉNÉRATEURGÉNÉRATEUR −− PROMPTSPROMPTS module.exports = function ( plop ) { plop.setGenerator( "module", { description: "create a new module", prompts: [ { type: "input", name: "name", message: "What is your module name?", validate: function (value) { if ((/.+/).test(value)) { return true; } return "name is required"; } } ], // … } ); }; C'est du !Inquirer
  • 20. 8 . 4 GÉNÉRATEURGÉNÉRATEUR −− ACTIONSACTIONS module.exports = function ( plop ) { plop.setGenerator( "module", { description: "create a new module", // … actions: [ { type: "add", path: "modules/{{camelCase name}}.js", templateFile: "templates/module.js" } ] } ); }; 3 types d'actions : add modify custom (fonction) Strings parsées avec Handlebars
  • 21. 8 . 5 GÉNÉRATEURGÉNÉRATEUR −− ACTIONSACTIONS actions: function( data ) { var actions = []; if( data.wantTacos ) { actions.push( { type: "add", path: "folder/{{dashCase name}}.txt", templateFile: "templates/tacos.txt" } ); } else { actions.push( { type: "add", path: "folder/{{dashCase name}}.txt", templateFile: "templates/burritos.txt" } ); } return actions; } actions peut aussi être une fonction qui : prend les réponses de prompts en paramètre retourne le tableau des actions à effectuer Permet d'adapter les actions en fonction des réponses données