-
Notifications
You must be signed in to change notification settings - Fork 9
/
create
132 lines (121 loc) · 3.22 KB
/
create
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
#!/usr/bin/env php
<?php
/**
* User: ben
* Email: [email protected]
* Date: 2019-01-01
* Time: 00:01
*/
$laravel_plus_basename = basename(__DIR__);
$remove_excess_files = [
'composer.lock',
'_config.yml',
'create',
'create_win',
'_ide_helper.php',
];
$remove_excess_dirs =[];
$filter_excess_dirs = [
'.',
'..',
'.git/',
'vendor/',
'node_modules/',
'.github/',
];
/**
*
*/
function testProjectStart(): void
{
if (is_file(__DIR__ . ".env")) {
die("error: have .env file" . PHP_EOL);
}
}
/**
*
*/
function checkProjectDirectory(): void
{
global $laravel_plus_basename;
if ("LaravelPlus" !== $laravel_plus_basename && "laravel-plus" !== $laravel_plus_basename) {
echo "error: Error original project path " . $laravel_plus_basename . PHP_EOL;
die;
}
}
/**
* @return string
*/
function checkRequestVariable(): string
{
global $argv, $laravel_plus_basename;
if (empty($argv) || !isset($argv[1]) || empty($argv[1])) {
echo "error: No project name set" . PHP_EOL;
echo "eg): php {$laravel_plus_basename}/create YourProject" . PHP_EOL;
die;
}
return $argv[1];
}
/**
*
*/
function removeExcessFileInNewProject($product): void
{
global $remove_excess_files, $remove_excess_dirs;
foreach ($remove_excess_files as $remove_excess_file) {
if (is_file("{$product}/{$remove_excess_file}")) {
exec("rm {$product}/{$remove_excess_file}");
}
}
foreach ($remove_excess_dirs as $remove_excess_dir) {
if (is_file("{$product}/{$remove_excess_dir}")) {
exec("rm -rf {$product}/{$remove_excess_dir}/*");
}
}
}
/**
* @param string $laravel_plus_basename
* @param $product
*/
function copyHideFile(string $laravel_plus_basename, $product): void
{
$hidden_files = [
".env.example",
".gitattributes",
".gitignore",
];
foreach ($hidden_files as $hidden_file) {
exec("cp {$laravel_plus_basename}/{$hidden_file} {$product}/{$hidden_file}");
}
exec("cp {$product}/.env.example {$product}/.env");
}
/**
* @param string $laravel_plus_basename
*/
function handle(string $laravel_plus_basename)
{
global $filter_excess_dirs;
$product = checkRequestVariable();
echo "\033[34mLaravelPlus Build \033[31m{$product}\e[0m \e[34mproject\e[0m" . PHP_EOL;
testProjectStart();
exec("cd {$laravel_plus_basename}");
checkProjectDirectory();
echo 'Loading ... ' . PHP_EOL;
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
exec("php LaravelPlus/create_win {$product} > create_win_log.txt");
}else{
$filter_excess = '';
foreach($filter_excess_dirs as $filter_excess_dir){
$filter_excess .= "--exclude {$filter_excess_dir} ";
}
exec("rsync -av {$filter_excess} {$laravel_plus_basename}/* {$product}");
}
if (!is_dir("{$product}")) {
die('Error: cp new project is error' . PHP_EOL);
}
removeExcessFileInNewProject($product);
copyHideFile($laravel_plus_basename, $product);
exec("cd {$product}");
echo "\033[32mCreate \033[31m{$product}\e[0m \e[32mproject success" . PHP_EOL;
}
handle($laravel_plus_basename);