Skip to content
sdamodharan edited this page Apr 5, 2017 · 4 revisions

Getting Started

npm install actionsuperhero

Setup initializer

Alter tsconfig.json to support decorators and emit node modules (unlike ES6 modules)

"compilerOptions": {
        "module": "none",
        "target": "es6",
        "noImplicitAny": true,
        "inlineSourceMap": true,
        "noImplicitReturns": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "outDir": "dist",
        "sourceRoot": "src",
        "moduleResolution": "node"
    }

Edit config/api.js and add the following to the paths array

paths: [
...
'superObjects': [path.join(__dirname, '/../dist')]
...
],

Create a file actionsuperhero.js under the initializers directory of your actionhero project, with the following content

'use strict'

const actionsuperhero = require("actionsuperhero");

actionsuperhero.setupInitializer(module);

Create your first action

import {Action, Api, ChainedFunction, IAction, IActionRequestData, Input} from "actionsuperhero";

@Action({
    actionName: "helloworld",
    description: "Just says hello world",
})
@Input({
    name: "user",
    required: false,
})
export class HelloWorld implements IAction {
    public run(api: Api, data: IActionRequestData, next: ChainedFunction): void {
        const name = data.params.user || "World";
        data.response.message = `Hello ${name}`;
        next();
    }
}

Clone this wiki locally