5.5.0 • Published 3 years ago
@swarm-host/cli v5.5.0
Swarm-Host-CLI
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/server';
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/server';
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/server';
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/server';
export default class UnitFactory extends Factory {
static factoryName = 'unit';
};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, field, hasOne, hasMany } from '@swarm-host/server';
export default class UnitFactory extends Factory {
static factoryName = 'unit';
@field()
get name() {
return '';
}
@field()
get age() {
return 0;
}
@hasMany('objective', null) objectives;
@hasOne('squad', 'units') squad;
}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.