Skip to content

Commit 523f358

Browse files
author
winjo
committed
feat: 增加 app 集成版本
1 parent a0c2a58 commit 523f358

55 files changed

Lines changed: 3203 additions & 14 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"cSpell.ignoreWords": [
3+
"signale"
4+
]
5+
}

global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare var monaco: any

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"prettier --write"
2828
],
2929
"*.ts?(x)": [
30-
"echo eslint TODO:",
3130
"prettier --parser=typescript --write"
3231
]
3332
},
@@ -50,6 +49,7 @@
5049
"jest": "^26.6.3",
5150
"lint-staged": "^10.5.1",
5251
"prettier": "^2.1.2",
52+
"react-dom": "^17.0.1",
5353
"signale": "^1.4.0",
5454
"ts-node": "^9.0.0",
5555
"typescript": "^4.0.5"

packages/core/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
# core
1+
# core
2+
3+
## client
4+
适配在前端场景下部分服务
5+
6+
- extension kt-ext 的静态文件及文件读取
7+
8+
## server
9+
实现相对 browser 端 的 server 端,使用 Proxy 代理到 server app
10+
最大程度复用 browser 端的代码,只需按照需要实现对应 server path 的服务即可
11+
12+
- DiskFileServicePath 文件系统服务
13+
- ExtensionNodeServiceServerPath 获取 extensions 相关数据服务
14+
- LogServiceForClientPath 日志服务
15+
- CommonServerPath 通用后端服务
16+
- FileSchemeDocNodeServicePath 文件文档服务

