Philosophy
- Standard is god.
- It only do following:
- Define folder structure
- Define where to load config
- Define how to setup and teardown modules
- Define how to pass around module
- Everything else is up to you.
Status
Under development, API might change for all Magnet modules.
Module boilerplate
; { /* E.g. You can put @google/maps | apollo-server-express | apollo-server, it will format to snake case _google_maps | apollo_server_express | apollo_server. So we can use it as _google_maps.geocode({ address: '1600 Amphitheatre Parkway, Mountain View, CA' }). It's a Magnet practice to use npm module name for scoping, to reduce clash on namespace */ thismoduleName = '<module npm name>' // Optional, path of default config folder thisdefaultConfig = __dirname } /** * Code to setup the module, either: * - Add module to this.app object * - Add middleware to this.app.application */ async { thisappmodule = {}; } /** * How to handle shutdown * Not implement yet */ async { thisappmodule = {}; }
Folders structure
- docs
- local_modules
- src
- builds
- config
- controllers
- database
- models
- queues
- routers
- graphql
- tcp
- command
- ws
- schedulers
- schemas
- services
- templates
- utils
- static
- tests
App structure
App = config: // magnet-config;
Modules
Allow Magnet module is searchable under magnetjs keywords NPM search
Usage
es6
;;;;; ;
es5
var magnet = default; ;
Magnet style
; ;
Example
Scheduler Server
;;;; ;
API Server
;;;;;;;;;;;; ;
Scheduler Server
; ; // app.sequelize.query(...)// app.sequelizeAnotherDb.query(...)
Multiple instance
;;;; ;
Naming
All magnet module is store under app variables. To avoid conflict some rules is introduced.
- magmet, config, log is reserved
- npm organization scope replaced with underscore
// Reservedconst app = magnet: null config: null log: null thisappkoa = thisapp_googleMaps =
CLI
Magnet come with cli command to copy all config files from following to server/config
:
local_modules/**/config/*.js
node_modules/**/config/*.js
Just run from ./node_modules/.bin/magnet
Or install globally npm install -g magnet-core
yarn global add magnet-core
And run magnet
Roadmap
- Find solution to copy config/* without babel
- Update
config/*.js
when extra field introduced - Make this.app = {} immutable? Only can set via Module.set('redis', redis), or map, or both
Todo
- Why copyConfig doesn't get magnet-koa/config/koa
- Auto build modules structure via npm dependencies