mirror of
https://github.com/opdavies/versa.git
synced 2025-03-13 05:26:56 +00:00
Add initial JavaScript/TypeScript support
Add JS/TS support to `versa install`. Run `npm install`, `yarn` or `pnpm install` based on which files are present in the project.
This commit is contained in:
parent
72dea5070b
commit
c5248bb061
|
@ -16,6 +16,14 @@ abstract class AbstractCommand extends Command
|
|||
description: 'Any additonal arguments to pass to the command.',
|
||||
);
|
||||
|
||||
$this->addOption(
|
||||
name: 'language',
|
||||
shortcut: 'l',
|
||||
mode: InputArgument::OPTIONAL,
|
||||
description: 'The project language',
|
||||
suggestedValues: ['php', 'javascript'],
|
||||
);
|
||||
|
||||
$this->addOption(
|
||||
name: 'type',
|
||||
shortcut: 't',
|
||||
|
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
namespace App\Console\Command;
|
||||
|
||||
use App\Enum\ProjectLanguage;
|
||||
use App\Process\Process;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
final class InstallCommand extends AbstractCommand
|
||||
{
|
||||
|
@ -14,9 +16,17 @@ final class InstallCommand extends AbstractCommand
|
|||
$extraArgs = $input->getOption('extra-args');
|
||||
$workingDir = $input->getOption('working-dir');
|
||||
|
||||
// TODO: What to do if a project contains multiple languages?
|
||||
// e.g. a composer.lock file (PHP) and pnpm-lock.yaml file (JS)?
|
||||
|
||||
// TODO: validate the language is an allowed value.
|
||||
|
||||
// TODO: Composer in Docker Compose?
|
||||
$process = Process::create(
|
||||
command: ['composer', 'install'],
|
||||
command: $this->getCommand(
|
||||
language: $input->getOption('language'),
|
||||
workingDir: $workingDir,
|
||||
),
|
||||
extraArgs: $extraArgs,
|
||||
workingDir: $workingDir,
|
||||
);
|
||||
|
@ -26,4 +36,27 @@ final class InstallCommand extends AbstractCommand
|
|||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param non-empty-string $language
|
||||
* @param non-empty-string $workingDir
|
||||
* @return non-empty-array<int, non-empty-string>
|
||||
*/
|
||||
private function getCommand(string $language, string $workingDir): array
|
||||
{
|
||||
$filesystem = new Filesystem();
|
||||
|
||||
if ($language === ProjectLanguage::JavaScript->value) {
|
||||
if ($filesystem->exists($workingDir.'/yarn.lock')) {
|
||||
return ['yarn'];
|
||||
} elseif ($filesystem->exists($workingDir.'/pnpm-lock.yaml')) {
|
||||
return ['pnpm', 'install'];
|
||||
} else {
|
||||
return ['npm', 'install'];
|
||||
}
|
||||
}
|
||||
|
||||
return ['composer', 'install'];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
11
src/Enum/ProjectLanguage.php
Normal file
11
src/Enum/ProjectLanguage.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Enum;
|
||||
|
||||
enum ProjectLanguage: string
|
||||
{
|
||||
case JavaScript = 'javascript';
|
||||
case PHP = 'php';
|
||||
}
|
Loading…
Reference in a new issue