SlideShare a Scribd company logo
1 of 42
Download to read offline
Getting to Know Grunt
By Writing Your Own Plugin
@jamiestrachan
1. Scaffold
2a. Develop
2b. Test
3. Publish
Scaffold
Scaffold Develop Test Publish
Scaffold Develop Test Publish
Running grunt-init
Running grunt-init
?
Scaffold Develop Test Publish
“This scaffolding task was always an odd-duck, and it really
deserves it’s own project. So, we’ve broken it into a separate
npm module, grunt-init … In the coming weeks, the Yeoman
team will be replacing this task entirely, using their rails-
inspired generator system.”
February 18, 2013
https://bocoup.com/weblog/tearing-grunt-apart/
Scaffold Develop Test Publish
Scaffold Develop Test Publish
README.md
Scaffolded plugin
package.json
Scaffolded plugin
Develop
Scaffold Develop Test Publish
Gruntfile.js
grunt-sass-version
tasks/sass_version.js
grunt-sass-version
Gruntfile.js
grunt-sass-version grunt-sass-version
tasks/sass_version.js
tasks/<plugin>.js
Scaffolded plugin
tasks/lib/_sass_version.js
grunt-sass-version
tasks/lib/_sass_version.js
grunt-sass-version
package.json
grunt-sass-version
Test
Scaffold Develop Test Publish
Scaffold Develop Test Publish
Code Quality
Scaffold Develop Test Publish
Unit Testing
Scaffold Develop Test Publish
Gruntfile.js
Scaffolded plugin
test/<plugin>_test.js
Scaffolded plugin
Scaffold Develop Test Publish
nodeunit tests
sass_version.js
lib/_sass_version.jsGrunt input Grunt output
success,
message
test/sass_version_test.js
grunt-sass-version
Integration Testing
Scaffold Develop Test Publish
package.json
{ "dependencies" : {
"til" : "~1.2",
"elf" : "^1.2.3",
"asd" : "http://asdf.com/asdf.tar.gz",
"gitproj" : "git://github.com/user/project.git#commit-ish",
"dyl" : "file:../dyl"
} }
Scaffold Develop Test Publish
npm link
Publish
Scaffold Develop Test Publish
npm publish
Scaffold Develop Test Publish
1. register at npmjs.com
2. npm adduser
7. (npm unpublish)
So what?
Scaffolding
solid tools available: grunt-init, Yeoman
saves time
avoids mistakes
makes dull work easier
you can find existing templates or make your own
Testing
develop with testing in mind
use an automated testing tool like nodeunit
Managing Dependencies
npm link for local dependencies
git repos for unregistered dependencies
create distributed projects with npm
Contributing
process is similar for:
gulp plugins
grunt-init templates
Yeoman generators
hubot scripts
Learn your tools
Thanks!
Getting to Know Grunt By Writing Your Own Plugin
@jamiestrachan

More Related Content

What's hot

Dyno cycling behavior of Heroku
Dyno cycling behavior of HerokuDyno cycling behavior of Heroku
Dyno cycling behavior of Heroku
Shunji Konishi
 

What's hot (20)

iOS Developers Conference-iOS Automation with Cucumber, Appium and Saucelabs
iOS Developers Conference-iOS Automation with Cucumber, Appium and SaucelabsiOS Developers Conference-iOS Automation with Cucumber, Appium and Saucelabs
iOS Developers Conference-iOS Automation with Cucumber, Appium and Saucelabs
 
Lazy angular w/ webpack
Lazy angular w/ webpackLazy angular w/ webpack
Lazy angular w/ webpack
 
Dyno cycling behavior of Heroku
Dyno cycling behavior of HerokuDyno cycling behavior of Heroku
Dyno cycling behavior of Heroku
 
Dockerising Appium : London Appium Meetup
Dockerising Appium : London Appium MeetupDockerising Appium : London Appium Meetup
Dockerising Appium : London Appium Meetup
 
J hipster
J hipsterJ hipster
J hipster
 
Angular & rails
Angular & railsAngular & rails
Angular & rails
 
Swagger code motion talk
Swagger code motion talkSwagger code motion talk
Swagger code motion talk
 
