Skip to content

Commit 30474e4

Browse files
committed
Add p8p minimal workflow runner
1 parent 2d733fd commit 30474e4

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ Version 0.224.1
2222
## Facebook Page Management
2323

2424
A simple web interface to manage the Facebook page **"Techno auf den Augen"** is included in the [`facebook-manager`](./facebook-manager) directory. It relies on Express and the built-in Node.js `fetch` API to list and create posts and display basic page insights. Further documentation is available in the [Facebook manager wiki](./facebook-manager/WIKI.md).
25+
26+
## p8p - open source workflows
27+
28+
An experimental project named **p8p** is included in the [`p8p`](./p8p) directory.
29+
It provides a very small workflow runner that can load and execute JSON-based
30+
workflows. Use it as a starting point for building your own automation tool.

p8p/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# p8p
2+
3+
p8p is a minimal open source workflow runner inspired by [n8n](https://n8n.io). It allows defining simple workflows in JSON and executing them either via a small HTTP API or from the command line.
4+
5+
## Features
6+
7+
- Create workflows via HTTP POST `/workflow/:name`
8+
- Run saved workflows via HTTP POST `/run/:name`
9+
- CLI mode to execute a workflow file directly
10+
- Supports basic `log`, `delay`, and `http` steps
11+
12+
## Usage
13+
14+
Install dependencies and start the server:
15+
16+
```bash
17+
cd p8p
18+
npm install
19+
node cli.js
20+
```
21+
22+
To run a workflow from a file:
23+
24+
```bash
25+
node cli.js my-workflow.json
26+
```
27+
28+
Example `my-workflow.json`:
29+
30+
```json
31+
[
32+
{ "type": "log", "message": "Hello from p8p" },
33+
{ "type": "delay", "ms": 1000 },
34+
{ "type": "http", "url": "https://example.com" }
35+
]
36+
```
37+
38+
This is not a full replacement for n8n but demonstrates how you might begin building your own automation tool.

p8p/cli.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env node
2+
import fs from 'fs/promises';
3+
import express from 'express';
4+
import path from 'path';
5+
import { fileURLToPath } from 'url';
6+
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8+
9+
const app = express();
10+
app.use(express.json());
11+
12+
// Simple in-memory workflows
13+
const workflows = new Map();
14+
15+
app.post('/workflow/:name', async (req, res) => {
16+
workflows.set(req.params.name, req.body);
17+
res.json({ status: 'saved', workflow: req.params.name });
18+
});
19+
20+
app.post('/run/:name', async (_req, res) => {
21+
const flow = workflows.get(_req.params.name);
22+
if (!flow) return res.status(404).json({ error: 'Workflow not found' });
23+
await runWorkflow(flow);
24+
res.json({ status: 'executed', workflow: _req.params.name });
25+
});
26+
27+
async function runWorkflow(steps) {
28+
for (const step of steps) {
29+
switch (step.type) {
30+
case 'log':
31+
console.log(step.message);
32+
break;
33+
case 'delay':
34+
await new Promise(resolve => setTimeout(resolve, step.ms || 0));
35+
break;
36+
case 'http':
37+
try {
38+
const res = await fetch(step.url, { method: step.method || 'GET' });
39+
console.log('HTTP', res.status, step.url);
40+
} catch (err) {
41+
console.error('HTTP error', err.message);
42+
}
43+
break;
44+
default:
45+
console.warn('Unknown step', step);
46+
}
47+
}
48+
}
49+
50+
const PORT = process.env.PORT || 3000;
51+
app.listen(PORT, () => {
52+
console.log(`p8p listening on port ${PORT}`);
53+
});
54+
55+
// CLI usage: load workflow from file and run
56+
if (process.argv[2]) {
57+
const filePath = path.resolve(process.cwd(), process.argv[2]);
58+
fs.readFile(filePath, 'utf8').then(data => {
59+
const flow = JSON.parse(data);
60+
runWorkflow(flow);
61+
});
62+
}

p8p/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "p8p",
3+
"version": "0.1.0",
4+
"description": "Minimal open source workflow engine inspired by n8n",
5+
"main": "cli.js",
6+
"type": "module",
7+
"bin": {
8+
"p8p": "./cli.js"
9+
},
10+
"dependencies": {
11+
"express": "^4.19.0"
12+
}
13+
}

0 commit comments

Comments
 (0)