3.1.0 • Published 4 years ago
swarm-host-cli v3.1.0
Swarm-Host-CLI
CLI for Swarm-Host
Install:
npm i -g swarm-host-cliUsage:
Create a new project (works in the empty dir):
swarm-host initCreate a new Route:
swarm-host g route unitsFile 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=postFile 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_idFile 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/unitFile 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:objectiveFile 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 unitsFile factories/units.ts will be deleted.
Destroy existing Route
swarm-host d route unitsFile routes/units.ts will be deleted.