Skip to content

Commit d013b5a

Browse files
committed
Added environment configs. Added lib_path configuration
1 parent 81da83b commit d013b5a

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

config/config.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ use Mix.Config
1515
format: "$date $time [$level] $metadata$message\n",
1616
metadata: [:user_id]
1717

18+
config :elixir_script,
19+
lib_path: nil #The path to the elixirscript core and standard library JavaScript files
1820
# It is also possible to import configuration files, relative to this
1921
# directory. For example, you can emulate configuration per environment
2022
# by uncommenting the line below and defining dev.exs, test.exs and such.
2123
# Configuration from the imported file will override the ones defined
2224
# here (which is why it is important to import them last).
2325
#
24-
# import_config "#{Mix.env}.exs"
26+
import_config "#{Mix.env}.exs"

config/dev.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use Mix.Config

config/prod.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use Mix.Config

config/test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use Mix.Config

lib/elixir_script.ex

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ defmodule ElixirScript do
4545
# This is the serialized state of the ElixirScript.State module containing references to the standard library
4646
@external_resource stdlib_state_path = Path.join([__DIR__, "elixir_script", "translator", "stdlib_state.bin"])
4747
@stdlib_state File.read!(stdlib_state_path)
48+
@lib_path Application.get_env(:elixir_script, :lib_path)
4849

4950
@doc """
5051
Compiles the given Elixir code string
@@ -71,6 +72,7 @@ defmodule ElixirScript do
7172
@spec compile_path(binary, Map.t) :: [binary | {binary, binary} | :ok]
7273
def compile_path(path, opts \\ %{}) do
7374
expanded_path = Path.wildcard(path)
75+
opts = build_compiler_options(opts)
7476

7577
compiler_cache = get_compiler_cache(path, opts)
7678

@@ -335,14 +337,20 @@ end
335337
#Gets path to js files whether the mix project is available
336338
#or when used as an escript
337339
defp operating_path do
338-
try do
339-
Mix.Project.build_path <> "/lib/elixir_script/priv"
340-
rescue
341-
UndefinedFunctionError ->
342-
split_path = Path.split(Application.app_dir(:elixirscript))
343-
replaced_path = List.delete_at(split_path, length(split_path) - 1)
344-
replaced_path = List.delete_at(replaced_path, length(replaced_path) - 1)
345-
Path.join(replaced_path)
340+
case @lib_path do
341+
nil ->
342+
try do
343+
Mix.Project.build_path <> "/lib/elixir_script/priv"
344+
rescue
345+
UndefinedFunctionError ->
346+
split_path = Path.split(Application.app_dir(:elixirscript))
347+
replaced_path = List.delete_at(split_path, length(split_path) - 1)
348+
replaced_path = List.delete_at(replaced_path, length(replaced_path) - 1)
349+
Path.join(replaced_path)
350+
end
351+
lib_path ->
352+
lib_path
346353
end
347354
end
355+
348356
end

0 commit comments

Comments
 (0)