~sjm/notesviz_files

b8b8ea4db7d92196a695008685c6b4a8db40d44d — Sam Marshall 2 years ago f1d1c81
add initial app, including a few file fns
A .formatter.exs => .formatter.exs +4 -0
@@ 0,0 1,4 @@
# Used by "mix format"
[
  inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

A .gitignore => .gitignore +27 -0
@@ 0,0 1,27 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
notesviz_files-*.tar


# Temporary files for e.g. tests
/tmp

A README.md => README.md +21 -0
@@ 0,0 1,21 @@
# NotesvizFiles

**TODO: Add description**

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `notesviz_files` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:notesviz_files, "~> 0.1.0"}
  ]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/notesviz_files](https://hexdocs.pm/notesviz_files).


A lib/notesviz_files.ex => lib/notesviz_files.ex +18 -0
@@ 0,0 1,18 @@
defmodule NotesvizFiles do
  @moduledoc """
  Documentation for `NotesvizFiles`.
  """

  @doc """
  Hello world.

  ## Examples

      iex> NotesvizFiles.hello()
      :world

  """
  def hello do
    :world
  end
end

A lib/notesviz_files/application.ex => lib/notesviz_files/application.ex +20 -0
@@ 0,0 1,20 @@
defmodule NotesvizFiles.Application do
  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  @moduledoc false

  use Application

  @impl true
  def start(_type, _args) do
    children = [
      # Starts a worker by calling: NotesvizFiles.Worker.start_link(arg)
      # {NotesvizFiles.Worker, arg}
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: NotesvizFiles.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

A lib/notesviz_files/files.ex => lib/notesviz_files/files.ex +26 -0
@@ 0,0 1,26 @@
defmodule NotesvizFiles.Files do

  def files(dir) do
    case File.dir?(dir) do
      true -> list_files(dir)
      false -> {:error, :input_not_dir}
    end
  end

  def metadata(file) do
    File.stat(file)
  end

  defp list_files(dir) do
    case File.ls(dir) do
      {:ok, paths} ->
        {:ok,
         paths
         |> Enum.map(fn i -> Path.expand(i, dir) end)
         |> Enum.filter(fn i -> !File.dir?(i) end)}

      {:err, reason} ->
        {:err, reason}
    end
  end
end

A mix.exs => mix.exs +29 -0
@@ 0,0 1,29 @@
defmodule NotesvizFiles.MixProject do
  use Mix.Project

  def project do
    [
      app: :notesviz_files,
      version: "0.1.0",
      elixir: "~> 1.11",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger],
      mod: {NotesvizFiles.Application, []}
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      # {:dep_from_hexpm, "~> 0.3.0"},
      # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
    ]
  end
end

A test/notesviz_files_test.exs => test/notesviz_files_test.exs +8 -0
@@ 0,0 1,8 @@
defmodule NotesvizFilesTest do
  use ExUnit.Case
  doctest NotesvizFiles

  test "greets the world" do
    assert NotesvizFiles.hello() == :world
  end
end

A test/test_helper.exs => test/test_helper.exs +1 -0
@@ 0,0 1,1 @@
ExUnit.start()