You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.2 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php namespace Wpstudio\AssetsManifest;
  2. use Backend;
  3. use Cms\Classes\Theme;
  4. use System\Classes\PluginBase;
  5. use Wpstudio\AssetsManifest\Classes\Bundlers\Bundler;
  6. use Wpstudio\AssetsManifest\Classes\ManifestReader;
  7. use Wpstudio\AssetsManifest\Classes\TwigFilters;
  8. use Config;
  9. /**
  10. * assetsmanifest Plugin Information File
  11. */
  12. class Plugin extends PluginBase
  13. {
  14. /**
  15. * Returns information about this plugin.
  16. *
  17. * @return array
  18. */
  19. public function pluginDetails()
  20. {
  21. return [
  22. 'name' => 'Assets manifest',
  23. 'description' => 'Assets with manifest.json',
  24. 'author' => 'wpstudio',
  25. 'icon' => 'icon-leaf'
  26. ];
  27. }
  28. /**
  29. * Register method, called when the plugin is first registered.
  30. *
  31. * @return void
  32. */
  33. public function register()
  34. {
  35. app()->singleton(Bundler::class, Config::get('wpstudio.assetsmanifest::bundler'));
  36. app()->singleton(ManifestReader::class, fn() => new ManifestReader(
  37. Theme::getActiveTheme()->getPath(
  38. sprintf(
  39. '%s/%s/manifest.json',
  40. Theme::getActiveTheme()->getDirName(),
  41. Config::get('wpstudio.assetsmanifest::vite_path_build')
  42. )
  43. ),
  44. ));
  45. }
  46. /**
  47. * Boot method, called right before the request route.
  48. *
  49. * @return array
  50. */
  51. public function boot()
  52. {
  53. }
  54. /**
  55. * Registers any front-end components implemented in this plugin.
  56. *
  57. * @return array
  58. */
  59. public function registerComponents()
  60. {
  61. return [
  62. ];
  63. }
  64. /**
  65. * Registers any back-end permissions used by this plugin.
  66. *
  67. * @return array
  68. */
  69. public function registerPermissions()
  70. {
  71. return []; // Remove this line to activate
  72. return [
  73. 'wpstudio.assetsmanifest.some_permission' => [
  74. 'tab' => 'assetsmanifest',
  75. 'label' => 'Some permission'
  76. ],
  77. ];
  78. }
  79. /**
  80. * Registers back-end navigation items for this plugin.
  81. *
  82. * @return array
  83. */
  84. public function registerNavigation()
  85. {
  86. return []; // Remove this line to activate
  87. return [
  88. 'assetsmanifest' => [
  89. 'label' => 'assetsmanifest',
  90. 'url' => Backend::url('wpstudio/assetsmanifest/mycontroller'),
  91. 'icon' => 'icon-leaf',
  92. 'permissions' => ['wpstudio.assetsmanifest.*'],
  93. 'order' => 500,
  94. ],
  95. ];
  96. }
  97. public function registerMarkupTags()
  98. {
  99. return [
  100. 'filters' => [
  101. 'encoreAsset' => [TwigFilters::class, 'encoreAsset'],
  102. ],
  103. 'functions' => [
  104. 'encoreAsset' => [TwigFilters::class, 'encoreAsset'],
  105. 'hmrAssets' => [TwigFilters::class, 'hmrAssets'],
  106. 'viteEntrypointStyles' => [TwigFilters::class, 'viteEntrypointStyles'],
  107. 'viteEntrypointAssets' => [TwigFilters::class, 'viteEntrypointAssets'],
  108. 'viteDevClientScriptTag' => [TwigFilters::class, 'viteDevClientScriptTag'],
  109. ],
  110. ];
  111. }
  112. }