Skip to content

Commit 2d34eee

Browse files
author
彦熹
committed
PullRequest: 45 优化 build及 textmate 加载
1 parent 237e300 commit 2d34eee

57 files changed

Lines changed: 554 additions & 302 deletions

Some content is hidden

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

.aci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ node-12:
2828
chown -R admin:admin ./
2929
time tnpm i -g yarn && tnpm i --install-node=12 --by=yarn --no-cache --internal-oss-cache
3030
node -e "console.log('%j, %j', process.versions, process.execPath)"
31-
time yarn build
31+
time tnpm run init
32+
time tnpm run test
3233
coverage: '(?<=Statements\s{1,10}:\s{1,10})\d{1,10}.\d{1,10}'
3334
passrate: '(?<=PASS_RATE: )\d{1,10}.\d{1,10}'
3435
publisher:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# General
2+
.DS_Store
3+
14
# Logs
25
logs
36
*.log

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.14.2](https://code.alipay.com/cloud-ide/crew-dragon/compare/v0.14.1...v0.14.2) (2021-05-08)
2+
3+
4+
15
## [0.14.1](https://code.alipay.com/cloud-ide/crew-dragon/compare/v0.14.0...v0.14.1) (2021-04-27)
26

37

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "alex",
3-
"version": "0.14.1",
3+
"version": "0.14.2",
44
"workspaces": [
55
"packages/*"
66
],
@@ -14,10 +14,10 @@
1414
"type-check": "tsc --skipLibCheck --noEmit",
1515
"preinstall": "node scripts/preinstall && npm run prepare:env",
1616
"prepare:env": "yum --version && sudo yum -y install unzip gcc-c++ libX11-devel libxkbfile-devel || echo 'no yum'",
17-
"init": "npm run clean && npm run build && npm run ext",
17+
"init": "npm run clean && npm run generate && npm run build && npm run ext",
1818
"start": "npm run dev",
1919
"ext": "alex ext",
20-
"inspect": "INTEGRATION=inspect npm run dev",
20+
"generate": "node scripts/generate",
2121
"editor": "INTEGRATION=editor npm run dev",
2222
"build": "node scripts/build",
2323
"bundle": "node scripts/bundle",
@@ -68,6 +68,7 @@
6868
"husky": "^4.3.0",
6969
"inquirer": "^7.3.3",
7070
"jest": "^26.6.3",
71+
"json5": "^2.2.0",
7172
"lint-staged": "^10.5.1",
7273
"minimist": "^1.2.5",
7374
"prettier": "^2.1.2",

packages/alex/package.json

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "@alipay/alex",
3-
"version": "0.14.1",
3+
"version": "0.14.2",
44
"description": "@alipay/alex",
55
"main": "lib/index.js",
6-
"typing": "types/index.d.ts",
6+
"typings": "lib/index.d.ts",
77
"files": [
88
"lib",
99
"bin",
@@ -13,7 +13,8 @@
1313
"languages",
1414
"shims",
1515
"polyfills",
16-
"bundle"
16+
"bundle",
17+
"typings"
1718
],
1819
"keywords": [
1920
"kaitian AntCodespaces"
@@ -67,14 +68,15 @@
6768
"@ali/ide-workspace": "2.2.0",
6869
"@ali/ide-workspace-edit": "2.2.0",
6970
"@ali/kaitian-textmate-languages": "^2.2.0",
70-
"@alipay/alex-cli": "0.14.1",
71-
"@alipay/alex-code-api": "0.14.1",
72-
"@alipay/alex-core": "0.14.1",
73-
"@alipay/alex-shared": "0.14.1",
74-
"@alipay/alex-code-service": "0.14.1",
75-
"@alipay/alex-i18n": "0.14.1",
76-
"@alipay/alex-lsif-service": "0.14.1",
77-
"@alipay/alex-plugin": "0.14.1",
71+
"@alipay/alex-cli": "0.14.2",
72+
"@alipay/alex-code-api": "0.14.2",
73+
"@alipay/alex-core": "0.14.2",
74+
"@alipay/alex-registry": "0.14.2",
75+
"@alipay/alex-shared": "0.14.2",
76+
"@alipay/alex-code-service": "0.14.2",
77+
"@alipay/alex-i18n": "0.14.2",
78+
"@alipay/alex-lsif-service": "0.14.2",
79+
"@alipay/alex-plugin": "0.14.2",
7880
"antd": "^3.20.3",
7981
"@ant-design/icons": "~2.1.1"
8082
},

packages/alex/src/api/createApp.tsx

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ import {
1313
IAppRenderer,
1414
FILES_DEFAULTS,
1515
IReporter,
16+
getPreferenceThemeId,
1617
} from '@ali/ide-core-browser';
1718
import { BoxPanel, SplitPanel } from '@ali/ide-core-browser/lib/components';
18-
import { IThemeService } from '@ali/ide-theme/lib/common';
1919
import '@ali/ide-core-browser/lib/style/index.less';
20-
import { FileTreeModelService } from '@ali/ide-file-tree-next/lib/browser/services/file-tree-model.service';
2120
import * as os from 'os';
2221

22+
import '../core/extension.patch';
2323
import { disposeMode } from '../core/patch';
2424

2525
import { modules } from '../core/modules';
2626
import { IconSlim, IDETheme } from '../core/extensions';
27-
import { mergeConfig, themeStorage } from '../core/utils';
27+
import { mergeConfig, getThemeTypeByPreferenceThemeId } from '../core/utils';
2828
import { LayoutComponent, getDefaultLayoutConfig } from '../core/layout';
2929
import { IConfig, IAppInstance } from './types';
3030
import { logPv } from '../core/tracert';
@@ -77,31 +77,18 @@ export function createApp({ appConfig, runtimeConfig }: IConfig): IAppInstance {
7777
}
7878
opts.workspaceDir = makeWorkspaceDir(opts.workspaceDir);
7979

80-
let themeType = themeStorage.get();
81-
if (!themeType) {
82-
const defaultTheme = opts.defaultPreferences?.['general.theme'];
83-
opts.extensionMetadata?.find((item) => {
84-
const themeConfig = item.packageJSON.contributes?.themes?.find(
85-
(item: any) => item.id === defaultTheme
86-
);
87-
if (themeConfig) {
88-
themeType = !themeConfig.uiTheme || themeConfig.uiTheme === 'vs-dark' ? 'dark' : 'light';
89-
themeStorage.set(themeType);
90-
}
91-
});
92-
}
93-
9480
const app = new ClientApp(opts) as IAppInstance;
9581

82+
Object.defineProperty(app, 'currentThemeType', {
83+
get() {
84+
const themeId = getPreferenceThemeId() || opts.defaultPreferences?.['general.theme'];
85+
return getThemeTypeByPreferenceThemeId(themeId, opts.extensionMetadata);
86+
},
87+
});
88+
9689
const _start = app.start;
9790
app.start = async (container: HTMLElement | IAppRenderer) => {
9891
await _start.call(app, container);
99-
// 在 start 不能 injector.get,否则有的 service 立即初始化,此时 file-system 还没有初始化完成
100-
(app.injector.get(IThemeService) as IThemeService).onThemeChange((e) => {
101-
themeStorage.set(e.type);
102-
});
103-
// IDE 销毁时,组件会触发 handleTreeBlur,但是 FileContextKey 实例尚未初始化,此时在 dispose 阶段,injector.get(FileContextKey) 会抛出错误
104-
app.injector.get(FileTreeModelService).handleTreeBlur();
10592

10693
setTimeout(() => {
10794
logPv(runtimeConfig.biz || location.hostname);

packages/alex/src/api/createEditor.tsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { IPluginConfig } from '@alipay/alex-plugin';
2222

2323
import { disposeMode } from '../core/patch';
2424
import { getModules } from '../core/editor/modules';
25-
import { mergeConfig, themeStorage } from '../core/utils';
25+
import { mergeConfig } from '../core/utils';
2626
import { EditorLayoutComponent, getEditorLayoutConfig } from '../core/layout';
2727
import { IConfig, IAppInstance } from './types';
2828
import { logPv } from '../core/tracert';
@@ -68,29 +68,12 @@ export function createEditor({ appConfig, runtimeConfig }: IConfig): IAppInstanc
6868
}
6969
opts.workspaceDir = makeWorkspaceDir(opts.workspaceDir);
7070

71-
let themeType = themeStorage.get();
72-
if (!themeType) {
73-
const defaultTheme = opts.defaultPreferences?.['general.theme'];
74-
opts.extensionMetadata?.find((item) => {
75-
const themeConfig = item.packageJSON.contributes?.themes?.find(
76-
(item: any) => item.id === defaultTheme
77-
);
78-
if (themeConfig) {
79-
themeType = !themeConfig.uiTheme || themeConfig.uiTheme === 'vs-dark' ? 'dark' : 'light';
80-
themeStorage.set(themeType);
81-
}
82-
});
83-
}
84-
8571
const app = new ClientApp(opts) as IAppInstance;
8672

8773
const _start = app.start;
8874
app.start = async (container: HTMLElement | IAppRenderer) => {
8975
await _start.call(app, container);
90-
// 在 start 不能 injector.get,否则有的 service 立即初始化,此时 file-system 还没有初始化完成
91-
(app.injector.get(IThemeService) as IThemeService).onThemeChange((e) => {
92-
themeStorage.set(e.type);
93-
});
76+
9477
setTimeout(() => {
9578
logPv(runtimeConfig.biz || location.hostname);
9679
});

packages/alex/src/api/register.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
import { LanguagesContribution, GrammarsContribution } from '@ali/ide-monaco';
2-
import { LanguageGrammarRegistrationService } from '@alipay/alex-core';
2+
import { centerRegistry } from '@alipay/alex-registry';
33

4+
export { centerRegistry };
5+
6+
/**
7+
* @deprecated please import language by path directly
8+
*
9+
* use `import "@alipay/alex/languages/<mode>"` to import specific language.
10+
* use `import "@alipay/alex/languages"` to import all languages
11+
*/
412
export const registerLanguage = (contrib: LanguagesContribution) => {
5-
LanguageGrammarRegistrationService.languageEmitter.fire(contrib);
13+
centerRegistry.register<LanguagesContribution>('language', contrib);
614
};
715

16+
/**
17+
* @deprecated please import language by path directly
18+
*
19+
* use `import "@alipay/alex/languages/<mode>"` to import specific language
20+
* use `import "@alipay/alex/languages"` to import all languages
21+
*/
822
export const registerGrammar = (contrib: GrammarsContribution) => {
9-
LanguageGrammarRegistrationService.grammarEmitter.fire(contrib);
23+
centerRegistry.register<GrammarsContribution>('grammar', contrib);
1024
};

packages/alex/src/api/renderApp.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { REPORT_NAME } from '@alipay/alex-core';
55
import { createApp } from './createApp';
66
import { Root } from '../core/Root';
77
import { RootProps, LandingProps } from '../core/types';
8-
import { themeStorage } from '../core/utils';
98
import { useConstant } from '../core/hooks';
109
import { IConfig, IAppInstance } from './types';
1110

@@ -17,7 +16,7 @@ export interface IRenderProps extends IConfig {
1716
export const renderApp = (domElement: HTMLElement, props: IRenderProps) => {
1817
const { onLoad, Landing, ...opts } = props;
1918
const app = createApp(opts);
20-
const themeType = themeStorage.get();
19+
const themeType = app.currentThemeType;
2120
ReactDOM.render(<Root status="loading" theme={themeType} Landing={Landing} />, domElement);
2221

2322
app
@@ -57,7 +56,7 @@ export const renderApp = (domElement: HTMLElement, props: IRenderProps) => {
5756

5857
export const AppRenderer: React.FC<IRenderProps> = ({ onLoad, Landing, ...opts }) => {
5958
const app = useConstant(() => createApp(opts));
60-
const themeType = useConstant(() => themeStorage.get());
59+
const themeType = useConstant(() => app.currentThemeType);
6160
const appElementRef = useRef<React.ReactElement | null>(null);
6261

6362
const [state, setState] = useState<{

packages/alex/src/api/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
/// <reference path="../../typings/thenable.d.ts" />
1+
/// <reference path="../../typings/index.d.ts" />
22

33
import { IAppOpts, RuntimeConfig, ClientApp } from '@alipay/alex-core';
44
import { IAppRenderer } from '@ali/ide-core-browser';
55
import { IPluginConfig } from '@alipay/alex-plugin';
6+
import { ThemeType } from '@ali/ide-theme';
67

78
export type { IPluginAPI, IPluginModule } from '@alipay/alex-plugin';
89

@@ -37,4 +38,9 @@ export interface IAppInstance extends ClientApp {
3738
* 销毁应用
3839
*/
3940
destroy(): void;
41+
42+
/**
43+
* 当前主题色, dark | light | hc
44+
*/
45+
readonly currentThemeType: ThemeType;
4046
}

0 commit comments

Comments
 (0)