chore(script): split-config optimize include position (#4322)
This commit is contained in:
parent
f7b34cb098
commit
d54410e560
|
@ -16,10 +16,13 @@ main(_) ->
|
||||||
{ok, Bin} = file:read_file("etc/emqx.conf"),
|
{ok, Bin} = file:read_file("etc/emqx.conf"),
|
||||||
Lines = binary:split(Bin, <<"\n">>, [global]),
|
Lines = binary:split(Bin, <<"\n">>, [global]),
|
||||||
Sections0 = parse_sections(Lines),
|
Sections0 = parse_sections(Lines),
|
||||||
Sections = lists:filter(fun({<<"modules">>, _}) -> false;
|
{value, _, Sections1} = lists:keytake(<<"modules">>, 1, Sections0),
|
||||||
(_) -> true
|
{value, {N, Base}, Sections2} = lists:keytake(<<"emqx">>, 1, Sections1),
|
||||||
end, Sections0),
|
IncludeNames = proplists:get_keys(Sections2),
|
||||||
ok = dump_sections(Sections).
|
Includes = lists:map(fun(Name) ->
|
||||||
|
iolist_to_binary(["include {{ platform_etc_dir }}/", Name, ".conf"])
|
||||||
|
end, IncludeNames),
|
||||||
|
ok = dump_sections([{N, Base ++ Includes}| Sections2]).
|
||||||
|
|
||||||
parse_sections(Lines) ->
|
parse_sections(Lines) ->
|
||||||
{ok, P} = re:compile("#+\s*CONFIG_SECTION_(BGN|END)\s*=\s*([^\s-]+)\s*="),
|
{ok, P} = re:compile("#+\s*CONFIG_SECTION_(BGN|END)\s*=\s*([^\s-]+)\s*="),
|
||||||
|
@ -42,9 +45,7 @@ parse_sections([Line | Lines], Parse, Section, Sections) ->
|
||||||
?BASE = Section, %% assert
|
?BASE = Section, %% assert
|
||||||
true = (Name =/= ?BASE), %% assert
|
true = (Name =/= ?BASE), %% assert
|
||||||
false = maps:is_key(Name, Sections), %% assert
|
false = maps:is_key(Name, Sections), %% assert
|
||||||
Include = iolist_to_binary(["include {{ platform_etc_dir }}/", Name, ".conf"]),
|
NewSections = Sections#{?BASE := maps:get(?BASE, Sections), Name => []},
|
||||||
Base = maps:get(?BASE, Sections),
|
|
||||||
NewSections = Sections#{?BASE := [Include | Base], Name => []},
|
|
||||||
parse_sections(Lines, Parse, Name, NewSections);
|
parse_sections(Lines, Parse, Name, NewSections);
|
||||||
{section_end, Name} ->
|
{section_end, Name} ->
|
||||||
true = (Name =:= Section), %% assert
|
true = (Name =:= Section), %% assert
|
||||||
|
|
Loading…
Reference in New Issue