#pragma once #include #include #include #include #include #include #include #include #include #include #include "loggable.h" #include "loggger.h" class Collection; class Component : protected Loggable { public: class WrongState; class WrongType; enum State { initial, reading, ready, building, error, done }; enum Type { file, directory, mason, unknown }; Component( const std::filesystem::path& path, const std::weak_ptr& collection, const std::shared_ptr& logger ); Type getType() const; State getState() const; std::filesystem::path getLocation() const; std::string getLibrariesPath() const; bool successfullyRead() const; void read(); void build(const std::filesystem::path& destination, const std::string& target); private: void tryReadingBuildScenarios(); bool readAsMason(); bool errorScenario(const std::string& message); void buildAsFile(const std::filesystem::path& destination); void buildAsDiractory(const std::filesystem::path& destination); void buildAsMason(const std::filesystem::path& destination, const std::string& target); bool readMasonDependencies(const nlohmann::json& deps, const std::string& manifestPath); private: State state; Type type; std::weak_ptr collection; std::filesystem::path location; std::optional manifest; }; class Component::WrongState : public std::runtime_error { public: explicit WrongState(State state, const std::string& action); }; class Component::WrongType : public std::runtime_error { public: explicit WrongType(Type type, const std::string& action); };