Skip to content

Commit

Permalink
Merge pull request #308 from ajthinking/use-nodejs
Browse files Browse the repository at this point in the history
Category for NodeJs nodes and allow interpolation for RunCommand
  • Loading branch information
ajthinking authored Sep 29, 2024
2 parents 51559d9 + d3d9726 commit a6aa91d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/nodejs/src/computers/JsonFileRead/JsonFileRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Computer, get, serializeError, str, stringifyError } from '@data-story/
export const JsonFileRead: Computer = {
name: 'JsonFile.read',
label: 'JsonFile.read',
category: 'NodeJs',
inputs: [],
outputs: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Computer, str } from '@data-story/core';
export const JsonFileWrite: Computer = {
name: 'JsonFile.write',
label: 'JsonFile.write',
category: 'NodeJs',
inputs: [{
name: 'input',
schema: {}
Expand Down
1 change: 1 addition & 0 deletions packages/nodejs/src/computers/ListFiles/ListFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as nodePath from 'path'
export const ListFiles: Computer = {
name: 'ListFiles',
label: 'ListFiles',
category: 'NodeJs',
inputs: [{
name: 'input',
schema: {},
Expand Down
1 change: 1 addition & 0 deletions packages/nodejs/src/computers/ReadFiles/ReadFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Computer, createDefaultStringable } from '@data-story/core';
export const ReadFiles: Computer = {
name: 'ReadFiles',
label: 'ReadFiles',
category: 'NodeJs',
inputs: [{
name: 'input',
schema: {}
Expand Down
19 changes: 8 additions & 11 deletions packages/nodejs/src/computers/RunCommand/RunCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { promisify } from 'util';
import { exec as execCallback } from 'child_process';
import { Computer, createDefaultStringable } from '@data-story/core';
import { Computer, str } from '@data-story/core';

const exec = promisify(execCallback);

Expand All @@ -23,6 +23,7 @@ async function awaitableExec(command: string): Promise<{
export const RunCommand: Computer = {
name: 'RunCommand',
label: 'RunCommand',
category: 'NodeJs',
inputs: [{
name: 'input',
schema: {},
Expand All @@ -38,22 +39,18 @@ export const RunCommand: Computer = {
},
],
params: [
createDefaultStringable({
str({
name: 'command',
label: 'Command',
help: 'Command to run',
multiline: true,
canInterpolate: false,
interpolate: false,
evaluations: [],
casts: [],
value: 'say "Hello World"',
help: 'Command to run',
canInterpolate: true,
})
],

async *run({ input, output, params }) {
async *run({ input, output }) {
while(true) {
const [ incoming ] = input.pull(1)

const command = incoming.params.command as string

const { stdout, stderr, error } = await awaitableExec(command);
Expand All @@ -79,7 +76,7 @@ export const RunCommand: Computer = {
continue;
}

throw new Error('Unknown exec result!')
yield;
}
},
};
1 change: 1 addition & 0 deletions packages/nodejs/src/computers/WriteFile/WriteFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Computer, str } from '@data-story/core';
export const WriteFile: Computer = {
name: 'WriteFile',
label: 'WriteFile',
category: 'NodeJs',
inputs: [{
name: 'input',
schema: {}
Expand Down

0 comments on commit a6aa91d

Please sign in to comment.