Creating a new module - mariuscoto/wouso-new GitHub Wiki
In wouso.js a module is organised as a NPM module and it is composed of:
- a backed API
- a single page React.js app (optional)
Modules can be games included in the platform (e.g. qotd, quest) or core modules that bring extra functionality to the platform (e.g. wouso-social-login) or themes, that change the visual aspect of the platform (e.g. wouso-foundation).
Building the module and API endpoints
- Start by choosing the type of module you want to develop (core module, game or theme) and add it to the appropiate section in the
/config.jsonfile. In this example we will go with a new game module called quest.
"games": {
"wouso-qotd" : true,
"wouso-quest": true
}
- Create the module that will hold your new game. Remember it has to bee a NPM module, so don't forget the
package.jsonfile. Your module should also have a file defining the endpoints of your module, calledroutes.js. Let's add a test route:
var express = require('express');
var router = express.Router();
router.get('/quest', function (req, res, next) {
res.send('Welcome to my new module.')
});
module.exports = router;
- Link you new shiny module to the platform (as a NPM module), using the following command, from the root of the repo:
npm link modules/wouso-quest
- Start the app and check out your new module endpoint, at
http://localhost:4000/quest
Creating the frontend
TODO:
Store date
TODO: module data, settings
Internationalisation
TODO:
Logging
There is a centralised logging system, which can be used by requiring the core/logging module from the repo.
var log = require('../../core/logging')('qotd')
To use it
log.info('User started game.')