From 3463cd0d371b0f645fee059d13bc15ee19803cf4 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Thu, 9 Mar 2023 09:30:25 +0100 Subject: [PATCH 1/3] refactor: generate document related artifacts to _build/docgen --- apps/emqx_conf/src/emqx_conf.erl | 3 +-- build | 3 ++- rebar.config.erl | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/emqx_conf/src/emqx_conf.erl b/apps/emqx_conf/src/emqx_conf.erl index 00648db31..3da9f0457 100644 --- a/apps/emqx_conf/src/emqx_conf.erl +++ b/apps/emqx_conf/src/emqx_conf.erl @@ -146,8 +146,7 @@ dump_schema(Dir, SchemaModule, I18nFile) -> fun(Lang) -> gen_config_md(Dir, I18nFile, SchemaModule, Lang), gen_api_schema_json(Dir, I18nFile, Lang), - ExampleDir = filename:join(filename:dirname(filename:dirname(I18nFile)), "etc"), - gen_example_conf(ExampleDir, I18nFile, SchemaModule, Lang) + gen_example_conf(Dir, I18nFile, SchemaModule, Lang) end, [en, zh] ), diff --git a/build b/build index de00aba6c..d473f84df 100755 --- a/build +++ b/build @@ -112,9 +112,10 @@ make_docs() { SCHEMA_MODULE='emqx_conf_schema' ;; esac + mkdir -p _build/docgen # shellcheck disable=SC2086 erl -noshell -pa $libs_dir1 $libs_dir2 $libs_dir3 -eval \ - "Dir = filename:join([apps, emqx_dashboard, priv, www, static]), \ + "Dir = filename:join(['_build', docgen]), \ I18nFile = filename:join([apps, emqx_dashboard, priv, 'i18n.conf']), \ ok = emqx_conf:dump_schema(Dir, $SCHEMA_MODULE, I18nFile), \ halt(0)." diff --git a/rebar.config.erl b/rebar.config.erl index 9d9b0f874..c64f3dda2 100644 --- a/rebar.config.erl +++ b/rebar.config.erl @@ -462,7 +462,7 @@ etc_overlay(ReleaseType, Edition) -> [ {mkdir, "etc/"}, {copy, "{{base_dir}}/lib/emqx/etc/certs", "etc/"}, - {copy, "apps/emqx_dashboard/etc/emqx.conf.en.example", "etc/emqx-example.conf"} + {copy, "_build/docgen/emqx.conf.en.example", "etc/emqx.conf.example"} ] ++ lists:map( fun From 1264254f23543095f2efb4c71ab16576c79b989b Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Thu, 9 Mar 2023 14:26:47 +0100 Subject: [PATCH 2/3] build: release hot config and bridge schema json files --- build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build b/build index d473f84df..f18d41ef6 100755 --- a/build +++ b/build @@ -112,13 +112,15 @@ make_docs() { SCHEMA_MODULE='emqx_conf_schema' ;; esac - mkdir -p _build/docgen + mkdir -p _build/docgen apps/emqx_dashboard/priv/www/static/ # shellcheck disable=SC2086 erl -noshell -pa $libs_dir1 $libs_dir2 $libs_dir3 -eval \ "Dir = filename:join(['_build', docgen]), \ I18nFile = filename:join([apps, emqx_dashboard, priv, 'i18n.conf']), \ ok = emqx_conf:dump_schema(Dir, $SCHEMA_MODULE, I18nFile), \ halt(0)." + cp _build/docgen/bridge-api-*.json apps/emqx_dashboard/priv/www/static/ + cp _build/docgen/hot-config-schema-*.json apps/emqx_dashboard/priv/www/static/ } assert_no_compile_time_only_deps() { From ab4b3dd60aa413e61208dc1c6c6a9c799d806ad8 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Thu, 9 Mar 2023 15:33:13 +0100 Subject: [PATCH 3/3] build: generate docs per profile --- build | 15 ++++++++------- mix.exs | 6 ++++-- rebar.config.erl | 6 +++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/build b/build index f18d41ef6..76298f1ab 100755 --- a/build +++ b/build @@ -92,7 +92,7 @@ log() { } make_docs() { - local libs_dir1 libs_dir2 libs_dir3 + local libs_dir1 libs_dir2 libs_dir3 docdir dashboard_www_static libs_dir1="$("$FIND" "_build/$PROFILE/lib/" -maxdepth 2 -name ebin -type d)" if [ -d "_build/default/lib/" ]; then libs_dir2="$("$FIND" "_build/default/lib/" -maxdepth 2 -name ebin -type d)" @@ -112,15 +112,16 @@ make_docs() { SCHEMA_MODULE='emqx_conf_schema' ;; esac - mkdir -p _build/docgen apps/emqx_dashboard/priv/www/static/ + docdir="_build/docgen/$PROFILE" + dashboard_www_static='apps/emqx_dashboard/priv/www/static/' + mkdir -p "$docdir" "$dashboard_www_static" # shellcheck disable=SC2086 erl -noshell -pa $libs_dir1 $libs_dir2 $libs_dir3 -eval \ - "Dir = filename:join(['_build', docgen]), \ - I18nFile = filename:join([apps, emqx_dashboard, priv, 'i18n.conf']), \ - ok = emqx_conf:dump_schema(Dir, $SCHEMA_MODULE, I18nFile), \ + "I18nFile = filename:join([apps, emqx_dashboard, priv, 'i18n.conf']), \ + ok = emqx_conf:dump_schema('$docdir', $SCHEMA_MODULE, I18nFile), \ halt(0)." - cp _build/docgen/bridge-api-*.json apps/emqx_dashboard/priv/www/static/ - cp _build/docgen/hot-config-schema-*.json apps/emqx_dashboard/priv/www/static/ + cp "$docdir"/bridge-api-*.json "$dashboard_www_static" + cp "$docdir"/hot-config-schema-*.json "$dashboard_www_static" } assert_no_compile_time_only_deps() { diff --git a/mix.exs b/mix.exs index 33828d11f..4153b1074 100644 --- a/mix.exs +++ b/mix.exs @@ -373,9 +373,11 @@ defmodule EMQXUmbrella.MixProject do Path.join(etc, "certs") ) + profile = System.get_env("MIX_ENV") + Mix.Generator.copy_file( - "apps/emqx_dashboard/etc/emqx.conf.en.example", - Path.join(etc, "emqx-example.conf"), + "_build/docgen/#{profile}/emqx.conf.en.example", + Path.join(etc, "emqx.conf.example"), force: overwrite? ) diff --git a/rebar.config.erl b/rebar.config.erl index c64f3dda2..bf6d8cee0 100644 --- a/rebar.config.erl +++ b/rebar.config.erl @@ -462,7 +462,8 @@ etc_overlay(ReleaseType, Edition) -> [ {mkdir, "etc/"}, {copy, "{{base_dir}}/lib/emqx/etc/certs", "etc/"}, - {copy, "_build/docgen/emqx.conf.en.example", "etc/emqx.conf.example"} + {copy, "_build/docgen/" ++ name(Edition) ++ "/emqx.conf.en.example", + "etc/emqx.conf.example"} ] ++ lists:map( fun @@ -598,3 +599,6 @@ list_dir(Dir) -> false -> [] end. + +name(ce) -> "emqx"; +name(ee) -> "emqx-enterprise".