1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-23 01:27:14 +02:00

Merge pull request #896 from moiseyenkoVladyslav/master

docs: Change from intall to install
This commit is contained in:
Patrik J. Braun 2024-04-29 19:23:57 +02:00 committed by GitHub
commit 7a6021785d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,16 +21,20 @@ You need at least a `server.js` in your extension folder that exports a `init(ex
<path to the extension fodler>/myextension/package.js <- this is optional. You can add extra npm packages here <path to the extension fodler>/myextension/package.js <- this is optional. You can add extra npm packages here
<path to the extension fodler>/myextension/server.js <- this is needed <path to the extension fodler>/myextension/server.js <- this is needed
``` ```
Where `<path to the extension fodler>` is what you set in the config and `myextension` is the name of your extension. Where `<path to the extension fodler>` is what you set in the config and `myextension` is the name of your extension.
Note: you do not need to add your `node_modules` folder. The app will call `npm intall` when initializing your extension. Note: you do not need to add your `node_modules` folder. The app will call `npm install` when initializing your extension.
## Extension environment ## Extension environment
The app runs the extension the following way: The app runs the extension the following way:
* It reads all extensions in `<path to the extension fodler>/**` folder
* Checks if `package.js` is present. If yes installs the packages - It reads all extensions in `<path to the extension fodler>/**` folder
* Checks if `server.js` is present. If yes, calls the `init` function. - Checks if `package.js` is present. If yes installs the packages
- Checks if `server.js` is present. If yes, calls the `init` function.
### Init and cleanup lifecycle ### Init and cleanup lifecycle
There is also a `cleanUp` function that you can implement in your extension. There is also a `cleanUp` function that you can implement in your extension.
The app can call your `init` and `cleanUp` functions any time. The app can call your `init` and `cleanUp` functions any time.
Always calls the `init` first then `cleanUp` later. Always calls the `init` first then `cleanUp` later.
@ -41,7 +45,6 @@ Main use-case: `init` is called on app startup. `cleanUp` and `init` called late
The app calls the `init` and `cleanUp` function with a `IExtensionObject` object. The app calls the `init` and `cleanUp` function with a `IExtensionObject` object.
See https://github.com/bpatrik/pigallery2/blob/master/src/backend/model/extension/IExtension.ts for details. See https://github.com/bpatrik/pigallery2/blob/master/src/backend/model/extension/IExtension.ts for details.
`IExtensionObject` exposes lifecycle events, configs, RestAPis with some limitation. `IExtensionObject` exposes lifecycle events, configs, RestAPis with some limitation.
Changes made during the these public apis you do not need to clean up in the `cleanUp` function. Changes made during the these public apis you do not need to clean up in the `cleanUp` function.
App also exposes private `_app` object to provide access to low level API. Any changes made here needs clean up. App also exposes private `_app` object to provide access to low level API. Any changes made here needs clean up.
@ -59,22 +62,22 @@ This doc assumes you do the development in `ts`.
You can import package from both the main app package.json and from your extension package.json. You can import package from both the main app package.json and from your extension package.json.
To import packages from the main app, you import as usual. To import packages from the main app, you import as usual.
For packages from the extension, you always need to write relative path. i.e.: prefix with `./node_modules` For packages from the extension, you always need to write relative path. i.e.: prefix with `./node_modules`
```ts ```ts
// Including dev-kit interfaces. It is not necessary, only helps development with types. // Including dev-kit interfaces. It is not necessary, only helps development with types.
// You need to prefix them with ./node_modules // You need to prefix them with ./node_modules
import {IExtensionObject} from './node_modules/pigallery2-extension-kit'; import { IExtensionObject } from "./node_modules/pigallery2-extension-kit";
// Including prod extension packages. You need to prefix them with ./node_modules // Including prod extension packages. You need to prefix them with ./node_modules
// lodash does not have types // lodash does not have types
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
import * as _ from './node_modules/lodash'; import * as _ from "./node_modules/lodash";
// Importing packages that are available in the main app (listed in the packages.json in pigallery2) // Importing packages that are available in the main app (listed in the packages.json in pigallery2)
import {Column, Entity, Index, PrimaryGeneratedColumn} from 'typeorm'; import { Column, Entity, Index, PrimaryGeneratedColumn } from "typeorm";
``` ```
#### pigallery2 extension dev-kit #### pigallery2 extension dev-kit
It is recommended to use the `pigallery2-extension-kit` node package. It is recommended to use the `pigallery2-extension-kit` node package.
@ -94,10 +97,7 @@ NOTE: this is not needed to create an extension it only helps your IDE and your
You need to implement the `init` function for a working extension: You need to implement the `init` function for a working extension:
```ts ```ts
export const init = async (extension: IExtensionObject<void>): Promise<void> => {};
export const init = async (extension: IExtensionObject<void>): Promise<void> => {
}
``` ```
#### pigallery2 lifecycle `events` #### pigallery2 lifecycle `events`
@ -105,5 +105,4 @@ export const init = async (extension: IExtensionObject<void>): Promise<void> =>
Tha app exposes multiple interfaces for the extensions to interact with the main app. `events` are one of the main interfaces. Tha app exposes multiple interfaces for the extensions to interact with the main app. `events` are one of the main interfaces.
Here are their flow: Here are their flow:
![events_lifecycle](events.png) ![events_lifecycle](events.png)