Skip to content

Commit

Permalink
feat(core): make plugins path configurable (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
TdyP authored Sep 18, 2024
1 parent c260a6f commit c91d7fd
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
11 changes: 9 additions & 2 deletions apps/core/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LEAV Engine - Core

### Create and set the local environment.
## Create and set the local environment.

leav_core depends on some variables such as the port for the server, the address of the database, the auth scheme...
Those different configurations can be found in the `config` folder.
Expand Down Expand Up @@ -30,7 +30,14 @@ module.exports = {
};
```

### Debugging in VS Code
## Add plugins

You can add plugins to the core by adding them to the plugins folder. Each plugin live in its own folder and have at least a `index.ts` file.

The plugin folder is located by default in `apps/core/src/plugins` on development environment and `apps/core/dist/plugins` on build.
It can be configured with the `PLUGINS_PATH` environment variable or the `pluginsPath` variable in the `config/local.js` file. ⚠️ The path must be under the `apps/core/src/plugins` folder (eg. `apps/core/src/plugins/my-own-repo/my-plugins`)

## Debugging in VS Code

In VS Code, the easiest way to debug the app in its Docker container is to install the extension "Remote Development".
Then, you will be able to open a container inside VS Code.
Expand Down
3 changes: 2 additions & 1 deletion apps/core/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,6 @@ module.exports = {
},
elasticSearch: {
url: process.env.ELASTIC_SEARCH_URL || 'http://elasticsearch:9200'
}
},
pluginsPath: process.env.PLUGINS_PATH || 'plugins'
};
1 change: 1 addition & 0 deletions apps/core/src/_types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface IConfig {
dbProfiler: IDbProfilerConfig;
instanceId: string;
elasticSearch: IElasticSearchConfig;
pluginsPath: string;
}

export enum CoreMode {
Expand Down
3 changes: 2 additions & 1 deletion apps/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ export const validateConfig = (conf: IConfig) => {
instanceId: Joi.string().required(),
elasticSearch: Joi.object().keys({
url: Joi.string().required()
})
}),
pluginsPath: Joi.string().required()
});

const isValid = configSchema.validate(conf);
Expand Down
7 changes: 4 additions & 3 deletions apps/core/src/depsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ export async function initDI(additionalModulesToRegister?: {
[registerKey: string]: any;
}): Promise<{coreContainer: AwilixContainer; pluginsContainer: AwilixContainer}> {
const srcFolder = __dirname;
const pluginsFolder = realpathSync(__dirname + '/plugins');
// Add a few extra dependencies
const coreConf = await getConfig();

const pluginsFolder = realpathSync(__dirname + '/' + coreConf.pluginsPath);
const modulesGlob = '+(app|domain|infra|interface|utils)/**/index.+(ts|js)';
const pluginsModulesGlob = `!(core)/${modulesGlob}`;

Expand All @@ -74,8 +77,6 @@ export async function initDI(additionalModulesToRegister?: {

await _registerModules(coreContainer, srcFolder, modulesGlob, 'core');

// Add a few extra dependencies
const coreConf = await getConfig();
coreContainer.register('config', asValue(coreConf));
coreContainer.register('pluginsFolder', asValue(pluginsFolder));

Expand Down
8 changes: 4 additions & 4 deletions docker/scripts/start-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ echo "Install apps dependencies"
yarn install

# Install plugins dependencies
for plugin in ./src/plugins/*/; do
echo "Install dependencies for $plugin"
yarn --cwd "$plugin" install
done
find ./src/plugins -name package.json -not -path "*/node_modules/*" -exec sh -c '
echo "🚧 Install dependencies for plugin $(basename $(dirname {}))"
(cd $(dirname {}) && yarn install)
' \;

yarn run db:migrate:dev

Expand Down

0 comments on commit c91d7fd

Please sign in to comment.