Skip to content

Commit

Permalink
Adds mkdir mask
Browse files Browse the repository at this point in the history
  • Loading branch information
ap0k4 committed Apr 28, 2024
1 parent c21b26c commit 151921f
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/protolib/bundles/os/context2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import {readFile} from './readFile'
import {writeFile} from './writeFile'
import { runCommand } from './RunCommand'
import {listDir} from './listDir'
import { makeDir } from './makeDir'
export default {
readFile,
writeFile,
listDir,
runCommand
runCommand,
makeDir
}
24 changes: 24 additions & 0 deletions packages/protolib/bundles/os/context2/makeDir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import fs from 'fs/promises';
import { join } from 'path';

export const makeDir = async(options: {
path: string,
done?: (dirPath) => {},
error?: (err) => {}
}) => {
const path = options.path;
const done = options.done || (() => {});
const error = options.error;

try {
await fs.mkdir(join('../../', path), { recursive: true });
done(path)
return path;
} catch(err) {
if (error) {
error(err);
} else {
throw err;
}
}
}
1 change: 1 addition & 0 deletions packages/protolib/bundles/os/masks/MkdirSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default {
id: 'CreateFolder',
type: 'CallExpression',
category: 'OS',
hidden: true,
keywords: ['fs', 'os', 'make', 'dir', 'mkdir'],
check: (node, nodeData) => {
return node.type == "CallExpression" && nodeData.to?.startsWith('context.os.createFolder')
Expand Down
46 changes: 46 additions & 0 deletions packages/protolib/bundles/os/masks2/MakeDir.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Node, NodeOutput, NodeParams, filterObject, restoreObject } from 'protoflow';
import { useColorFromPalette } from 'protoflow/src/diagram/Theme'
import { FolderPlus } from 'lucide-react'

const MakeDir = ({ node = {}, nodeData = {}, children }: any) => {
const color = useColorFromPalette(10) // Cambio de color para diferenciar del ListDir
return (
<Node icon={FolderPlus} node={node} isPreview={!node.id} title='Make Directory' color={color} id={node.id} skipCustom={true}>
<NodeParams id={node.id} params={[{ label: 'Path', field: 'mask-path', type: 'input' }]} />
<div style={{height: '30px'}} />
<NodeOutput id={node.id} type={'input'} label={'Done'} vars={['path']} handleId={'mask-done'} />
<NodeOutput id={node.id} type={'input'} label={'Error'} vars={['err']} handleId={'mask-error'} />
</Node>
)
}

export default {
id: 'os2.makeDir',
type: 'CallExpression',
category: "OS",
keywords: ['fs', 'os', 'create', 'directory', 'mkdir'],
check: (node, nodeData) => {
return node.type == "CallExpression" && nodeData.to?.startsWith('context.os2.makeDir')
},
getComponent: (node, nodeData, children) => <MakeDir node={node} nodeData={nodeData} children={children} />,
filterChildren: filterObject({keys: {
path: 'input',
done: 'output',
error: 'output'
}}),
restoreChildren: restoreObject({keys: {
path: 'input',
done: { params: {'param-done': { key: "path"}}},
error: { params: { 'param-error': { key: "err"}}}
}}),
getInitialData: () => {
return {
await: true,
to: 'context.os2.makeDir',
"mask-path": {
value: "",
kind: "StringLiteral"
}
}
}
}
4 changes: 3 additions & 1 deletion packages/protolib/bundles/os/masks2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import ReadFile from "./ReadFile";
import WriteFile from './WriteFile';
import RunCommand from "./RunCommand";
import ListDir from "./ListDir";
import MakeDir from "./MakeDir";
export default [
ReadFile,
WriteFile,
ListDir,
RunCommand
RunCommand,
MakeDir
]

0 comments on commit 151921f

Please sign in to comment.