Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow generating --dev projects outside Phoenix source #1224

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ $ mix phoenix.new path/to/your/app --dev

The command above will create a new application, using your current Phoenix checkout thanks to the `--dev` flag.

Note that `path/to/your/app` must be within the directory containing the Phoenix source code. This is so that a relative path can be used for the `:phoenix` dependency.

### Building phoenix.js

```bash
Expand Down
24 changes: 3 additions & 21 deletions installer/lib/phoenix_new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ defmodule Mix.Tasks.Phoenix.New do
ecto = Keyword.get(opts, :ecto, true)
html = Keyword.get(opts, :html, true)
brunch = Keyword.get(opts, :brunch, true)
phoenix_path = phoenix_path(path, Keyword.get(opts, :dev, false))
phoenix_path = phoenix_path(Keyword.get(opts, :dev, false))

# We lowercase the database name because according to the
# SQL spec, they are case insensitive unless quoted, which
Expand All @@ -182,7 +182,6 @@ defmodule Mix.Tasks.Phoenix.New do
application_module: mod,
phoenix_dep: phoenix_dep(phoenix_path),
phoenix_path: phoenix_path,
phoenix_static_path: phoenix_static_path(phoenix_path),
pubsub_server: pubsub_server,
secret_key_base: random_string(64),
prod_secret_key_base: random_string(64),
Expand Down Expand Up @@ -462,26 +461,9 @@ defmodule Mix.Tasks.Phoenix.New do
defp phoenix_dep("deps/phoenix"), do: ~s[{:phoenix, "~> 1.0.2"}]
defp phoenix_dep(path), do: ~s[{:phoenix, path: #{inspect path}, override: true}]

defp phoenix_static_path("deps/phoenix"), do: "deps/phoenix"
defp phoenix_static_path(path), do: Path.join("..", path)

defp phoenix_path(path, true) do
absolute = Path.expand(path)
relative = Path.relative_to(absolute, @phoenix)

if absolute == relative do
Mix.raise "--dev project must be inside Phoenix directory"
end

relative
|> Path.split
|> Enum.map(fn _ -> ".." end)
|> Path.join
end

defp phoenix_path(_path, false) do
"deps/phoenix"
end
defp phoenix_path(true), do: @phoenix
defp phoenix_path(false), do: "deps/phoenix"

## Template helpers

Expand Down
2 changes: 1 addition & 1 deletion installer/templates/static/brunch/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// To use Phoenix channels, the first step is to import Socket
// and connect at the socket path in "lib/my_app/endpoint.ex":
import {Socket} from "<%= static_deps_prefix %><%= phoenix_static_path %>/web/static/js/phoenix"
import {Socket} from "<%= static_deps_prefix %><%= phoenix_path %>/web/static/js/phoenix"

let socket = new Socket("/socket")

Expand Down
13 changes: 13 additions & 0 deletions installer/test/phoenix_new_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ defmodule Mix.Tasks.Phoenix.NewTest do

assert_file "photo_blog/README.md"
assert_file "photo_blog/mix.exs", fn file ->
assert file =~ "[{:phoenix, \"~> "
assert file =~ "app: :photo_blog"
refute file =~ "deps_path: \"../../deps\""
refute file =~ "lockfile: \"../../mix.lock\""
Expand Down Expand Up @@ -338,6 +339,18 @@ defmodule Mix.Tasks.Phoenix.NewTest do
end
end

test "new with --dev" do
in_tmp "new with --dev", fn ->
Mix.Tasks.Phoenix.New.run([@app_name, "--dev"])

assert_file "photo_blog/mix.exs", fn file ->
path = Path.expand("../..", __DIR__)
assert file =~ "{:phoenix, path: \"#{path}\", override: true},"
end
end
end


test "new defaults to pg adapter" do
in_tmp "new defaults to pg adapter", fn ->
project_path = Path.join(File.cwd!, "custom_path")
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"repository": {
},
"dependencies": {
"brunch": "^1.8.1",
"brunch": "^1.8.5",
"babel-brunch": "^5.1.1",
"clean-css-brunch": ">= 1.0 < 1.8",
"css-brunch": ">= 1.0 < 1.8",
Expand Down