#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, Collection* collection, const std::shared_ptr& logger ); Type getType() const; State getState() const; std::filesystem::path getLocation() const; std::string getLibrariesPath() const; bool successfullyRead() const; bool successfullyBuilt() 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 buildAsDirectory(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); void copyFile(const std::filesystem::path& from, const std::filesystem::path& to) const; void masonFilesArray(const nlohmann::json& files, const std::filesystem::path& destination); bool allowedForTarget(const nlohmann::json& object, const std::string& target) const; std::optional getFileSource(const nlohmann::json& object) const; std::optional getFileTarget(const nlohmann::json& object) const; static std::optional tryStringValue (const nlohmann::json& object, const std::string& key); private: State state; Type type; Collection* 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); };