-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProject.cpp
More file actions
114 lines (108 loc) · 3.4 KB
/
Project.cpp
File metadata and controls
114 lines (108 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// Created by georgeckito on 8/5/2024.
//
#include "Project.h"
#include <fstream>
#include <iomanip>
#include "windows.h"
#include "Log/Log.h"
namespace project {
std::string Project::getPath() {
return this->path;
}
void Project::setPath(const std::string& path) {
this->path = path;
}
projectType Project::getType() {
return this->type;
}
void Project::setType(projectType type) {
this->type = type;
}
std::string Project::getSrcDir() {
return this->srcDir;
}
void Project::setSrcDir(const std::string& srcDir) {
this->srcDir = srcDir;
}
std::vector<std::string> Project::getFiles() {
return this->files;
}
void Project::setFiles(const std::vector<std::string>& files) {
this->files = files;
}
std::vector<std::string> Project::getFolders() {
return this->folders;
}
void Project::setFolders(const std::vector<std::string>& folders) {
this->folders = folders;
}
nlohmann::json Project::getJsquick() {
return this->jsquick;
}
void Project::setJsquick(const nlohmann::json& jsquick) {
this->jsquick = jsquick;
}
std::string Project::getPackages() {
return this->packages;
}
void Project::setPackages(const std::string& packages) {
this->packages = packages;
}
void Project::createFiles() {
for(const auto& file : this->files) {
const std::string src = this->srcDir + file;
const std::string dest = this->path + file;
Utility::copyFile(src, dest);
}
}
void Project::createFolders() {
for(const auto& folder : this->folders) {
const std::string dest = this->path + folder;
CreateDirectory(dest.c_str(), nullptr);
}
}
void Project::createJsquick() {
const std::string jsquickFile = this->path + "\\.jsquick";
std::ofstream jsquick(jsquickFile);
jsquick << std::setw(4) << this->jsquick << std::endl;
jsquick.close();
Log::logSUCC("Created the files");
Log::logWarn("Don't modify the .jsquick file");
Log::logInfo("Installing Packages...");
}
void Project::createPackage() {
const std::string packageFile = this->path + "\\package.json";
std::ofstream package(packageFile);
nlohmann::json pkg;
pkg["name"] = this->jsquick["name"];
pkg["version"] = "1.0.0";
pkg["description"] = "Generated by jsquick";
pkg["main"] = "index.js";
pkg["scripts"]["start"] = "node index.js";
pkg["dependencies"]["express"] = "^4.17.1";
package << std::setw(4) << pkg << std::endl;
package.close();
}
void Project::installPackages() {
const std::string cmd = "cd " + this->path + " && npm install " + this->packages;
int result = std::system(cmd.c_str());
if(result == 0) {
Log::logSUCC("Installed packages");
} else {
Log::logError("Could not install packages");
}
}
void Project::create() {
try {
this->createENV();
} catch (const std::exception& e) {
Log::logError("Could not/Did not create .env file");
}
this->createFolders();
this->createFiles();
this->createJsquick();
this->createPackage();
this->installPackages();
}
} // project