MoodleNet: Difference between revisions
No edit summary |
No edit summary |
||
Line 39: | Line 39: | ||
yarn dev-backend my-dev | yarn dev-backend my-dev | ||
Questions? Please take a look in the [https://moodle.org/mod/forum/view.php?id=8726 MoodleNet Community] and [https://tracker.moodle.org/projects/MDLNET/summary Tracker] for answers or to ask for help. | Questions? Please take a look in the [https://moodle.org/mod/forum/view.php?id=8726 MoodleNet Community] and [https://tracker.moodle.org/projects/MDLNET/summary Tracker] for answers or to ask for help. | ||
== Creating MoodleNet packages == | == Creating MoodleNet packages == | ||
A Moodlenet package is a standard | A Moodlenet package is a standard [https://nodejs.org/api/esm.html#introduction ESM] package defining a main [https://nodejs.org/api/esm.html#introduction ESM] module. | ||
@moodlenet/core will import it at startup. | @moodlenet/core will import it at startup. | ||
Line 61: | Line 60: | ||
} | } | ||
===== Your MN package must declare its dependency to the @moodlenet/core package. ===== | |||
The core will import the main module at startup. | |||
The package "connects” to the core: | |||
// package.json | |||
{ | |||
"peerDependencies”: { | |||
"@moodlenet/core”: "^0.1.0” | |||
} | |||
} | |||
When adding/removing peerDependencies in the main repository based development environment, remember to execute: | |||
yarn bs | |||
to link dependent packages. | |||
// src/server/main.mjs | |||
import { connectPkg } from '@moodlenet/core' | |||
const connection = await connectPkg(import.meta, { | |||
apis: { } | |||
}) | |||
===== Test the package template ===== | |||
* adding the template package in installation dependencies | |||
* delete "installed” prop in the MoodleNet lock file | |||
* restart the backend | |||
Edit '''.dev-machines/my-dev/package.json''' adding the template package folder as dependency, similarly to other core package dependencies. | |||
// .dev-machines/my-dev/package.json | |||
{ | |||
... | |||
"dependencies”:{ | |||
... | |||
"my-moodlenet-mjs-pkg-template”: "file:[repofolder]/packages/my-moodlenet-mjs-pkg-template” | |||
} | |||
} | |||
===== Define and deploy APIs ===== | |||
Your package will probably need to define and deploy its own APIs. | |||
APIs are simply a collection of async functions - along with a params formal validation function - organized in a structured Js object. | |||
APIs will be registered in the system with a path-like string, having your package name as prefix and apth following api structure. | |||
// src/server/main.mjs | |||
import { connectPkg, defApi } from '@moodlenet/core' | |||
const myApis = { | |||
hello:{ | |||
world: defApi( ctx => | |||
async (p1,p2) => { return // something } , | |||
(...params) => { /* … validate params */ } | |||
) | |||
} | |||
const connection = await connectPkg(import.meta, { | |||
apis: myApis | |||
}) | |||
// will register 1 api: | |||
// my-moodlenet-package/1.0/hello/world | |||
== Important links == | == Important links == |
Revision as of 14:26, 29 November 2022
What is MoodleNet?
MoodleNet is a flexible Open Education Technology platform for curating collections of the best known Open Educational (and other) Resources. You'll find more general information in the MoodleNet user documentation.
If you are looking to get started as a MoodleNet developer, we recommend taking the MoodleNet for Developers course with Moodle Academy.
Current status
Take a look at MoodleNet releases in our Tracker.
Roadmap
- The MoodleNet release schedule is available on the MoodleNet Roadmap.
MoodleNet architecture
MoodleNet is a full stack TypeScript/JavaScript system using:
MoodleNet development environment
- NodeJs v16+ https://nodejs.org/
- ArangoDB (we suggest using Docker)
- Visual Studio Code https://code.visualstudio.com/
Setup development environment
From the command line interface (CLI):
Ensure ArangoDB is running on localhost
docker run -e ARANGO_NO_AUTH=1 -p 8529:8529 --rm --name=mn3arango arangodb
Clone the repository
git clone https://gitlab.com/moodlenet/moodlenet.git
Initialize the project
cd moodlenet
yarn
yarn init-dev
Install a development deployment
yarn dev-install-be my-dev
Run development backend
yarn dev-backend my-dev
Questions? Please take a look in the MoodleNet Community and Tracker for answers or to ask for help.
Creating MoodleNet packages
A Moodlenet package is a standard ESM package defining a main ESM module.
@moodlenet/core will import it at startup.
// package.json
{
"name”: "my-moodlenet-package”,
"version”: "1",
"type": "module",
"exports": {
".": "./src/server/main.mjs"
}
}
Your MN package must declare its dependency to the @moodlenet/core package.
The core will import the main module at startup.
The package "connects” to the core:
// package.json
{
"peerDependencies”: {
"@moodlenet/core”: "^0.1.0”
}
}
When adding/removing peerDependencies in the main repository based development environment, remember to execute:
yarn bs
to link dependent packages.
// src/server/main.mjs
import { connectPkg } from '@moodlenet/core'
const connection = await connectPkg(import.meta, {
apis: { }
})
Test the package template
- adding the template package in installation dependencies
- delete "installed” prop in the MoodleNet lock file
- restart the backend
Edit .dev-machines/my-dev/package.json adding the template package folder as dependency, similarly to other core package dependencies.
// .dev-machines/my-dev/package.json
{
...
"dependencies”:{
...
"my-moodlenet-mjs-pkg-template”: "file:[repofolder]/packages/my-moodlenet-mjs-pkg-template”
}
}
Define and deploy APIs
Your package will probably need to define and deploy its own APIs.
APIs are simply a collection of async functions - along with a params formal validation function - organized in a structured Js object.
APIs will be registered in the system with a path-like string, having your package name as prefix and apth following api structure.
// src/server/main.mjs
import { connectPkg, defApi } from '@moodlenet/core'
const myApis = {
hello:{
world: defApi( ctx =>
async (p1,p2) => { return // something } ,
(...params) => { /* … validate params */ }
)
}
const connection = await connectPkg(import.meta, {
apis: myApis
})
// will register 1 api:
// my-moodlenet-package/1.0/hello/world