Datagen loads files, remains register to custom models to mongodb
This commit is contained in:
parent
89c33d397f
commit
1e4072dae6
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,6 +15,7 @@ client/public/plugins/
|
|||||||
|
|
||||||
# Backend
|
# Backend
|
||||||
backend/plugins/
|
backend/plugins/
|
||||||
|
backend/datagen/
|
||||||
|
|
||||||
# Docs
|
# Docs
|
||||||
documentation/docs/.vuepress/.cache
|
documentation/docs/.vuepress/.cache
|
||||||
|
@ -13,18 +13,20 @@ class BackendApi {
|
|||||||
#_router;
|
#_router;
|
||||||
#_expressRouter;
|
#_expressRouter;
|
||||||
#_internalSocket;
|
#_internalSocket;
|
||||||
|
#_datagenRegisrty;
|
||||||
#_socket;
|
#_socket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This object is already created for you
|
* This object is already created for you
|
||||||
* @param {plugin} Plugin instance
|
* @param {plugin} Plugin instance
|
||||||
*/
|
*/
|
||||||
constructor(plugin, router, internalSocket){
|
constructor(plugin, router, internalSocket, datagenRegistry){
|
||||||
this.#_plugin = plugin;
|
this.#_plugin = plugin;
|
||||||
this.#_expressRouter = router;
|
this.#_expressRouter = router;
|
||||||
this.#_internalSocket = internalSocket;
|
this.#_internalSocket = internalSocket;
|
||||||
this.#_socket = new BackendSocket(`plugins/${plugin.package}`, internalSocket);
|
this.#_socket = new BackendSocket(`plugins/${plugin.package}`, internalSocket);
|
||||||
this.#_router = new BackendRouter(`${plugin.package}`, this.#_expressRouter);
|
this.#_router = new BackendRouter(`${plugin.package}`, this.#_expressRouter);
|
||||||
|
this.#_datagenRegisrty = datagenRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,6 +65,10 @@ class BackendApi {
|
|||||||
createModule(id){
|
createModule(id){
|
||||||
return new BackendModule(this.#_plugin, id, this.#_expressRouter, this.#_internalSocket);
|
return new BackendModule(this.#_plugin, id, this.#_expressRouter, this.#_internalSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerDatagen(model){
|
||||||
|
this.#_datagenRegisrty.modelNames.push(model.mongoName);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -289,6 +295,10 @@ class BackendModel {
|
|||||||
get mongoSchema() {
|
get mongoSchema() {
|
||||||
return this.#_mongoSchema;
|
return this.#_mongoSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get mongoName(){
|
||||||
|
return `${this.#_prefix}/${this.#_name}`
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class BackendSocket {
|
class BackendSocket {
|
||||||
|
53
backend/services/datagen.js
Normal file
53
backend/services/datagen.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const { default: mongoose } = require('mongoose');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const basePath = path.resolve(__dirname, '../')
|
||||||
|
|
||||||
|
async function datagenTask(models) {
|
||||||
|
console.log("Inicializing datagen task");
|
||||||
|
|
||||||
|
const datagenPluginFolders = fs.readdirSync(path.resolve(basePath + '/datagen'));
|
||||||
|
datagenPluginFolders.forEach(datagenPluginFolder => {
|
||||||
|
const datagenFolders = fs.readdirSync(path.resolve(basePath + '/datagen/' + datagenPluginFolder));
|
||||||
|
datagenFolders.forEach(datagenFolder => {
|
||||||
|
console.log(datagenFolder);
|
||||||
|
let folder = basePath + '/datagen/' + datagenPluginFolder + "/" + datagenFolder;
|
||||||
|
const datagenInfo = JSON.parse(fs.readFileSync(
|
||||||
|
path.resolve(folder + "/datagen.json")
|
||||||
|
));
|
||||||
|
|
||||||
|
resolveDatagen(models, folder, datagenInfo);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Ended datagen task");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resolveDatagen(models, path, info){
|
||||||
|
// Do locale translation with info somewhere...?
|
||||||
|
const modelNames = models[info.package].modelNames;
|
||||||
|
modelNames.forEach(modelName => {
|
||||||
|
if(Object.keys(mongoose.models).includes(modelName)){
|
||||||
|
let modelLastName = modelName.split('/').pop();
|
||||||
|
let modelDataPath = path + "/data/" + modelLastName;
|
||||||
|
if(fs.existsSync(modelDataPath)){
|
||||||
|
const jsonFiles = fs.readdirSync(path + "/data/" + modelLastName, {recursive: true});
|
||||||
|
let modelPath = path + "/data/" + modelLastName;
|
||||||
|
jsonFiles.forEach(file => {
|
||||||
|
if(fs.lstatSync(modelPath + "/" + file).isFile()){
|
||||||
|
appendDatagen(modelPath + "/" + file, modelName, info);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function appendDatagen(file, modelName, info){
|
||||||
|
// "Appending " + file + " to model " + modelName + " from " + info.id + " for package " + info.package
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
datagenTask
|
||||||
|
}
|
@ -1,18 +1,19 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path')
|
const path = require('path');
|
||||||
const BackendApi = require('./api').BackendApi
|
const BackendApi = require('./api').BackendApi
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const { getIo } = require('../io/socket');
|
const { getIo } = require('../io/socket');
|
||||||
|
const { datagenTask } = require('./datagen');
|
||||||
const router = express.Router({
|
const router = express.Router({
|
||||||
mergeParams: true
|
mergeParams: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const basePath = path.resolve(__dirname, '../')
|
const basePath = path.resolve(__dirname, '../')
|
||||||
console.log(basePath)
|
|
||||||
|
|
||||||
let pluginsInfo = [];
|
let pluginsInfo = [];
|
||||||
let plugins = {};
|
let plugins = {};
|
||||||
let internalSocket = {};
|
let internalSocket = {};
|
||||||
|
let datagenRegistry = {};
|
||||||
|
|
||||||
function init(){
|
function init(){
|
||||||
console.log("Initializing plugins");
|
console.log("Initializing plugins");
|
||||||
@ -31,10 +32,13 @@ function init(){
|
|||||||
|
|
||||||
// Execute main
|
// Execute main
|
||||||
Object.keys(plugins).forEach(k => {
|
Object.keys(plugins).forEach(k => {
|
||||||
let pluginApi = new BackendApi(plugins[k].info, router, internalSocket);
|
datagenRegistry[k] = {modelNames: []};
|
||||||
|
let pluginApi = new BackendApi(plugins[k].info, router, internalSocket, datagenRegistry[k]);
|
||||||
plugins[k].payload.Main(pluginApi);
|
plugins[k].payload.Main(pluginApi);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
datagenTask(datagenRegistry);
|
||||||
|
|
||||||
console.log(internalSocket);
|
console.log(internalSocket);
|
||||||
getIo().on('connect', (socket) => {
|
getIo().on('connect', (socket) => {
|
||||||
Object.keys(internalSocket).forEach(k => {
|
Object.keys(internalSocket).forEach(k => {
|
||||||
|
@ -8,6 +8,7 @@ import * as _Tooltip from "@/services/Tooltip"
|
|||||||
import * as _Windows from "@/services/Windows"
|
import * as _Windows from "@/services/Windows"
|
||||||
import Server from '@/services/Server';
|
import Server from '@/services/Server';
|
||||||
import { socket } from '@/services/Socket';
|
import { socket } from '@/services/Socket';
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for managing the client api
|
* Class for managing the client api
|
||||||
@ -75,6 +76,10 @@ class ClientApi {
|
|||||||
_Windows.ClearWindow(id);
|
_Windows.ClearWindow(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t(key){
|
||||||
|
return t(`plugins.${plugin.package}.${key}`);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the client router
|
* Returns the client router
|
||||||
* @type {ClientRouter}
|
* @type {ClientRouter}
|
||||||
|
@ -84,6 +84,13 @@ function Main(api){
|
|||||||
dndModule.createModelRoutes(effectsModel);
|
dndModule.createModelRoutes(effectsModel);
|
||||||
dndModule.createModelRoutes(entityModel);
|
dndModule.createModelRoutes(entityModel);
|
||||||
|
|
||||||
|
Api.registerDatagen(itemModel);
|
||||||
|
Api.registerDatagen(monsterModel);
|
||||||
|
Api.registerDatagen(actorModel);
|
||||||
|
Api.registerDatagen(tableModel);
|
||||||
|
Api.registerDatagen(progressableModel);
|
||||||
|
Api.registerDatagen(effectsModel);
|
||||||
|
|
||||||
// Api.socket.on("test", () => console.log("test"));
|
// Api.socket.on("test", () => console.log("test"));
|
||||||
// Api.router.createModelRoutes(itemModel, 'item');
|
// Api.router.createModelRoutes(itemModel, 'item');
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"package": "dnd-5e",
|
"package": "dnd-5e",
|
||||||
|
"id": "dnd-5e-base",
|
||||||
"name": "info.name",
|
"name": "info.name",
|
||||||
"desc": "info.description"
|
"desc": "info.description"
|
||||||
}
|
}
|
11
prebuild.js
11
prebuild.js
@ -88,23 +88,34 @@ for(let i = 0; i < locales.length; i++){
|
|||||||
|
|
||||||
|
|
||||||
console.log("Updated Locales")
|
console.log("Updated Locales")
|
||||||
|
|
||||||
// #endregion
|
// #endregion
|
||||||
// #region plugins
|
// #region plugins
|
||||||
|
|
||||||
for(let j = 0; j < plugins.length; j++){
|
for(let j = 0; j < plugins.length; j++){
|
||||||
|
// Cient scripts and views
|
||||||
if(fs.existsSync(`./plugins/${plugins[j]}/client/`)){
|
if(fs.existsSync(`./plugins/${plugins[j]}/client/`)){
|
||||||
fs.cpSync(`./plugins/${plugins[j]}/client/`, `./client/plugins/${plugins[j]}`, {recursive: true});
|
fs.cpSync(`./plugins/${plugins[j]}/client/`, `./client/plugins/${plugins[j]}`, {recursive: true});
|
||||||
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`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backend scripts
|
||||||
if(fs.existsSync(`./plugins/${plugins[j]}/backend/`)){
|
if(fs.existsSync(`./plugins/${plugins[j]}/backend/`)){
|
||||||
fs.cpSync(`./plugins/${plugins[j]}/backend/`, `./backend/plugins/${plugins[j]}`, {recursive: true});
|
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`);
|
fs.copyFileSync(`./plugins/${plugins[j]}/plugin.json`, `./backend/plugins/${plugins[j]}/plugin.json`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Public folder
|
||||||
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});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Datagen
|
||||||
|
if(fs.existsSync(`./plugins/${plugins[j]}/datagen`)){
|
||||||
|
fs.readdirSync(`./plugins/${plugins[j]}/datagen`).forEach(d => {
|
||||||
|
fs.cpSync(`./plugins/${plugins[j]}/datagen/${d}`, `./backend/datagen/${plugins[j]}/${d}`, {recursive: true});
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(outputPath, JSON.stringify({
|
fs.writeFileSync(outputPath, JSON.stringify({
|
||||||
|
Loading…
Reference in New Issue
Block a user