/
Launch.php
156 lines (133 loc) Β· 5.19 KB
/
Launch.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
namespace A17\Blast\Commands;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use A17\Blast\Traits\Helpers;
use A17\Blast\Traits\TailwindViewports;
class Launch extends Command
{
use Helpers;
use TailwindViewports;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'blast:launch
{--install : Force install dependencies}
{--noInstall : Deprecated. Launch Blast without installing dependencies}
{--noGenerate : Skip auto-generating stories based on existing components}
{--port= : Port used to run Storybook}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Init the Blast Storybook instance.';
/**
* @var Filesystem
*/
protected $filesystem;
/**
* @param Filesystem $filesystem
*/
public function __construct(Filesystem $filesystem)
{
parent::__construct();
$this->filesystem = $filesystem;
$this->storybookServer = config('blast.storybook_server_url');
$this->vendorPath = $this->getVendorPath();
$this->storybookStatuses = config('blast.storybook_statuses');
$this->storybookTheme = config('blast.storybook_theme', 'normal');
$this->customTheme = config('blast.storybook_custom_theme', false);
$this->docsTheme = config('blast.storybook_docs_theme', 'normal');
$this->expandedControls = config('blast.storybook_expanded_controls');
$this->storybookGlobalTypes = config(
'blast.storybook_global_types',
[],
);
$this->storybookSortOrder = config('blast.storybook_sort_order', []);
$this->storybookViewports = config('blast.storybook_viewports', false);
}
/*
* Executes the console command.
*
* @return mixed
*/
public function handle()
{
$noGenerate = $this->option('noGenerate');
$npmInstall = $this->option('install');
$noInstall = $this->option('noInstall');
$installMessage = $this->getInstallMessage($npmInstall);
$port = $this->option('port');
// init progress bar
$progressBar = $this->output->createProgressBar(2);
$progressBar->setFormat('%current%/%max% [%bar%] %message%');
// Install step
$progressBar->setMessage($installMessage);
$progressBar->start();
if ($npmInstall) {
$this->newLine();
}
if ($noInstall) {
$this->info(
'The `--noInstall` option has been removed and npm dependencies are now installed automatically. Run `php artisan blast:launch` without options to skip installing dependencies and use the `--install` option to force install dependencies',
);
sleep(5);
}
// install
$this->installDependencies($npmInstall);
usleep(250000);
// generate stories
if (!$noGenerate) {
$this->info('');
$progressBar->setMessage('Generating Stories...');
$progressBar->advance();
$generatedDocs = $this->callSilently('blast:generate-docs', [
'--update-data' => 1,
]);
if (!$generatedDocs) {
$this->call('blast:generate-stories');
}
} else {
$this->info('');
$progressBar->setMessage('Skipping Story Generation...');
$progressBar->advance();
}
usleep(250000);
// init storybook and watch stories
$this->info('');
$progressBar->setMessage(
'Setup Complete. Booting Storybook and watching stories.',
);
$progressBar->finish();
// fix CORS in dev
$this->filesystem->ensureDirectoryExists($this->vendorPath . '/tmp');
$this->filesystem->put($this->vendorPath . '/tmp/_blast', '');
$this->runProcessInBlast(['npm', 'run', 'storybook'], true, [
'STORYBOOK_SERVER_URL' => $this->storybookServer,
'STORYBOOK_STATIC_PATH' => public_path(),
'STORYBOOK_PORT' => $port ?? 6006,
'STORYBOOK_STATUSES' => json_encode($this->storybookStatuses),
'STORYBOOK_THEME' => json_encode($this->storybookTheme),
'STORYBOOK_CUSTOM_THEME' => json_encode($this->customTheme),
'STORYBOOK_DOCS_THEME' => json_encode($this->docsTheme),
'STORYBOOK_EXPANDED_CONTROLS' => json_encode(
$this->expandedControls,
),
'STORYBOOK_GLOBAL_TYPES' => json_encode(
$this->storybookGlobalTypes,
),
'STORYBOOK_SORT_ORDER' => json_encode($this->storybookSortOrder),
'STORYBOOK_VIEWPORTS' => json_encode(
$this->buildTailwindViewports(),
),
'LIBSTORYPATH' => $this->vendorPath . '/stories',
'PROJECTPATH' => base_path(),
'COMPONENTPATH' => base_path('resources/views/stories'),
]);
}
}