🎉 dropALog for n8n 1.x
This commit is contained in:
parent
7eb8838df5
commit
1a75c1ba1c
12 changed files with 182 additions and 542 deletions
6
nodes/DropALog/DropALog.node.json
Normal file
6
nodes/DropALog/DropALog.node.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"node":"n8n-nodes-drop-a-log.DropALog",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories":["Miscellaneous"],
|
||||
}
|
||||
142
nodes/DropALog/DropALog.node.ts
Normal file
142
nodes/DropALog/DropALog.node.ts
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
import {
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { execFile } from 'child_process';
|
||||
|
||||
interface IExecReturnData {
|
||||
exitCode: number;
|
||||
error?: Error;
|
||||
stderr: string;
|
||||
stdout: string;
|
||||
}
|
||||
|
||||
interface ILogData {
|
||||
log: string;
|
||||
title: string;
|
||||
date: string;
|
||||
includeJson: boolean;
|
||||
item: any;
|
||||
out: IExecReturnData|null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Promisifiy exec manually to also get the exit code
|
||||
*
|
||||
* @param {string} command
|
||||
* @returns {Promise<IExecReturnData>}
|
||||
*/
|
||||
function execPromise(command: string, args: string[]): Promise<IExecReturnData> {
|
||||
const returnData: IExecReturnData = {
|
||||
exitCode: 0,
|
||||
stderr: '',
|
||||
stdout: '',
|
||||
};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
execFile(command, args, { cwd: process.cwd() }, (error, stdout, stderr) => {
|
||||
returnData.stdout = stdout.trim();
|
||||
returnData.stderr = stderr.trim();
|
||||
|
||||
if (error) {
|
||||
returnData.error = error;
|
||||
}
|
||||
|
||||
resolve(returnData);
|
||||
}).on('exit', code => { returnData.exitCode = code || 0; });
|
||||
});
|
||||
}
|
||||
|
||||
export class DropALog implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Drop A Log',
|
||||
name: 'dropALog',
|
||||
icon: 'file:dropalog.svg',
|
||||
group: ['transform'],
|
||||
version: 1,
|
||||
description: 'Drops data into droplog',
|
||||
defaults: {
|
||||
name: 'Drop A Log',
|
||||
color: '#772244',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
properties: [
|
||||
// Node properties which the user gets displayed and
|
||||
// can change on the node.
|
||||
{
|
||||
displayName: 'Log',
|
||||
name: 'log',
|
||||
type: 'string',
|
||||
default: 'n8n',
|
||||
placeholder: 'posts',
|
||||
description: 'Name of log to use',
|
||||
},
|
||||
{
|
||||
displayName: 'Title',
|
||||
name: 'title',
|
||||
type: 'string',
|
||||
default: 'New Post',
|
||||
placeholder: '',
|
||||
description: 'Name of title for each post'
|
||||
},
|
||||
{
|
||||
displayName: 'Date',
|
||||
name: 'date',
|
||||
type: 'string',
|
||||
default: 'now',
|
||||
placeholder: '',
|
||||
description: 'Date to use for each post'
|
||||
},
|
||||
{
|
||||
displayName: 'Include entire post',
|
||||
name: 'includeJson',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'If activated, the entire item will be logged. If inactive, only title and date will be used'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
for (let idx = 0; idx < items.length; idx++) {
|
||||
let item = items[idx];
|
||||
|
||||
let data: ILogData = {
|
||||
log: this.getNodeParameter('log', idx) as string,
|
||||
title: this.getNodeParameter('title', idx) as string,
|
||||
date: this.getNodeParameter('date', idx) as string,
|
||||
includeJson: this.getNodeParameter('includeJson', idx) as boolean,
|
||||
item: null,
|
||||
out: null,
|
||||
};
|
||||
|
||||
const args: string[] = ['drop'];
|
||||
|
||||
args.push(data.log, data.title, '-d', data.date);
|
||||
|
||||
if (data.includeJson) {
|
||||
const copy = JSON.parse(JSON.stringify(item.json));
|
||||
delete copy.title;
|
||||
delete copy.date;
|
||||
|
||||
args.push('-j', JSON.stringify(copy));
|
||||
data.item = copy;
|
||||
}
|
||||
|
||||
const exit = await execPromise('my-log', args);
|
||||
data.out = exit;
|
||||
returnData.push(data as unknown as IDataObject);
|
||||
}
|
||||
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
}
|
||||
}
|
||||
11
nodes/DropALog/dropalog.svg
Normal file
11
nodes/DropALog/dropalog.svg
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
<svg width="800px" height="800px" viewBox="0 -5.99 48.891 48.891" xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="log_book" data-name="log book" transform="translate(-130.272 -425.601)">
|
||||
<path id="Path_135" data-name="Path 135" d="M178.663,434.083H142.745v23.323h35.918V434.083Z" fill="#ffe959" fill-rule="evenodd"/>
|
||||
<path id="Path_136" data-name="Path 136" d="M150.727,454.038V430.092a3.99,3.99,0,0,0-3.991-3.991H130.772v23.946h15.964a3.99,3.99,0,0,1,3.991,3.991Z" fill="#ffe959" fill-rule="evenodd"/>
|
||||
<path id="Path_137" data-name="Path 137" d="M178.663,457.406H142.745v4.613h35.918v-4.613Z" fill="#354077" fill-rule="evenodd"/>
|
||||
<path id="Path_138" data-name="Path 138" d="M150.727,457.406h-7.982v4.613h7.982v-4.613Z" fill="#354077" fill-rule="evenodd"/>
|
||||
<path id="Path_139" data-name="Path 139" d="M150.727,457.406h-7.982v4.613h7.982v-4.613Zm19.954,4.613h7.982v-4.613H142.745v4.613H162.7m3.492,0h1m7.483-7.981H166.69m-11.972-15.964h19.954m-23.945,19.332v-3.368m0,0V430.092a3.99,3.99,0,0,0-3.991-3.991H130.772v23.946h15.964a3.99,3.99,0,0,1,3.991,3.991Zm-7.982-3.991v7.359h35.918V434.083H150.727" fill="none" stroke="#0f0e0b" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
Loading…
Add table
Add a link
Reference in a new issue