Skip to content

Commit

Permalink
Added .env patcher.
Browse files Browse the repository at this point in the history
  • Loading branch information
5cript committed Apr 10, 2024
1 parent 0a964f8 commit 4c215d0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ else()
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/patch_acorn)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/parcel_adapter)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/patch_emscripten_config)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/patch_dotenv)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/inline_parser)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/inline_injector)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tools/webview_uuid)
Expand Down
11 changes: 11 additions & 0 deletions tools/patch_dotenv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.16)

project(patch-dotenv VERSION 0.1.0)

add_executable(patch-dotenv main.cpp)
target_compile_features(patch-dotenv PRIVATE cxx_std_20)

set_target_properties(patch-dotenv
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tools_bin"
)
35 changes: 35 additions & 0 deletions tools/patch_dotenv/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <fstream>
#include <iostream>

int main(int argc, char** argv)
{
if (argc != 4)
{
std::cout << "Expected 3 arguments: <.env file source> <.env file target> <nui-root-dir>, but got " << argc - 1
<< "\n";
std::cout << "Usage: " << argv[0] << " <.env file source> <.env file target> <nui-root-dir>" << "\n";
return 1;
}

const std::string source = argv[1];
const std::string target = argv[2];
const std::string nuiRootDir = argv[3];

std::ofstream ofs{target, std::ios_base::binary};
if (!ofs)
{
std::cout << "Failed to open file: " << target << "\n";
return 1;
}

std::ifstream ifs{source, std::ios_base::binary};
if (!ifs)
{
ofs << "NUI_PROJECT_ROOT=" << nuiRootDir << "\n";
return 0;
}

ofs << "NUI_PROJECT_ROOT=" << nuiRootDir << "\n";
ofs << ifs.rdbuf();
return 0;
}

0 comments on commit 4c215d0

Please sign in to comment.