Skip to content

Commit

Permalink
feat: Add verbose config option to prevent spam
Browse files Browse the repository at this point in the history
  • Loading branch information
xLuxy committed Jun 6, 2024
1 parent f08aafd commit 767d6af
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
8 changes: 6 additions & 2 deletions compiler/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using namespace BytecodeCompiler;

bool Compiler::CompileModule(const std::string& fileName, bool compileDependencies)
bool Compiler::CompileModule(const std::string& fileName, bool compileDependencies, bool verbose)
{
// Read the file
if(!package->FileExists(fileName))
Expand Down Expand Up @@ -61,7 +61,11 @@ bool Compiler::CompileModule(const std::string& fileName, bool compileDependenci
cache->buffer_policy = v8::ScriptCompiler::CachedData::BufferPolicy::BufferOwned;
delete cache;

logger->Log("Converted file to bytecode: " + logger->GetHighlightColor() + fileName);
if (verbose)
{
logger->Log("Converted file to bytecode: " + logger->GetHighlightColor() + fileName);
}

compiledFiles.push_back(fileName);

// Compile all dependencies
Expand Down
2 changes: 1 addition & 1 deletion compiler/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace BytecodeCompiler
return magicBytes;
}

bool CompileModule(const std::string& fileName, bool compileDependencies = true);
bool CompileModule(const std::string& fileName, bool compileDependencies = true, bool verbose = false);

bool IsBytecodeFile(void* buffer, size_t size);

Expand Down
8 changes: 6 additions & 2 deletions module/src/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ void JSBytecodeRuntime::ProcessClientFile(alt::IResource* resource, alt::IPackag
// Get ignored files
std::vector<std::string> ignoredModules = { "alt", "alt-client", "natives", "alt-worker", "alt-shared" };
Config::Value::ValuePtr ignoredFiles = config->Get("ignored-files");
Config::Value::Bool verboseLogging = config->Get("verbose")->AsBool(false);

if(ignoredFiles->IsList())
{
Config::Value::List list = ignoredFiles->As<Config::Value::List>();
Expand All @@ -33,7 +35,7 @@ void JSBytecodeRuntime::ProcessClientFile(alt::IResource* resource, alt::IPackag
compiler.SetIgnoredModules(ignoredModules);

// Compile client main file
bool result = compiler.CompileModule(resource->GetClientMain());
bool result = compiler.CompileModule(resource->GetClientMain(), true, verboseLogging);
if(!result) return;

// Compile the extra files
Expand All @@ -51,7 +53,7 @@ void JSBytecodeRuntime::ProcessClientFile(alt::IResource* resource, alt::IPackag
std::set<std::string> files = resource->GetMatchedFiles(extraFilePatterns);
for(const std::string& file : files)
{
bool result = compiler.CompileModule(file, false);
bool result = compiler.CompileModule(file, false, verboseLogging);
if(!result) return;
}
}
Expand All @@ -77,6 +79,8 @@ void JSBytecodeRuntime::ProcessClientFile(alt::IResource* resource, alt::IPackag
package->WriteFile(clientPkgFile, buffer.data(), buffer.size());
package->CloseFile(clientPkgFile);
}

compilerLogger.Log("Converted " + std::to_string(compiledFiles.size()) + " script files to bytecode");
}

bool JSBytecodeRuntime::GetProcessClientType(std::string& clientType)
Expand Down
8 changes: 6 additions & 2 deletions module/src/runtimev2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ void JSBytecodeRuntimeV2::ProcessClientFile(alt::IResource* resource, alt::IPack
// Get ignored files
std::vector<std::string> ignoredModules = { "alt", "alt-client", "natives", "alt-worker", "alt-shared", "@altv/client", "@altv/server", "@altv/shared", "@altv/natives" };
Config::Value::ValuePtr ignoredFiles = config->Get("ignored-files");
Config::Value::Bool verboseLogging = config->Get("verbose")->AsBool(false);

if(ignoredFiles->IsList())
{
Config::Value::List list = ignoredFiles->As<Config::Value::List>();
Expand All @@ -33,7 +35,7 @@ void JSBytecodeRuntimeV2::ProcessClientFile(alt::IResource* resource, alt::IPack
compiler.SetIgnoredModules(ignoredModules);

// Compile client main file
bool result = compiler.CompileModule(resource->GetClientMain());
bool result = compiler.CompileModule(resource->GetClientMain(), true, verboseLogging);
if(!result) return;

// Compile the extra files
Expand All @@ -51,7 +53,7 @@ void JSBytecodeRuntimeV2::ProcessClientFile(alt::IResource* resource, alt::IPack
std::set<std::string> files = resource->GetMatchedFiles(extraFilePatterns);
for(const std::string& file : files)
{
bool result = compiler.CompileModule(file, false);
bool result = compiler.CompileModule(file, false, verboseLogging);
if(!result) return;
}
}
Expand All @@ -77,6 +79,8 @@ void JSBytecodeRuntimeV2::ProcessClientFile(alt::IResource* resource, alt::IPack
package->WriteFile(clientPkgFile, buffer.data(), buffer.size());
package->CloseFile(clientPkgFile);
}

compilerLogger.Log("Converted " + std::to_string(compiledFiles.size()) + " script files to bytecode");
}

bool JSBytecodeRuntimeV2::GetProcessClientType(std::string& clientType)
Expand Down

0 comments on commit 767d6af

Please sign in to comment.