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} 8.*",$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 = "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";