-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NOTICKET: Add storybook twig linter.
- Loading branch information
1 parent
9d89be8
commit 0b8aa9b
Showing
2 changed files
with
53 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
declare(strict_types=1); | ||
|
||
if (PHP_SAPI !== 'cli') { | ||
return; | ||
} | ||
|
||
if (is_file(__DIR__ . '/../../../autoload.php')) { | ||
require_once __DIR__ . '/../../../autoload.php'; | ||
} | ||
else { | ||
echo "Composer autoload file not found.\n"; | ||
echo "You need to run 'composer install'.\n"; | ||
exit(1); | ||
} | ||
|
||
use Drupal\Core\Datetime\DateFormatterInterface; | ||
use Drupal\Core\File\FileUrlGenerator; | ||
use Drupal\Core\Render\RendererInterface; | ||
use Drupal\Core\Routing\UrlGeneratorInterface; | ||
use Drupal\Core\Theme\ThemeManagerInterface; | ||
use Symfony\Component\Console\Application; | ||
use Twig\Loader\ArrayLoader; | ||
use PackageVersions\Versions; | ||
|
||
use Sserbin\TwigLinter\StubEnvironment; | ||
use Drupal\Core\Template\TwigExtension; | ||
use Sserbin\TwigLinter\Command\LintCommand; | ||
|
||
use TwigStorybook\Service\StoryCollector; | ||
use TwigStorybook\Twig\TwigExtension as StorybookTwigExtension; | ||
|
||
$twig = new StubEnvironment(new ArrayLoader, []); | ||
|
||
$renderer = Mockery::mock(RendererInterface::class); | ||
$urlGenerator = Mockery::mock(UrlGeneratorInterface::class); | ||
$themeManager = Mockery::mock(ThemeManagerInterface::class); | ||
$dateFormatter = Mockery::mock(DateFormatterInterface::class); | ||
$fileUrlGenerator = Mockery::mock(FileUrlGenerator::class); | ||
|
||
$twig->addExtension(new TwigExtension($renderer, $urlGenerator, $themeManager, $dateFormatter, $fileUrlGenerator)); | ||
|
||
$storyCollector= new StoryCollector(); | ||
$twig->addExtension(new StorybookTwigExtension($storyCollector, __DIR__)); | ||
|
||
$lintCommand = new LintCommand($twig); | ||
|
||
$app = new Application('twig-linter', (string) Versions::getVersion('sserbin/twig-linter')); | ||
$app->add($lintCommand); | ||
$app->setDefaultCommand('lint'); | ||
$app->run(); |
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