generator-magnetjs
v0.3.0
Published
Yo generator for magnetjs
Downloads
1
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-magnetjs
Make 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 magnetjs
Controller
Generates a controller
Example:
yo magnetjs:controller user
Produces 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 user
Produces 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 http
Produces 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 --typescript
Produces app/scripts/controller/user.ts
: