Skip to content

Commit

Permalink
build: 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
javiergarea committed Jan 10, 2024
1 parent 61d48a7 commit e1e0b48
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: rebar3_ndto ci
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

env:
OTP-VERSION: 25.2.3
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# rebar3_ndto
![rebar3_ndto ci](https://github.com/nomasystems/rebar3_ndto/actions/workflows/ci.yml/badge.svg)
![CI](https://github.com/nomasystems/rebar3_ndto/actions/workflows/ci.yml/badge.svg)

A rebar3 plugin for the automatic generation of [`ndto`](https://github.com/nomasystems/ndto) modules.

Expand All @@ -8,7 +8,7 @@ A rebar3 plugin for the automatic generation of [`ndto`](https://github.com/noma
To use `rebar3_ndto` in your project, you need to declare it in the `plugins` section of your `rebar.config` file:
```erl
{plugins, [
{rebar3_ndto, {git, "https://github.com/nomasystems/rebar3_ndto.git", {branch, "main"}}}
{rebar3_ndto, {git, "https://github.com/nomasystems/rebar3_ndto.git", {tag, "0.2.0"}}}
]}.
```

Expand All @@ -26,7 +26,7 @@ Finally, configure the plugin's option under the `ndto` key:
```erl
{ndto, [
{output_dir, "foo/foo_output_dir/"}, % defaults to "_gen/dtos"
{parser, foo_parser}, % defaults to ndto_parser_json_schema_draft_04
{parser, foo_parser}, % defaults to ndto_parser_json_schema_draft
{specs, [
"foo/specs/foo.json", % uses default options
{"foo/bar/specs/foo_bar.json", [
Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{erl_opts, [warnings_as_errors]}.

{deps, [
{ndto, {git, "[email protected]:nomasystems/ndto.git", {branch, "main"}}}
{ndto, {git, "[email protected]:nomasystems/ndto.git", {tag, "0.2.0"}}}
]}.

{project_plugins, [
Expand Down
4 changes: 2 additions & 2 deletions rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
1},
{<<"ndto">>,
{git,"[email protected]:nomasystems/ndto.git",
{ref,"48941b5b29498d45bfbb9c6d05c18ec17c66e051"}},
{ref,"02890286d8846f6e0449b815b2d494edb4a9fa8f"}},
0},
{<<"njson">>,
{git,"[email protected]:nomasystems/njson.git",
{ref,"76ab40033ee977f876e7b3addca5de981ff4a9ef"}},
{ref,"b230b3e6fb5e35320aeaa203762f3f12277c9970"}},
1}].
2 changes: 1 addition & 1 deletion src/rebar3_ndto.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, rebar3_ndto, [
{description, "A rebar3 plugin for the automatic generation of ndto modules."},
{vsn, "0.1.0"},
{vsn, "0.2.0"},
{registered, []},
{applications, [kernel, stdlib, ndto]},
{env, []}
Expand Down
17 changes: 7 additions & 10 deletions src/rebar3_ndto.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

%%% MACROS
-define(DEFAULT_OUTPUT_DIR, "_gen/dtos").
-define(DEFAULT_PARSER, ndto_parser_json_schema_draft_04).
-define(DEFAULT_PARSER, ndto_parser_json_schema).

%%%-----------------------------------------------------------------------------
%%% INIT/STOP EXPORTS
Expand Down Expand Up @@ -89,13 +89,10 @@ clean(AppInfo, State) ->
%%% INTERNAL FUNCTIONS
%%%-----------------------------------------------------------------------------
compile(AppDir, OutputDir, Parser, RawSpec) ->
Spec = filename:join(AppDir, RawSpec),
Basename = filename:basename(Spec),
Extension = filename:extension(Basename),
Namespace = erlang:list_to_atom(string:trim(Basename, trailing, Extension)),
case ndto_parser:parse(Parser, Namespace, Spec) of
SpecPath = unicode:characters_to_binary(filename:join(AppDir, RawSpec)),
case ndto_parser:parse(Parser, SpecPath) of
{error, Reason} ->
rebar_utils:abort("[rebar3_ndto] Failed parsing ~s spec: ~p\n", [Spec, Reason]);
rebar_utils:abort("[rebar3_ndto] Failed parsing ~s spec: ~p\n", [SpecPath, Reason]);
{ok, Schemas} ->
case filelib:ensure_path(OutputDir) of
{error, Reason} ->
Expand All @@ -104,10 +101,10 @@ compile(AppDir, OutputDir, Parser, RawSpec) ->
]);
ok ->
lists:foreach(
fun({Name, Schema}) ->
DTO = ndto:generate(Name, Schema),
fun({SchemaName, Schema}) ->
DTO = ndto:generate(SchemaName, Schema),
OutputFile = filename:join(
OutputDir, erlang:atom_to_list(Name) ++ ".erl"
OutputDir, erlang:atom_to_list(SchemaName) ++ ".erl"
),
case ndto:write(DTO, OutputFile) of
{error, Reason} ->
Expand Down

0 comments on commit e1e0b48

Please sign in to comment.