CLI for swarm-host
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
blueprints
lib
tests
.gitignore
.npmignore
.travis.yml
README.md
package.json
publish.sh
tsconfig.json
tslint.json

README.md

Swarm-Host-CLI

Build Status Codacy Badge npm version

CLI for Swarm-Host

Install:

npm i -g swarm-host-cli

Usage:

Create a new project (works in the empty dir):

swarm-host init

Create a new Route:

swarm-host g route units

File routes/units.ts will be created. Its content:

// routes/units.ts
import {Route} from 'swarm-host';

export default Route.createRoute('get', 'units', (req, res, next, lair) => {
  res.json({});
});

Create a new Route with options:

swarm-host g route units/new --url=api/v1/units --method=post

File routes/units/new.ts will be created. Its content:

// routes/units/new.ts
import {Route} from 'swarm-host';

export default Route.createRoute('post', 'api/v1/units', (req, res, next, lair) => {
  res.json({});
});

Create a new Route with dynamic parts:

swarm-host g route units/unit/objectives/objective --url=units/:unit_id/objectives/:objective_id

File routes/units/unit/objectives/objective.ts will be created. Its content:

//routes/units/unit/objectives/objective.ts
import {Route} from 'swarm-host';

export default Route.createRoute('get', '/units/:unit_id/objectives/:objective_id', ({params: {unit_id, objective_id}}, res, next, lair) => {
  res.json({});
});

Create a new Factory:

swarm-host g factory my/unit

File factories/my/unit.ts will be created. Its content:

// factories/my/unit.ts
import {Factory} from 'swarm-host';

export default Factory.create({
  name: 'unit',
  attrs: {
  }
});

Create a new Factory with attributes:

swarm-host g factory my/unit name:string squad:has-one:squad:units objectives:has-many:objective

File factories/my/unit.ts will be created. Its content:

// factories/my/unit.ts
import {Factory} from 'swarm-host';

export default Factory.create({
  name: 'unit',
  attrs: {
    name: Factory.field({
      value() {
        return '';
      },
      preferredType: 'string'
    }),
    age: Factory.field({
      value() {
        return 0;
      },
      preferredType: 'number'
    }),
    objectives: Factory.hasMany('objective', null),
    squad: Factory.hasOne('squad', 'units'),
  }
});

Destroy existing Factory

swarm-host d factory units

File factories/units.ts will be deleted.

Destroy existing Route

swarm-host d route units

File routes/units.ts will be deleted.