Skip to content

Commit

Permalink
Move generated files into a new index directory (#57)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Jan 3, 2025
1 parent ad0b7a4 commit 80912bf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/enterprise/enterprise_explorer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static auto explorer_end(std::ostringstream &html,

static auto file_manager(std::ostringstream &html,
const std::filesystem::path &directory) -> void {
const auto meta_path{directory / ".meta.json"};
const auto meta_path{directory / "index.json"};
assert(std::filesystem::exists(meta_path));
const auto meta{sourcemeta::jsontoolkit::from_file(meta_path)};

Expand Down
13 changes: 6 additions & 7 deletions src/enterprise/enterprise_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ auto generate_toc(const sourcemeta::jsontoolkit::JSON &configuration,
assert(directory.string().starts_with(base.string()));
auto entries{sourcemeta::jsontoolkit::JSON::make_array()};

assert(configuration.is_object());
assert(configuration.defines("schemas"));
assert(configuration.at("schemas").is_object());

for (const auto &entry : std::filesystem::directory_iterator{directory}) {
auto entry_json{sourcemeta::jsontoolkit::JSON::make_object()};
entry_json.assign("name",
Expand Down Expand Up @@ -128,9 +124,12 @@ auto generate_toc(const sourcemeta::jsontoolkit::JSON &configuration,
result.at("breadcrumb").push_back(std::move(breadcrumb_entry));
}

const auto meta_path{directory / ".meta.json"};
std::cerr << "Saving into: " << meta_path.string() << "\n";
std::ofstream stream{meta_path};
const auto index_path{base.parent_path() / "generated" /
std::filesystem::relative(directory, base) /
"index.json"};
std::cerr << "Saving into: " << index_path.string() << "\n";
std::filesystem::create_directories(index_path.parent_path());
std::ofstream stream{index_path};
assert(!stream.fail());
sourcemeta::jsontoolkit::prettify(result, stream);
stream << "\n";
Expand Down
10 changes: 5 additions & 5 deletions src/enterprise/enterprise_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ auto on_index(const sourcemeta::hydra::http::ServerLogger &,
static const auto SERVER_TITLE{configuration().at("title").to_string()};
static const auto SERVER_DESCRIPTION{
configuration().at("description").to_string()};
static const auto SCHEMAS_BASE_DIRECTORY{*(__global_data) / "schemas"};
static const auto GENERATED_BASE_DIRECTORY{*(__global_data) / "generated"};
explore_index(SERVER_TITLE, SERVER_TITLE, SERVER_DESCRIPTION, SERVER_BASE_URL,
SCHEMAS_BASE_DIRECTORY, request, response);
GENERATED_BASE_DIRECTORY, request, response);
}

auto on_request(const sourcemeta::hydra::http::ServerLogger &logger,
Expand All @@ -44,9 +44,9 @@ auto on_request(const sourcemeta::hydra::http::ServerLogger &logger,
static const auto SERVER_TITLE{configuration().at("title").to_string()};

// Explorer
static const auto SCHEMAS_BASE_DIRECTORY{*(__global_data) / "schemas"};
const auto directory_path{
sourcemeta::registry::path_join(SCHEMAS_BASE_DIRECTORY, request.path())};
static const auto GENERATED_BASE_DIRECTORY{*(__global_data) / "generated"};
const auto directory_path{sourcemeta::registry::path_join(
GENERATED_BASE_DIRECTORY, request.path())};
if (std::filesystem::is_directory(directory_path)) {
static const auto SERVER_BASE_URL{configuration().at("url").to_string()};
explore_directory(SERVER_TITLE, directory_path, SERVER_BASE_URL, request,
Expand Down
21 changes: 14 additions & 7 deletions test/sandbox/manifest-ee.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
./configuration.json
./generated
./generated/doc
./generated/doc/index.json
./generated/example
./generated/example/bundling
./generated/example/bundling/index.json
./generated/example/extension
./generated/example/extension/index.json
./generated/example/index.json
./generated/example/schemas
./generated/example/schemas/index.json
./generated/example/v2.0
./generated/example/v2.0/index.json
./generated/index.json
./schemas
./schemas/.meta.json
./schemas/doc
./schemas/doc/.meta.json
./schemas/doc/string-1.json
./schemas/example
./schemas/example/.meta.json
./schemas/example/bundling
./schemas/example/bundling/.meta.json
./schemas/example/bundling/single.json
./schemas/example/extension
./schemas/example/extension/.meta.json
./schemas/example/extension/with.schema.json
./schemas/example/schemas
./schemas/example/schemas/.meta.json
./schemas/example/schemas/camelcase.json
./schemas/example/schemas/string.json
./schemas/example/v2.0
./schemas/example/v2.0/.meta.json
./schemas/example/v2.0/schema.json

0 comments on commit 80912bf

Please sign in to comment.