-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Phabalicious\Method; | ||
|
||
use Phabalicious\Configuration\HostConfig; | ||
use Phabalicious\Validation\ValidationErrorBagInterface; | ||
use Phabalicious\Validation\ValidationService; | ||
|
||
class NpmMethod extends RunCommandBaseMethod | ||
{ | ||
|
||
public function getName(): string | ||
{ | ||
return 'npm'; | ||
} | ||
|
||
protected function getExecutableName(): string | ||
{ | ||
return 'npm'; | ||
} | ||
|
||
protected function getRootFolderKey(): string | ||
{ | ||
return 'npmRootFolder'; | ||
} | ||
|
||
public function validateConfig(array $config, ValidationErrorBagInterface $errors) | ||
{ | ||
parent::validateConfig($config, $errors); // TODO: Change the autogenerated stub | ||
$service = new ValidationService($config, $errors, 'NPM'); | ||
$service->hasKey('npmBuildCommand', 'build command to run with npm'); | ||
} | ||
|
||
protected function prepareCommand(HostConfig $host_config, TaskContextInterface $context, string $command) | ||
{ | ||
$production = !in_array($host_config['type'], array('dev', 'test')); | ||
$command .= ' --no-interaction --silent'; | ||
|
||
return $command; | ||
} | ||
/** | ||
* @param HostConfig $host_config | ||
* @param TaskContextInterface $context | ||
*/ | ||
public function resetPrepare(HostConfig $host_config, TaskContextInterface $context) | ||
{ | ||
$this->runCommand($host_config, $context, 'install'); | ||
$this->runCommand($host_config, $context, $host_config->get('npmBuildCommand')); | ||
} | ||
|
||
public function installPrepare(HostConfig $host_config, TaskContextInterface $context) | ||
{ | ||
$this->resetPrepare($host_config, $context); | ||
} | ||
|
||
public function appCreate(HostConfig $host_config, TaskContextInterface $context) | ||
{ | ||
if (!$current_stage = $context->get('currentStage', false)) { | ||
throw new \InvalidArgumentException('Missing currentStage on context!'); | ||
} | ||
|
||
if ($current_stage == 'installDependencies') { | ||
$this->resetPrepare($host_config, $context); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters