diff --git a/include/Frate/Lua/LuaAPI.hpp b/include/Frate/Lua/LuaAPI.hpp index e65c1ed..9fbd116 100644 --- a/include/Frate/Lua/LuaAPI.hpp +++ b/include/Frate/Lua/LuaAPI.hpp @@ -22,41 +22,9 @@ namespace Frate::Lua { static std::string format(const std::string &str, sol::table in_table, sol::this_state s); - static void print_table(sol::table in_table); static std::string fetch_text(const std::string &url); static sol::table fetch_json(const std::string &url, sol::this_state lua); }; - /* - * Registers the project scripts with the project that is specifed - */ - [[deprecated("Use TemplateEnvironment")]] - bool registerProjectScripts(inja::Environment &env, sol::state &lua, - path script_path, - std::shared_ptr project); - - /* - * Registers the project with the user types for the project struct - */ - [[deprecated("Use TemplateEnvironment")]] - bool registerProject(sol::state &lua, std::shared_ptr pro); - /* - * Registers api functions for the lua state - * and initializes the lua state - */ - [[deprecated("Use TemplateEnvironment")]] - void registerAPI(sol::state &lua); - - /* - * Runs __init__ scripts - */ - [[deprecated("Use TemplateEnvironment")]] - bool initScripts(sol::state &lua, std::shared_ptr project); - - /* - * Runs __post__ scripts - */ - [[deprecated("Use TemplateEnvironment")]] - bool postScripts(sol::state &lua, std::shared_ptr project); } // namespace Frate::Lua diff --git a/include/Frate/Project/Local.hpp b/include/Frate/Project/Local.hpp index 3dfce82..fbcbbb0 100644 --- a/include/Frate/Project/Local.hpp +++ b/include/Frate/Project/Local.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include #include +#include +#include namespace Frate::Project { @@ -9,7 +9,8 @@ namespace Frate::Project { class OverrideHashException : public FrateException { public: - OverrideHashException(const std::string &message) : FrateException(message) {} + OverrideHashException(const std::string &message) + : FrateException(message) {} }; class LocalIOException : public FrateException { @@ -18,28 +19,32 @@ namespace Frate::Project { }; class Config; + class Local { private: - std::string build_command{"cmake -build ."}; - std::string test_command{"ctest"}; - std::string run_command{"./bin/"}; + std::string build_command; + std::string test_command; + std::string run_command; + std::string build_mode; int requested_jobs{1}; int max_jobs{1}; std::string override_change_hash{}; - std::shared_ptr config; - void create_local_file(); + std::shared_ptr project; bool local_file_loaded = false; + void create_local_file(); + void gen_default_build_command(); + void gen_default_test_command(); + void gen_default_run_command(); public: Local() = default; - Local(std::shared_ptr config) : config(config) {} - // Getters - std::string &getBuildCommand() { return build_command; } + Local(std::shared_ptr config) : project(config) {} - std::string &getTestCommand() { return test_command; } - - std::string &getRunCommand() { return run_command; } + // Getters + std::string &getBuildCommand(); + std::string &getTestCommand(); + std::string &getRunCommand(); std::string &getOverrideChangeHash() { return override_change_hash; } @@ -47,32 +52,40 @@ namespace Frate::Project { int &getMaxJobs() { return max_jobs; } + std::string &getBuildMode() { return build_mode; } + + std::string getProjectPath(); + // Setters - void setBuildCommand(const std::string &build_command) { + void setBuildCommand(std::string build_command) { this->build_command = build_command; } - void setTestCommand(const std::string &test_command) { + void setTestCommand(std::string test_command) { this->test_command = test_command; } - void setRunCommand(const std::string &run_command) { + void setRunCommand(std::string run_command) { this->run_command = run_command; } + void setRequestedJobs(int requested_jobs) { + this->requested_jobs = requested_jobs; + } + + void setBuildMode(std::string build_mode) { this->build_mode = build_mode; } + void generateOverrideChangeHash(); - //JSON + // JSON friend void from_json(const nlohmann::json &json_obj, Local &cache_obj); friend void to_json(nlohmann::json &json_obj, const Local &cache_obj); - //IO - + // IO + void load(); void save(); - - }; } // namespace Frate::Project diff --git a/src/Command/Actions/Build.cpp b/src/Command/Actions/Build.cpp index 7f01b80..dd1fa35 100644 --- a/src/Command/Actions/Build.cpp +++ b/src/Command/Actions/Build.cpp @@ -33,7 +33,6 @@ namespace Frate::Command::Build { } inter->pro->load(); - inter->pro->current_template.refresh(inter->pro, inter->local); Utils::info << "Building project with: " << std::endl; @@ -42,27 +41,14 @@ namespace Frate::Command::Build { Utils::info << "Jobs: " << jobs << std::endl; // TODO: Handle different targets - for (Project::Mode &curr_mode : inter->pro->modes) { - if (curr_mode.name == mode) { - std::string workdir_cmd = "cd " + inter->pro->path.string(); - Utils::replaceKey(inter->pro->build_command, "\n", ";"); - std::string full_build_cmd = inter->pro->build_command; - if (Utils::hSystem(workdir_cmd + ";" + full_build_cmd) != 0) { - Utils::error << "Build failed" << std::endl; - return false; - } - else { - Utils::info << "Build success" << std::endl; - return true; - } - } - } + inter->local->setBuildMode(mode == "" ? inter->pro->default_mode : mode); + inter->local->setRequestedJobs(jobs); + + inter->pro->current_template.refresh(inter->pro, inter->local); - std::string workdir_cmd = "cd " + inter->pro->path.string(); - Utils::replaceKey(inter->pro->build_command, "\n", ";"); - std::string full_build_cmd = workdir_cmd + ";" + inter->pro->build_command; + Utils::verbose << "Build command" << inter->local->getBuildCommand() << std::endl; - if (Utils::hSystem(full_build_cmd) != 0) { + if (Utils::hSystem(inter->local->getBuildCommand()) != 0) { Utils::error << "Build failed" << std::endl; return false; } diff --git a/src/Command/Helpers/Interface.cpp b/src/Command/Helpers/Interface.cpp index c81a85b..e68fc47 100644 --- a/src/Command/Helpers/Interface.cpp +++ b/src/Command/Helpers/Interface.cpp @@ -69,7 +69,6 @@ namespace Frate::Command { this->argc = argc; this->argv = argv; this->pro = std::make_shared(); - this->local = std::make_shared(this->pro); #ifdef DEBUG //Setting the path to ./build so that we can test the build process std::cout << "DEBUG MODE ENABLED\n"; @@ -90,6 +89,8 @@ namespace Frate::Command { config = std::make_shared(); config->load(); + + this->local = std::make_shared(this->pro); local->load(); @@ -104,6 +105,10 @@ namespace Frate::Command { Utils::error << "Error loading installed templates: " << e.what() << std::endl; } + + Utils::verbose << local->getBuildCommand() << std::endl; + Utils::verbose << local->getTestCommand() << std::endl; + Utils::verbose << local->getRunCommand() << std::endl; } bool execute(std::shared_ptr inter) { diff --git a/src/Generators/DockerTemplate.cpp b/src/Generators/DockerTemplate.cpp index 52370df..846d7aa 100644 --- a/src/Generators/DockerTemplate.cpp +++ b/src/Generators/DockerTemplate.cpp @@ -21,25 +21,26 @@ namespace Frate::Generators::DockerTemplate { bool create(std::shared_ptr inter) { - inja::Environment env; - sol::state lua; - Lua::registerAPI(lua); - - if (!Lua::registerProject(lua, inter->pro)) { - Utils::debug("Error while registering project"); - return false; - } - - if (!Lua::registerProjectScripts( - env, lua, inter->pro->path / "templates/scripts", inter->pro)) { - Utils::debug("Error while registering project scripts"); - return false; - } - return true; - } - - bool remove(std::shared_ptr inter) { - (void)inter; - return true; - } +// inja::Environment env; +// sol::state lua; +// Lua::registerAPI(lua); +// +// if (!Lua::registerProject(lua, inter->pro)) { +// Utils::debug("Error while registering project"); +// return false; +// } +// +// if (!Lua::registerProjectScripts( +// env, lua, inter->pro->path / "templates/scripts", inter->pro)) { +// Utils::debug("Error while registering project scripts"); +// return false; +// } +// return true; +// } +// +// bool remove(std::shared_ptr inter) { +// (void)inter; +// return true; +// } + } } // namespace Frate::Generators::DockerTemplate diff --git a/src/Lua/API.cpp b/src/Lua/API.cpp deleted file mode 100644 index 97a24db..0000000 --- a/src/Lua/API.cpp +++ /dev/null @@ -1,224 +0,0 @@ -#include "Frate/Lua/Exceptions.hpp" -#include "Frate/Lua/LuaAPI.hpp" -#include "Frate/Project/Config.hpp" -#include "Frate/Utils/General.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Frate::Lua { - using Project::Config; - using std::filesystem::path; - - void registerTemplateMacroScript(inja::Environment &env, sol::state &lua, - path script_path, - std::shared_ptr project) { - - if (!std::filesystem::exists(script_path)) { - Utils::error << "Script not found at path: " << script_path << std::endl; - throw LuaException("Script not found at path: " + script_path.string()); - } - - lua.set("project", project); - - auto result = lua.script_file(script_path); - - if (!result.valid()) { - throw LuaException("Error while executing lua script at: " + - script_path.string()); - } - - project = lua.get>("project"); - } - - bool registerProjectScripts(inja::Environment &env, sol::state &lua, - path script_path, - std::shared_ptr project) { - - std::unordered_map scripts = {}; - - sol::table global_table = to_table(project->global, lua); - - lua.set("global", global_table); - try { - for (const std::filesystem::path ¤t_path : - std::filesystem::recursive_directory_iterator(script_path)) { - if (current_path.extension() == ".lua") { - std::string file_name = current_path.filename(); - std::string full_script_path = current_path.string(); - // Yoinkin off the lua extension - file_name = file_name.substr(0, file_name.find(".lua")); - - std::string prefix; - - // Remove the script path - Utils::replaceKey(full_script_path, script_path.string(), ""); - - // Remove the file name - Utils::replaceKey(full_script_path, file_name + ".lua", ""); - - // Remove the first slash - Utils::replaceKey(full_script_path, "/", "."); - - // Remove the first dot - full_script_path = - full_script_path.substr(1, full_script_path.size()); - - prefix = full_script_path; - - scripts[prefix + file_name] = current_path.string(); - } - } - } catch (...) { - Utils::error << "Error while iterating over scripts" << std::endl; - return false; - } - - for (auto &[key, script_path] : scripts) { - env.add_callback( - key, -1, [&lua, script_path](inja::Arguments input_args) { - sol::table args_table = lua.create_table(); - for (const nlohmann::json *arg : input_args) { - if (arg->is_string()) { - args_table.add(arg->get()); - } - else if (arg->is_number()) { - args_table.add(arg->get()); - } - else if (arg->is_boolean()) { - args_table.add(arg->get()); - } - else { - Utils::error << "Error while converting arguments in inja " - "callback for script at: " - << script_path << std::endl; - exit(1); - } - } - lua.set("args", args_table); - - if (!std::filesystem::exists(script_path)) { - Utils::error << "Lua script not found at path: " << script_path - << std::endl; - exit(1); - } - - // lua.set("global", global_table); - auto result = lua.script_file(script_path); - - if (result.valid()) { - return result; - } - - Utils::error << "Error while executing lua script at: " - << script_path << std::endl; - exit(1); - }); - } - return true; - } - - void registerAPI(sol::state &lua) { - lua.open_libraries(sol::lib::base, sol::lib::package, sol::lib::string); - // clang-format off - lua.new_usertype( - "frate", - "new", sol::no_constructor, - "get_os", &FrateApi::get_os, - "get_path", &FrateApi::get_path, - "get_paths_recurse", &FrateApi::get_paths_recurse, - "format", &FrateApi::format, - "print_table", &FrateApi::print_table, - "fetch_text", &FrateApi::fetch_text, - "fetch_json", &FrateApi::fetch_json - ); - // clang-format on - } - - bool initScripts(sol::state &lua, std::shared_ptr project) { - path script_path = project->template_path / Constants::INIT_SCRIPTS_PATH; - - if (!std::filesystem::exists(script_path)) { - Utils::verbose << "No init scripts found at: " << script_path - << std::endl; - return false; - } - - std::vector script_paths = {}; - - for (const path ¤t_path : - std::filesystem::recursive_directory_iterator(script_path)) { - if (current_path.extension() == ".lua") { - script_paths.emplace_back(current_path); - } - } - - for (const path ¤t_script_path : script_paths) { - - lua.set("project", project); - - if (!std::filesystem::exists(current_script_path)) { - Utils::error << "Script not found: " << current_script_path - << " at: " << script_path << std::endl; - return false; - } - - auto result = lua.script_file(current_script_path); - - if (!result.valid()) { - Utils::error << "Error while executing lua script at: " - << current_script_path << std::endl; - return false; - } - - project = lua.get>("project"); - } - return true; - } - - bool postScripts(sol::state &lua, std::shared_ptr project) { - path script_path = project->template_path / Constants::POST_SCRIPTS_PATH; - - if (!std::filesystem::exists(script_path)) { - Utils::verbose << "No post scripts found" - << " at: " << script_path << std::endl; - return false; - } - - std::vector scripts = {}; - - for (const path ¤t_path : - std::filesystem::recursive_directory_iterator(script_path)) { - - if (current_path.extension() == ".lua") { - scripts.emplace_back(current_path); - } - } - - for (const path &script : scripts) { - - lua.set("project", project); - - if (!std::filesystem::exists(script)) { - Utils::error << "Script not found: " << script - << " at path: " << script_path << std::endl; - return false; - } - - auto result = lua.script_file(script); - if (!result.valid()) { - Utils::error << "Error while executing lua script" << std::endl; - return false; - } - - project = lua.get>("project"); - } - return true; - } -} // namespace Frate::Lua diff --git a/src/Lua/RegisterProject.cpp b/src/Lua/RegisterProject.cpp deleted file mode 100644 index 772fd78..0000000 --- a/src/Lua/RegisterProject.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#include -#include -#include -#include - -namespace Frate::Lua { - [[deprecated("Use the template environment instead")]] - bool registerProject(sol::state &lua, std::shared_ptr pro) { - - lua.set("project", pro); - // clang-format off - lua.new_usertype("Package", - "new", - sol::no_constructor, - "name", - &Command::Package::name, - "git", - &Command::Package::git, - "git_short", - &Command::Package::git_short, - "git_prefixed", - &Command::Package::git_prefixed, - "versions", - &Command::Package::versions, - "target_link", - &Command::Package::target_link, - "description", - &Command::Package::description, - "git_description", - &Command::Package::git_description, - "language", - &Command::Package::language, - "license", - &Command::Package::license, - "owner", - &Command::Package::owner, - "owner_type", - &Command::Package::owner_type, - "stars", - &Command::Package::stars, - "forks", - &Command::Package::forks, - "open_issues", - &Command::Package::open_issues, - "watchers", - &Command::Package::watchers); - lua.new_usertype("Dependency", - "new", - sol::no_constructor, - "name", - &Command::Dependency::name, - "version", - &Command::Dependency::version, - "git", - &Command::Dependency::git, - "git_short", - &Command::Dependency::git_short, - "git_prefixed", - &Command::Dependency::git_prefixed, - "target_link", - &Command::Dependency::target_link); - - lua.new_usertype("Mode", - "new", - sol::no_constructor, - "name", - &Project::Mode::name, - "flags", - &Project::Mode::flags, - "dependencies", - &Project::Mode::dependencies); - - lua.new_usertype("Project" - "new", - sol::no_constructor, - "name", - &Project::Config::name, - "version", - &Project::Config::version, - "description", - &Project::Config::description, - "authors", - &Project::Config::authors, - "dependencies", - &Project::Config::dependencies, - "toolchains", - &Project::Config::toolchains, - "flags", - &Project::Config::flags, - "modes", - &Project::Config::modes, - "libs", - &Project::Config::libs, - "license", - &Project::Config::license, - "git", - &Project::Config::git, - "cmake_version", - &Project::Config::cmake_version, - "build_command", - &Project::Config::build_command, - "build_dir", - &Project::Config::build_dir, - "src_dir", - &Project::Config::src_dir, - "include_dir", - &Project::Config::include_dir, - "lang_version", - &Project::Config::lang_version, - "lang", - &Project::Config::lang, - "project_type", - &Project::Config::type, - "keywords", - &Project::Config::keywords, - "prompts", - &Project::Config::prompts); - - lua.new_usertype( - "ProjectPrompt", - "value", - &Project::ProjectPrompt::value, - "default", - &Project::ProjectPrompt::default_value, - "get_str", - &Project::ProjectPrompt::get, - "get_int", - &Project::ProjectPrompt::get, - "get_bool", - &Project::ProjectPrompt::get, - "get_float", - &Project::ProjectPrompt::get); - - - // clang-format on - return true; - } -} // namespace Frate::Lua diff --git a/src/Lua/TemplateEnvironment.cpp b/src/Lua/TemplateEnvironment.cpp index 4411bcd..409f306 100644 --- a/src/Lua/TemplateEnvironment.cpp +++ b/src/Lua/TemplateEnvironment.cpp @@ -24,21 +24,30 @@ namespace Frate::Lua { void TemplateEnvironment::runInitScripts(){ for(auto &script : init_scripts){ + lua->set("project", pro); + lua->set("plocal", local); + Utils::verbose << "Build command: " << local->getBuildCommand() << std::endl; auto result = lua->script(script.second); - std::cout << "Running init script: " << script.second << std::endl; - std::cout << "Result: " << result.get() << std::endl; if (!result.valid()) { throw LuaException("Failed to run init script: " + script.first + result.get().what()); } + *pro = lua->get("project"); + *local = lua->get("plocal"); + // *local = lua->get("plocal"); + Utils::verbose << "Build command: " << local->getBuildCommand() << std::endl; } } void TemplateEnvironment::runPostScripts(){ for(auto &script : post_scripts){ + lua->set("project", pro); + lua->set("plocal", local); auto result = lua->script(script.second); if (!result.valid()) { throw LuaException("Failed to run post script: " + script.first + result.get().what()); } + *pro = lua->get("project"); + *local = lua->get("plocal"); } } @@ -156,7 +165,7 @@ namespace Frate::Lua { void TemplateEnvironment::register_user_types() { lua->set("project", pro); - lua->set("plocal", local); + //lua->set("plocal", local); // clang-format off lua->new_usertype("Package", @@ -280,30 +289,21 @@ namespace Frate::Lua { &Project::ProjectPrompt::get, "getfloat", &Project::ProjectPrompt::get); - - lua->new_usertype( - "Local", - "new", - sol::no_constructor, - "get_build_command", - &Project::Local::getBuildCommand, - "get_test_command", - &Project::Local::getTestCommand, - "get_run_command", - &Project::Local::getRunCommand, - "get_requested_jobs", - &Project::Local::getRequestedJobs, - "get_max_jobs", - &Project::Local::getMaxJobs, - "get_override_change_hash", - &Project::Local::getOverrideChangeHash, - "set_build_command", - &Project::Local::setBuildCommand, - "set_test_command", - &Project::Local::setTestCommand, - "set_run_command", - &Project::Local::setRunCommand - ); + lua->new_usertype("Local"); + lua->set_function("get_build_command",&Project::Local::getBuildCommand); + lua->set_function("get_test_command",&Project::Local::getTestCommand); + lua->set_function("get_run_command",&Project::Local::getRunCommand); + lua->set_function("get_requested_jobs",&Project::Local::getRequestedJobs); + lua->set_function("get_max_jobs",&Project::Local::getMaxJobs); + lua->set_function("get_override_change_hash",&Project::Local::getOverrideChangeHash); + lua->set_function("set_build_command",&Project::Local::setBuildCommand); + lua->set_function("set_test_command",&Project::Local::setTestCommand); + lua->set_function("set_run_command",&Project::Local::setRunCommand); + lua->set_function("get_build_mode",&Project::Local::getBuildMode); + lua->set_function("set_build_mode",&Project::Local::setBuildMode); + lua->set_function("get_current_mode",&Project::Local::setBuildMode); + lua->set_function("get_project_path",&Project::Local::getProjectPath); + // clang-format on } } // namespace Frate::Lua diff --git a/src/Project/Local.cpp b/src/Project/Local.cpp index 1706aaf..dd04a9d 100644 --- a/src/Project/Local.cpp +++ b/src/Project/Local.cpp @@ -1,31 +1,34 @@ #include "Frate/Utils/Crypto/md5.hpp" -#include #include +#include #include #include +#include +#include #include #include -#include namespace Frate::Project { void from_json(const nlohmann::json &json_obj, Local &cache_obj) { - FROM_JSON_FIELD(cache_obj, build_command); - FROM_JSON_FIELD(cache_obj, test_command); - FROM_JSON_FIELD(cache_obj, run_command); + // FROM_JSON_FIELD(cache_obj, build_command); + // FROM_JSON_FIELD(cache_obj, test_command); + // FROM_JSON_FIELD(cache_obj, run_command); FROM_JSON_FIELD(cache_obj, override_change_hash); } void to_json(nlohmann::json &json_obj, const Local &cache_obj) { - TO_JSON_FIELD(cache_obj, build_command); - TO_JSON_FIELD(cache_obj, test_command); - TO_JSON_FIELD(cache_obj, run_command); + // TO_JSON_FIELD(cache_obj, build_command); + // TO_JSON_FIELD(cache_obj, test_command); + // TO_JSON_FIELD(cache_obj, run_command); TO_JSON_FIELD(cache_obj, override_change_hash); } - void Local::create_local_file(){ - std::ofstream file(this->config->path / LOCAL_FILE_NAME); + + void Local::create_local_file() { + std::ofstream file(this->project->path / LOCAL_FILE_NAME); if (!file.is_open()) { - throw LocalIOException("Could not create local file at: " + this->config->path.string()); + throw LocalIOException("Could not create local file at: " + + this->project->path.string()); } nlohmann::json json_obj; @@ -33,22 +36,22 @@ namespace Frate::Project { file << json_obj.dump(2); } - void Local::load(){ - - if(local_file_loaded){ + void Local::load() { + if (local_file_loaded) { return; } - if(!std::filesystem::exists(this->config->path / LOCAL_FILE_NAME)){ + if (!std::filesystem::exists(this->project->path / LOCAL_FILE_NAME)) { this->create_local_file(); this->local_file_loaded = true; return; } - std::ifstream file(this->config->path / LOCAL_FILE_NAME); + std::ifstream file(this->project->path / LOCAL_FILE_NAME); if (!file.is_open()) { - throw LocalIOException("Could not open local file at: " + this->config->path.string()); + throw LocalIOException("Could not open local file at: " + + this->project->path.string()); } nlohmann::json json_obj; @@ -57,31 +60,79 @@ namespace Frate::Project { try { from_json(json_obj, *this); } catch (nlohmann::json::exception &e) { - throw LocalIOException("Could not parse local file at: " + this->config->path.string()); + throw LocalIOException("Could not parse local file at: " + + this->project->path.string()); } this->local_file_loaded = true; - } - void Local::save(){ - if(!local_file_loaded){ - throw LocalIOException("Could not save the local file either because it was not loaded or it was not created"); + void Local::save() { + + if (!local_file_loaded) { + throw LocalIOException("Could not save the local file either because it " + "was not loaded or it was not created"); } nlohmann::json json_obj; to_json(json_obj, *this); - - std::ofstream file(this->config->path / LOCAL_FILE_NAME); + + std::ofstream file(this->project->path / LOCAL_FILE_NAME); if (!file.is_open()) { - throw LocalIOException("Could not open local file at: " + this->config->path.string()); + throw LocalIOException("Could not open local file at: " + + this->project->path.string()); } file << json_obj.dump(2); } + void Local::gen_default_build_command() { + this->build_command = + std::format( + "cd {};cmake -DCMAKE_BUILD_TYPE={} . && make -j{}", + this->project->path.string(), + this->build_mode.empty() ? "Debug" : this->build_mode, + this->requested_jobs + ); + }; + + void Local::gen_default_test_command() { + this->test_command = + std::format("cd {};ctest", this->project->path.string()); + } + + void Local::gen_default_run_command() { + this->run_command = + std::format("cd {};./{}/{}", this->project->path.string(), + this->project->build_dir, this->project->name); + } + + std::string &Local::getBuildCommand() { + if (build_command.empty()) { + gen_default_build_command(); + } + return build_command; + } + + std::string &Local::getTestCommand() { + if (test_command.empty()) { + gen_default_test_command(); + } + return test_command; + } + + std::string &Local::getRunCommand() { + if (run_command.empty()) { + gen_default_run_command(); + } + + return run_command; + } + std::string Local::getProjectPath(){ + return this->project->path.string(); + }; void Local::generateOverrideChangeHash() { Utils::MD5Encoder encoder; @@ -89,8 +140,8 @@ namespace Frate::Project { std::stringstream entry_time; for (auto &dir_entry : std::filesystem::recursive_directory_iterator( - this->config->path / "override")) { - entry_time << dir_entry.last_write_time().time_since_epoch().count(); + this->project->path / "override")) { + entry_time << dir_entry.last_write_time().time_since_epoch().count(); } std::string entry_time_str = entry_time.str(); this->override_change_hash = encoder.intake(entry_time_str).getDigest(); diff --git a/src/Template/Renderer.cpp b/src/Template/Renderer.cpp index c5e3e6d..fd6c4b7 100644 --- a/src/Template/Renderer.cpp +++ b/src/Template/Renderer.cpp @@ -309,6 +309,7 @@ namespace Frate::Project { } } + env->runInitScripts(); // Generate a list of all files that are templates for (auto [relative_path, file_path] : file_map) { if (file_path.extension() == ".inja") { @@ -323,10 +324,10 @@ namespace Frate::Project { throw Lua::LuaException( "Project config is null before templating file"); } - env->templateFile(file_path, output_file); } } + env->runPostScripts(); } } // namespace Frate::Project