Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Your app deservers its own CLI: Try sidekick

Your app deservers its own CLI: Try sidekick

## Abstract

Automate everything! That's easier said than done.

A simple bash script in your /tool directory is a good start, but to be honest: None of us is "good at bash" and nobody really wants to learn it. It doesn't scale, doesn't support dependencies and is not testable.

Dart to the rescue! Sidekick generates a Dart command-line application for you. You can use the built-in command

- `deps` gets all dependencies for all packages
- `gen` runs the build_runner, and formats the code afterwards
- `format` runs dart format across the project, ignores generated files.

or use the project a starting point for you own commands to be shared with your team. Need some ideas:

- Automatically bump your version number
- Release your app to the Play Store / AWS / Firebase
- Generate a changelog based on the merged PRs
- Home-made build flavors: Switch between environments by editing and swapping of some files

Pascal Welsch

October 28, 2022
Tweet

More Decks by Pascal Welsch

Other Decks in Programming

Transcript

  1. Sidekick by @passsy (Pascal Welsch) Your app deserves its own

    CLI: Try sidekick Pascal Welsch Google Developer Expert Co-Founder of wiredash.io CTO at phntm GmbH Droidcon London 2022 @passsy
  2. Sidekick by @passsy (Pascal Welsch) Automating our workday at PHNTM

    - Get dependencies for all packages - Bump app version - Update localization files - Create release notes with Jira tickets from merged PR descriptions - Standup: What are open PRs across multiple repos? - Publish releases
  3. Sidekick by @passsy (Pascal Welsch) Bash scripts Pros: - Run

    everywhere (even on Windows) - No installation required - No compilation Cons: - Hard to write (unknown feature set) - Hard to read - No dependency management - No debugger - No testing
  4. Sidekick by @passsy (Pascal Welsch) Gradle scripts Pros: - stable

    framework - bash entry, downloads gradle jar on demand - Debugging possible - Testing possible Cons: - Requires a JRE installed - Gradle is a build system, not a CLI - Flutter/Dart are not compatible with Gradle
  5. Sidekick by @passsy (Pascal Welsch) Dart scripts in /tool Pros:

    - Dart is easy to read and write for everyone - pub dependency manager - Rich set of pub packages - Debugging - Testing Cons: - Shared dependencies with your app - functions of different scripts are hard to discover - Dart need to be installed - No fixed dart version for execution
  6. Sidekick by @passsy (Pascal Welsch) Sidekick CLIs combines the best

    of all worlds Bash entrypoint, no other software required on system. Auto-compile on change Self-executing, automatically downloads a dart runtime, compiles the cli and executes it Dart is easy to read and write, and extendable with dependencies from pub. Support for debugging and testing comes for free
  7. Sidekick by @passsy (Pascal Welsch) $ sidekick init $ dart

    pub global activate sidekick Dart CLI generator • With bash entrypoint • Self executable (automatically downloads dart runtime, auto recompile) • Build-in commands for Dart / Flutter projects • Write your own custom commands • Share commands with others using the plugin system
  8. Sidekick by @passsy (Pascal Welsch) entrypoint Dart binary entry point

    Command registration Your custom commands magic bash scripts
  9. Sidekick by @passsy (Pascal Welsch) $ <cli> sidekick plugins install

    <package> Install a sidekick plugin from pub
  10. Sidekick by @passsy (Pascal Welsch) Plugin installation 1. Download the

    pub package 2. Get plugin dependencies with cli dart runtime 3. Execute /tool/install.dart of plugin The plugin is now free to modify the cli package - Add dependencies - Add files - Modify files (to register Commands)
  11. Sidekick by @passsy (Pascal Welsch) Which plugin template should I

    use? Allow users to edit the Command code? yes no shared-command Wanna share some code with a pub package? yes no shared-code install-only
  12. Sidekick by @passsy (Pascal Welsch) Plugin template comparison install-only •

    All generated code is directly accessible for devs • Code can not be updated with pub upgrade
  13. Sidekick by @passsy (Pascal Welsch) install-only plugins <cli> sidekick plugins

    create \ -t install-only \ --name install_only_sidekick_plugin
  14. Sidekick by @passsy (Pascal Welsch) Which plugin template should I

    use? Allow users to edit the Command code? yes no shared-command Wanna share some code with a pub package? yes no shared-code install-only
  15. Sidekick by @passsy (Pascal Welsch) Plugin template comparison shared-command install-only

    • All generated code is directly accessible for devs • Code can not be updated with pub upgrade • The generated command code can not be modified • The command can be update via pub • Inject properties via Command constructor
  16. Sidekick by @passsy (Pascal Welsch) shared-command plugins <cli> sidekick plugins

    create \ -t shared-command \ --name shared_command_sidekick_plugin
  17. Sidekick by @passsy (Pascal Welsch) Which plugin template should I

    use? Allow users to edit the Command code? yes no shared-command Wanna share some code with a pub package? yes no shared-code install-only
  18. Sidekick by @passsy (Pascal Welsch) Plugin template comparison shared-command shared-code

    install-only • All generated code is directly accessible for devs • Code can not be updated with pub upgrade • The generated command can be modified • Command uses reusable functionality from pub package • The generated command code can not be modified • The command can be update via pub • Inject properties via Command constructor
  19. Sidekick by @passsy (Pascal Welsch) shared-code plugins <cli> sidekick plugins

    create \ -t shared-code \ --name shared_code_sidekick_plugin
  20. Sidekick by @passsy (Pascal Welsch) Which plugin template should I

    use? Allow users to edit the Command code? yes no shared-command Wanna share some code with a pub package? yes no shared-code install-only
  21. Sidekick by @passsy (Pascal Welsch) Please share your awesome cli

    commands as sidekick plugins with the community! github.com/phntmxyz/sidekick
  22. Sidekick by @passsy (Pascal Welsch) Your app deserves its own

    CLI: Try sidekick Pascal Welsch Google Developer Expert Co-Founder of wiredash.io CTO at phntm GmbH Droidcon London 2022 @passsy