Skip to content

Commit

Permalink
added Project generator docs
Browse files Browse the repository at this point in the history
  • Loading branch information
DeaSTL committed Dec 15, 2023
1 parent cc51714 commit 453b4ee
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 13 deletions.
89 changes: 76 additions & 13 deletions include/Frate/Generators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,95 @@ namespace Frate::Generators{
std::string description;
} Template;

static void from_json(const json& j, Template& t){
t.name = j.at("name").get<std::string>();
t.git = j.at("git").get<std::string>();
t.description = j.at("description").get<std::string>();
}

std::pair<bool, Template> promptForProjectName(json index);

/*
* ===========================
* External functions
* ===========================
*/

/*
* This is the external callback used when ever a new project is created
* @param pro: the project context
* @return true if the creation was successful
*/
bool create(std::shared_ptr<Command::Project> pro);

/*
* This is the external callback used when ever the tempalte needs to be refreshed
* @param pro: the project context
* @return true if the refresh was successful
*/
bool refresh(std::shared_ptr<Command::Project> pro);

std::pair<bool, Template> promptForTemplateName(json index);

bool renderTemplate(
Environment &env,
std::shared_ptr<Command::Project> pro);

bool refreshTemplate(Environment &env, std::shared_ptr<Command::Project> pro);
/*
* ===========================
* Internal functions
* ===========================
*/

/*
* Impliceitly converts a json object to a Template object
* Intended to to convert the json objects from the template index to Template objects
* @param j: the json object
* @param t: the template object
*/
void from_json(const json& j, Template& t);
/*
* Prompts the user for a template name, only used if the template has not been specified
* @param index: the json index of the templates
* @return a pair of bool and Template, the bool is true if the template was found
* and the Template is the template that was found
*/
std::pair<bool, Template> promptForTemplateName(json index);

/*
* Renders the entire template, this is only used when creating a new project
* @param env: the inja environment
* @param pro: the project context
* @return true if the render was successful
*/
bool renderTemplate(Environment &env, std::shared_ptr<Command::Project> pro);

/*
* Refreshes only specific files that are considerer dynamic files
* @param env: the inja environment
* @param pro: the project context
* @return true if the refresh was successful
*/
bool refreshTemplate(Environment &env, std::shared_ptr<Command::Project> pro);

/*
* Runs user prompts from the template
* @param pro: the project context
* @return true if the prompts were successful
*/
bool runTemplatePrompts(std::shared_ptr<Command::Project> pro);

/*
* Downloads the templates from from the github repo
* @param git_url: the url of the git repo
* @param project_path: the path of the project
* @return true if the download was successful
*/
bool downloadTemplate(std::string git_url, path project_path);

/*
* Loads the template config file and merges into the project context
* @param pro: the project context
* @return true if the load was successful
*/
bool loadTemplateConfig(std::shared_ptr<Command::Project> pro);


/*
* Initializes the lua environment after by loading user scripts into the inja environment
* @param env: the inja environment
* @param lua: the lua state
* @param pro: the project context
* @return true if the initialization was successful
*/
bool initializeLua(Environment &env, sol::state &lua, std::shared_ptr<Command::Project> pro);
}
namespace GitIgnore{
Expand Down
5 changes: 5 additions & 0 deletions src/Generators/ProjectGenerator/ProjectGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include <git2/clone.h>

namespace Frate::Generators::Project {
void from_json(const json& j, Template& t){
t.name = j.at("name").get<std::string>();
t.git = j.at("git").get<std::string>();
t.description = j.at("description").get<std::string>();
}
json getTemplateIndex() {
std::cout << "Getting Template Index" << std::endl;
std::string index_url = static_cast<std::string>(Constants::FRATE_TEMPLATES);
Expand Down

0 comments on commit 453b4ee

Please sign in to comment.