Connected Plugins with backend (Part 1)
This commit is contained in:
parent
7676cb2192
commit
45fa85a6f4
14
.gitignore
vendored
14
.gitignore
vendored
@ -1,16 +1,20 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
server/node_modules/
|
server/node_modules/
|
||||||
client/node_modules/
|
|
||||||
node_modules/
|
node_modules/
|
||||||
client/dist/
|
|
||||||
client/plugins/
|
|
||||||
backend/plugins/
|
|
||||||
|
|
||||||
client/public/data/
|
|
||||||
server/uploads/
|
server/uploads/
|
||||||
|
|
||||||
|
# Client
|
||||||
|
client/plugins/
|
||||||
|
client/dist/
|
||||||
|
client/public/data/
|
||||||
|
client/node_modules/
|
||||||
client/src/locales/
|
client/src/locales/
|
||||||
client/public/plugins/
|
client/public/plugins/
|
||||||
|
|
||||||
|
# Backend
|
||||||
|
backend/plugins/
|
||||||
|
|
||||||
# local env files
|
# local env files
|
||||||
.env.local
|
.env.local
|
||||||
.env.*.local
|
.env.*.local
|
||||||
|
21
README.md
21
README.md
@ -15,5 +15,24 @@ Dragonroll is an open source online virtual tabletop aimed to be an alternative
|
|||||||
|
|
||||||
## Installation 🛠️
|
## Installation 🛠️
|
||||||
|
|
||||||
TODO
|
Run
|
||||||
|
```
|
||||||
|
./install.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
This will install all the necesary npm packages both for the frontend and the backend
|
||||||
|
|
||||||
|
## Running 🚀
|
||||||
|
|
||||||
|
Run
|
||||||
|
```
|
||||||
|
./start.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
```
|
||||||
|
./start-dev.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
if you want to start the development environment
|
||||||
|
@ -13,6 +13,8 @@ const passport = require('passport');
|
|||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
const config = JSON.parse(fs.readFileSync("config.json"));
|
const config = JSON.parse(fs.readFileSync("config.json"));
|
||||||
|
|
||||||
|
const pluginManager = require('./services/plugins')
|
||||||
|
|
||||||
// SET CONSTANTS
|
// SET CONSTANTS
|
||||||
const PORT = 8081;
|
const PORT = 8081;
|
||||||
global.appRoot = path.resolve(__dirname);
|
global.appRoot = path.resolve(__dirname);
|
||||||
@ -69,6 +71,8 @@ app.use('/user', require('./routes/user'));
|
|||||||
checkAuth = passport.authenticate('jwt', {session: false});
|
checkAuth = passport.authenticate('jwt', {session: false});
|
||||||
app.use(checkAuth);
|
app.use(checkAuth);
|
||||||
|
|
||||||
|
pluginManager.init();
|
||||||
|
|
||||||
// ROUTES WITH AUTH
|
// ROUTES WITH AUTH
|
||||||
app.use('/campaign', require('./routes/campaign'));
|
app.use('/campaign', require('./routes/campaign'));
|
||||||
app.use('/maps', require('./routes/map'))
|
app.use('/maps', require('./routes/map'))
|
||||||
|
34
backend/services/plugins.js
Normal file
34
backend/services/plugins.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path')
|
||||||
|
const Api = {}
|
||||||
|
|
||||||
|
const basePath = path.resolve(__dirname, '../')
|
||||||
|
console.log(basePath)
|
||||||
|
|
||||||
|
let pluginsInfo = [];
|
||||||
|
let plugins = {};
|
||||||
|
|
||||||
|
function init(){
|
||||||
|
console.log("Initializing plugins");
|
||||||
|
const pluginFolders = fs.readdirSync(path.resolve(basePath + '/plugins'));
|
||||||
|
pluginFolders.forEach(pluginFolder => {
|
||||||
|
pluginsInfo.push(JSON.parse(fs.readFileSync(
|
||||||
|
path.resolve(basePath, 'plugins', pluginFolder, "plugin.json")
|
||||||
|
)));
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Launching using the following plugins:");
|
||||||
|
pluginsInfo.forEach(pluginInfo => {
|
||||||
|
console.log(`\t- ${pluginInfo.name}`);
|
||||||
|
plugins[pluginInfo.package] = require(`${basePath}/plugins/${pluginInfo.package}/${pluginInfo.backend.entrypoint}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Execute main
|
||||||
|
Object.keys(plugins).forEach(k => {
|
||||||
|
plugins[k].Main(Api)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
init
|
||||||
|
}
|
@ -26,6 +26,7 @@ function PopulateContext(val){
|
|||||||
let children = [];
|
let children = [];
|
||||||
|
|
||||||
let elementNum = 0;
|
let elementNum = 0;
|
||||||
|
console.log(val);
|
||||||
val.forEach(element => {
|
val.forEach(element => {
|
||||||
let contextMenuElement = document.createElement('div');
|
let contextMenuElement = document.createElement('div');
|
||||||
contextMenuElement.classList.add("context-menu-element");
|
contextMenuElement.classList.add("context-menu-element");
|
||||||
|
@ -23,13 +23,13 @@ async function updateElement(){
|
|||||||
if(tooltip) AddTooltip(tooltipContainer.value, tooltip);
|
if(tooltip) AddTooltip(tooltipContainer.value, tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
updateElement();
|
updateElement();
|
||||||
watch(() => props.element, () => {
|
watch(() => props.element, () => {
|
||||||
updateElement();
|
updateElement();
|
||||||
});
|
});
|
||||||
|
|
||||||
let context = props.context();
|
let context = await props.context();
|
||||||
if(context) AddContextMenu(elementDiv.value, context);
|
if(context) AddContextMenu(elementDiv.value, context);
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
6
plugins/dnd-5e/backend/main.js
Normal file
6
plugins/dnd-5e/backend/main.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
// Entrypoint
|
||||||
|
function Main(Api){
|
||||||
|
console.log("Hello World from backend!");
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Main };
|
@ -1,6 +1,5 @@
|
|||||||
// TODO: We should move client/plugin.json to plugin.json and generate the client plugin.json
|
|
||||||
// with the prebuild.js
|
|
||||||
|
|
||||||
|
// Entrypoint
|
||||||
function Main(Api){
|
function Main(Api){
|
||||||
console.log("Hello World!");
|
console.log("Hello World!");
|
||||||
console.log(Api);
|
console.log(Api);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"package": "dnd-5e",
|
||||||
"name": "Dnd 5e System",
|
"name": "Dnd 5e System",
|
||||||
"description": "This plugin provides the Dnd 5e module",
|
"description": "This plugin provides the Dnd 5e module",
|
||||||
"authors": [
|
"authors": [
|
||||||
@ -9,5 +10,8 @@
|
|||||||
"version": "0.1",
|
"version": "0.1",
|
||||||
"client": {
|
"client": {
|
||||||
"entrypoint": "main.js"
|
"entrypoint": "main.js"
|
||||||
|
},
|
||||||
|
"backend": {
|
||||||
|
"entrypoint": "main.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"package": "example-plugin"
|
||||||
"name": "Dragonroll example plugin",
|
"name": "Dragonroll example plugin",
|
||||||
"description": "This is an example plugin to help you getting started with the Dragonroll API",
|
"description": "This is an example plugin to help you getting started with the Dragonroll API",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
@ -97,6 +97,11 @@ for(let j = 0; j < plugins.length; j++){
|
|||||||
fs.copyFileSync(`./plugins/${plugins[j]}/plugin.json`, `./client/plugins/${plugins[j]}/plugin.json`);
|
fs.copyFileSync(`./plugins/${plugins[j]}/plugin.json`, `./client/plugins/${plugins[j]}/plugin.json`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(fs.existsSync(`./plugins/${plugins[j]}/backend/`)){
|
||||||
|
fs.cpSync(`./plugins/${plugins[j]}/backend/`, `./backend/plugins/${plugins[j]}`, {recursive: true});
|
||||||
|
fs.copyFileSync(`./plugins/${plugins[j]}/plugin.json`, `./backend/plugins/${plugins[j]}/plugin.json`);
|
||||||
|
}
|
||||||
|
|
||||||
if(fs.existsSync(`./plugins/${plugins[j]}/public/`)){
|
if(fs.existsSync(`./plugins/${plugins[j]}/public/`)){
|
||||||
fs.cpSync(`./plugins/${plugins[j]}/public/`, `./client/public/plugins/${plugins[j]}`, {recursive: true});
|
fs.cpSync(`./plugins/${plugins[j]}/public/`, `./client/public/plugins/${plugins[j]}`, {recursive: true});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user