Skip to content

Commit fbe6b8d

Browse files
committed
feat(new): add backend template scaffolding
2 parents 5b6cf36 + 3de62e3 commit fbe6b8d

22 files changed

Lines changed: 2364 additions & 1495 deletions

include/vix/cli/commands/new/NewGenerator.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,19 @@ namespace vix::commands::new_cmd::generator
7272
const std::string &projName,
7373
std::string &err);
7474

75+
/// Generates all files for a production backend project under projectDir.
76+
bool generate_backend_project(
77+
const fs::path &projectDir,
78+
const std::string &projName,
79+
const FeaturesSelection &features,
80+
std::string &err);
81+
7582
// ------------------------------------------------------------------
7683
// Post-generation output
7784
// ------------------------------------------------------------------
78-
7985
void print_next_steps_app(const fs::path &projectDir, const std::string &projName);
8086
void print_next_steps_vue(const fs::path &projectDir, const std::string &projName);
8187
void print_next_steps_lib(const fs::path &projectDir, const std::string &projName);
8288
void print_next_steps_game(const fs::path &projectDir, const std::string &projName);
89+
void print_next_steps_backend(const fs::path &projectDir, const std::string &projName);
8390
} // namespace vix::commands::new_cmd::generator

include/vix/cli/commands/new/NewOutput.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ namespace vix::commands::new_cmd::output
4848
const std::filesystem::path &projectDir,
4949
const std::string &projName);
5050

51+
/// Full creation summary for a Backend project.
52+
void print_creation_backend(
53+
const std::filesystem::path &projectDir,
54+
const std::string &projName,
55+
const FeaturesSelection &features);
56+
5157
} // namespace vix::commands::new_cmd::output
5258

5359
#endif

include/vix/cli/commands/new/NewTemplates.hpp

Lines changed: 8 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -4,188 +4,17 @@
44
* @file NewTemplates.hpp
55
* @author Gaspard Kirira
66
*
7-
* Copyright 2025, Gaspard Kirira. All rights reserved.
7+
* Copyright 2025, Gaspard Kirira. All rights reserved.
88
* https://github.com/vixcpp/vix
99
* Use of this source code is governed by a MIT license
1010
* that can be found in the License file.
1111
*
12-
* File content templates for the `vix new` command.
13-
* All functions return the textual content of a generated file.
12+
* Public facade for all `vix new` file-content templates.
1413
*/
1514

