Skip to content

Commit e64d41c

Browse files
authored
feat: use fs-extra package (#9)
1 parent b8f021d commit e64d41c

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

filesystem.tsx

+3-11
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import '@codeblitzjs/ide-core/languages';
77
import Select from 'antd/lib/select';
88
import 'antd/lib/select/style/index.css';
99
import { Button } from 'antd';
10-
import type { IFileServiceClient as TFileServiceClient } from '@opensumi/ide-file-service/lib/common';
1110

1211
const path = requireModule('path');
12+
const fse = requireModule('fs-extra');
1313

1414
const dirMap: Record<string, [string, FileType][]> = {
1515
'/': [
@@ -146,16 +146,8 @@ const App = () => {
146146
<Button onClick={async () => {
147147
// All files in codeblitz are mounted to /workspace/${workspaceDir}
148148
const targetFile = path.join('/workspace', workspaceDir, 'readme.md');
149-
const fileService = window.app.injector.get(IFileServiceClient) as TFileServiceClient;
150-
const uri = Uri.file(targetFile).toString();
151-
const stat = await fileService.getFileStat(uri);
152-
if (stat) {
153-
const content = await fileService.readFile(uri);
154-
const text = content.content.toString();
155-
await fileService.setContent(stat, text +'\n\nThis is a demo file.', {
156-
encoding: 'utf8',
157-
});
158-
}
149+
const content = await fse.readFile(targetFile);
150+
await fse.writeFile(targetFile, content.toString() +'\n\nThis is a demo file.', { encoding: 'utf8' });
159151
}}>
160152
修改 readme.md
161153
</Button>

0 commit comments

Comments
 (0)