packages/core/package.json

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "core",
55
"main": "lib/index.js",
66
"module": "esm/index.js",
7-
"typing": "types/index.d.ts",
7+
"typings": "types/index.d.ts",
88
"files": [
99
"lib",
1010
"esm",
@@ -21,10 +21,24 @@
2121
"publishConfig": {
2222
"registry": "https://registry.npm.alibaba-inc.com"
2323
},
24-
"dependencies": {
25-
"@alipay/spacex-core": "0.0.1"
26-
},
2724
"tnpm": {
2825
"mode": "yarn"
26+
},
27+
"dependencies": {
28+
"@ali/common-di": "^5.2.2",
29+
"@ali/ide-core-browser": "^1.23.1",
30+
"@ali/ide-core-common": "^1.23.1",
31+
"@ali/ide-editor": "^1.23.1",
32+
"@ali/ide-kaitian-extension": "^1.23.1",
33+
"@ali/ide-monaco": "^1.23.1",
34+
"@isomorphic-git/lightning-fs": "^4.3.0",
35+
"assert": "^2.0.0",
36+
"browserfs": "~1.4.3",
37+
"fs-extra-factory": "^0.2.0",
38+
"uuid": "^8.3.1"
39+
},
40+
"devDependencies": {
41+
"@types/fs-extra": "^9.0.4",
42+
"vscode": "^1.1.37"
2943
}
30-
}
44+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { Injectable } from '@ali/common-di'
2+
import { Uri, Event } from '@ali/ide-core-browser'
3+
import { FileSystemProvider, FileStat, FileType, FileChangeEvent } from '@ali/ide-file-service'
4+
5+
/**
6+
* @class 解析 kt-ext:// 文件,解决前端插件加载问题
7+
*/
8+
@Injectable()
9+
export class KaitianExtFsProvider implements FileSystemProvider {
10+
onDidChangeFile: Event<FileChangeEvent>
11+
12+
watch(): number {
13+
throw new Error('Method not implemented.')
14+
}
15+
16+
stat(): Thenable<FileStat> {
17+
throw new Error('Method not implemented.')
18+
}
19+
20+
readDirectory(): [string, FileType][] | Thenable<[string, FileType][]> {
21+
throw new Error('Method not implemented.')
22+
}
23+
24+
createDirectory(): void | Thenable<void | FileStat> {
25+
throw new Error('Method not implemented.')
26+
}
27+
28+
async readFile(uri: Uri): Promise<string> {
29+
const requestUrl = uri.with({ scheme: 'https' })
30+
31+
return await fetch(requestUrl.toString(), {
32+
headers: {
33+
'Accept-Encoding': 'gzip, deflate',
34+
},
35+
}).then((res) => res.text())
36+
}
37+
38+
writeFile(): void | Thenable<void | FileStat> {
39+
throw new Error('Method not implemented.')
40+
}
41+
42+
delete(): void | Thenable<void> {
43+
throw new Error('Method not implemented.')
44+
}
45+
46+
rename(): void | Thenable<void | FileStat> {
47+
throw new Error('Method not implemented.')
48+
}
49+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Autowired } from '@ali/common-di'
2+
import { Domain, URI, FsProviderContribution } from '@ali/ide-core-browser'
3+
import {
4+
StaticResourceContribution,
5+
StaticResourceService,
6+
} from '@ali/ide-static-resource/lib/browser/static.definition'
7+
import { IFileServiceClient } from '@ali/ide-file-service'
8+
9+
import { KaitianExtFsProvider } from './extension-fs.provider'
10+
import { EXT_SCHEME } from '../../common/constant'
11+
12+
/**
13+
* @class 扩展静态资源转换
14+
*/
15+
@Domain(StaticResourceContribution, FsProviderContribution)
16+
export class KtExtFsProviderContribution
17+
implements StaticResourceContribution, FsProviderContribution {
18+
@Autowired()
19+
private readonly ktExtFsProvider: KaitianExtFsProvider
20+
21+
registerStaticResolver(service: StaticResourceService): void {
22+
// 直接依赖插件市场内置的插件服务,无需抽象外部依赖
23+
// 处理 kt-ext 的协议内容获取
24+
service.registerStaticResourceProvider({
25+
scheme: EXT_SCHEME,
26+
resolveStaticResource: (uri: URI) => {
27+
// kt-ext 协议统一走 scheme 头转换为 https
28+
return uri.withScheme('https')
29+
},
30+
})
31+
}
32+
33+
registerProvider(registry: IFileServiceClient) {
34+
registry.registerProvider(EXT_SCHEME, this.ktExtFsProvider)
35+
}
36+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './extension.contribution'
2+
export * from './extension-fs.provider'

packages/core/src/client/index.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { Injectable, Injector, ConstructorOf, Provider } from '@ali/common-di'
2+
import {
3+
BrowserModule,
4+
ClientApp as BasicClientApp,
5+
IAppRenderer,
6+
IClientAppOpts as IBasicClientAppOpts,
7+
} from '@ali/ide-core-browser'
8+
import { BasicModule } from '@ali/ide-core-common'
9+
10+
import { FCServiceCenter, ClientPort, initFCService } from '../connection'
11+
import { KaitianExtFsProvider, KtExtFsProviderContribution } from './extension'
12+
import { IServerApp } from '../common'
13+
14+
export * from './extension'
15+
16+
export type ModuleConstructor = ConstructorOf<BrowserModule>
17+
18+
@Injectable()
19+
export class ClientModule extends BrowserModule {
20+
providers = [KaitianExtFsProvider, KtExtFsProviderContribution]
21+
}
22+
23+
export interface IClientAppOpts extends IBasicClientAppOpts {
24+
serverApp: IServerApp
25+
}
26+
27+
export class ClientApp extends BasicClientApp {
28+
constructor(opts: IClientAppOpts) {
29+
super(opts)
30+
opts.injector?.addProviders({
31+
token: IServerApp,
32+
useValue: opts.serverApp,
33+
})
34+
}
35+
36+
public async start(container: HTMLElement | IAppRenderer, type?: string): Promise<void> {
37+
bindConnectionService(this.injector, this.modules)
38+
return super.start(container, type)
39+
}
40+
41+
public dispose() {
42+
this.injector.disposeAll()
43+
this.injector.get(IServerApp).dispose()
44+
}
45+
}
46+
47+
export async function bindConnectionService(injector: Injector, modules: ModuleConstructor[]) {
48+
const clientCenter = new FCServiceCenter(ClientPort)
49+
50+
const { getFCService } = initFCService(clientCenter)
51+
52+
for (const module of modules) {
53+
const moduleInstance = injector.get(module) as BasicModule
54+
if (!moduleInstance.backServices) {
55+
continue
56+
}
57+
for (const backService of moduleInstance.backServices) {
58+
const { servicePath } = backService
59+
const fcService = getFCService(servicePath)
60+
61+
const injectService = {
62+
token: servicePath,
63+
useValue: fcService,
64+
} as Provider
65+
66+
injector.addProviders(injectService)
67+
68+
if (backService.clientToken) {
69+
const clientService = injector.get(backService.clientToken)
70+
fcService.onRequestService(clientService)
71+
}
72+
}
73+
}
74+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const EXT_SCHEME = 'kt-ext'
2+
3+
export const HOME = '/root'
4+
5+
export const EXTENSION_DIR = '.kaitian'
6+
7+
export const WORKSPACE_DIR = '/root/workspace'
8+
9+
export const IServerApp = Symbol('IServerApp')
10+
11+
export interface IServerApp {
12+
start(): Promise<void>
13+
dispose(): void
14+
}

0 commit comments

Comments
 (0)