Flutter Community
Published in

Flutter Community

Run scripts from pubspec with Flutter

Lately, I have had a chance to work on React Native project, and I love how they have scripts in package.json, from cleaning the project to uploading the build.

With a quick search, I found an issue but not much. Luckily there are few projects in pub.dev. Packages that I found are derry, rps, and flutter_scripts.

Run Pubspec Script (RPS)

rps does the job for me. Using it is pretty straightforward.

First, install the package. You need to have dart installed.

dart pub global activate rps

Then, define your scripts in pubspec.yaml. It can be in anywhere in the file. I put the above dependencies. Just make sure they have the same indentation with dependencies.

You can just give the command as I did for "run" or under "test".
Or you can put them in a folder and give the path for those scripts, like: "./scripts/firebase/android.sh"

Then for running the "gen" script, you need to write

rps gen

Nested Scripts

As you can see in the screenshot, some scripts are nested with indentation. That allows me to group them.
If I want to create an iOS build for Firebase with the development flavor, I need to run:

rps firebase ios dev

Here's where I put my scripts to tidy them up and keep pubspec.yaml neat.

Hope it will be helpful for you and your teammates. Let me know what you think, and ask your questions if you have any on https://mirkan.dev/contact

Follow Flutter Community on Twitter: https://www.twitter.com/FlutterComm

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store