|
| 1 | +title: Custom Toolkit |
| 2 | +sidebar_position: 44 |
| 3 | +--- |
| 4 | +Similar to the Scala Toolkit and Typelevel toolkit, it is possible to create your own, custom toolkit. |
| 5 | +Having a custom toolkit with common libraries can speed up the development using scala-cli. |
| 6 | + |
| 7 | +Let's look at how we can create a new toolkit. |
| 8 | + |
| 9 | +For example, to create a LiHaoyi ecosystem toolkit, we can name the file as `LiHaoyiToolkit.scala` and add the required libraries as dependency directives: |
| 10 | + |
| 11 | +```scala |
| 12 | +//> using scala 2.13, 3 |
| 13 | +//> using publish.name toolkit |
| 14 | +//> using dep com.lihaoyi::upickle::3.1.3 |
| 15 | +//> using dep com.lihaoyi::os-lib::0.9.2 |
| 16 | +//> using dep com.lihaoyi::requests::0.8.0 |
| 17 | +//> using dep com.lihaoyi::fansi::0.4.0 |
| 18 | +``` |
| 19 | +This toolkit is a combination of 4 libraries from `com.lihaoyi` organization as defined before. The key `publish.name` must have the value `toolkit` to be used as a toolkit. |
| 20 | + |
| 21 | +Similarly, define the scalajs version of toolkit in `LiHaoyiToolkit.js.scala` file. Notice the `js.scala` extension. It should also have `publish.name` as `toolkit`. |
| 22 | + |
| 23 | +If testkit is supported, it can also be added as another file, `LiHaoyiToolkitTest.scala` with `publish.name` as `toolkit-test`: |
| 24 | +``` |
| 25 | +//> using scala 2.13, 3 |
| 26 | +//> using publish.name toolkit-test |
| 27 | +//> using dep com.lihaoyi::utest::0.8.2 |
| 28 | +``` |
| 29 | + |
| 30 | +Additionally, more configurations needed for publishing the toolkit can be kept in a conf file, for example, `publish-conf.scala`: |
| 31 | +``` |
| 32 | +//> using publish.organization com.yadavan88 |
| 33 | +//> using publish.version 0.1.0 |
| 34 | +//> using publish.url https://github.com/yadavan88/lihaoyi-toolkit |
| 35 | +//> using publish.license Apache-2.0 |
| 36 | +//> using publish.repository central |
| 37 | +//> using publish.developer "yadavan88|Yadu Krishnan|https://github.com/yadavan88" |
| 38 | +//> using repository sonatype:public |
| 39 | +``` |
| 40 | + |
| 41 | +The toolkit can be published locally using the command: |
| 42 | +``` |
| 43 | +scala-cli --power publish local --cross LiHaoyiToolkit.scala publish-conf.scala |
| 44 | +``` |
| 45 | + |
| 46 | +Similarly, it is also possible to publish to a central repository. Refer to the [GitHub Action workflow](https://github.com/scala/toolkit/blob/main/.github/workflows/deploy.yaml) for more details. |
| 47 | + |
| 48 | +Once it is published, it can be accessed using the org-name with which it got published. For example, with the published toolkit under the organization `com.yadavan88`, it can be accessed as: |
| 49 | + |
| 50 | +``` |
| 51 | +//> using toolkit com.yadavan88:0.1.0 |
| 52 | +
|
| 53 | +@main |
| 54 | +def main() = { |
| 55 | + println(fansi.Color.Blue("Hello world!")) |
| 56 | + println("path is : " + os.pwd) |
| 57 | +} |
| 58 | +
|
| 59 | +``` |
| 60 | +This brings in all the dependencies mentioned in the custom toolkit file. |
0 commit comments