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)
    sidekick
    A CLI for your app

    View Slide

  2. 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

    View Slide

  3. Sidekick by @passsy (Pascal Welsch)

    View Slide

  4. Sidekick by @passsy (Pascal Welsch)
    PHNTM
    ['fæntəm]
    Flutter Agency with 15 Flutter Experts from all across Germany

    View Slide

  5. 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

    View Slide

  6. Sidekick by @passsy (Pascal Welsch)
    Where to place the automation code?

    View Slide

  7. 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

    View Slide

  8. 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

    View Slide

  9. 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

    View Slide

  10. Sidekick by @passsy (Pascal Welsch)
    sidekick

    View Slide

  11. 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

    View Slide

  12. Sidekick by @passsy (Pascal Welsch)
    $ sidekick init
    $ dart pub global activate sidekick

    View Slide

  13. 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

    View Slide

  14. Sidekick by @passsy (Pascal Welsch)
    $ sidekick init
    $ dart pub global activate sidekick

    View Slide

  15. Sidekick by @passsy (Pascal Welsch)

    View Slide

  16. Sidekick by @passsy (Pascal Welsch)
    > vgs
    > sidekick init
    > y

    View Slide

  17. Sidekick by @passsy (Pascal Welsch)
    > vgs
    > y

    View Slide

  18. Sidekick by @passsy (Pascal Welsch)

    View Slide

  19. Sidekick by @passsy (Pascal Welsch)

    View Slide

  20. Sidekick by @passsy (Pascal Welsch)
    entrypoint
    Dart binary entry point
    Command registration
    Your custom commands
    magic bash scripts

    View Slide

  21. Sidekick by @passsy (Pascal Welsch)

    View Slide

  22. Sidekick by @passsy (Pascal Welsch)

    View Slide

  23. Sidekick by @passsy (Pascal Welsch)
    Extending your CLI

    View Slide

  24. Sidekick by @passsy (Pascal Welsch)
    Task: Build our app for web

    View Slide

  25. Sidekick by @passsy (Pascal Welsch)

    View Slide

  26. Sidekick by @passsy (Pascal Welsch)

    View Slide

  27. Sidekick by @passsy (Pascal Welsch)
    > vgs
    compile takes ~5s

    View Slide

  28. Sidekick by @passsy (Pascal Welsch)
    > vgs

    View Slide

  29. Sidekick by @passsy (Pascal Welsch)

    View Slide

  30. Sidekick by @passsy (Pascal Welsch)
    The Plugins System
    Share your commands with others

    View Slide

  31. Sidekick by @passsy (Pascal Welsch)
    $ sidekick plugins install
    Install a sidekick plugin from pub

    View Slide

  32. 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)

    View Slide

  33. Sidekick by @passsy (Pascal Welsch)

    View Slide

  34. 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

    View Slide

  35. 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

    View Slide

  36. Sidekick by @passsy (Pascal Welsch)
    install-only plugins
    sidekick plugins create
    \ -t install-only
    \ --name install_only_sidekick_plugin

    View Slide

  37. Sidekick by @passsy (Pascal Welsch)

    View Slide

  38. Sidekick by @passsy (Pascal Welsch)

    View Slide

  39. Sidekick by @passsy (Pascal Welsch)

    View Slide

  40. Sidekick by @passsy (Pascal Welsch)

    View Slide

  41. 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

    View Slide

  42. 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

    View Slide

  43. Sidekick by @passsy (Pascal Welsch)
    shared-command plugins
    sidekick plugins create
    \ -t shared-command
    \ --name shared_command_sidekick_plugin

    View Slide

  44. Sidekick by @passsy (Pascal Welsch)
    shared_command_sidekick_plugin/tool/install.dart

    View Slide

  45. 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

    View Slide

  46. 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

    View Slide

  47. Sidekick by @passsy (Pascal Welsch)
    shared-code plugins
    sidekick plugins create
    \ -t shared-code
    \ --name shared_code_sidekick_plugin

    View Slide

  48. Sidekick by @passsy (Pascal Welsch)
    shared-code plugins

    View Slide

  49. 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

    View Slide

  50. Sidekick by @passsy (Pascal Welsch)
    Plugins can be found on pub.dev

    View Slide

  51. Sidekick by @passsy (Pascal Welsch)
    github.com/phntmxyz/sidekick

    View Slide

  52. Sidekick by @passsy (Pascal Welsch)
    Please share your
    awesome cli commands
    as sidekick plugins
    with the community!
    github.com/phntmxyz/sidekick

    View Slide

  53. 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

    View Slide