mix coelho.install (coelho v0.18.0)

Copy Markdown View Source

Does what stands between adding the dependency and typing in an editor.

mix coelho.install

Which is: the hook in assets/js/app.js, the stylesheet in assets/css/app.css, and the attachments migration. Every one of them is small and none of them is guessable, which is a poor trade for the first ten minutes of trying a library.

It installs no npm package. The hook is imported from the bundle Coelho ships, priv/static/coelho.esm.js, with ProseMirror inside, and resolves as coelho through the deps/ path a Phoenix application already gives esbuild — the way phoenix_live_view does.

It changes nothing it does not have to. Run it twice and the second run reports that everything is already there.

What it touches

  • assets/js/app.js — import { Coelho } from "coelho", and Coelho added to the LiveSocket's hooks. Only when the file's shape is recognised; otherwise the two lines are printed for you to place. An application already importing Coelho, from the bundle or from source, is left alone
  • assets/css/app.css — the stylesheet, imported after the last @import already there, because CSS refuses one that follows a rule
  • config/config.exs — checked, never edited: coelho resolves through a deps/ entry in esbuild's NODE_PATH. When a profile has none, the task prints the path to add
  • priv/repo/migrations — mix coelho.gen.migration, which is the only part an application without attachments does not need

The npm packages instead

An application that already uses ProseMirror itself wants one copy of it, so it imports coelho.js from source and installs ProseMirror from npm:

mix coelho.install --npm

That installs the packages coelho.js imports, taken from Coelho's own peerDependencies so the list cannot drift, with the package manager the application uses — after asking — and imports the hook from deps/coelho/assets/js/coelho.js. Never use both: two copies of ProseMirror are two sets of classes, and an editor built across them never mounts.

Options

  • --dry-run — say what would change and change nothing
  • --npm — the npm packages and the source, as above
  • --yes — with --npm, do not ask before installing
  • --no-install — with --npm, print the command instead of running it
  • --no-migration — skip the attachments table

Summary

Functions

The install command for this application, and the manager it names.

The browser packages the hook imports, as {name, requirement} pairs.

Functions

installer()

@spec installer() :: {String.t(), String.t()}

The install command for this application, and the manager it names.

Read off the lockfile: assets/ first, since that is where a Phoenix application keeps its browser packages, then the project root for one that keeps them there. npm when nothing says otherwise, which is what a freshly generated application has.

packages()

@spec packages() :: [{String.t(), String.t()}]

The browser packages the hook imports, as {name, requirement} pairs.