Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[Empire Elixir] Giving Back - Building Your Fir...

[Empire Elixir] Giving Back - Building Your First Elixir Package

Brian Cardarella

May 22, 2016
Tweet

More Decks by Brian Cardarella

Other Decks in Programming

Transcript

  1. Generating a new package -> mix new crazy_pants * creating

    README.md * creating .gitignore * creating mix.exs * creating config * creating config/config.exs * creating lib * creating lib/crazy_pants.ex * creating test * creating test/test_helper.exs * creating test/crazy_pants_test.exs Your Mix project was created successfully. You can use "mix" to compile it, test it, and more: cd crazy_pants mix test Run "mix help" for more commands.
  2. What we’ll cover • Customizing the package • Writing good

    documentation • Typespecs • Using your package • Distributing • Contributing to Elixir Core
  3. Customizing the package -> mix new crazy_pants * creating README.md

    * creating .gitignore * creating mix.exs * creating config * creating config/config.exs * creating lib * creating lib/crazy_pants.ex * creating test * creating test/test_helper.exs * creating test/crazy_pants_test.exs Your Mix project was created successfully. You can use "mix" to compile it, test it, and more: cd crazy_pants mix test Run "mix help" for more commands.
  4. Customizing the package defmodule CrazyPants.Mixfile do use Mix.Project def project

    do [app: :crazy_pants, version: "0.0.1", elixir: "~> 1.2", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, deps: deps] end # Configuration for the OTP application # # Type "mix help compile.app" for more information def application do [applications: [:logger]] end # Dependencies can be Hex packages: # # {:mydep, "~> 0.3.0"} # # Or git/path repositories: # # {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"} # # Type "mix help deps" for more examples and options defp deps do [] end end
  5. Customizing the package defmodule CrazyPants.Mixfile do use Mix.Project def project

    do [app: :crazy_pants, version: "0.0.1", elixir: "~> 1.2", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, package: package(), description: description(), deps: deps] end def package do [maintainers: ["Krazy Kat"], licenses: ["MIT"], links: %{"GitHub" => "https://github.com/whodat/crazy_pants"}] end def description do "These pretzels are making me thirsty" end
  6. defmodule CrazyPants.Mixfile do use Mix.Project def project do [app: :crazy_pants,

    version: "0.0.1", elixir: "~> 1.2", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, package: package(), description: description(), deps: deps] end def package do [maintainers: ["Krazy Kat"], licenses: ["MIT"], links: %{"GitHub" => "https://github.com/whodat/crazy_pants"}] end def description do "These pretzels are making me thirsty" end Customizing the package
  7. Writing good documentation defmodule CrazyPants @moduledoc """ This is the

    greatest library every written """ @doc """ This is the best function ever written """ def drop(location) do "They're at the #{location}” end end
  8. Writing good documentation defp deps do [ {:earmark, "~> 0.1",

    only: :dev}, {:ex_doc, "~> 0.11", only: :dev} ] end
  9. Writing good documentation defmodule CrazyPants.Mixfile do use Mix.Project def project

    do [app: :crazy_pants, version: "0.0.1", elixir: "~> 1.2", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, package: package(), description: description(), deps: deps, docs: [ main: "CrazyPants" ]] end
  10. Writing good documentation defmodule CrazyPants.Mixfile do use Mix.Project def project

    do [app: :crazy_pants, version: "0.0.1", elixir: "~> 1.2", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, package: package(), description: description(), deps: deps, docs: [ main: “CrazyPants”, logo: “crazy_pants.jpg” ]] end
  11. Typespecs defmodule CrazyPants do @moduledoc """ This is the greatest

    library ever written """ @doc """ This is the greatest function ever written """ @spec drop(binary) :: binary def drop(location) do "They're at the #{location}" end end
  12. Typespecs defmodule CrazyPantsTest do use ExUnit.Case test "using numbers" do

    assert CrazyPants.number_drop(1) == "They're at the 1" end end ➜ mix test . Finished in 0.02 seconds (0.02s on load, 0.00s on tests) 1 test, 0 failures
  13. Typespecs defp deps do [{:earmark, "~> 0.1", only: :dev}, {:ex_doc,

    "~> 0.11", only: :dev}, {:dialyxir, "~> 0.3.3", only: :dev}] end ➜ mix dialyzer.plt Starting PLT Core Build ... this will take awhile
  14. Typespecs ➜ mix dialyzer Compiled lib/crazy_pants.ex Starting Dialyzer crazy_pants.ex:15: The

    call 'Elixir.CrazyPants':drop(1) breaks the contract (binary()) -> binary() done in 0m0.80s done (warnings were emitted)
  15. Typespecs defmodule CrazyPants do @moduledoc """ This is the greatest

    library ever written """ @doc """ This is the greatest function ever written """ @spec drop(binary) :: binary def drop(location) do "They're at the #{location}" end def num_drop() do drop(1) end end
  16. Typespecs defmodule CrazyPants do @moduledoc """ This is the greatest

    library ever written """ @doc """ This is the greatest function ever written """ @spec drop(binary) :: binary def drop(location) do "They're at the #{location}" end def num_drop() do 1 |> Integer.to_string() |> drop() end end
  17. Distributing defmodule CrazyPants.Mixfile do use Mix.Project def project do [app:

    :crazy_pants, version: "0.0.1", elixir: "~> 1.2", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, package: package(), description: description(), deps: deps, docs: [ main: “CrazyPants”, logo: “crazy_pants.jpg” ]] end
  18. Distributing ➜ mix hex.publish Publishing crazy_pants 0.0.1 Dependencies: Files: lib/crazy_pants.ex

    mix.exs README.md App: crazy_pants Name: crazy_pants Description: These pretzels are making me thirsty Version: 0.0.1 Build tools: mix Licenses: MIT Maintainers: Krazy Kat Links: GitHub: https://github.com/whodat/crazy_pants Elixir: ~> 1.2 WARNING! Excluded dependencies (not part of the Hex package): earmark ex_doc dialyxir Before publishing, please read Hex Code of Conduct: https://hex.pm/policies/ codeofconduct Proceed? [Yn]
  19. Distributing ➜ mix hex.docs Docs successfully generated. View them at

    "doc/index.html". [#########################] 100% Published docs for crazy_pants 0.0.1 Hosted at https://hexdocs.pm/crazy_pants/0.0.1
  20. Other places to promote your package • reddit.com/r/elixir • elixir-lang-talk

    Google Group • phoenix-talk Google Group • https://elixirstatus.com • Elixir Slack • #elixir-lang IRC