| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,33 @@ | |||
| 1 | + #ifndef VIX_CLI_MODULES_MODULE_MANIFEST_HPP | ||
| 2 | + #define VIX_CLI_MODULES_MODULE_MANIFEST_HPP | ||
| 3 | + | ||
| 4 | + #include <filesystem> | ||
| 5 | + #include <optional> | ||
| 6 | + #include <string> | ||
| 7 | + #include <vector> | ||
| 8 | + | ||
| 9 | + namespace vix::cli::modules | ||
| 10 | + { | ||
| 11 | + struct ModuleWebSocket | ||
| 12 | + { | ||
| 13 | + std::string workflow, path, host; | ||
| 14 | + std::optional<unsigned short> port; | ||
| 15 | + bool longPolling{false}; | ||
| 16 | + bool metrics{false}; | ||
| 17 | + }; | ||
| 18 | + struct ModuleManifest | ||
| 19 | + { | ||
| 20 | + std::string name, kind, workflow, routePrefix, exportInclude; | ||
| 21 | + bool runtime{false}, testsEnabled{true}; | ||
| 22 | + std::vector<std::string> registryDependencies, links; | ||
| 23 | + std::optional<ModuleWebSocket> websocket; | ||
| 24 | + }; | ||
| 25 | + struct ModuleManifestLoadResult | ||
| 26 | + { | ||
| 27 | + ModuleManifest manifest; | ||
| 28 | + std::string error; | ||
| 29 | + bool success() const { return error.empty(); } | ||
| 30 | + }; | ||
| 31 | + ModuleManifestLoadResult load_module_manifest(const std::filesystem::path &path); | ||
| 32 | + } | ||
| 33 | + #endif | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,7 @@ | |||
| 15 | 15 | */ | |
| 16 | 16 | ||
| 17 | 17 | #include <vix/cli/app/AppCMakeGenerator.hpp> | |
| 18 | + #include <vix/cli/modules/ModuleManifest.hpp> | ||
| 18 | 19 | ||
| 19 | 20 | #include <algorithm> | |
| 20 | 21 | #include <cctype> | |
@@ -115,184 +116,6 @@ namespace vix::cli::app | |||
| 115 | 116 | return name; | |
| 116 | 117 | } | |
| 117 | 118 | ||
| 118 | - static std::string trim_copy_local(std::string value) | ||
| 119 | - { | ||
| 120 | - auto is_space = [](unsigned char c) | ||
| 121 | - { | ||
| 122 | - return std::isspace(c) != 0; | ||
| 123 | - }; | ||
| 124 | - | ||
| 125 | - while (!value.empty() && is_space(static_cast<unsigned char>(value.front()))) | ||
| 126 | - value.erase(value.begin()); | ||
| 127 | - | ||
| 128 | - while (!value.empty() && is_space(static_cast<unsigned char>(value.back()))) | ||
| 129 | - value.pop_back(); | ||
| 130 | - | ||
| 131 | - return value; | ||
| 132 | - } | ||
| 133 | - | ||
| 134 | - static std::string strip_quotes_local(const std::string &value) | ||
| 135 | - { | ||
| 136 | - const std::string s = trim_copy_local(value); | ||
| 137 | - | ||
| 138 | - if (s.size() >= 2 && | ||
| 139 | - ((s.front() == '"' && s.back() == '"') || | ||
| 140 | - (s.front() == '\'' && s.back() == '\''))) | ||
| 141 | - { | ||
| 142 | - return s.substr(1, s.size() - 2); | ||
| 143 | - } | ||
| 144 | - | ||
| 145 | - return s; | ||
| 146 | - } | ||
| 147 | - | ||
| 148 | - static std::string parse_vix_module_value( | ||
| 149 | - const fs::path &path, | ||
| 150 | - const std::string §ion, | ||
| 151 | - const std::string &key) | ||
| 152 | - { | ||
| 153 | - std::ifstream in(path); | ||
| 154 | - | ||
| 155 | - if (!in) | ||
| 156 | - return ""; | ||
| 157 | - | ||
| 158 | - std::string activeSection; | ||
| 159 | - std::string line; | ||
| 160 | - | ||
| 161 | - while (std::getline(in, line)) | ||
| 162 | - { | ||
| 163 | - std::string s = trim_copy_local(line); | ||
| 164 | - | ||
| 165 | - const std::size_t comment = s.find('#'); | ||
| 166 | - if (comment != std::string::npos) | ||
| 167 | - s = trim_copy_local(s.substr(0, comment)); | ||
| 168 | - | ||
| 169 | - if (s.empty()) | ||
| 170 | - continue; | ||
| 171 | - | ||
| 172 | - if (s.size() >= 2 && s.front() == '[' && s.back() == ']') | ||
| 173 | - { | ||
| 174 | - activeSection = trim_copy_local(s.substr(1, s.size() - 2)); | ||
| 175 | - continue; | ||
| 176 | - } | ||
| 177 | - | ||
| 178 | - if (activeSection != section) | ||
| 179 | - continue; | ||
| 180 | - | ||
| 181 | - const std::size_t eq = s.find('='); | ||
| 182 | - | ||
| 183 | - if (eq == std::string::npos) | ||
| 184 | - continue; | ||
| 185 | - | ||
| 186 | - const std::string currentKey = | ||
| 187 | - trim_copy_local(s.substr(0, eq)); | ||
| 188 | - | ||
| 189 | - if (currentKey != key) | ||
| 190 | - continue; | ||
| 191 | - | ||
| 192 | - return strip_quotes_local(trim_copy_local(s.substr(eq + 1))); | ||
| 193 | - } | ||
| 194 | - | ||
| 195 | - return ""; | ||
| 196 | - } | ||
| 197 | - | ||
| 198 | - static std::vector<std::string> parse_vix_module_array( | ||
| 199 | - const fs::path &path, | ||
| 200 | - const std::string §ion, | ||
| 201 | - const std::string &key) | ||
| 202 | - { | ||
| 203 | - std::vector<std::string> out; | ||
| 204 | - | ||
| 205 | - std::ifstream in(path); | ||
| 206 | - if (!in) | ||
| 207 | - return out; | ||
| 208 | - | ||
| 209 | - std::string activeSection; | ||
| 210 | - bool collecting = false; | ||
| 211 | - std::string line; | ||
| 212 | - | ||
| 213 | - while (std::getline(in, line)) | ||
| 214 | - { | ||
| 215 | - std::string s = trim_copy_local(line); | ||
| 216 | - | ||
| 217 | - const std::size_t comment = s.find('#'); | ||
| 218 | - if (comment != std::string::npos) | ||
| 219 | - s = trim_copy_local(s.substr(0, comment)); | ||
| 220 | - | ||
| 221 | - if (s.empty()) | ||
| 222 | - continue; | ||
| 223 | - | ||
| 224 | - if (!collecting && s.size() >= 2 && s.front() == '[' && s.back() == ']') | ||
| 225 | - { | ||
| 226 | - activeSection = trim_copy_local(s.substr(1, s.size() - 2)); | ||
| 227 | - continue; | ||
| 228 | - } | ||
| 229 | - | ||
| 230 | - if (activeSection != section) | ||
| 231 | - continue; | ||
| 232 | - | ||
| 233 | - if (!collecting) | ||
| 234 | - { | ||
| 235 | - const std::size_t eq = s.find('='); | ||
| 236 | - if (eq == std::string::npos) | ||
| 237 | - continue; | ||
| 238 | - | ||
| 239 | - const std::string currentKey = | ||
| 240 | - trim_copy_local(s.substr(0, eq)); | ||
| 241 | - | ||
| 242 | - if (currentKey != key) | ||
| 243 | - continue; | ||
| 244 | - | ||
| 245 | - std::string value = trim_copy_local(s.substr(eq + 1)); | ||
| 246 | - | ||
| 247 | - if (value.find('[') == std::string::npos) | ||
| 248 | - continue; | ||
| 249 | - | ||
| 250 | - collecting = true; | ||
| 251 | - | ||
| 252 | - const std::size_t open = value.find('['); | ||
| 253 | - value = value.substr(open + 1); | ||
| 254 | - | ||
| 255 | - const std::size_t close = value.find(']'); | ||
| 256 | - if (close != std::string::npos) | ||
| 257 | - { | ||
| 258 | - value = value.substr(0, close); | ||
| 259 | - collecting = false; | ||
| 260 | - } | ||
| 261 | - | ||
| 262 | - std::stringstream ss(value); | ||
| 263 | - std::string item; | ||
| 264 | - | ||
| 265 | - while (std::getline(ss, item, ',')) | ||
| 266 | - { | ||
| 267 | - item = strip_quotes_local(trim_copy_local(item)); | ||
| 268 | - if (!item.empty()) | ||
| 269 | - out.push_back(item); | ||
| 270 | - } | ||
| 271 | - | ||
| 272 | - continue; | ||
| 273 | - } | ||
| 274 | - | ||
| 275 | - const std::size_t close = s.find(']'); | ||
| 276 | - if (close != std::string::npos) | ||
| 277 | - { | ||
| 278 | - s = s.substr(0, close); | ||
| 279 | - collecting = false; | ||
| 280 | - } | ||
| 281 | - | ||
| 282 | - std::stringstream ss(s); | ||
| 283 | - std::string item; | ||
| 284 | - | ||
| 285 | - while (std::getline(ss, item, ',')) | ||
| 286 | - { | ||
| 287 | - item = strip_quotes_local(trim_copy_local(item)); | ||
| 288 | - if (!item.empty()) | ||
| 289 | - out.push_back(item); | ||
| 290 | - } | ||
| 291 | - } | ||
| 292 | - | ||
| 293 | - return out; | ||
| 294 | - } | ||
| 295 | - | ||
| 296 | 119 | static fs::path module_manifest_path( | |
| 297 | 120 | const fs::path &projectDir, | |
| 298 | 121 | const AppModule &module) | |
@@ -318,8 +141,8 @@ namespace vix::cli::app | |||
| 318 | 141 | const fs::path manifestPath = | |
| 319 | 142 | module_manifest_path(projectDir, module); | |
| 320 | 143 | ||
| 321 | - const std::vector<std::string> registryDeps = | ||
| 322 | - parse_vix_module_array(manifestPath, "deps", "registry"); | ||
| 144 | + const auto loaded = vix::cli::modules::load_module_manifest(manifestPath); | ||
| 145 | + const std::vector<std::string> registryDeps = loaded.success() ? loaded.manifest.registryDependencies : std::vector<std::string>{}; | ||
| 323 | 146 | ||
| 324 | 147 | if (!registryDeps.empty()) | |
| 325 | 148 | return true; | |
@@ -358,8 +181,8 @@ namespace vix::cli::app | |||
| 358 | 181 | const fs::path manifestPath = | |
| 359 | 182 | module_manifest_path(projectDir, module); | |
| 360 | 183 | ||
| 361 | - const std::vector<std::string> links = | ||
| 362 | - parse_vix_module_array(manifestPath, "deps", "links"); | ||
| 184 | + const auto loaded = vix::cli::modules::load_module_manifest(manifestPath); | ||
| 185 | + const std::vector<std::string> links = loaded.success() ? loaded.manifest.links : std::vector<std::string>{}; | ||
| 363 | 186 | ||
| 364 | 187 | if (links.empty()) | |
| 365 | 188 | continue; | |
@@ -408,19 +231,15 @@ namespace vix::cli::app | |||
| 408 | 231 | const fs::path manifestPath = | |
| 409 | 232 | module_manifest_path(projectDir, module); | |
| 410 | 233 | ||
| 411 | - const std::string workflow = | ||
| 412 | - lower_copy(parse_vix_module_value(manifestPath, "", "workflow")); | ||
| 234 | + const auto loaded = vix::cli::modules::load_module_manifest(manifestPath); | ||
| 235 | + const std::string workflow = loaded.success() ? lower_copy(loaded.manifest.workflow) : ""; | ||
| 413 | 236 | ||
| 414 | 237 | if (workflow == "websocket.client") | |
| 415 | 238 | return false; | |
| 416 | 239 | ||
| 417 | - const std::string runtime = | ||
| 418 | - lower_copy(parse_vix_module_value(manifestPath, "", "runtime")); | ||
| 240 | + const bool runtime = loaded.success() && loaded.manifest.runtime; | ||
| 419 | 241 | ||
| 420 | - if (runtime == "true" || | ||
| 421 | - runtime == "yes" || | ||
| 422 | - runtime == "on" || | ||
| 423 | - runtime == "1") | ||
| 242 | + if (runtime) | ||
| 424 | 243 | { | |
| 425 | 244 | return true; | |
| 426 | 245 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments