Skip to content

Commit

Permalink
feat: Compatibility with Nodejs and Browser
Browse files Browse the repository at this point in the history
  • Loading branch information
rrr523 committed Apr 23, 2024
1 parent 2deb579 commit ed5aad2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/js-sdk/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions packages/js-sdk/src/node/adapter.ts
Original file line number Diff line number Diff line change
@@ -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),
};
}

0 comments on commit ed5aad2

Please sign in to comment.