Lifthub (#rpscala 26)
Lifthub (#rpscala 26)Lifthub (#rpscala 26)
Lifthub (#rpscala 26)
 
AngularJS
AngularJSAngularJS
AngularJS
 
Gitlab flow solo
Gitlab flow soloGitlab flow solo
Gitlab flow solo
 
GR8Conf 2015 - Spring Boot and Groovy. What more do you need?
GR8Conf 2015 - Spring Boot and Groovy. What more do you need?GR8Conf 2015 - Spring Boot and Groovy. What more do you need?
GR8Conf 2015 - Spring Boot and Groovy. What more do you need?
 
Presentacion minitest
Presentacion minitestPresentacion minitest
Presentacion minitest
 
What grunt?
What grunt?What grunt?
What grunt?
 
MVC way to introduce Sails.js - node.js framework
MVC way to introduce Sails.js - node.js frameworkMVC way to introduce Sails.js - node.js framework
MVC way to introduce Sails.js - node.js framework
 
What's New in JHipsterLand - Devoxx Poland 2017
What's New in JHipsterLand - Devoxx Poland 2017What's New in JHipsterLand - Devoxx Poland 2017
What's New in JHipsterLand - Devoxx Poland 2017
 
Use groovy & grails in your spring boot projects
Use groovy & grails in your spring boot projectsUse groovy & grails in your spring boot projects
Use groovy & grails in your spring boot projects
 
C初心者がbyebugにPR出した話
C初心者がbyebugにPR出した話C初心者がbyebugにPR出した話
C初心者がbyebugにPR出した話
 
APIテストあれこれ
APIテストあれこれAPIテストあれこれ
APIテストあれこれ
 
Node.js x Azure, cli usage, website deployment
Node.js x Azure, cli usage, website deploymentNode.js x Azure, cli usage, website deployment
Node.js x Azure, cli usage, website deployment
 
WebSocketでカメラの映像を共有してみた
WebSocketでカメラの映像を共有してみたWebSocketでカメラの映像を共有してみた
WebSocketでカメラの映像を共有してみた
 

Similar to Getting to Know Grunt by Writing Your Own Plugin

Automated Performance Testing With J Meter And Maven
Automated  Performance  Testing With  J Meter And  MavenAutomated  Performance  Testing With  J Meter And  Maven
Automated Performance Testing With J Meter And Maven
PerconaPerformance
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
Igor Khotin
 
20091226 名古屋SGGAE/J勉強会発表資料『Lift on GAE/J』
20091226 名古屋SGGAE/J勉強会発表資料『Lift on GAE/J』20091226 名古屋SGGAE/J勉強会発表資料『Lift on GAE/J』
20091226 名古屋SGGAE/J勉強会発表資料『Lift on GAE/J』
Ryo RKTM
 
Bundling Client Side Assets
Bundling Client Side AssetsBundling Client Side Assets
Bundling Client Side Assets
Timothy Oxley
 

Similar to Getting to Know Grunt by Writing Your Own Plugin (20)

Groovy Maven Builds
Groovy Maven BuildsGroovy Maven Builds
Groovy Maven Builds
 
Scripting Support in GFv3 Prelude - Full Version
Scripting Support in GFv3 Prelude - Full VersionScripting Support in GFv3 Prelude - Full Version
Scripting Support in GFv3 Prelude - Full Version
 
G*なクラウド 雲のかなたに ショートバージョン
G*なクラウド 雲のかなたに ショートバージョンG*なクラウド 雲のかなたに ショートバージョン
G*なクラウド 雲のかなたに ショートバージョン
 
Grunt
GruntGrunt
Grunt
 
Grunt & Front-end Workflow
Grunt & Front-end WorkflowGrunt & Front-end Workflow
Grunt & Front-end Workflow
 
Let Grunt do the work, focus on the fun!
Let Grunt do the work, focus on the fun!Let Grunt do the work, focus on the fun!
Let Grunt do the work, focus on the fun!
 
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
Let Grunt do the work, focus on the fun! [Open Web Camp 2013]
 
Npm scripts
Npm scriptsNpm scripts
Npm scripts
 
Workshop 3: JavaScript build tools
Workshop 3: JavaScript build toolsWorkshop 3: JavaScript build tools
Workshop 3: JavaScript build tools
 
Automated Performance Testing With J Meter And Maven
Automated  Performance  Testing With  J Meter And  MavenAutomated  Performance  Testing With  J Meter And  Maven
Automated Performance Testing With J Meter And Maven
 
Testing Drupal with Ghosts and Gherkin
Testing Drupal  with Ghosts and GherkinTesting Drupal  with Ghosts and Gherkin
Testing Drupal with Ghosts and Gherkin
 
Grunt - The JavaScript Task Runner
Grunt - The JavaScript Task RunnerGrunt - The JavaScript Task Runner
Grunt - The JavaScript Task Runner
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
 
20091226 名古屋SGGAE/J勉強会発表資料『Lift on GAE/J』
20091226 名古屋SGGAE/J勉強会発表資料『Lift on GAE/J』20091226 名古屋SGGAE/J勉強会発表資料『Lift on GAE/J』
20091226 名古屋SGGAE/J勉強会発表資料『Lift on GAE/J』
 
Bundling Client Side Assets
Bundling Client Side AssetsBundling Client Side Assets
Bundling Client Side Assets
 
Yeoman Workflow
Yeoman WorkflowYeoman Workflow
Yeoman Workflow
 
2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build
 
GlassFish Embedded API
GlassFish Embedded APIGlassFish Embedded API
GlassFish Embedded API
 
Automating Front-End Workflow
Automating Front-End WorkflowAutomating Front-End Workflow
Automating Front-End Workflow
 
JLPDevs - Optimization Tooling for Modern Web App Development
JLPDevs - Optimization Tooling for Modern Web App DevelopmentJLPDevs - Optimization Tooling for Modern Web App Development
JLPDevs - Optimization Tooling for Modern Web App Development
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

Getting to Know Grunt by Writing Your Own Plugin

Editor's Notes

  1. workflow problem using Sass and Grunt (ruby + node) grunt-sass-version to ensure Sass version since it can't be directly managed by npm
  2. workflow problem using Sass and Grunt (ruby + node) grunt-sass-version to ensure Sass version since it can't be directly managed by npm
  3. you publishing a plugin isn’t the point I got a lot out of the process of building one that I’ve used in other projects and wanted to share I went into the process looking at these tools as black boxes and benefited from getting better understanding I want you to think about your tool and consider what you could get out of investigating them more deeply
  4. not that complicated really, 1-4 are just scaffolding, 5 is build, 6 is publish
  5. not that complicated really, 1-4 are just scaffolding, 5 is build, 6 is publish
  6. not that complicated really, 1-4 are just scaffolding, 5 is build, 6 is publish
  7. sounds a lot like Yeoman
  8. grunt-init is kind of replaced by Yeoman but both work point is that scaffolding projects is really useful but the tool isn’t that important grunt-init seems simpler but Yeoman has more community support
  9. *highlight grunt.loadTasks('tasks');* this is the line that actually includes your plugin code I don’t like “black magic” code where things happen because of naming convention etc…
  10. Start of my plugin this.options and this.data are how you talk to a plugin
  11. The options object is used to override the default value you identify in your plugin Any key/value pairs provided in the task get passed into this.data
  12. *collapse warnings* don’t need to go into too much detail here but a quick read makes it clear that this if file I/O maybe fine for your plugin but not for mine
  13. my plugin gets expected version generated regex for testing based on options runs `sass –v` to get available Sass version compares available version to regex and return result object
  14. need to include shelljs which means it’s a dependency for the module
  15. devDependencies are what you need when you `git clone` dependencies are what you need when you `npm install` peerDependencies are required for a plugin relationship
  16. don’t follow the order of this presentation think about testing with or before development, not after https://www.flickr.com/photos/catherinekolodziej/8866489274 I wish: https://www.flickr.com/photos/37423935@N00/10373620734
  17. included in scaffolding nice sanity check for your js make sure it’s checking all your js files
  18. *show clean, webu, nodeunit tasks and registering test task* scaffolded Gruntfile.js sets up way to run the plugin itself, identifies the tests, then created the test task
  19. scaffolded test/plugin_test.js runs tests against created output files using ‘fixtures’ and ‘expected’
  20. my tests call on _sass_version which is my library
  21. Catch-22 don’t want to publish module until it’s testing can’t test until published (at least with normal way of using npm)
  22. we can acquire dependencies by version number, tarball, git URL, or local path
  23. npm link creates a symbolic link to a local dependency
  24. Started as scratching my own itch Became about contributing to something bigger But ultimately was a powerful opportunity to “level up” my skills You can read the docs and browse the code but building something is the best way to learn