Skip to content
Browse files

Created mix publish task.

  • Loading branch information...
1 parent 2c7c8ab commit 56f26d936360158614c4190d829e5a43ed5d85d2 @jjh42 jjh42 committed Jun 17, 2013
Showing with 68 additions and 0 deletions.
  1. +62 −0 lib/publish_task.ex
  2. +6 −0 test/repository_auth_test.exs
View
62 lib/publish_task.ex
@@ -0,0 +1,62 @@
+defmodule Mix.Tasks.Publish do
+ use Mix.Task
+
+ @shortdoc """
+ Publish your project on expm.
+ """
+
+ @moduledoc """
+ Publish your project on expm.
+
+ ## Options
+
+ `--repository url`
+
+ By default, this is [https://expm.co/](https://expm.co/)
+
+ `--username USER` and `--password PASSWORD`
+
+ If not available, uses config file.
+ """
+
+ # Get the repo - finding authentication from config file
+ # if not available elsewhere.
+ defp get_repo(opts) do
+ url = opts[:repository] || "https://expm.co"
+ Expm.Repository.HTTP.new(url: url,
+ username: opts[:username], password: opts[:password])
+ end
+
+ # Update options based on the configuration file
+ defp read_config(opts) do
+ config_opts = [:username, :password]
+ update_config(opts, config_opts)
+ end
+
+ defp update_config(opts, []), do: opts
+ defp update_config(opts, [key|t]) do
+ if opts[key] == nil do
+ opts = Keyword.put opts, key, Expm.UserConfig.get key
+ end
+ update_config(opts, t)
+ end
+
+ def run(args) do
+ { opts, [] } = OptionParser.parse(args)
+ opts = read_config(opts)
+ Application.Behaviour.start :expm
+ publish get_repo(opts)
+ end
+
+ def publish(repo) do
+ proj = Mix.project
+ package = Expm.Package.new(name: atom_to_binary(proj[:app]),
+ version: proj[:version],
+ description: proj[:description],
+ keywords: proj[:keywords],
+ maintainers: proj[:maintainers],
+ repositories: proj[:repositories]
+ )
+ Expm.Package.publish repo, package
+ end
+end
View
6 test/repository_auth_test.exs
@@ -16,6 +16,12 @@ defmodule Expm.Test.Repository.Auth do
assert package.metadata[:published_by] == "user"
end
+ test "uploading a new package with mix", data do
+ auth = Expm.Repository.Auth.new(repository: data[:repo], username: "user", auth_token: "password")
+ package = Mix.Tasks.Publish.publish(auth)
+ assert package.metadata[:published_by] == "user"
+ end
+
test "uploading a package with the same version", data do
package = Expm.Package.new(name: "test", version: "0.1")
auth = Expm.Repository.Auth.new(repository: data[:repo], username: "user", auth_token: "password")

0 comments on commit 56f26d9

Please sign in to comment.
Something went wrong with that request. Please try again.