Packages

Plugin adding i18n to live_svelte using compile-time extraction

Current section

Files

Jump to

mix.exs

defmodule LiveSvelteGettext.MixProject do
use Mix.Project
@version "0.2.0"
@source_url "https://github.com/xnilsson/live_svelte_gettext"
def project do
[
app: :live_svelte_gettext,
version: @version,
elixir: "~> 1.18",
start_permanent: Mix.env() == :prod,
deps: deps(),
aliases: aliases(),
# Hex package metadata
description: "Plugin adding i18n to live_svelte using compile-time extraction",
package: package(),
# Documentation
name: "LiveSvelteGettext",
source_url: @source_url,
homepage_url: @source_url,
docs: docs(),
# Testing
test_coverage: [tool: ExCoveralls],
# Dialyzer
dialyzer: [
plt_add_apps: [:mix]
]
]
end
def cli do
[
preferred_envs: [
coveralls: :test,
"coveralls.detail": :test,
"coveralls.html": :test,
"release.check": :test
]
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
defp deps do
[
# Core dependencies
# 0.26 is the real floor: `use Gettext.Backend` and the msgctxt-aware
# lgettext/5 and lngettext/7 callbacks were all introduced there.
{:gettext, "~> 0.26 or ~> 1.0"},
# Used to read plural msgstr entries straight from .po files. Matches
# Gettext's own requirement, so it never forces a different version.
{:expo, "~> 0.5.1 or ~> 1.0"},
{:phoenix_live_view, "~> 1.0"},
# Optional: used for JSON encoding when present. On OTP 27+ the built-in
# :json module is used instead, matching live_svelte 0.17+.
{:jason, "~> 1.4", optional: true},
# Development dependencies
{:igniter, "~> 0.6", optional: true},
{:ex_doc, "~> 0.31", only: :dev, runtime: false},
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false},
{:excoveralls, "~> 0.18", only: :test}
]
end
# The Hex package ships assets/dist, but assets/dist is gitignored and built
# by tsc. Without this, a fresh clone would publish either no bundle at all or
# whatever stale build happened to be lying around - which is how the npm
# package drifted behind the Hex package in 0.1.x.
#
# Mix runs a self-referencing alias once and then falls through to the real
# task, so these augment `hex.build` and `hex.publish` rather than replacing
# them.
defp aliases do
[
"assets.build": [
"cmd --cd assets npm install --no-audit --no-fund --silent",
"cmd --cd assets npm run build"
],
"assets.test": ["cmd --cd assets npm test"],
"release.check": [&check_versions_in_sync/1, "assets.build", "assets.test", "test"],
"hex.build": [&check_versions_in_sync/1, "assets.build", "hex.build"],
"hex.publish": [&check_versions_in_sync/1, "assets.build", "hex.publish"]
]
end
# The Elixir and npm packages are published separately and must not drift.
defp check_versions_in_sync(_args) do
npm_version =
"assets/package.json"
|> File.read!()
|> then(&Regex.run(~r/"version":\s*"([^"]+)"/, &1))
|> case do
[_, version] -> version
_ -> nil
end
if npm_version != @version do
Mix.raise("""
Version mismatch between mix.exs and assets/package.json:
mix.exs #{@version}
assets/package.json #{npm_version || "(not found)"}
Both packages are published from this repository and must stay in sync.
Update assets/package.json and try again.
""")
end
end
defp package do
[
name: "live_svelte_gettext",
files: ~w(
lib
priv
assets/dist
assets/package.json
assets/README.md
.formatter.exs
mix.exs
README.md
LICENSE
CHANGELOG.md
),
licenses: ["MIT"],
links: %{
"GitHub" => @source_url,
"Changelog" => "#{@source_url}/blob/main/CHANGELOG.md"
},
maintainers: ["Christopher Nilsson"]
]
end
defp docs do
[
main: "LiveSvelteGettext",
source_ref: "v#{@version}",
source_url: @source_url,
extras: [
"README.md",
"CHANGELOG.md",
"LICENSE"
],
groups_for_modules: [
Core: [
LiveSvelteGettext,
LiveSvelteGettext.Components
],
Internal: [
LiveSvelteGettext.Extractor,
LiveSvelteGettext.Compiler,
LiveSvelteGettext.Runtime,
LiveSvelteGettext.Plurals,
LiveSvelteGettext.CustomExtractor,
LiveSvelteGettext.JSON
],
Tasks: [
Mix.Tasks.LiveSvelteGettext.Install,
Mix.Tasks.LiveSvelteGettext.Setup,
Mix.Tasks.LiveSvelteGettext.FixReferences
]
],
groups_for_extras: [
"Getting Started": ["README.md"],
"Project Info": ["CHANGELOG.md", "LICENSE"]
],
skip_undefined_reference_warnings_on: ["CHANGELOG.md"]
]
end
end