Skip to content

Commit 06823d5

Browse files
author
Andrey Helldar
committed
lorisleiva#52 Optimized initialization command
1 parent aaca87a commit 06823d5

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

src/LaravelDeployer/Commands/DeployInit.php

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,35 +141,44 @@ public function defineDeployementPath()
141141
public function defineAdditionalHooks()
142142
{
143143
$npm = $this->choice(
144-
'Do you want to compile your asset during deployment with NPM?',
145-
['No', 'Yes using `npm run production`', 'Yes using `npm run development`'], 1
144+
'Do you want to compile your asset during deployment with npm/yarn?',
145+
[
146+
'No',
147+
'Yes using `npm run production`',
148+
'Yes using `npm run development`',
149+
'Yes using `yarn production`',
150+
'Yes using `yarn development`',
151+
], 1
146152
);
147153

148-
if ($npm !== 'No') {
149-
$build = $npm === 'Yes using `npm run production`' ? 'production' : 'development';
150-
$this->builder->add('hooks.build', 'npm:install');
151-
$this->builder->add('hooks.build', "npm:$build");
154+
if ($npm === 'Yes using `npm run production`') {
155+
$this->addHooksCompileAssets('npm', 'production');
152156
}
153157

154-
if ($npm === 'No') {
155-
$yarn = $this->choice(
156-
'Do you want to compile your asset during deployment with YARN?',
157-
['No', 'Yes using `yarn production`', 'Yes using `yarn development`'], 1
158-
);
158+
if ($npm === 'Yes using `npm run development`') {
159+
$this->addHooksCompileAssets('npm', 'development');
160+
}
159161

160-
if ($yarn !== 'No') {
161-
$build = $yarn === 'Yes using `yarn production`' ? 'production' : 'development';
162-
$this->builder->add('hooks.build', 'yarn:install');
163-
$this->builder->add('hooks.build', "yarn:$build");
164-
}
162+
if ($npm === 'Yes using `yarn production`') {
163+
$this->addHooksCompileAssets('yarn', 'production');
165164
}
166-
165+
166+
if ($npm === 'Yes using `yarn development`') {
167+
$this->addHooksCompileAssets('yarn', 'development');
168+
}
169+
167170
if ($this->confirm('Do you want to migrate during deployment?', true)) {
168171
$this->builder->add('hooks.ready', 'artisan:migrate');
169172
}
170-
173+
171174
if ($this->confirm('Do you want to terminate horizon after each deployment?')) {
172175
$this->builder->add('hooks.ready', 'artisan:horizon:terminate');
173176
}
174177
}
178+
179+
private function addHooksCompileAssets($manager, $environment)
180+
{
181+
$this->builder->add('hooks.build', "$manager:install");
182+
$this->builder->add('hooks.build', "$manager:$environment");
183+
}
175184
}

0 commit comments

Comments
 (0)