dartfn
is a command-line (CLI) tool for working with Dart Functions Framework
projects. In this early version of the tool, you can use it to generate sample
projects from templates. Currently there are three templates:
- helloworld - a basic HTTP handler function
- json - a simple function handler that accepts and sends JSON
- cloudevent - a simple cloudevent function handler
- Dart SDK v2.12+
To install dartfn
on your machine, run the following command:
dart pub global activate dartfn
Output
dart pub global activate functions_framework_tool
Resolving dependencies... (1.2s)
...
Precompiling executables... (1.1s)
Precompiled functions_framework_tool:dartfn.
Installed executable dartfn.
Activated functions_framework_tool 0.3.0.
dartfn generate --list
Output
Available generators:
cloudevent - A sample Functions Framework project for handling a cloudevent.
helloworld - A sample "Hello, World!" Functions Framework project.
json - A sample Functions Framework project for handling JSON.
Generate a helloworld
project, for example:
mkdir helloworld
cd helloworld
dartfn generate helloworld
Output
project: demo
Creating helloworld application `ex`:
demo/.gitignore
demo/Dockerfile
demo/README.md
demo/analysis_options.yaml
demo/bin/server.dart
demo/lib/functions.dart
demo/pubspec.yaml
demo/test/function_test.dart
8 files written.
--> to provision required packages, run 'pub get'
dart pub get
Output
Resolving dependencies... (2.1s)
...
Changed 74 dependencies!