SlideShare a Scribd company logo
Getting to Know Grunt
By Writing Your Own Plugin
@jamiestrachan
Getting to Know Grunt by Writing Your Own Plugin
Getting to Know Grunt by Writing Your Own Plugin
Getting to Know Grunt by Writing Your Own Plugin
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

PDF
Cloud Native Progressive Web Applications - Denver JUG 2016
PDF
What's New in JHipsterLand - DevNexus 2017
PDF
Building a PWA with Ionic, Angular and Spring Boot - Jfokus 2017
PPTX
When a Sassquatch and a Board get together (or how to use Grunt to chew Sass)
PPTX
Introduction to yeoman
PPT
Headless BDD & Responsive Test Automation
PPT
Behat sauce
PPTX
How can i enforce swift style
Cloud Native Progressive Web Applications - Denver JUG 2016
What's New in JHipsterLand - DevNexus 2017
Building a PWA with Ionic, Angular and Spring Boot - Jfokus 2017
When a Sassquatch and a Board get together (or how to use Grunt to chew Sass)
Introduction to yeoman
Headless BDD & Responsive Test Automation
Behat sauce
How can i enforce swift style

What's hot (20)

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

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

PDF
Front-end development automation with Grunt
PDF
Front End Development Automation with Grunt
PDF
Grunt training deck
PDF
Grunt All Day
PPTX
Introducing grunt, npm and sass
PDF
Grunt: the wild boar dev's best friend - WordCamp London 2018
PDF
Grunt JS - Getting Started With Grunt
PPTX
Angular boilerplate generator
PPTX
Modern Development Tools
PDF
Intro to grunt
PDF
Bootstrapping your plugin
PDF
Modern Web Application Development Workflow - EclipseCon France 2014
Front-end development automation with Grunt
Front End Development Automation with Grunt
Grunt training deck
Grunt All Day
Introducing grunt, npm and sass
Grunt: the wild boar dev's best friend - WordCamp London 2018
Grunt JS - Getting Started With Grunt
Angular boilerplate generator
Modern Development Tools
Intro to grunt
Bootstrapping your plugin
Modern Web Application Development Workflow - EclipseCon France 2014
Ad

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
cuic standard and advanced reporting.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
KodekX | Application Modernization Development
PDF
Modernizing your data center with Dell and AMD
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
DOCX
The AUB Centre for AI in Media Proposal.docx
Building Integrated photovoltaic BIPV_UPV.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
Per capita expenditure prediction using model stacking based on satellite ima...
cuic standard and advanced reporting.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Advanced methodologies resolving dimensionality complications for autism neur...
KodekX | Application Modernization Development
Modernizing your data center with Dell and AMD
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Dropbox Q2 2025 Financial Results & Investor Presentation
“AI and Expert System Decision Support & Business Intelligence Systems”
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
The AUB Centre for AI in Media Proposal.docx

Getting to Know Grunt by Writing Your Own Plugin

Editor's Notes

  • #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: workflow problem using Sass and Grunt (ruby + node) grunt-sass-version to ensure Sass version since it can't be directly managed by npm
  • #4: 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
  • #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
  • #8: not that complicated really, 1-4 are just scaffolding, 5 is build, 6 is publish
  • #11: sounds a lot like Yeoman
  • #12: 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
  • #17: *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…
  • #18: Start of my plugin this.options and this.data are how you talk to a plugin
  • #19: 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
  • #20: *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
  • #21: 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
  • #22: need to include shelljs which means it’s a dependency for the module
  • #23: 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
  • #25: 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
  • #26: included in scaffolding nice sanity check for your js make sure it’s checking all your js files
  • #28: *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
  • #29: scaffolded test/plugin_test.js runs tests against created output files using ‘fixtures’ and ‘expected’
  • #31: my tests call on _sass_version which is my library
  • #32: 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)
  • #33: we can acquire dependencies by version number, tarball, git URL, or local path
  • #34: npm link creates a symbolic link to a local dependency
  • #42: 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