-
Notifications
You must be signed in to change notification settings - Fork 0
/
projectGeneration.php
289 lines (238 loc) · 9.32 KB
/
projectGeneration.php
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
class NewProject
{
/**
* project Name
*/
var $appName;
/**
* project Author team
*/
var $authors = [];
/**
* project mainclass
*/
var $mainClass = "main";
/**
* project Infos
*/
var $infos;
/**
* project version
*/
var $version = "1.0.0";
/**
* project License
*/
var $License = "MIT";
/**
* project packageName
*/
var $packageName;
var $CompilationTarget =
[
"MACOS" =>
[
"10.9.*",
"10.10.*",
"10.11.*",
"10.12.*",
"10.13.*",
"10.14.*"
],
"WINDOWS" =>
[
"7.*",
"8.*",
"10.*"
],
"LINUX" =>
[
"*"
]
];
/**
* project language
*/
var $lang = "EN-UK/US";
public function __construct() {
$filename = "appInfos.json";
if (!file_exists($filename)) {
$this->appName = readline("app Name > ");
$this->history[] = "app Name : ".$this->appName."\r\n";
$this->authors = readline("developpement team > ");
$this->history[] = "developpement team : ".$this->authors."\r\n";
$this->mainClass = str_replace(" ","_",readline("main Class > "));
$this->history[] = "main Class : ".$this->mainClass."\r\n";
$this->infos = readline("package infos > ");
$this->history[] = "package infos : ".$this->infos."\r\n";
$this->version = readline("version > ");
$this->history[] = "version : ".$this->version."\r\n";
$this->License = readline("License > ");
$this->history[] = "License : ".$this->License."\r\n";
$this->packageName = readline("package Name > ");
$this->history[] = "package Name : ".$this->packageName."\r\n";
} else {
$this->history[] = "APP INFO PRELOADED\r\n";
}
}
public function parseJsonProject()
{
$filename = "appInfos.json";
if (!file_exists($filename)) {
$appInfos["appName"] = $this->appName;
$appInfos["authors"] = $this->authors;
$appInfos["mainClass"] = $this->mainClass;
$appInfos["infos"] = $this->infos;
$appInfos["version"] = $this->version;
$appInfos["License"] = $this->License;
$appInfos["packageName"] = $this->packageName;
$appInfos["CompilationTarget"] = $this->CompilationTarget;
$output = json_encode($appInfos,JSON_PRETTY_PRINT);
file_put_contents($filename,$output);
$this->history[] = "project values generated\r\n";
} else {
$jsonvals = json_decode(file_get_contents($filename));
$this->appName = $jsonvals->appName;
$this->authors = $jsonvals->authors;
$this->mainClass = $jsonvals->mainClass;
$this->infos = $jsonvals->infos;
$this->version = $jsonvals->version;
$this->License = $jsonvals->License;
$this->useComposer = $jsonvals->useComposer;
$jsonvals = json_decode(file_get_contents($filename),JSON_PRETTY_PRINT);
$this->CompilationTarget = $jsonvals["appName"];
echo "nothing to generate here\r\n";
}
}
public function generateMainClass()
{
$file =
"<?php
/**
*
* Main Class of KeyPHP Project nammed ".$this->appName."
*
* @author ".$this->authors."
*
*/
class ".$this->mainClass." extends KeyPHPKernel\KEYPHPAPPLICATION
{
/**
* Var example
*/
var \$greetings = \"Hello World!\";
/**
*
* loop() function
*
* main function of the class ".$this->mainClass."
*
* @return bool
*
*/
public function loop(){
print \$this->greetings.\"\\r\\n\";
return false;
}
}";
mkdir("app");
$this->history[] = "app/ folder generated\r\n";
$my_file = "app/".$this->mainClass.".php";
$handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file); //implicitly creates file
$this->history[] = $my_file." created\r\n";
fwrite($handle, $file);
$this->history[] = "Main class successfuly generated\r\n";
fclose($handle);
}
public function generateSourceFiles()
{
$files[0] = "ENV.php";
$files[1] = "autoload.php";
$files[2] = "application.php";
$files[3] = "env.json";
$files[4] = "LICENSE.keyphp";
$files[4] = "LICENSECOMPOSER";
$files[5] = "doc.txt";
$files[6] = "readme.rtf";
$files[7] = "readme.txt";
$files[8] = "readme.md";
$files[9] = "Makefile";
$files[10] = "projectDestroyer.php";
$files[11] = "appInfos.json";
file_put_contents("included_sourcefiles.json", json_encode($files,JSON_PRETTY_PRINT));
unset($files[11]);
$this->history[] = "source files added to queue\r\n";
$wantComposer = null;
$first = true;
if (isset($this->useComposer)) {
if ($this->useComposer == true) {
$wantComposer = "Y";
} elseif ($this->useComposer == false) {
$wantComposer = "N";
}
}
while ($wantComposer != "Y" && $wantComposer != "N") {
if (!$first) {
$wantComposer = print("Incorrect answer, must be Y or N\r\n");
}
$wantComposer = readline("DO YOU WANT TO INSALL COMPOSER ON THE PROJECT? (Y/N) : ");
$first = false;
}
if ($wantComposer == "Y") {
echo "downloading composer\r\n";
echo "to stop process ctrl+C\r\n";
$output = shell_exec("php -r \"copy('https://getcomposer.org/installer', 'composer-setup.php');\"
php composer-setup.php
php -r \"unlink('composer-setup.php');\"");
print_r($output);
echo "\r\ncomposer installed\r\n";
$this->history[] = "composer installed localy\r\n";
}
$this->history[] = "source file queue treatment starting";
foreach ($files as $value) {
echo "creating $value\r\n";
echo "downloading from https://raw.githubusercontent.com/PYLOTT/KeyPHP/master/$value\r\n";
file_put_contents($value, file_get_contents("https://raw.githubusercontent.com/PYLOTT/KeyPHP/master/".$value));
echo "$value fully downloaded and created\r\n";
$this->history[] = "$value fully downloaded and created\r\n";
}
if (file_exists("Makefile")) {
if (PHP_OS == "Darwin" || PHP_OS == "BSD" || PHP_OS == "Linux" || PHP_OS == "Solaris") {
mkdir("libraries");
$output = shell_exec('make Download_Basic_Libraries');
print_r($output);
echo "\r\nBasic Libraries Downloaded\r\n";
$this->history[] = "Basic Libraries Downloaded\r\n";
} elseif (PHP_OS == "Windows") {
mkdir("libraries");
// since this program is developped on OSX, tests of NMAKE
// can't be made. We please you to do so and publish results
// on https://github.com/PYLOTT/KeyPHP/issues.
// issues can come from the makefile itself. please purpose
// your corrections if you find one.
// thank you for your understanding. Louis Bertrand <adressepro111@pylott.yt>
$output = shell_exec('nmake Download_Basic_Libraries');
print_r($output);
echo "\r\nBasic Libraries Downloaded\r\n";
$this->history[] = "Basic Libraries Downloaded\r\n";
} else {
echo "\r\nYour os can't be nammed.\r\nplease proceed yourself to Makefile\r\n";
$this->history[] = "Your os can't be nammed.\r\nplease proceed yourself to Makefile\r\n";
}
} else {
echo "\r\nMakefile can't be found, ignoring\r\n";
$this->history[] = "Unable to find Makefile\r\n";
}
}
public function logger()
{
mkdir("logs");
file_put_contents("logs/install_latest", $this->history);
}
}
$newApp = new NewProject;
$newApp->parseJsonProject();
$newApp->generateMainClass();
$newApp->generateSourceFiles();
$newApp->logger();