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.

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