diff --git a/packages/js-sdk/rollup.config.js b/packages/js-sdk/rollup.config.js index 9c6c0651..a4053398 100644 --- a/packages/js-sdk/rollup.config.js +++ b/packages/js-sdk/rollup.config.js @@ -52,7 +52,7 @@ export default async () => { ], }, { - input: './src/index.ts', + input: ['./src/index.ts', './src/node/adapter.ts'], output: { dir: './dist/cjs', format: 'cjs', diff --git a/packages/js-sdk/src/node/adapter.ts b/packages/js-sdk/src/node/adapter.ts new file mode 100644 index 00000000..5f5d9af2 --- /dev/null +++ b/packages/js-sdk/src/node/adapter.ts @@ -0,0 +1,21 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import mimeTypes from 'mime-types'; +import { NodeFile } from '@/types/sp/Common'; + +export function createFile(filePath: string): NodeFile { + const stats = fs.statSync(filePath); + const fileSize = stats.size; + + const extname = path.extname(filePath); + const type = mimeTypes.lookup(extname); + + if (!type) throw new Error(`Unsupported file type: ${filePath}`); + + return { + name: filePath, + type, + size: fileSize, + content: fs.readFileSync(filePath), + }; +}