@@ -6,6 +6,10 @@ import '@codeblitzjs/ide-core/bundle/codeblitz.css';
6
6
import '@codeblitzjs/ide-core/languages' ;
7
7
import Select from 'antd/lib/select' ;
8
8
import 'antd/lib/select/style/index.css' ;
9
+ import { Button } from 'antd' ;
10
+ import type { IFileServiceClient as TFileServiceClient } from '@opensumi/ide-file-service/lib/common' ;
11
+
12
+ const path = requireModule ( 'path' ) ;
9
13
10
14
const dirMap : Record < string , [ string , FileType ] [ ] > = {
11
15
'/' : [
@@ -35,8 +39,10 @@ const zipDataPromise = (async () => {
35
39
zipData = Buffer . from ( new Uint8Array ( buf ) ) ;
36
40
} ) ( ) ;
37
41
42
+ const workspaceDir = 'filesystem' ;
43
+
38
44
const App = ( ) => {
39
- const [ fsType , setFsType ] = useState < string > ( 'OverlayFS ' ) ;
45
+ const [ fsType , setFsType ] = useState < string > ( 'FileIndexSystem ' ) ;
40
46
41
47
const filesystem = useMemo <
42
48
NonNullable < IAppRendererProps [ 'runtimeConfig' ] [ 'workspace' ] > [ 'filesystem' ] | undefined
@@ -63,7 +69,8 @@ const App = () => {
63
69
'main.html' : '<div id="root"></div>' ,
64
70
'main.css' : 'body {}' ,
65
71
'main.js' : 'console.log("main")' ,
66
- 'package.json' : '{\n "name": "Riddle"\n}' ,
72
+ 'package.json' : '{\n "name": "Codeblitz"\n}' ,
73
+ 'readme.md' : '# Codeblitz' ,
67
74
} ) ;
68
75
} ,
69
76
} ,
@@ -124,7 +131,7 @@ const App = () => {
124
131
return (
125
132
< div style = { { height : '100%' } } >
126
133
< div style = { { height : 48 , display : 'flex' , alignItems : 'center' } } >
127
- < Select < string > onChange = { ( e ) => setFsType ( e ) } style = { { width : 200 } } >
134
+ < Select < string > onChange = { ( e ) => setFsType ( e ) } style = { { width : 200 } } value = { fsType } >
128
135
< Select . Option value = "IndexedDB" > IndexedDB</ Select . Option >
129
136
< Select . Option value = "InMemory" > InMemory</ Select . Option >
130
137
< Select . Option value = "FileIndexSystem" > FileIndexSystem</ Select . Option >
@@ -133,7 +140,29 @@ const App = () => {
133
140
< Select . Option value = "FolderAdapter" > FolderAdapter</ Select . Option >
134
141
< Select . Option value = "OverlayFS" > OverlayFS</ Select . Option >
135
142
</ Select >
143
+
144
+ {
145
+ fsType === 'FileIndexSystem' && (
146
+ < Button onClick = { async ( ) => {
147
+ // All files in codeblitz are mounted to /workspace/${workspaceDir}
148
+ 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
+ }
159
+ } } >
160
+ 修改 readme.md
161
+ </ Button >
162
+ )
163
+ }
136
164
</ div >
165
+
137
166
< div style = { { height : 'calc(100% - 48px)' } } >
138
167
< AppRenderer
139
168
key = { fsType }
@@ -165,7 +194,7 @@ const App = () => {
165
194
} ) ;
166
195
} }
167
196
appConfig = { {
168
- workspaceDir : 'filesystem' ,
197
+ workspaceDir,
169
198
defaultPreferences : {
170
199
'general.theme' : 'opensumi-light' ,
171
200
} ,
0 commit comments