16-
#include <string>
17-
#include <vix/cli/commands/new/NewTypes.hpp>
18-
19-
namespace vix::commands::new_cmd::templates
20-
{
21-
22-
// ------------------------------------------------------------------
23-
// Static content (inline constants)
24-
// ------------------------------------------------------------------
25-
26-
/// src/main.cpp for a new App project
27-
constexpr const char *kMainCpp = R"(#include <vix.hpp>
28-
using namespace vix;
29-
30-
int main()
31-
{
32-
App app;
33-
34-
// GET /
35-
app.get("/", [](Request&, Response& res) {
36-
res.send("Hello world");
37-
});
38-
39-
app.run(8080);
40-
}
41-
)";
42-
43-
/// tests/test_basic.cpp for a new App project
44-
constexpr const char *kBasicTestCpp_App = R"(#include <vix/tests/tests.hpp>
45-
46-
int main()
47-
{
48-
using namespace vix::tests;
49-
50-
auto &registry = TestRegistry::instance();
51-
registry.clear();
52-
53-
registry.add(TestCase("app basic test", [] {
54-
Assert::equal(2 + 2, 4);
55-
}));
56-
57-
return TestRunner::run_all_and_exit();
58-
}
59-
)";
60-
61-
/// config/app.json default content
62-
constexpr const char *kAppConfigJson = R"JSON({
63-
"server": {
64-
"port": 8080,
65-
"request_timeout": 2000,
66-
"io_threads": 0,
67-
"session_timeout_sec": 20
68-
},
69-
"logging": {
70-
"async": true,
71-
"queue_max": 20000,
72-
"drop_on_overflow": true
73-
},
74-
"waf": {
75-
"mode": "basic",
76-
"max_target_len": 4096,
77-
"max_body_bytes": 1048576
78-
},
79-
"database": {
80-
"default": {
81-
"host": "localhost",
82-
"user": "root",
83-
"password": "",
84-
"name": "",
85-
"port": 3306
86-
}
87-
}
88-
}
89-
)JSON";
90-
91-
/// Default .env.example / .env content for an App project
92-
constexpr const char *kEnvExample = R"(# ----------------------------------
93-
# Server
94-
# ----------------------------------
95-
SERVER_PORT=8080
96-
97-
# ----------------------------------
98-
# Database
99-
# ----------------------------------
100-
DATABASE_ENGINE=mysql
101-
DATABASE_DEFAULT_HOST=127.0.0.1
102-
DATABASE_DEFAULT_PORT=3306
103-
DATABASE_DEFAULT_USER=root
104-
DATABASE_DEFAULT_PASSWORD=
105-
DATABASE_DEFAULT_NAME=appdb
106-
107-
# ----------------------------------
108-
# Logging
109-
# ----------------------------------
110-
LOGGING_ASYNC=true
111-
112-
# ----------------------------------
113-
# Security / WAF
114-
# ----------------------------------
115-
WAF_MODE=basic
116-
)";
117-
118-
// ------------------------------------------------------------------
119-
// Library scaffold helpers
120-
// ------------------------------------------------------------------
121-
122-
/// include/<name>/<name>.hpp (header-only library stub)
123-
std::string make_lib_header(const std::string &name);
124-
125-
/// tests/test_basic.cpp for a library project
126-
std::string make_basic_test_cpp_lib(const std::string &name);
127-
128-
/// examples/basic.cpp for a library project
129-
std::string make_basic_example_cpp_lib(const std::string &name);
130-
131-
/// examples/CMakeLists.txt for a library project
132-
std::string make_examples_cmakelists_lib(const std::string &name);
133-
134-
// ------------------------------------------------------------------
135-
// README generators
136-
// ------------------------------------------------------------------
137-
138-
std::string make_readme_app(const std::string &projectName);
139-
std::string make_readme_vue_app(const std::string &projectName);
140-
std::string make_readme_lib(const std::string &name);
141-
142-
// ------------------------------------------------------------------
143-
// CMakePresets.json generators
144-
// ------------------------------------------------------------------
145-
146-
std::string make_cmake_presets_json_app(const FeaturesSelection &f);
147-
std::string make_cmake_presets_json_lib();
148-
149-
// ------------------------------------------------------------------
150-
// Project manifest (.vix) generators
151-
// ------------------------------------------------------------------
152-
153-
std::string make_project_manifest_app(const std::string &name, const FeaturesSelection &f);
154-
std::string make_project_manifest_lib(const std::string &name);
155-
156-
// ------------------------------------------------------------------
157-
// vix.json generators
158-
// ------------------------------------------------------------------
159-
160-
std::string make_vix_json_app(const std::string &name);
161-
std::string make_vix_json_lib(const std::string &name);
162-
std::string make_vix_json_vue_app(const std::string &name);
163-
164-
// ------------------------------------------------------------------
165-
// Vue frontend generators
166-
// ------------------------------------------------------------------
167-
168-
std::string make_vue_package_json(const std::string &projectName);
169-
std::string make_vue_index_html(const std::string &projectName);
170-
std::string make_vue_vite_config();
171-
std::string make_vue_main_js();
172-
std::string make_vue_app_vue();
173-
174-
// ------------------------------------------------------------------
175-
// Game generators
176-
// ------------------------------------------------------------------
177-
178-
std::string make_game_main_cpp(const std::string &projectName);
179-
std::string make_game_package_json(const std::string &projectName);
180-
std::string make_readme_game(const std::string &projectName);
181-
std::string make_project_manifest_game(const std::string &projectName);
182-
std::string make_vix_json_game(const std::string &projectName);
183-
184-
// ------------------------------------------------------------------
185-
// CMakeLists.txt generators
186-
// ------------------------------------------------------------------
187-
188-
std::string make_cmakelists_app(const std::string &projectName, const FeaturesSelection &f);
189-
std::string make_cmakelists_lib(const std::string &name);
190-
191-
} // namespace vix::commands::new_cmd::templates
15+
#include <vix/cli/commands/new/templates/AppTemplates.hpp>
16+
#include <vix/cli/commands/new/templates/BackendTemplates.hpp>
17+
#include <vix/cli/commands/new/templates/CommonTemplates.hpp>
18+
#include <vix/cli/commands/new/templates/GameTemplates.hpp>
19+
#include <vix/cli/commands/new/templates/LibTemplates.hpp>
20+
#include <vix/cli/commands/new/templates/VueTemplates.hpp>

