mix kotoba.install (Kotoba v0.5.0)

Copy Markdown View Source

Sets up Kotoba in a Phoenix application.

$ mix kotoba.install
$ mix kotoba.install --dry-run

The task edits three files:

  • assets/js/app.js - adds import { Kotoba } from "kotoba" and puts Kotoba in the hooks of the LiveSocket. When it cannot find the new LiveSocket(...) call, or its hooks are not an object or a variable, it changes nothing and prints the lines to add.
  • assets/css/app.css - adds @import "../../deps/kotoba/priv/static/kotoba.css";, and the Sumi theme import as a comment. The imports follow the deps directory of the project (Mix.Project.deps_path/0) when it is not deps/, as in an umbrella child or with MIX_DEPS_PATH. For a path dependency ({:kotoba, path: "../kotoba"}), which Mix does not copy into deps/, the imports point at the dependency's directory instead.
  • config/config.exs - adds config :kotoba, storage: Kotoba.Storage.Local, with a comment that shows the directory config for config/runtime.exs.

Then it prints the Kotoba.Storage.Local directory config for the :prod block of config/runtime.exs and for config/dev.exs (the adapter needs a :root before the first upload), the esbuild note (the app's esbuild must resolve kotoba through NODE_PATH: from deps/, or, for a path dependency, from the directory that holds it) and the router line for Kotoba.Storage.Local.Plug.

The task is idempotent: it does not add what a file already has, and when there is nothing to add it says so.

Options

  • --dry-run - prints the changes as a diff and writes nothing.