3.0.11 • Published 4 years ago
beanify-autoload v3.0.11
beanify-autoload
Convenience plugin for Beanify that loads all plugins found in a directory
Install
npm i beanify-autoload --savewith yarn
yarn add beanify-autoloadUsage
const Beanify = require('beanify')
const Autoload = require('beanify-autoload')
const path = require('path')
const beanify = Beanify({})
beanify
.register(Autoload, {
dir: path.join(__dirname, 'test')
// dirAsScope: false
// name: 'aaa'
// prefix: 'bbb'
})
.ready(e => {
console.log(e && e.message)
beanify.print()
})with route
// ./routes/math/tan.js
const { route } = require('beanify-autoload')
module.exports = route({
// url:'tan' route.url will be set to the file name, automatically remove the extension
handler (req, rep) {}
})// index.js
const Beanify = require('beanify')
const Autoload = require('beanify-autoload')
const path = require('path')
const beanify = Beanify({})
beanify
.register(Autoload, {
dir: path.join(__dirname, 'routes'),
dirAsScope: true
})
.ready(e => {
console.log(e && e.message)
beanify.print()
})Options
dir: (required) - Base directory containing plugins to be loadeddirAsScope: Make each directory a new scope.default trueignorePattern: Regex matching any file that should not be loadedindexPattern: Regex to override theindex.jsnaming conventionmaxDepth: Limits the depth at which nested plugins are loaded