Skip to content

Commit

Permalink
Merge pull request activepieces#2941 from Salem-Alaa/read-file
Browse files Browse the repository at this point in the history
feat(file): create a read file piece
  • Loading branch information
AbdulTheActivePiecer authored Oct 17, 2023
2 parents 1a2c280 + 4716149 commit 415bcbd
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/pieces/filesHelper/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error"
}
}
]
}
7 changes: 7 additions & 0 deletions packages/pieces/filesHelper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pieces-fileshelper

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build pieces-fileshelper` to build the library.
8 changes: 8 additions & 0 deletions packages/pieces/filesHelper/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@activepieces/piece-file-helper",
"version": "0.0.1",
"dependencies": {
"@activepieces/pieces-framework": "*",
"tslib": "2.6.2"
}
}
44 changes: 44 additions & 0 deletions packages/pieces/filesHelper/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "pieces-filesHelper",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/pieces/filesHelper/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": [
"{options.outputPath}"
],
"options": {
"outputPath": "dist/packages/pieces/filesHelper",
"tsConfig": "packages/pieces/filesHelper/tsconfig.lib.json",
"packageJson": "packages/pieces/filesHelper/package.json",
"main": "packages/pieces/filesHelper/src/index.ts",
"assets": [
"packages/pieces/filesHelper/*.md"
],
"buildableProjectDepsInPackageJsonType": "dependencies",
"updateBuildableProjectDepsInPackageJson": true
}
},
"publish": {
"command": "node tools/scripts/publish.mjs pieces-filesHelper {args.ver} {args.tag}",
"dependsOn": [
"build"
]
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": [
"{options.outputFile}"
],
"options": {
"lintFilePatterns": [
"packages/pieces/filesHelper/**/*.ts",
"packages/pieces/filesHelper/package.json"
]
}
}
},
"tags": []
}
13 changes: 13 additions & 0 deletions packages/pieces/filesHelper/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import { createPiece, PieceAuth } from "@activepieces/pieces-framework";
import { readFileAction } from "./lib/actions/read-file";

export const filesHelper = createPiece({
displayName: "Files Helper",
auth: PieceAuth.None(),
minimumSupportedRelease: '0.9.0',
logoUrl: "https://cdn.activepieces.com/pieces/file-piece.svg",
authors: ["Salem-Alaa"],
actions: [readFileAction],
triggers: [],
});
49 changes: 49 additions & 0 deletions packages/pieces/filesHelper/src/lib/actions/read-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Property, createAction } from "@activepieces/pieces-framework";

export const filesOutput = {
Text: "text",
Base64: "base64"
}

export const readFileAction = createAction({
name: 'read_file',
displayName: 'Read File',
description: 'Read a file from the file system',
props:{
file : Property.File({
displayName: "File",
required: true
}),
readOptions : Property.StaticDropdown({
displayName: "Output format",
description: "The output format",
required: true,
options: {
options: [
{ label: "Text", value: filesOutput.Text },
{ label: "Base64", value: filesOutput.Base64 },

]
}
}),
},
async run(context) {
const file = context.propsValue.file;
const readOptions = context.propsValue.readOptions;
switch(readOptions){
case filesOutput.Base64:
return {
"Base64" : file.data.toString('base64')
}
case filesOutput.Text:
return {
"Text" : file.data.toString('utf-8')
}
default:
throw new Error(
`Invalid output format: ${readOptions}`
);
}

}
});
19 changes: 19 additions & 0 deletions packages/pieces/filesHelper/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
}
]
}
11 changes: 11 additions & 0 deletions packages/pieces/filesHelper/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
3 changes: 3 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
"@activepieces/piece-posthog": ["packages/pieces/posthog/src/index.ts"],
"@activepieces/piece-pushover": ["packages/pieces/pushover/src/index.ts"],
"@activepieces/piece-qdrant": ["packages/pieces/qdrant/src/index.ts"],
"@activepieces/piece-read-file": [
"packages/pieces/read-file/src/index.ts"
],
"@activepieces/piece-rss": ["packages/pieces/rss/src/index.ts"],
"@activepieces/piece-salesforce": [
"packages/pieces/salesforce/src/index.ts"
Expand Down

0 comments on commit 415bcbd

Please sign in to comment.