2.10.8 • Published 7 years ago

genericrunner v2.10.8

Weekly downloads
3
License
MIT
Repository
-
Last release
7 years ago

genericrunner

A generic task runner

Usage:

This is a example to get all input in the page by using the genericrunner

import {Engine, buildFlowFromConfig} from 'genericrunner';
let flowConfig = {
    id: 'flow', // id is a unique string
    type: 'flow', // means this is a flow node
    nodes: [
        // start node
        {
            id: '0',
            type: 'ready',
            name: 'ready'
        },
        // we initial the chrome headless mode
        {
            id: '1',
            type: 'launchchrome',
            options: {
                port: 9222
            },
            name: 'init chrome headless'
        },
        // open a page
        {
            id: '2',
            type: 'openpage',
            options: {
                url: 'http://www.xxx.com'
            },
            name: 'open baidu'
        },
        // transform node is for data transform
        // we get chrome instance from prev node result
        {
            id: '3',
            type: 'transform',
            options: {
                code: 'return arguments[0].chrome;'
            },
            name: 'get chrome from {chrome, network}'
        },
        // get all input from the page
        {
            id: '4',
            type: 'dom',
            options: {
                selector: 'input'
            },
            name: 'get dom'
        }
    ],
    links: [
        {
            type: 'link',
            fromId: '0',
            fromPort: 0,
            toId: '1',
            toPort: 0
        },
        {
            type: 'link',
            fromId: '1',
            fromPort:0, 
            toId: '2',
            toPort: 0
        },
        {
            type: 'link',
            fromId: '2',
            fromPort: 0,
            toId: '3',
            toPort: 0
        },
        {
            type: 'link',
            fromId: '3',
            fromPort: 0,
            toId: '4',
            toPort: 0
        }
    ]
}
let flow = buildFlowFromConfig(flowConfig);
let engine = new Engine(flow);
await engine.run();
console.log('done');

nodes:

ready: start node
dom: get dom from page
launchchrome: initial a headless chrome with a blank page
openpage: open a page in headless chrome, return network & dom modules
shell: execute a shell command, hold the process util command executed
transform: when the input & output requires diffrent struct of data, please use transform to adapt
There will be more~

How can I extends more kinds of node?

very easy:

import {
    addCustomNodeSeachPath,
    Node,
    ReturnValue
} from 'genericrunner';

// the path where you node placed; 
addCustomNodeSeachPath('xxx');
export default class MyNode extends Node {
    name = 'myNode';

    // The type is exactly the same with your filename,
    // genericrunner find your node by filename, so don't make it diffrent 
    static type = 'myNode';

    async exec(param) {
        super.exec(param);
        // custom options
        let {xxx, yyy} = this.options;
        // do what you want
        let ret = 'ret';
        // and return a ReturnValue instance
        return new ReturnValue(0, ret, this);
    }
}

another way

publish your own npm

git clone https://github.com/li-yinan/generic-runner-plugin-example modify package.json rename these code

{
    "name": "generic-runner-plugin-xxx",
    "description": "xxx",
    "version": "xxx",
    "author": "xxx"
}

then npm publish

2.10.8

7 years ago

2.10.7

7 years ago

2.10.6

7 years ago

2.10.5

7 years ago

2.10.4

7 years ago

2.10.3

7 years ago

2.10.2

7 years ago

2.10.1

7 years ago

2.10.0

7 years ago

2.9.6

7 years ago

2.9.5

7 years ago

2.9.4

7 years ago

2.9.3

7 years ago

2.9.2

7 years ago

2.9.1

7 years ago

2.9.0

7 years ago

2.8.4

7 years ago

2.8.3

7 years ago

2.8.2

7 years ago

2.8.1

7 years ago

2.8.0

7 years ago

2.7.19

7 years ago

2.7.18

7 years ago

2.7.17

7 years ago

2.7.16

7 years ago

2.7.15

7 years ago

2.7.14

7 years ago

2.7.13

7 years ago

2.7.12

7 years ago

2.7.11

7 years ago

2.7.10

7 years ago

2.7.9

7 years ago

2.7.8

7 years ago

2.7.7

7 years ago

2.7.6

7 years ago

2.7.5

7 years ago

2.7.4

7 years ago

2.7.3

7 years ago

2.7.2

7 years ago

2.7.1

7 years ago

2.7.0

7 years ago

2.6.2

7 years ago

2.6.1

7 years ago

2.6.0

7 years ago

2.5.2

7 years ago

2.5.1

7 years ago

2.5.0

7 years ago

2.4.1

7 years ago

2.4.0

7 years ago

2.3.2

7 years ago

2.3.1

7 years ago

2.3.0

7 years ago

2.2.0

7 years ago

2.0.0

7 years ago