forked from elapse-annals/laravel-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update
79 lines (70 loc) · 2.04 KB
/
update
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
#!/usr/bin/env php
<?php
/**
* User: ben
* Email: benhuang1024@gmail.com
* Date: 2019-01-01
* Time: 00:01
*/
$laravel_plus_basename = basename(__DIR__);
$update_files = [
'storage' => [
'app' => [
'tmpl' => [
'framework',
],
],
],
];
/**
* @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 handle()
{
$product = checkRequestVariable();
echo "\033[34m Update \033[31m{$product}\e[0m \e[34m project loading ... \e[0m" . PHP_EOL;
global $update_files;
replaceFile($update_files, $product);
copyFramework($product);
echo "\033[32mUpdate \033[31m{$product}\e[0m \e[32mproject success" . PHP_EOL;
}
function copyFramework($product)
{
global $laravel_plus_basename;
$copy_exec = "cp {$laravel_plus_basename}/app/Console/Commands/Framework.php {$product}/app/Console/Commands/Framework.php" . PHP_EOL;
echo $copy_exec;
exec($copy_exec);
$copy_exec = "cp {$laravel_plus_basename}/app/Http/Controllers/FrameworkController.php {$product}/app/Http/Controllers/FrameworkController.php" . PHP_EOL;
echo $copy_exec;
exec($copy_exec);
}
/**
* @param array $update_files
* @param string $product
* @param string|null $file_path
*/
function replaceFile(array $update_files, string $product, string $file_path = null): void
{
global $laravel_plus_basename;
foreach ($update_files as $key => $update_file) {
if (is_array($update_file)) {
$file_path .= '/' . $key;
replaceFile($update_file, $product, $file_path);
} else {
$copy_exec = "cp -rf {$laravel_plus_basename}{$file_path} {$product}{$file_path}/../" . PHP_EOL;
echo $copy_exec;
exec($copy_exec);
}
}
}
handle();