|
| 1 | +# Installing and using dartfn |
| 2 | + |
| 3 | +`dartfn` is a command-line (CLI) tool for working with Dart Functions Framework |
| 4 | +projects. In this early version of the tool, you can use it to generate sample |
| 5 | +projects from templates. Currently there are three templates: |
| 6 | + |
| 7 | +- helloworld - a basic HTTP handler function |
| 8 | +- json - a simple function handler that accepts and sends JSON |
| 9 | +- cloudevent - a simple cloudevent function handler |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +- [Dart SDK] v2.10+ |
| 14 | + |
| 15 | +## Install dartfn |
| 16 | + |
| 17 | +To install `dartfn` on your machine, run the following command: |
| 18 | + |
| 19 | +```shell |
| 20 | +dart pub global activate dartfn |
| 21 | +``` |
| 22 | + |
| 23 | +Output |
| 24 | + |
| 25 | +```text |
| 26 | +dart pub global activate functions_framework_tool |
| 27 | +Resolving dependencies... (1.2s) |
| 28 | +... |
| 29 | +Precompiling executables... (1.1s) |
| 30 | +Precompiled functions_framework_tool:dartfn. |
| 31 | +Installed executable dartfn. |
| 32 | +Activated functions_framework_tool 0.3.0. |
| 33 | +``` |
| 34 | + |
| 35 | +## Using dartfn |
| 36 | + |
| 37 | +### List available generators |
| 38 | + |
| 39 | +```shell |
| 40 | +dartfn generate --list |
| 41 | +``` |
| 42 | + |
| 43 | +Output |
| 44 | + |
| 45 | +```text |
| 46 | +Available generators: |
| 47 | +cloudevent - A sample Functions Framework project for handling a cloudevent. |
| 48 | +helloworld - A sample "Hello, World!" Functions Framework project. |
| 49 | +json - A sample Functions Framework project for handling JSON. |
| 50 | +``` |
| 51 | + |
| 52 | +### Generate a project |
| 53 | + |
| 54 | +Generate a `helloworld` project, for example: |
| 55 | + |
| 56 | +```shell |
| 57 | +mkdir helloworld |
| 58 | +cd helloworld |
| 59 | +dartfn generate helloworld |
| 60 | +``` |
| 61 | + |
| 62 | +Output |
| 63 | + |
| 64 | +```text |
| 65 | +project: demo |
| 66 | +Creating helloworld application `ex`: |
| 67 | + demo/.gitignore |
| 68 | + demo/Dockerfile |
| 69 | + demo/README.md |
| 70 | + demo/analysis_options.yaml |
| 71 | + demo/bin/server.dart |
| 72 | + demo/lib/functions.dart |
| 73 | + demo/pubspec.yaml |
| 74 | + demo/test/function_test.dart |
| 75 | +8 files written. |
| 76 | +
|
| 77 | +--> to provision required packages, run 'pub get' |
| 78 | +``` |
| 79 | + |
| 80 | +### Get the new project package dependencies |
| 81 | + |
| 82 | +```shell |
| 83 | +dart pub get |
| 84 | +``` |
| 85 | + |
| 86 | +Output |
| 87 | + |
| 88 | +```text |
| 89 | +Resolving dependencies... (2.1s) |
| 90 | +... |
| 91 | +Changed 74 dependencies! |
| 92 | +``` |
| 93 | + |
| 94 | +--- |
| 95 | +[[toc]](../README.md) |
| 96 | +[[back]](../01-introduction.md) |
| 97 | +[[next]](01-quickstart-dart.md) |
| 98 | + |
| 99 | +<!-- reference links --> |
| 100 | +[Dart SDK]: https://dart.dev/get-dart |
0 commit comments