Although we’ve got tools like Stagehand to generate the boilerplate for a Dart project, a pain-point I’ve experienced regularly is managing Dart packages. Whenever I needed to add a new package, I usually followed the steps below:
Lookup package details on pub.dev
Hit the Installing tab and copy the latest version
Open my pubspec.yaml file in the Dart project
Add the package and version to
dependencies
ordev_dependencies
listSave file.
Run
pub get
to update my packages
Having programmed in Nodejs I was aware of the npm tool which provided the init
and install
commands to automate the creation and maintenance of packages.
After searching around I came across the Pubspec Assist extension for VS Code that enabled me to search and install a package through the UI. It works in most cases but I wasn’t content that I had to be in the editor in order to use it! So instead of complaining I decided I’ll write my own.
Introducing Crawl
Crawl helps you manage Dart packages in your pubspec.yaml files. It borrows inspiration from the npm tool and will be familiar if you have used it.
The only pre-requisite is the Dart runtime and you can install Crawl by running pub global activate crawl
. This will enable the crawl
executable in your terminal.
To launch the usage screen simply run crawl
in your terminal:
To create a new pubspec.yaml file enter crawl init
in your terminal and follow the interactive prompt:
To add a new package run the following command:
$ crawl install -p <package-name> # eg: `crawl install -p shelf`
$ crawl install -p <package-name> -v <version> # eg: `crawl install -p shelf -v 0.7.9`
To remove a package run the following command:
$ crawl uninstall <package-name>
This package is still early days, but currently you are able to:
Create a pubspec.yaml file
Add to
dependencies
including specifying a particular versionAdd to
dev_dependencies
including specifying a particular versionRun
pub get
automatically to update project dependenciesUninstall package
List unused dependencies in project
Lookup package information on Pub repository
Try it out and let me know what you think ? Although the Dart team will be introducing a pub add
and pub remove
command in the next release, this tool provides other commands that will be useful in your projects.