From b8b8ea4db7d92196a695008685c6b4a8db40d44d Mon Sep 17 00:00:00 2001 From: Sam Marshall Date: Sun, 29 Nov 2020 19:23:12 +0000 Subject: [PATCH] add initial app, including a few file fns --- .formatter.exs | 4 ++++ .gitignore | 27 +++++++++++++++++++++++++++ README.md | 21 +++++++++++++++++++++ lib/notesviz_files.ex | 18 ++++++++++++++++++ lib/notesviz_files/application.ex | 20 ++++++++++++++++++++ lib/notesviz_files/files.ex | 26 ++++++++++++++++++++++++++ mix.exs | 29 +++++++++++++++++++++++++++++ test/notesviz_files_test.exs | 8 ++++++++ test/test_helper.exs | 1 + 9 files changed, 154 insertions(+) create mode 100644 .formatter.exs create mode 100644 .gitignore create mode 100644 README.md create mode 100644 lib/notesviz_files.ex create mode 100644 lib/notesviz_files/application.ex create mode 100644 lib/notesviz_files/files.ex create mode 100644 mix.exs create mode 100644 test/notesviz_files_test.exs create mode 100644 test/test_helper.exs diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a366f0b --- /dev/null +++ b/.gitignore @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..3e19056 --- /dev/null +++ b/README.md @@ -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). + diff --git a/lib/notesviz_files.ex b/lib/notesviz_files.ex new file mode 100644 index 0000000..37facc4 --- /dev/null +++ b/lib/notesviz_files.ex @@ -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 diff --git a/lib/notesviz_files/application.ex b/lib/notesviz_files/application.ex new file mode 100644 index 0000000..a4858f9 --- /dev/null +++ b/lib/notesviz_files/application.ex @@ -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 diff --git a/lib/notesviz_files/files.ex b/lib/notesviz_files/files.ex new file mode 100644 index 0000000..06c3136 --- /dev/null +++ b/lib/notesviz_files/files.ex @@ -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 diff --git a/mix.exs b/mix.exs new file mode 100644 index 0000000..4bb6a5a --- /dev/null +++ b/mix.exs @@ -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 diff --git a/test/notesviz_files_test.exs b/test/notesviz_files_test.exs new file mode 100644 index 0000000..135b9ea --- /dev/null +++ b/test/notesviz_files_test.exs @@ -0,0 +1,8 @@ +defmodule NotesvizFilesTest do + use ExUnit.Case + doctest NotesvizFiles + + test "greets the world" do + assert NotesvizFiles.hello() == :world + end +end diff --git a/test/test_helper.exs b/test/test_helper.exs new file mode 100644 index 0000000..869559e --- /dev/null +++ b/test/test_helper.exs @@ -0,0 +1 @@ +ExUnit.start() -- 2.45.2