include/vix/cli/commands/new/NewTypes.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ namespace vix::commands::new_cmd
1919
App,
2020
Lib,
2121
Vue,
22-
Game
22+
Game,
23+
Backend
2324
};
2425

2526
struct FeaturesSelection
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#pragma once
2+
3+
/**
4+
* @file AppTemplates.hpp
5+
* @author Gaspard Kirira
6+
*
7+
* File-content templates for the default `vix new` application template.
8+
*/
9+
10+
#include <string>
11+
12+
#include <vix/cli/commands/new/NewTypes.hpp>
13+
14+
namespace vix::commands::new_cmd::templates
15+
{
16+
17+
/// src/main.cpp for a new App project.
18+
constexpr const char *kMainCpp = R"(#include <vix.hpp>
19+
using namespace vix;
20+
21+
int main()
22+
{
23+
App app;
24+
25+
// GET /
26+
app.get("/", [](Request&, Response& res) {
27+
res.send("Hello world");
28+
});
29+
30+
app.run(8080);
31+
}
32+
)";
33+
34+
/// tests/test_basic.cpp for a new App project.
35+
constexpr const char *kBasicTestCpp_App = R"(#include <vix/tests/tests.hpp>
36+
37+
int main()
38+
{
39+
using namespace vix::tests;
40+
41+
auto &registry = TestRegistry::instance();
42+
registry.clear();
43+
44+
registry.add(TestCase("app basic test", [] {
45+
Assert::equal(2 + 2, 4);
46+
}));
47+
48+
return TestRunner::run_all_and_exit();
49+
}
50+
)";
51+
52+
/// config/app.json default content.
53+
constexpr const char *kAppConfigJson = R"JSON({
54+
"server": {
55+
"port": 8080,
56+
"request_timeout": 2000,
57+
"io_threads": 0,
58+
"session_timeout_sec": 20
59+
},
60+
"logging": {
61+
"async": true,
62+
"queue_max": 20000,
63+
"drop_on_overflow": true
64+
},
65+
"waf": {
66+
"mode": "basic",
67+
"max_target_len": 4096,
68+
"max_body_bytes": 1048576
69+
},
70+
"database": {
71+
"default": {
72+
"host": "localhost",
73+
"user": "root",
74+
"password": "",
75+
"name": "",
76+
"port": 3306
77+
}
78+
}
79+
}
80+
)JSON";
81+
82+
/// Default .env.example content for an App project.
83+
constexpr const char *kEnvExample = R"(# ----------------------------------
84+
# Server
85+
# ----------------------------------
86+
SERVER_PORT=8080
87+
88+
# ----------------------------------
89+
# Database
90+
# ----------------------------------
91+
DATABASE_ENGINE=mysql
92+
DATABASE_DEFAULT_HOST=127.0.0.1
93+
DATABASE_DEFAULT_PORT=3306
94+
DATABASE_DEFAULT_USER=root
95+
DATABASE_DEFAULT_PASSWORD=
96+
DATABASE_DEFAULT_NAME=appdb
97+
98+
# ----------------------------------
99+
# Logging
100+
# ----------------------------------
101+
LOGGING_ASYNC=true
102+
103+
# ----------------------------------
104+
# Security / WAF
105+
# ----------------------------------
106+
WAF_MODE=basic
107+
)";
108+
109+
std::string make_readme_app(const std::string &projectName);
110+
111+
std::string make_cmake_presets_json_app(const FeaturesSelection &features);
112+
113+
std::string make_project_manifest_app(
114+
const std::string &projectName,
115+
const FeaturesSelection &features);
116+
117+
std::string make_vix_json_app(const std::string &projectName);
118+
119+
std::string make_cmakelists_app(
120+
const std::string &projectName,
121+
const FeaturesSelection &features);
122+
123+
} // namespace vix::commands::new_cmd::templates

0 commit comments

Comments
 (0)