-
Notifications
You must be signed in to change notification settings - Fork 3
/
startup-bundle.tsx
166 lines (142 loc) · 4.21 KB
/
startup-bundle.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import React from 'react';
import ReactDOM from 'react-dom/client';
import { AppRenderer, BrowserFSFileType as FileType, requireModule } from '@codeblitzjs/ide-core/bundle/codeblitz'
import '@codeblitzjs/ide-core/bundle/codeblitz.css';
import '@codeblitzjs/ide-core/languages';
import WorkerExample from './extensions/worker-example/worker-example';
const { Autowired, Injectable } = requireModule('@opensumi/di');
const { IEventBus, BrowserModule, Domain, ClientAppContribution, Disposable } = requireModule('@opensumi/ide-core-browser');
const { EditorDocumentModelWillSaveEvent, IEditorDocumentModelService } = requireModule('@opensumi/ide-editor');
const dirMap: Record<string, [string, FileType][]> = {
'/': [
['doc', FileType.DIRECTORY],
['hello.html', FileType.FILE],
['hello.js', FileType.FILE],
['hello.py', FileType.FILE],
['Hello.java', FileType.FILE],
['hello.go', FileType.FILE],
['appveyor.yml', FileType.FILE],
['test.yaml', FileType.FILE],
],
'/doc': [
['README.md', FileType.FILE],
],
};
const fileMap = {
'/doc/README.md': '# codeblitz-startup\n> codeblitz demo',
'/hello.html': `
<!DOCTYPE html>
<html>
<body>
<p>Hello, World!</p>
</body>
</html>
`.trimStart(),
'/hello.js': 'console.log("Hello, World!");',
'/hello.py': 'print("Hello, World!")',
'/Hello.java': `
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
`.trimStart(),
'/hello.go': `
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
`.trimStart(),
'/appveyor.yml': `# version format
version: 1.0.{build}
# you can use {branch} name in version format too
# version: 1.0.{build}-{branch}
# branches to build
branches:
# whitelist
only:
- master
- production
# blacklist
except:
- gh-pages
# Do not build on tags (GitHub, Bitbucket, GitLab, Gitea)
skip_tags: true
# Start builds on tags only (GitHub, BitBucket, GitLab, Gitea)
skip_non_tags: true`.trimStart()
}
@Domain(ClientAppContribution)
class DocumentSaverContribution extends Disposable implements ClientAppContribution {
@Autowired(IEventBus)
eventBus: IEventBus;
@Autowired(IEditorDocumentModelService)
documentService: IEditorDocumentModelService;
onDidStart() {
this.addDispose(
this.eventBus.on(EditorDocumentModelWillSaveEvent, (event) => {
console.log("Document will save", event.payload);
const docModel = this.documentService.getModelReference(event.payload.uri);
if (!docModel) return;
const fullText = docModel.instance.getText();
// now we can do something with the text
console.log('First five characters of the document are: ', fullText.substr(0, 5));
})
)
}
}
@Injectable()
class CustomModule extends BrowserModule {
providers = [DocumentSaverContribution];
}
const App = () => {
return (
<AppRenderer
appConfig={{
// 工作空间目录
workspaceDir: 'codeblitz-startup',
// modules:[unregisterKeybindingModule],
extensionMetadata: [WorkerExample],
modules: [CustomModule],
defaultPreferences:{
'general.theme': 'opensumi-design-dark-theme',
},
}}
runtimeConfig={{
workspace: {
// 文件系统
// filesystem: {
// fs: 'DynamicRequest',
// options: {
// readDirectory(p: string) {
// return dirMap[p];
// },
// readFile(p) {
// return new TextEncoder().encode(fileMap[p])
// },
// },
// }
// 本地indexedDB文件系统
filesystem: {
fs: 'OverlayFS',
options: {
writable: { fs: 'IndexedDB' },
readable: {
fs: 'DynamicRequest',
options: {
readDirectory(p: string) {
return dirMap[p];
},
async readFile(p) {
return new TextEncoder().encode(fileMap[p])
},
},
},
}
}
},
}}
/>
)
}
ReactDOM.createRoot(document.getElementById('main')!).render(<App />);