-
Notifications
You must be signed in to change notification settings - Fork 16
feat: use cache file to replace Symfony commands #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: use cache file to replace Symfony commands #47
Conversation
db97903 to
4c5fb18
Compare
| private function getConfigForExtension(ExtensionInterface $extension, ContainerBuilder $container) | ||
| { | ||
| $extensionAlias = $extension->getAlias(); | ||
|
|
||
| if (isset($this->extensionConfig[$extensionAlias])) { | ||
| return $this->extensionConfig[$extensionAlias]; | ||
| } | ||
|
|
||
| $configs = $container->getExtensionConfig($extensionAlias); | ||
|
|
||
| $configuration = $extension instanceof ConfigurationInterface ? $extension : $extension->getConfiguration($configs, $container); | ||
|
|
||
| return $this->extensionConfig[$extensionAlias] = (new Processor())->processConfiguration($configuration, $configs); | ||
| } | ||
|
|
||
| private function getConfig(ContainerBuilder $container, ExtensionInterface $extension): array | ||
| { | ||
| return $container->resolveEnvPlaceholders( | ||
| $container->getParameterBag()->resolveValue( | ||
| $this->getConfigForExtension($extension, $container) | ||
| ), true | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This process is based on debug:config command.
I'm not really sure about the implementation. It gives me expected output, but there could be other ways to achieve this. Let me know if it could be improved
| public function __invoke(): Response | ||
| { | ||
| $this->eventDispatcher->dispatch(new GeneratePreviewEvent()); | ||
|
|
||
| $content = $this->twig->render('@Storybook/preview.html.twig'); | ||
|
|
||
| return new Response($content); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same process as storybook:generate-preview. This command should be removed before merging
af6549d to
1c9fe90
Compare
| join(twigPath, symfonyConfig.twig_component_config.anonymous_template_directory) | ||
| ); | ||
|
|
||
| const runtimeDir = (await getBundleConfig()).runtime_dir; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the usage of runtime_dir. I didn't find anything in source code
9ae6e11 to
dc17a81
Compare
26e9f49 to
c31f352
Compare
c31f352 to
78eb6c2
Compare
…ditional watch path with absolute path
ba2753e to
50ed82a
Compare
|
Here's my import 'dotenv/config';
import type { StorybookConfig } from '@sensiolabs/storybook-symfony-webpack5';
const config: StorybookConfig = {
stories: [
'../templates/components/**/*.stories.[tj]s'
],
addons: [
'@storybook/addon-webpack5-compiler-swc',
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
],
framework: {
name: '@sensiolabs/storybook-symfony-webpack5',
options: {
// 👇 Here configure the framework
symfony: {
storybookCachePath: `var/cache/${process.env.APP_ENV}/storybook`,
server: process.env.ETU_URL,
proxyPaths: [
'/dist',
],
additionalWatchPaths: [
'/assets'
],
}
},
},
};
export default config;Now Important
|
Hi ! First thanks for this project, it looks very promising.
I'd like to use it in my projects, but I encountered some limitations.
When running
npm run storybook/yarn storybook, it is expected to have a local PHP binary to run Symfony commands. I don't have PHP on my machine as our projects use Docker Compose.Internal command can accept options
StorybookBundle/storybook/src/server/lib/symfony.ts
Lines 21 to 31 in 8c0ca89
But there is no way to provide custom PHP path nor use
docker execcommands.So here I am, with a proposal to not rely on PHP binary, and only use Symfony as we do every day : with cache files.
This PR aims to generate and use a file containing all configurations required by JS scripts. The file structure would be as follow
/path/to/app/var/cache/dev/storybook/symfony_parameters.json
{ "twig_config": { "paths": { "\/var\/www\/templates": "Shared", "\/var\/www\/apps\/foo\/templates": "Foo" } }, "twig_component_config": { "defaults": { "Front\\Twig\\Components\\": { "template_directory": "components\/", "name_prefix": "Shared" }, "Front\\Foo\\Twig\\Components\\Bar\\Baz\\": { "template_directory": "bar\/baz\/components\/", "name_prefix": "Bar:Baz" }, "Front\\Foo\\Twig\\Components\\": { "template_directory": "components", "name_prefix": "" } }, "anonymous_template_directory": "components\/" } }Every command providing a configuration in
symfony.tsis now a distinct entry in thissymfony_parameters.json(any better name would be accepted)WDYT about this ? This is still a draft, and more code should be adjusted in order to remove
symfony.tsfile and all related processesTODO
symfony.tsbased on command executionsymfony.test.tsGeneratePreviewCommand.storybook/main.ts