Skip to content

Commit

Permalink
Merge pull request #108 from NuiCpp/feat/tailwindcss
Browse files Browse the repository at this point in the history
Feat/tailwindcss
  • Loading branch information
5cript authored Apr 10, 2024
2 parents 0a964f8 + 6a35dad commit a37f28d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 5 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
25 changes: 24 additions & 1 deletion cmake/backend/emscripten.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function(nui_add_emscripten_target)

cmake_parse_arguments(
NUI_ADD_EMSCRIPTEN_TARGET_ARGS
"DISABLE_BIN2HPP;DISABLE_PARCEL_ADAPTER"
"DISABLE_BIN2HPP;DISABLE_PARCEL_ADAPTER;ENABLE_TAILWIND;ENABLE_DOTENV"
"TARGET;PREJS;SOURCE_DIR"
"CMAKE_OPTIONS"
${ARGN}
Expand Down Expand Up @@ -105,6 +105,25 @@ function(nui_add_emscripten_target)
set(BIN2HPP_COMMAND COMMAND cmake -E true)
endif()

if (NUI_ADD_EMSCRIPTEN_TARGET_ARGS_ENABLE_DOTENV)
set(ENABLE_DOTENV on)
else()
set(ENABLE_DOTENV off)
endif()

if (NUI_ADD_EMSCRIPTEN_TARGET_ARGS_ENABLE_TAILWIND)
set(COPY_TAILWIND_CONFIG_COMMAND COMMAND cmake -E copy "${SOURCE_DIR}/tailwind.config.js" "${SOURCE_DIR}/.postcssrc" "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}")
set(ENABLE_DOTENV on)
else()
set(COPY_TAILWIND_CONFIG_COMMAND COMMAND cmake -E true)
endif()

if (ENABLE_DOTENV AND ${ENABLE_DOTENV})
set(PATCH_DOTENV_COMMAND COMMAND $<TARGET_FILE:patch-dotenv> "${SOURCE_DIR}/.env" "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/.env" "${SOURCE_DIR}")
else()
set(PATCH_DOTENV_COMMAND COMMAND cmake -E true)
endif()

include(ExternalProject)
ExternalProject_Add(
"${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-emscripten"
Expand All @@ -121,6 +140,10 @@ function(nui_add_emscripten_target)
"${SOURCE_DIR}"
# copy over package.json and fill parcel options that do not exist on it
${BUILD_COMMAND}
# patch .env file if needed
${PATCH_DOTENV_COMMAND}
# copy tailwind config if needed
${COPY_TAILWIND_CONFIG_COMMAND}
# emscripten make
COMMAND cmake --build "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}" --target ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-parcel
# convert result to header file containing the page
Expand Down
9 changes: 5 additions & 4 deletions tools/parcel_adapter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void createPackageJsonIfMissing(std::filesystem::path const& where, std::string
}
}

void copyParcelRc(std::filesystem::path const& from, std::filesystem::path const& to)
void copyIfNotExists(std::filesystem::path const& from, std::filesystem::path const& to)
{
if (std::filesystem::exists(from))
std::filesystem::copy_file(from, to, std::filesystem::copy_options::overwrite_existing);
Expand All @@ -58,15 +58,16 @@ int main(int argc, char** argv)
{
std::cout << "Expected 3 argument: <package_in.json> <package_out.json> <target-name>, but got " << argc - 1
<< "\n";
std::cout << "Usage: " << argv[0] << " <package_in.json> <package_out.json> <target-name>"
<< "\n";
std::cout << "Usage: " << argv[0] << " <package_in.json> <package_out.json> <target-name>" << "\n";
return 1;
}

createPackageJsonIfMissing(argv[1], argv[3]);
copyParcelRc(

copyIfNotExists(
std::filesystem::path{argv[1]}.parent_path() / ".parcelrc",
std::filesystem::path{argv[2]}.parent_path() / ".parcelrc");

std::ifstream ifs(argv[1], std::ios_base::binary);
if (!ifs.is_open())
{
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 a37f28d

Please sign in to comment.