forked from studio1902/statamic-peak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StarterKitPostInstall.php
139 lines (120 loc) · 6.38 KB
/
StarterKitPostInstall.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
<?php
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
class StarterKitPostInstall
{
public function handle($console)
{
if ($console->confirm('Do you want overwrite your `.env` file with the Peak presets?', true)) {
$appName = $console->ask('What should be your app name?');
$appName = preg_replace('/([\'|\"|#])/m', '', $appName);
$debugBarEnabled = $console->confirm('Do you want to use the debugbar?', false);
$originalAppUrl = env('APP_URL');
$originalAppKey = env('APP_KEY');
$env = app('files')->get(base_path('.env.example'));
$env = str_replace('APP_NAME="Statamic Peak"', "APP_NAME=\"{$appName}\"", $env);
$env = str_replace('APP_URL=', "APP_URL=\"{$originalAppUrl}\"", $env);
$env = str_replace('APP_KEY=', "APP_KEY=\"{$originalAppKey}\"", $env);
if (! $debugBarEnabled) {
$env = str_replace('DEBUGBAR_ENABLED=true', 'DEBUGBAR_ENABLED=false', $env);
}
$readme = app('files')->get(base_path('README.md'));
$readme = str_replace('APP_NAME="Statamic Peak"', "APP_NAME=\"{$appName}\"", $readme);
$readme = str_replace('APP_KEY=', "APP_KEY=\"{$originalAppKey}\"", $readme);
if ($console->confirm('Do you want use Imagick as an image processor instead of GD?', true)) {
$env = str_replace('#IMAGE_MANIPULATION_DRIVER=imagick', 'IMAGE_MANIPULATION_DRIVER=imagick', $env);
$readme = str_replace('#IMAGE_MANIPULATION_DRIVER=imagick', 'IMAGE_MANIPULATION_DRIVER=imagick', $readme);
}
if ($console->confirm('Do you want to enable `SAVE_CACHED_IMAGES` (slower initial page load)?', false)) {
$env = str_replace('SAVE_CACHED_IMAGES=false', 'SAVE_CACHED_IMAGES=true', $env);
$readme = str_replace('SAVE_CACHED_IMAGES=false', 'SAVE_CACHED_IMAGES=true', $readme);
}
app('files')->put(base_path('.env'), $env);
app('files')->put(base_path('README.md'), $readme);
}
if ($console->confirm('Do you want to init a git repo and configure gitignore?', true)) {
$process = new Process(['git', 'init']);
try {
$process->mustRun();
$console->info('Repo initialised.');
} catch (ProcessFailedException $exception) {
$console->info($exception->getMessage());
}
if ($console->confirm('Do you want to exclude the `public/build` folder from git?', true)) {
app('files')->append(base_path('.gitignore'), "\n/public/build/");
}
if ($console->confirm('Do you want to exclude the `users` folder from git?', false)) {
app('files')->append(base_path('.gitignore'), "\n/users");
}
if ($console->confirm('Do you want to exclude the `storage/form` folder from git?', false)) {
app('files')->append(base_path('.gitignore'), "\n/storage/forms");
}
}
if ($console->confirm('Do you want to install npm dependencies?', true)) {
$process = new Process(['npm', 'i']);
try {
$process->mustRun();
$console->info('Dependencies installed.');
} catch (ProcessFailedException $exception) {
$console->info($exception->getMessage());
}
}
if ($console->confirm('Do you want to `npm i puppeteer` and `composer require spatie/browsershot` for generating social images?', true)) {
$process = new Process(['npm', 'i', 'puppeteer']);
try {
$process->mustRun();
$console->info('Puppeteer installed.');
} catch (ProcessFailedException $exception) {
$console->info($exception->getMessage());
}
$process = new Process(['composer', 'require', 'spatie/browsershot']);
try {
$process->mustRun();
$console->info('Browsershot installed.');
} catch (ProcessFailedException $exception) {
$console->info($exception->getMessage());
}
}
if ($console->confirm('Do you want to install missing Laravel translation files using the Laravel Lang package?', true)) {
$process = new Process(['composer', 'require', 'laravel-lang/common', '--dev']);
try {
$process->mustRun();
$console->info('Laravel Lang installed.');
} catch (ProcessFailedException $exception) {
$console->info($exception->getMessage());
}
$console->info('Enter the handles of the languages you want to install. Press enter when you\'re done.');
do {
if ($handle = $console->ask('Handle of language (e.g. "nl")')) {
$process = new Process(['php', 'artisan', 'lang:add', $handle]);
try {
$process->mustRun();
$console->info("Language \"{$handle}\" installed.");
} catch (ProcessFailedException $exception) {
$console->info($exception->getMessage());
}
}
} while ($handle !== null);
}
if ($console->confirm('Would you like to star the Peak repo?', false)) {
if (PHP_OS_FAMILY == 'Darwin') {
exec('open https://github.com/studio1902/statamic-peak');
}
if (PHP_OS_FAMILY == 'Windows') {
exec('start https://github.com/studio1902/statamic-peak');
}
if (PHP_OS_FAMILY == 'Linux') {
exec('xdg-open https://github.com/studio1902/statamic-peak');
}
$console->info('Thank you!');
}
$console->info('<info>[✓]</info> Peak is installed. Enjoy the view!');
$console->newline();
$console->warn('Run `php please peak:clear-site` to get rid of default content.');
$console->newline();
$console->warn('Run `php please peak:install-preset` to install premade sets onto your website.');
$console->newline();
$console->warn('Run `php please peak:install-block` to install premade blocks onto your page builder.');
$console->newline();
}
}