generator-magnetjs
v0.3.0
Published
Yo generator for magnetjs
Maintainers
Readme
MagnetJS generator
Yeoman generator for MagnetJS - lets you quickly set up a project with sensible defaults and best practices.
Usage
For step-by-step instructions on using Yeoman and this generator to build a Koa api server from scratch
Install yo, generator-magnetjs:
yarn global add yo generator-magnetjsMake a new directory, and cd into it:
mkdir my-new-project && cd $_Run yo magnetjs, optionally passing an app name:
yo magnetjs [app-name]Generators
Available generators:
magnetjs (aka magnetjs:app)
App
Sets up a new Magnet app, generating all the boilerplate you need to get started. The app generator also optionally additional MagnetJS modules, such as magnet-config (installed by default).
Example:
yo magnetjsController
Generates a controller
Example:
yo magnetjs:controller userProduces src/controllers/mycontroller.js:
export default function ({
config,
log,
acl,
models,
utils: {
blueprint: { Controller },
// permission: { authenticatedDeco, isAllowedDeco }
}
}) {
class UserController extends Controller {
// @authenticatedDeco()
// async list (params, state) {
// return []
// }
}
return new UserController('user')
}Router
Generates a router in app/scripts/controllers.
Example:
yo magnetjs:router userProduces src/routers/graphql/user.js:
import { graphqlToController } from '../../utils/route'
export default function (app) {
const Query = {
// companys: graphqlToController(app, 'company', 'list'),
}
const Mutation = {
// createCompany: graphqlToController(app, 'company', 'create'),
}
return { Query, Mutation }
}Example:
yo magnetjs:router user --type httpProduces src/routers/http/user.js:
export default function ({
config,
ctrls,
log,
koa_router
}) {
koa_router
.get('/', async (ctx) => {
ctx.body = 'ok'
})
}Options
In general, these options can be applied to any generator, though they only affect generators that produce scripts.
TypeScript
For generators that output scripts, the --typescript will output TypeScript instead of JavaScript.
For example:
yo magnetjs:controller user --typescriptProduces app/scripts/controller/user.ts:
