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
<?php
function removeDir($dir) {
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file) {
(is_dir("$dir/$file")) ? removeDir("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}
if(count($argv)>1)
{
$projectName = $argv[1];
}else{
$projectName = readline('Enter project name: ');
}
if(empty($projectName)){
echo "\033[0;31mInvaild project name\033[0m\n";
exit(255);
}
echo "\033[01;32mInitializing lumen framework...\033[0m\n";
$code = 0;
system ("composer create-project --prefer-dist laravel/lumen {$projectName} 5.7.*",$code);
if($code>0){
echo "\033[0;31mInitialize lumen framework failed!\033[0m";
}
echo "\033[01;32mCleaning up needless files...\033[0m\n";
removeDir("./$projectName/routes");
removeDir("./$projectName/app/Events");
removeDir("./$projectName/app/Exceptions");
removeDir("./$projectName/app/Http");
removeDir("./$projectName/app/Jobs");
removeDir("./$projectName/app/Listeners");
removeDir("./$projectName/app/Providers");
@unlink("./$projectName/app/User.php");
if(!is_dir("./$projectName/app/Http")){
mkdir("./$projectName/app/Http");
}
echo "\033[01;32mSetting composer.json...\033[0m\n";
$composerData = json_decode(file_get_contents("./$projectName/composer.json"),true);
if(isset($composerData["autoload"])){
$composerData["autoload"]["classmap"] = [];
}
$composerData["repositories"] = [
["type"=>"composer","url"=>"http://composer.project.360cbs.com:8090"]
];
$composerData["config"] = [
"secure-http"=>false
];
file_put_contents("./$projectName/composer.json",json_encode($composerData,JSON_UNESCAPED_SLASHES));
echo "\033[01;32mInstalling tourmaline framework...\033[0m\n";
system ("composer require -d ./$projectName tourmaline/infrastructure",$code);
if($code>0){
echo "\033[0;31mLibrary tourmaline/infrastructure install failed,you may need reinstall it with command \"composer require tourmaline/infrastructure\"\033[0m";
}
system ("composer require -d ./$projectName tourmaline/word",$code);
if($code>0){
echo "\033[0;31mLibrary tourmaline/word install failed,you may need reinstall it with command \"composer require tourmaline/word\"\033[0m";
}
echo "\033[01;32mCreating project default config file...\033[0m\n";
$templateContent = file_get_contents("http://gitlab.project.360cbs.com:8090/snippets/5/raw");
$templateContent = str_replace("[\$projectName]",$projectName,$templateContent);
if(!is_dir("./$projectName/app/Config/")){
mkdir("./$projectName/app/Config");
}
file_put_contents("./$projectName/app/Config/{$projectName}Config.php",$templateContent);
echo "\033[01;32mCreating project initialize file...\033[0m\n";
$initializeFileContent = "<?php\n";
$initializeFileContent .= "\$app->withFacades();\n";
$initializeFileContent .= "\$app->withEloquent();\n";
$initializeFileContent .= "\$app->register(Tourmaline\Infrastructure\InfrastructureServiceProvider::class);\n";
$initializeFileContent .= "\Tourmaline\Infrastructure\Config\ConfigLib::addConfigurationBinding(0,\App\Config\\{$projectName}Config::class);\n";
file_put_contents("./$projectName/app/initialize.php",$initializeFileContent);
$bootstrapFileContent = file_get_contents("./$projectName/bootstrap/app.php");
$bootstrapFileContent = preg_replace('/\$app->router[\s\S]+\}\);?/i',"",$bootstrapFileContent);
$bootstrapFileContent = preg_replace('/\$app->singleton\([\s\S]+App\\\\Exceptions\\\\Handler::class\s\);/i',"",$bootstrapFileContent);
$bootstrapFileContent = str_replace("return \$app;","require __DIR__ . '/../app/initialize.php';\nreturn \$app;",$bootstrapFileContent);
file_put_contents("./$projectName/bootstrap/app.php",$bootstrapFileContent);
echo "\033[01;32mUpdating project env file...\033[0m\n";
$envFileContent = file_get_contents("./$projectName/.env");
$envFileContent = preg_replace('/APP_TIMEZONE=[\S]+/i',"APP_TIMEZONE=PRC",$envFileContent);
$envFileContent = preg_replace('/DB_PASSWORD=secret/i',"DB_PASSWORD=secret\nDB_TIMEZONE=+08:00",$envFileContent);
file_put_contents("./$projectName/.env",$envFileContent);
echo "\033[01;32mProject $projectName has been created!\033[0m\n";