@@ -28,3 +28,313 @@ php artisan micropowermanager:new-package {package-name}
28
28
29
29
This command creates a plugin template in the src/backend/packages/inensus folder. Upon creation, you can proceed with plugin development. You can check other plugins for reference.
30
30
Additionally, this command will create UI folders for the newly created plugin. Move the created UI folder to the src/frontend/src/plugins folder.
31
+
32
+ ## Plugin Integration Process
33
+
34
+ ### Backend Integration
35
+
36
+ To make your plugin discoverable and properly integrated with MPM, follow these steps:
37
+
38
+ #### 1. Register Your Plugin's Installation Command
39
+
40
+ Add your plugin's installation command class to the core application's console kernel:
41
+
42
+ ``` php
43
+ // src/backend/app/Console/Kernel.php
44
+
45
+ use Inensus\YourPlugin\Console\Commands\InstallYourPluginPackage;
46
+
47
+ class Kernel extends ConsoleKernel {
48
+ /**
49
+ * The Artisan commands provided by your application.
50
+ *
51
+ * @var array
52
+ */
53
+ protected $commands = [
54
+ Commands\AddMeterAddress::class,
55
+ InstallYourPluginPackage::class,
56
+ // ...other commands
57
+ ];
58
+ // ...
59
+ }
60
+ ```
61
+
62
+ #### 2. Register Your Plugin's Service Provider
63
+
64
+ Add your plugin's service provider to the core application's configuration:
65
+
66
+ ``` php
67
+ // src/backend/config/app.php
68
+
69
+ <?php
70
+
71
+ return [
72
+ // rest of app configuration
73
+ // ...
74
+ /*
75
+ * Laravel Framework Service Providers...
76
+ */
77
+ 'providers' => [
78
+ // ...other providers
79
+ Inensus\YourPlugin\Providers\YourPluginServiceProvider::class,
80
+ ]
81
+ ];
82
+ ```
83
+
84
+ #### 3. Register Custom HTTP Route Resolver
85
+
86
+ If your plugin requires API endpoints, register your custom route resolver:
87
+
88
+ ``` php
89
+ // src/backend/app/modules/Sharding/ApiResolvers/Data/ApiResolvers
90
+
91
+ class ApiResolverMap {
92
+ // ...other API constants
93
+ public const YOUR_PLUGIN_API = 'api/your-plugin/callback';
94
+
95
+ public const RESOLVABLE_APIS = [
96
+ // ...other resolvable APIs
97
+ self::YOUR_PLUGIN_API,
98
+ ];
99
+
100
+ private const API_RESOLVER = [
101
+ // ...other API resolvers
102
+ self::YOUR_PLUGIN_API => YourPluginApiResolver::class,
103
+ ];
104
+
105
+ public function getResolvableApis(): array {
106
+ return self::RESOLVABLE_APIS;
107
+ }
108
+
109
+ public function getApiResolver(string $api): string {
110
+ return self::API_RESOLVER[$api];
111
+ }
112
+ }
113
+ ```
114
+
115
+ #### 4. Register Plugin in MPM Plugins Model
116
+
117
+ Add your plugin to the MPM plugins model:
118
+
119
+ ``` php
120
+ // src/backend/app/Models/MpmPlugin.php
121
+
122
+ <?php
123
+
124
+ namespace App\Models;
125
+
126
+ use App\Models\Base\BaseModelCore;
127
+ use Illuminate\Database\Eloquent\Factories\HasFactory;
128
+
129
+ class MpmPlugin extends BaseModelCore {
130
+ use HasFactory;
131
+ // ...other plugin constants
132
+ public const YOUR_PLUGIN = 19; // Add your plugin ID (increment sequentially)
133
+
134
+ protected $table = 'mpm_plugins';
135
+
136
+ public function plugins() {
137
+ return $this->hasMany(Plugins::class);
138
+ }
139
+ }
140
+ ```
141
+
142
+ #### 5. Create Required Migrations
143
+
144
+ ##### a. Protected Page Migration
145
+
146
+ Create a migration to register your plugin's overview page:
147
+
148
+ ``` php
149
+ <?php
150
+
151
+ use Carbon\Carbon;
152
+ use Illuminate\Database\Migrations\Migration;
153
+ use Illuminate\Support\Facades\DB;
154
+
155
+ return new class extends Migration {
156
+ /**
157
+ * Run the migrations.
158
+ *
159
+ * @return void
160
+ */
161
+ public function up() {
162
+ DB::table('protected_pages')->insert([
163
+ [
164
+ 'name' => '/your-plugin/your-plugin-overview',
165
+ 'created_at' => Carbon::now(),
166
+ 'updated_at' => Carbon::now(),
167
+ ],
168
+ ]);
169
+ }
170
+
171
+ /**
172
+ * Reverse the migrations.
173
+ *
174
+ * @return void
175
+ */
176
+ public function down() {
177
+ DB::table('protected_pages')->where('name', '/your-plugin/your-plugin-overview')->delete();
178
+ }
179
+ };
180
+ ```
181
+
182
+ ##### b. Plugin Models Migration
183
+
184
+ Create tenant migrations for your plugin's models using:
185
+
186
+ ``` bash
187
+ php artisan make:migration-tenant
188
+ ```
189
+
190
+ Make sure to create stub files for these migrations in your plugin's ` database/migrations/ ` directory.
191
+
192
+ ##### c. Register Plugin in MPM Plugins Table
193
+
194
+ Create a migration to add your plugin to the ` mpm_plugins ` table:
195
+
196
+ ``` php
197
+ <?php
198
+
199
+ use App\Models\MpmPlugin;
200
+ use Carbon\Carbon;
201
+ use Illuminate\Database\Migrations\Migration;
202
+ use Illuminate\Support\Facades\DB;
203
+
204
+ return new class extends Migration {
205
+ public function up() {
206
+ DB::table('mpm_plugins')->insert([
207
+ [
208
+ 'id' => MpmPlugin::YOUR_PLUGIN,
209
+ 'name' => 'YourPlugin',
210
+ 'description' => 'This plugin developed for [describe your plugin functionality].',
211
+ 'tail_tag' => 'Your Plugin',
212
+ 'installation_command' => 'your-plugin:install',
213
+ 'root_class' => 'YourPlugin',
214
+ 'created_at' => Carbon::now(),
215
+ 'updated_at' => Carbon::now(),
216
+ ],
217
+ ]);
218
+ }
219
+
220
+ public function down() {
221
+ DB::table('mpm_plugins')
222
+ ->where('id', MpmPlugin::YOUR_PLUGIN)
223
+ ->delete();
224
+ }
225
+ };
226
+ ```
227
+
228
+ #### 6. Implement Installation Command
229
+
230
+ Create an installation command for your plugin:
231
+
232
+ ``` php
233
+ <?php
234
+
235
+ namespace Inensus\YourPlugin\Console\Commands;
236
+
237
+ use Illuminate\Console\Command;
238
+ use Inensus\YourPlugin\Services\YourPluginService;
239
+
240
+ class InstallPackage extends Command {
241
+ protected $signature = 'your-plugin:install';
242
+ protected $description = 'Install YourPlugin Package';
243
+
244
+ public function __construct(
245
+ private YourPluginService $pluginService,
246
+ ) {
247
+ parent::__construct();
248
+ }
249
+
250
+ public function handle(): void {
251
+ $this->info('Installing YourPlugin Integration Package\n');
252
+ $this->pluginService->initialize();
253
+ $this->info('Package installed successfully..');
254
+ }
255
+ }
256
+ ```
257
+
258
+ #### 7. Register Plugin in Composer.json
259
+
260
+ Add your plugin to the ` autoload-dev ` section in composer.json:
261
+
262
+ ``` json
263
+ "autoload-dev" : {
264
+ "psr-4" : {
265
+ "Inensus\\ YourPlugin\\ " : " packages/inensus/your-plugin/src" ,
266
+ }
267
+ }
268
+ ```
269
+
270
+ ### Frontend Integration
271
+
272
+ #### 1. Register Plugin Routes
273
+
274
+ Add your plugin's routes to the exported routes:
275
+
276
+ ``` js
277
+ // src/frontend/src/ExportedRoutes.js
278
+
279
+ import YourPluginOverview from " ./plugins/your-plugin/js/modules/Overview/Overview"
280
+
281
+ export const exportedRoutes = [
282
+ // ...other routes
283
+ {
284
+ path: " /your-plugin" ,
285
+ component: ChildRouteWrapper,
286
+ meta: {
287
+ sidebar: {
288
+ enabled_by_mpm_plugin_id: 19 , // Your plugin ID from MpmPlugin
289
+ name: " Your Plugin" ,
290
+ icon: " plugin-icon" , // Choose an appropriate icon
291
+ },
292
+ },
293
+ children: [
294
+ {
295
+ path: " your-plugin-overview" ,
296
+ component: YourPluginOverview,
297
+ meta: {
298
+ layout: " default" ,
299
+ sidebar: {
300
+ enabled: true ,
301
+ name: " Overview" ,
302
+ },
303
+ },
304
+ },
305
+ // Add more routes as needed
306
+ ],
307
+ },
308
+ ]
309
+ ```
310
+
311
+ #### 2. Mount Plugin Components
312
+
313
+ Register your Vue components in the main app:
314
+
315
+ ``` js
316
+ // src/frontend/src/main.js
317
+
318
+ import YourPlugin from " @/plugins/your-plugin/js/modules/Overview/Component"
319
+
320
+ Vue .component (" Your-Plugin" , YourPlugin)
321
+
322
+ // ...
323
+
324
+ /* eslint-disable */
325
+ const app = new Vue ({
326
+ el: " #app" ,
327
+ // ...
328
+ })
329
+ ```
330
+
331
+ ## Plugin Development Best Practices
332
+
333
+ 1 . Keep your plugin self-contained as much as possible
334
+ 2 . Follow the established directory structure for consistency
335
+ 3 . Use the MPM core services when appropriate to maintain integration
336
+ 4 . Thoroughly test your plugin's functionality before integration
337
+ 5 . Document your plugin's features and configuration requirements
338
+ 6 . Use proper versioning for your plugin package
339
+
340
+ Remember to check existing plugins for reference implementations that might help guide your development.
0 commit comments