@qlover/create-app 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -27
- package/bin/create-app.js +0 -0
- package/configs/_common/package.json.template +10 -0
- package/configs/react-app/eslint.config.js +70 -42
- package/dist/index.cjs +1 -3631
- package/dist/index.js +1 -3625
- package/package.json +7 -7
- package/templates/react-app/.env +1 -0
- package/templates/react-app/config/ErrorIdentifier.ts +27 -0
- package/templates/react-app/config/app.router.json +9 -0
- package/templates/react-app/config/common.ts +12 -0
- package/templates/react-app/config/feapi.mock.json +15 -2
- package/templates/react-app/config/i18n.ts +3 -11
- package/templates/react-app/package.json +7 -4
- package/templates/react-app/pnpm-lock.yaml +176 -25
- package/templates/react-app/public/locales/en/common.json +6 -2
- package/templates/react-app/public/locales/zh/common.json +6 -3
- package/templates/react-app/src/App.tsx +8 -8
- package/templates/react-app/src/base/apis/AiApi.ts +55 -0
- package/templates/react-app/src/base/apis/feApi/FeApi.ts +13 -44
- package/templates/react-app/src/base/apis/feApi/FeApiAdapter.ts +14 -0
- package/templates/react-app/src/base/apis/feApi/FeApiBootstarp.ts +67 -0
- package/templates/react-app/src/base/apis/feApi/FeApiType.ts +2 -35
- package/templates/react-app/src/base/apis/userApi/UserApi.ts +64 -0
- package/templates/react-app/src/base/apis/userApi/UserApiAdapter.ts +14 -0
- package/templates/react-app/src/base/apis/userApi/UserApiBootstarp.ts +75 -0
- package/templates/react-app/src/base/apis/userApi/UserApiType.ts +52 -0
- package/templates/react-app/src/base/cases/RequestLogger.ts +71 -0
- package/templates/react-app/src/base/cases/RequestStatusCatcher.ts +41 -0
- package/templates/react-app/src/base/cases/appError/AppError.ts +13 -0
- package/templates/react-app/{lib/router-loader/RouterLoader.ts → src/base/cases/router-loader/index.ts} +1 -1
- package/templates/react-app/src/base/port/ApiTransactionInterface.ts +7 -0
- package/templates/react-app/src/base/port/InversifyIocInterface.ts +1 -1
- package/templates/react-app/src/base/port/LoginInterface.ts +4 -0
- package/templates/react-app/src/base/port/RequestCatcherInterface.ts +12 -0
- package/templates/react-app/src/{services → base/services}/I18nService.ts +7 -2
- package/templates/react-app/src/{services/processer → base/services}/ProcesserService.ts +10 -11
- package/templates/react-app/src/base/types/Page.ts +1 -13
- package/templates/react-app/src/core/AppConfig.ts +14 -5
- package/templates/react-app/src/core/IOC.ts +77 -37
- package/templates/react-app/src/core/bootstrap.ts +38 -25
- package/templates/react-app/src/core/bootstraps/BootstrapApp.ts +7 -0
- package/templates/react-app/src/core/bootstraps/index.ts +12 -0
- package/templates/react-app/src/core/globals.ts +7 -10
- package/templates/react-app/src/core/registers/RegisterApi.ts +1 -52
- package/templates/react-app/src/core/registers/RegisterCommon.ts +44 -6
- package/templates/react-app/src/core/registers/RegisterControllers.ts +5 -34
- package/templates/react-app/src/core/registers/RegisterGlobals.ts +8 -2
- package/templates/react-app/src/core/registers/index.ts +2 -1
- package/templates/react-app/src/main.tsx +4 -1
- package/templates/react-app/src/pages/auth/Layout.tsx +4 -3
- package/templates/react-app/src/pages/auth/Login.tsx +5 -3
- package/templates/react-app/src/pages/base/ErrorIdentifier.tsx +39 -0
- package/templates/react-app/src/pages/base/Executor.tsx +31 -10
- package/templates/react-app/src/pages/base/Home.tsx +58 -30
- package/templates/react-app/src/pages/base/JSONStorage.tsx +2 -4
- package/templates/react-app/src/pages/base/Request.tsx +318 -73
- package/templates/react-app/src/pages/base/components/BaseHeader.tsx +2 -2
- package/templates/react-app/src/{components → uikit/components}/RouterRenderComponent.tsx +1 -1
- package/templates/react-app/src/{components → uikit/components}/ThemeSwitcher.tsx +6 -6
- package/templates/react-app/src/uikit/contexts/BaseRouteContext.ts +6 -3
- package/templates/react-app/src/uikit/controllers/ExecutorController.ts +52 -22
- package/templates/react-app/src/uikit/controllers/JSONStorageController.ts +7 -3
- package/templates/react-app/src/uikit/controllers/RequestController.ts +65 -11
- package/templates/react-app/src/uikit/controllers/RouterController.ts +8 -7
- package/templates/react-app/src/uikit/controllers/UserController.ts +48 -54
- package/templates/react-app/src/uikit/hooks/useLanguageGuard.ts +1 -2
- package/templates/react-app/src/uikit/providers/ProcessProvider.tsx +4 -4
- package/templates/react-app/src/uikit/styles/css/index.css +1 -1
- package/templates/react-app/src/uikit/styles/css/page.css +1 -1
- package/templates/react-app/tailwind.config.js +2 -2
- package/templates/react-app/tsconfig.json +0 -1
- package/templates/react-app/tsconfig.node.json +1 -2
- package/templates/react-app/vite.config.ts +21 -26
- package/templates/react-app/.env.local +0 -24
- package/templates/react-app/lib/bootstrap/Bootstrap.ts +0 -36
- package/templates/react-app/lib/bootstrap/BootstrapExecutorPlugin.ts +0 -20
- package/templates/react-app/lib/bootstrap/IOCContainerInterface.ts +0 -33
- package/templates/react-app/lib/bootstrap/IOCManagerInterface.ts +0 -12
- package/templates/react-app/lib/bootstrap/index.ts +0 -7
- package/templates/react-app/lib/bootstrap/plugins/InjectEnv.ts +0 -61
- package/templates/react-app/lib/bootstrap/plugins/InjectGlobal.ts +0 -36
- package/templates/react-app/lib/bootstrap/plugins/InjectIOC.ts +0 -24
- package/templates/react-app/lib/env-config/injectPkgConfig.ts +0 -11
- package/templates/react-app/lib/fe-react-controller/FeController.ts +0 -19
- package/templates/react-app/lib/fe-react-controller/index.ts +0 -2
- package/templates/react-app/lib/fe-react-controller/useController.ts +0 -71
- package/templates/react-app/lib/fe-react-theme/ThemeController.ts +0 -40
- package/templates/react-app/lib/fe-react-theme/ThemeStateGetter.ts +0 -53
- package/templates/react-app/lib/fe-react-theme/index.ts +0 -3
- package/templates/react-app/lib/fe-react-theme/type.ts +0 -21
- package/templates/react-app/lib/openAiApi/OpenAIAuthPlugin.ts +0 -29
- package/templates/react-app/lib/openAiApi/OpenAIClient.ts +0 -51
- package/templates/react-app/lib/openAiApi/StreamProcessor.ts +0 -81
- package/templates/react-app/lib/openAiApi/index.ts +0 -3
- package/templates/react-app/lib/request-common-plugin/index.ts +0 -169
- package/templates/react-app/lib/router-loader/Page.ts +0 -68
- package/templates/react-app/lib/tw-root10px/index.css +0 -4
- package/templates/react-app/src/base/apis/feApi/FeApiMockPlugin.ts +0 -44
- package/templates/react-app/src/base/apis/feApi/index.ts +0 -2
- package/templates/react-app/src/base/cases/UserToken.ts +0 -47
- package/templates/react-app/src/base/consts/IOCIdentifier.ts +0 -16
- package/templates/react-app/src/base/port/IOCFunctionInterface.ts +0 -39
- package/templates/react-app/src/base/port/StorageTokenInterface.ts +0 -27
- package/templates/react-app/src/core/AppIOCContainer.ts +0 -30
- package/templates/react-app/src/uikit/utils/RequestLogger.ts +0 -37
- package/templates/react-app/src/uikit/utils/datetime.ts +0 -30
- package/templates/react-app/src/uikit/utils/thread.ts +0 -3
- /package/templates/react-app/lib/{tw-root10px/index.js → tailwind/root10px.js} +0 -0
- /package/templates/react-app/lib/{fe-react-theme/tw-generator.js → tailwind/theme-generator.js} +0 -0
- /package/templates/react-app/src/{components → uikit/components}/Loading.tsx +0 -0
- /package/templates/react-app/src/{components → uikit/components}/LocaleLink.tsx +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RequestCatcherInterface
|
|
3
|
+
*
|
|
4
|
+
* @description
|
|
5
|
+
* RequestCatcherInterface is a interface that catches the request error
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export interface RequestCatcherInterface<Context> {
|
|
9
|
+
handler(context: Context): void;
|
|
10
|
+
|
|
11
|
+
default(context: Context): void;
|
|
12
|
+
}
|
|
@@ -3,23 +3,28 @@ import { initReactI18next } from 'react-i18next';
|
|
|
3
3
|
import LanguageDetector from 'i18next-browser-languagedetector';
|
|
4
4
|
import HttpApi from 'i18next-http-backend';
|
|
5
5
|
import merge from 'lodash/merge';
|
|
6
|
-
import
|
|
7
|
-
import type { BootstrapExecutorPlugin } from '@
|
|
6
|
+
import i18nConfig from '@config/i18n';
|
|
7
|
+
import type { BootstrapExecutorPlugin } from '@qlover/corekit-bridge';
|
|
8
8
|
|
|
9
9
|
const { supportedLngs, fallbackLng } = i18nConfig;
|
|
10
10
|
|
|
11
|
+
export type I18nServiceLocale = (typeof supportedLngs)[number];
|
|
12
|
+
|
|
11
13
|
export class I18nService implements BootstrapExecutorPlugin {
|
|
12
14
|
readonly pluginName = 'I18nService';
|
|
13
15
|
|
|
14
16
|
constructor(private pathname: string) {}
|
|
15
17
|
|
|
16
18
|
onBefore(): void {
|
|
19
|
+
const debug = false;
|
|
20
|
+
|
|
17
21
|
i18n
|
|
18
22
|
.use(HttpApi)
|
|
19
23
|
.use(LanguageDetector)
|
|
20
24
|
.use(initReactI18next)
|
|
21
25
|
.init(
|
|
22
26
|
merge({}, i18nConfig, {
|
|
27
|
+
debug,
|
|
23
28
|
detection: {
|
|
24
29
|
order: ['pathLanguageDetector', 'navigator'], // use custom detector
|
|
25
30
|
caches: []
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { AsyncExecutor, ExecutorPlugin, Logger } from '@qlover/fe-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
logger: Logger;
|
|
5
|
-
}
|
|
1
|
+
import { AsyncExecutor, ExecutorPlugin, Logger } from '@qlover/fe-corekit';
|
|
2
|
+
import { IOCIdentifier } from '@/core/IOC';
|
|
3
|
+
import { injectable, inject } from 'inversify';
|
|
6
4
|
|
|
5
|
+
@injectable()
|
|
7
6
|
export class ProcesserService {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
7
|
+
constructor(
|
|
8
|
+
@inject(IOCIdentifier.Logger) private logger: Logger,
|
|
9
|
+
@inject(AsyncExecutor) private executor: AsyncExecutor
|
|
10
|
+
) {}
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
use(plugin: ExecutorPlugin): this {
|
|
14
13
|
this.executor.use(plugin);
|
|
15
14
|
return this;
|
|
16
15
|
}
|
|
@@ -23,7 +22,7 @@ export class ProcesserService {
|
|
|
23
22
|
|
|
24
23
|
init(): Promise<unknown> {
|
|
25
24
|
return this.executor.exec(this.handler).catch((err) => {
|
|
26
|
-
this.
|
|
25
|
+
this.logger.error('PageProcesser init failed', err);
|
|
27
26
|
});
|
|
28
27
|
}
|
|
29
28
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type { LazyExoticComponent, PropsWithChildren } from 'react';
|
|
2
1
|
import type { TFunction } from 'i18next';
|
|
3
2
|
import type { UseTranslationResponse } from 'react-i18next';
|
|
4
|
-
import type { RouteConfigValue } from '@lib/router-loader/RouterLoader';
|
|
5
3
|
|
|
6
4
|
export interface BasePageProvider {
|
|
7
5
|
meta: RouteMeta;
|
|
@@ -9,7 +7,7 @@ export interface BasePageProvider {
|
|
|
9
7
|
t: TFunction<string, string>;
|
|
10
8
|
}
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
type RouteCategory = 'main' | 'auth' | 'common';
|
|
13
11
|
|
|
14
12
|
export interface RouteMeta {
|
|
15
13
|
category?: RouteCategory;
|
|
@@ -25,13 +23,3 @@ export interface RouteMeta {
|
|
|
25
23
|
*/
|
|
26
24
|
localNamespace?: string;
|
|
27
25
|
}
|
|
28
|
-
|
|
29
|
-
export type RouteConfig = {
|
|
30
|
-
routes: RouteConfigValue[];
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type PagesMaps = Record<
|
|
34
|
-
string,
|
|
35
|
-
| (() => LazyExoticComponent<React.ComponentType<unknown>>)
|
|
36
|
-
| (() => React.ComponentType<unknown>)
|
|
37
|
-
>;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import type { EnvConfigInterface } from '@
|
|
1
|
+
import type { EnvConfigInterface } from '@qlover/corekit-bridge';
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
export class AppConfigImpl implements EnvConfigInterface {
|
|
4
4
|
readonly appName = '';
|
|
5
5
|
readonly appVersion = '';
|
|
6
6
|
/**
|
|
7
7
|
* vite mode
|
|
8
|
+
*
|
|
8
9
|
*/
|
|
9
|
-
readonly env =
|
|
10
|
+
readonly env: string = '';
|
|
10
11
|
|
|
11
|
-
readonly userTokenStorageKey = '
|
|
12
|
+
readonly userTokenStorageKey = '';
|
|
12
13
|
readonly openAiModels = [
|
|
13
14
|
'gpt-4o-mini',
|
|
14
15
|
'gpt-3.5-turbo',
|
|
@@ -22,6 +23,14 @@ class AppConfig implements EnvConfigInterface {
|
|
|
22
23
|
readonly openAiRequireToken = true;
|
|
23
24
|
readonly loginUser = '';
|
|
24
25
|
readonly loginPassword = '';
|
|
26
|
+
|
|
27
|
+
readonly feApiBaseUrl = '';
|
|
28
|
+
readonly userApiBaseUrl = '';
|
|
29
|
+
|
|
30
|
+
readonly aiApiBaseUrl = 'https://api.openai.com/v1';
|
|
31
|
+
readonly aiApiToken = '';
|
|
32
|
+
readonly aiApiTokenPrefix = 'Bearer';
|
|
33
|
+
readonly aiApiRequireToken = true;
|
|
25
34
|
}
|
|
26
35
|
|
|
27
|
-
export default new
|
|
36
|
+
export default new AppConfigImpl();
|
|
@@ -1,48 +1,88 @@
|
|
|
1
1
|
// ! dont't import tsx, only ts file
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
import {
|
|
3
|
+
ApiMockPlugin,
|
|
4
|
+
EnvConfigInterface,
|
|
5
|
+
StorageTokenInterface,
|
|
6
|
+
RequestCommonPlugin,
|
|
7
|
+
ApiCatchPlugin,
|
|
8
|
+
IOCContainerInterface,
|
|
9
|
+
createIOCFunction,
|
|
10
|
+
ServiceIdentifier
|
|
11
|
+
} from '@qlover/corekit-bridge';
|
|
12
|
+
import type { JSONSerializer, JSONStorage, Logger } from '@qlover/fe-corekit';
|
|
13
|
+
import { Container } from 'inversify';
|
|
14
|
+
import { InversifyRegisterInterface } from '@/base/port/InversifyIocInterface';
|
|
15
|
+
|
|
16
|
+
export class InversifyContainer implements IOCContainerInterface {
|
|
17
|
+
private container: Container;
|
|
18
|
+
|
|
19
|
+
constructor() {
|
|
20
|
+
this.container = new Container({
|
|
21
|
+
// allow `@injectable` decorator, auto bind injectable classes
|
|
22
|
+
autobind: true,
|
|
23
|
+
// use singleton scope
|
|
24
|
+
defaultScope: 'Singleton'
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
configure(registers?: InversifyRegisterInterface[]): void {
|
|
29
|
+
if (registers) {
|
|
30
|
+
registers.forEach((register) => register.register(this.container, this));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
bind<T>(key: ServiceIdentifier<T>, value: T): void {
|
|
35
|
+
this.container.bind<T>(key).toConstantValue(value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get<K extends keyof IOCIdentifierMap>(
|
|
39
|
+
serviceIdentifier: K
|
|
40
|
+
): IOCIdentifierMap[K];
|
|
41
|
+
get<T>(serviceIdentifier: ServiceIdentifier<T>): T;
|
|
42
|
+
get<T, K extends keyof IOCIdentifierMap>(
|
|
43
|
+
serviceIdentifier: ServiceIdentifier<T> | K
|
|
44
|
+
): T | IOCIdentifierMap[K] {
|
|
45
|
+
return this.container.get<T>(serviceIdentifier);
|
|
20
46
|
}
|
|
21
|
-
return implemention.get(serviceIdentifier);
|
|
22
47
|
}
|
|
23
48
|
|
|
24
49
|
/**
|
|
25
|
-
* IOC
|
|
50
|
+
* IOC identifier
|
|
26
51
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* class A {}
|
|
30
|
-
* const a = IOC(A);
|
|
31
|
-
* ```
|
|
52
|
+
* @description
|
|
53
|
+
* IOC identifier is used to identify the service in the IOC container.
|
|
32
54
|
*
|
|
33
|
-
*
|
|
55
|
+
* @example
|
|
34
56
|
* ```ts
|
|
35
|
-
* const a = IOC
|
|
57
|
+
* const a = IOC(IOCIdentifier.JSON);
|
|
58
|
+
* const b = IOC('JSON');
|
|
36
59
|
* ```
|
|
37
|
-
*
|
|
38
|
-
* or use get(),
|
|
39
60
|
*/
|
|
40
|
-
export const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
61
|
+
export const IOCIdentifier = Object.freeze({
|
|
62
|
+
JSON: 'JSON',
|
|
63
|
+
JSONStorage: 'JSONStorage',
|
|
64
|
+
Logger: 'Logger',
|
|
65
|
+
FeApiToken: 'FeApiToken',
|
|
66
|
+
FeApiCommonPlugin: 'FeApiCommonPlugin',
|
|
67
|
+
AppConfig: 'AppConfig',
|
|
68
|
+
ApiMockPlugin: 'ApiMockPlugin',
|
|
69
|
+
ApiCatchPlugin: 'ApiCatchPlugin'
|
|
48
70
|
});
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* IOC identifier map
|
|
74
|
+
*/
|
|
75
|
+
export interface IOCIdentifierMap {
|
|
76
|
+
[IOCIdentifier.JSON]: JSONSerializer;
|
|
77
|
+
[IOCIdentifier.JSONStorage]: JSONStorage;
|
|
78
|
+
[IOCIdentifier.Logger]: Logger;
|
|
79
|
+
[IOCIdentifier.FeApiToken]: StorageTokenInterface<string>;
|
|
80
|
+
[IOCIdentifier.FeApiCommonPlugin]: RequestCommonPlugin;
|
|
81
|
+
[IOCIdentifier.AppConfig]: EnvConfigInterface;
|
|
82
|
+
[IOCIdentifier.ApiMockPlugin]: ApiMockPlugin;
|
|
83
|
+
[IOCIdentifier.ApiCatchPlugin]: ApiCatchPlugin;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const IOC = createIOCFunction<IOCIdentifierMap>(
|
|
87
|
+
new InversifyContainer()
|
|
88
|
+
);
|
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Bootstrap,
|
|
3
|
-
BootstrapExecutorPlugin,
|
|
3
|
+
type BootstrapExecutorPlugin,
|
|
4
4
|
InjectEnv,
|
|
5
5
|
InjectIOC,
|
|
6
6
|
InjectGlobal
|
|
7
|
-
} from '@
|
|
8
|
-
import { AppIOCContainer } from '@/core/AppIOCContainer';
|
|
7
|
+
} from '@qlover/corekit-bridge';
|
|
9
8
|
import AppConfig from '@/core/AppConfig';
|
|
10
|
-
import { envPrefix, browserGlobalsName } from '@config/common';
|
|
9
|
+
import { envPrefix, browserGlobalsName, envBlackList } from '@config/common';
|
|
11
10
|
import { IOC } from './IOC';
|
|
12
11
|
import * as globals from '@/core/globals';
|
|
13
|
-
import { I18nService } from '@/services/I18nService';
|
|
12
|
+
import { I18nService } from '@/base/services/I18nService';
|
|
14
13
|
import { registerList } from './registers';
|
|
14
|
+
import { appBootstrapList } from './bootstraps';
|
|
15
|
+
import { GLOBAL_NO_WINDOW } from '@config/ErrorIdentifier';
|
|
16
|
+
|
|
17
|
+
const printBootstrap: BootstrapExecutorPlugin = {
|
|
18
|
+
pluginName: 'PrintBootstrap',
|
|
19
|
+
onSuccess({ parameters: { logger } }) {
|
|
20
|
+
logger.info(
|
|
21
|
+
'bootstrap success!\n\n' +
|
|
22
|
+
`You can use \`%cwindow.${browserGlobalsName}%c\` to access the globals`,
|
|
23
|
+
'color: #0ff; font-weight: bold;',
|
|
24
|
+
'all: unset;'
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
15
28
|
|
|
16
29
|
/**
|
|
17
30
|
* Bootstrap
|
|
@@ -21,15 +34,20 @@ import { registerList } from './registers';
|
|
|
21
34
|
* 3. inject globals to window
|
|
22
35
|
*
|
|
23
36
|
*/
|
|
24
|
-
export default function startup(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
export default function startup({
|
|
38
|
+
window,
|
|
39
|
+
envSource
|
|
40
|
+
}: {
|
|
41
|
+
window: unknown;
|
|
42
|
+
envSource: Record<string, unknown>;
|
|
43
|
+
}) {
|
|
44
|
+
if (!(typeof window !== 'undefined' && window instanceof Window)) {
|
|
45
|
+
throw new Error(GLOBAL_NO_WINDOW);
|
|
30
46
|
}
|
|
31
47
|
|
|
32
|
-
const
|
|
48
|
+
const { logger } = globals;
|
|
49
|
+
|
|
50
|
+
const bootstrap = new Bootstrap(window, IOC.implemention!, logger);
|
|
33
51
|
|
|
34
52
|
/**
|
|
35
53
|
* bootstrap start list
|
|
@@ -40,27 +58,22 @@ export default function startup(root: typeof globalThis) {
|
|
|
40
58
|
* - inject i18n service to Application
|
|
41
59
|
*/
|
|
42
60
|
const bootstrapList: BootstrapExecutorPlugin[] = [
|
|
43
|
-
new InjectEnv(AppConfig,
|
|
61
|
+
new InjectEnv(AppConfig, envSource, envPrefix, envBlackList),
|
|
44
62
|
new InjectIOC(IOC, registerList),
|
|
45
63
|
new InjectGlobal(globals, browserGlobalsName),
|
|
46
|
-
new I18nService(window.location.pathname)
|
|
64
|
+
new I18nService(window.location.pathname),
|
|
65
|
+
...appBootstrapList
|
|
47
66
|
];
|
|
48
67
|
|
|
49
68
|
if (AppConfig.env !== 'production') {
|
|
50
|
-
bootstrapList.push(
|
|
51
|
-
pluginName: 'InjectDevTools',
|
|
52
|
-
onBefore() {
|
|
53
|
-
console.log(AppConfig);
|
|
54
|
-
},
|
|
55
|
-
onError({ error }) {
|
|
56
|
-
console.error(`${AppConfig.appName} starup error:`, error);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
69
|
+
bootstrapList.push(printBootstrap);
|
|
59
70
|
}
|
|
60
71
|
|
|
61
72
|
try {
|
|
62
|
-
|
|
73
|
+
logger.info('bootstrap start...');
|
|
74
|
+
|
|
75
|
+
bootstrap.use(bootstrapList).start();
|
|
63
76
|
} catch (error) {
|
|
64
|
-
|
|
77
|
+
logger.error(`${AppConfig.appName} starup error:`, error);
|
|
65
78
|
}
|
|
66
79
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BootstrapExecutorPlugin } from '@qlover/corekit-bridge';
|
|
2
|
+
import { BootstrapApp } from './BootstrapApp';
|
|
3
|
+
import { UserApiBootstarp } from '@/base/apis/userApi/UserApiBootstarp';
|
|
4
|
+
import { FeApiBootstarp } from '@/base/apis/feApi/FeApiBootstarp';
|
|
5
|
+
import { AiApiBootstarp } from '@/base/apis/AiApi';
|
|
6
|
+
|
|
7
|
+
export const appBootstrapList: BootstrapExecutorPlugin[] = [
|
|
8
|
+
new UserApiBootstarp(),
|
|
9
|
+
new FeApiBootstarp(),
|
|
10
|
+
AiApiBootstarp,
|
|
11
|
+
new BootstrapApp()
|
|
12
|
+
];
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
// ! global variables, don't import any dependencies and don't have side effects
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Logger,
|
|
6
|
-
SyncStorage
|
|
7
|
-
} from '@qlover/fe-utils';
|
|
2
|
+
import { JSONStorage, JSONSerializer, SyncStorage } from '@qlover/fe-corekit';
|
|
3
|
+
import { ColorLogger } from '@qlover/corekit-bridge';
|
|
4
|
+
import { loggerStyles } from '@config/common';
|
|
8
5
|
|
|
9
|
-
|
|
10
|
-
export const isProduction = env === 'production';
|
|
6
|
+
const isProduction = import.meta.env.VITE_USER_NODE_ENV === 'production';
|
|
11
7
|
|
|
12
8
|
/**
|
|
13
9
|
* Global logger
|
|
14
10
|
*/
|
|
15
|
-
export const logger = new
|
|
11
|
+
export const logger = new ColorLogger({
|
|
16
12
|
silent: isProduction,
|
|
17
|
-
debug: !isProduction
|
|
13
|
+
debug: !isProduction,
|
|
14
|
+
colorsMaps: loggerStyles
|
|
18
15
|
});
|
|
19
16
|
|
|
20
17
|
/**
|
|
@@ -3,57 +3,6 @@ import type {
|
|
|
3
3
|
InversifyRegisterContainer
|
|
4
4
|
} from '@/base/port/InversifyIocInterface';
|
|
5
5
|
|
|
6
|
-
import { RequestLogger } from '@/uikit/utils/RequestLogger';
|
|
7
|
-
import { localJsonStorage } from '../globals';
|
|
8
|
-
import { FetchAbortPlugin, FetchURLPlugin } from '@qlover/fe-utils';
|
|
9
|
-
import { FeApiMockPlugin } from '@/base/apis/feApi';
|
|
10
|
-
import { OpenAIClient } from '@lib/openAiApi';
|
|
11
|
-
import { FeApi } from '@/base/apis/feApi';
|
|
12
|
-
import { RequestCommonPlugin } from '@lib/request-common-plugin';
|
|
13
|
-
import mockDataJson from '@config/feapi.mock.json';
|
|
14
|
-
import AppConfig from '@/core/AppConfig';
|
|
15
|
-
|
|
16
6
|
export class RegisterApi implements InversifyRegisterInterface {
|
|
17
|
-
register(
|
|
18
|
-
const openAiApi = new OpenAIClient({
|
|
19
|
-
baseURL: AppConfig.openAiBaseUrl,
|
|
20
|
-
models: AppConfig.openAiModels,
|
|
21
|
-
commonPluginConfig: {
|
|
22
|
-
tokenPrefix: AppConfig.openAiTokenPrefix,
|
|
23
|
-
token: AppConfig.openAiToken,
|
|
24
|
-
defaultHeaders: {
|
|
25
|
-
'Content-Type': 'application/json'
|
|
26
|
-
},
|
|
27
|
-
defaultRequestData: {
|
|
28
|
-
model: AppConfig.openAiModels[0],
|
|
29
|
-
stream: true
|
|
30
|
-
},
|
|
31
|
-
requiredToken: true,
|
|
32
|
-
requestDataSerializer: (data) => JSON.stringify(data)
|
|
33
|
-
}
|
|
34
|
-
}).usePlugin(container.get(RequestLogger));
|
|
35
|
-
|
|
36
|
-
const abortPlugin = container.get(FetchAbortPlugin);
|
|
37
|
-
const feApi = new FeApi({
|
|
38
|
-
abortPlugin,
|
|
39
|
-
config: {
|
|
40
|
-
responseType: 'json',
|
|
41
|
-
baseURL: 'https://api.example.com/'
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
.usePlugin(new FetchURLPlugin())
|
|
45
|
-
.usePlugin(
|
|
46
|
-
new RequestCommonPlugin({
|
|
47
|
-
tokenPrefix: AppConfig.openAiTokenPrefix,
|
|
48
|
-
requiredToken: true,
|
|
49
|
-
token: () => localJsonStorage.getItem('fe_user_token')
|
|
50
|
-
})
|
|
51
|
-
)
|
|
52
|
-
.usePlugin(new FeApiMockPlugin(mockDataJson))
|
|
53
|
-
.usePlugin(container.get(RequestLogger))
|
|
54
|
-
.usePlugin(abortPlugin);
|
|
55
|
-
|
|
56
|
-
container.bind(OpenAIClient).toConstantValue(openAiApi);
|
|
57
|
-
container.bind(FeApi).toConstantValue(feApi);
|
|
58
|
-
}
|
|
7
|
+
register(_container: InversifyRegisterContainer): void {}
|
|
59
8
|
}
|
|
@@ -2,20 +2,58 @@ import type {
|
|
|
2
2
|
InversifyRegisterInterface,
|
|
3
3
|
InversifyRegisterContainer
|
|
4
4
|
} from '@/base/port/InversifyIocInterface';
|
|
5
|
-
|
|
6
|
-
import { FetchAbortPlugin, JSONStorage } from '@qlover/fe-utils';
|
|
7
|
-
import { UserToken } from '@/base/cases/UserToken';
|
|
5
|
+
import { FetchAbortPlugin, JSONStorage, Logger } from '@qlover/fe-corekit';
|
|
8
6
|
import AppConfig from '@/core/AppConfig';
|
|
7
|
+
import { IOCIdentifier } from '@/core/IOC';
|
|
8
|
+
import {
|
|
9
|
+
UserToken,
|
|
10
|
+
RequestCommonPlugin,
|
|
11
|
+
ApiMockPlugin,
|
|
12
|
+
ApiCatchPlugin,
|
|
13
|
+
ThemeService
|
|
14
|
+
} from '@qlover/corekit-bridge';
|
|
15
|
+
import mockDataJson from '@config/feapi.mock.json';
|
|
16
|
+
import { RequestStatusCatcher } from '@/base/cases/RequestStatusCatcher';
|
|
17
|
+
import { override as themeOverride } from '@config/theme.json';
|
|
18
|
+
import { localJsonStorage } from '../globals';
|
|
9
19
|
|
|
10
20
|
export class RegisterCommon implements InversifyRegisterInterface {
|
|
11
21
|
register(container: InversifyRegisterContainer): void {
|
|
22
|
+
const userToken = new UserToken(
|
|
23
|
+
AppConfig.userTokenStorageKey,
|
|
24
|
+
container.get(JSONStorage)
|
|
25
|
+
);
|
|
12
26
|
const feApiAbort = new FetchAbortPlugin();
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
27
|
+
const feApiRequestCommonPlugin = new RequestCommonPlugin({
|
|
28
|
+
tokenPrefix: AppConfig.openAiTokenPrefix,
|
|
29
|
+
requiredToken: true,
|
|
30
|
+
token: () => userToken.getToken()
|
|
16
31
|
});
|
|
17
32
|
|
|
18
33
|
container.bind(FetchAbortPlugin).toConstantValue(feApiAbort);
|
|
19
34
|
container.bind(UserToken).toConstantValue(userToken);
|
|
35
|
+
|
|
36
|
+
container.bind(IOCIdentifier.FeApiToken).toConstantValue(userToken);
|
|
37
|
+
container
|
|
38
|
+
.bind(IOCIdentifier.FeApiCommonPlugin)
|
|
39
|
+
.toConstantValue(feApiRequestCommonPlugin);
|
|
40
|
+
container
|
|
41
|
+
.bind(IOCIdentifier.ApiMockPlugin)
|
|
42
|
+
.toConstantValue(new ApiMockPlugin(mockDataJson, container.get(Logger)));
|
|
43
|
+
container
|
|
44
|
+
.bind(IOCIdentifier.ApiCatchPlugin)
|
|
45
|
+
.toConstantValue(
|
|
46
|
+
new ApiCatchPlugin(
|
|
47
|
+
container.get(Logger),
|
|
48
|
+
container.get(RequestStatusCatcher)
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
container.bind(ThemeService).toConstantValue(
|
|
53
|
+
new ThemeService({
|
|
54
|
+
...themeOverride,
|
|
55
|
+
storage: localJsonStorage
|
|
56
|
+
})
|
|
57
|
+
);
|
|
20
58
|
}
|
|
21
59
|
}
|
|
@@ -6,53 +6,24 @@ import type {
|
|
|
6
6
|
import { localJsonStorage, logger } from '../globals';
|
|
7
7
|
import { RouterController } from '@/uikit/controllers/RouterController';
|
|
8
8
|
import { JSONStorageController } from '@/uikit/controllers/JSONStorageController';
|
|
9
|
-
import {
|
|
10
|
-
import { ProcesserService } from '@/services/processer/ProcesserService';
|
|
11
|
-
import { ExecutorController } from '@/uikit/controllers/ExecutorController';
|
|
9
|
+
import { ProcesserService } from '@/base/services/ProcesserService';
|
|
12
10
|
import { UserController } from '@/uikit/controllers/UserController';
|
|
13
|
-
import {
|
|
14
|
-
import { RouteConfig } from '@/base/types/Page';
|
|
15
|
-
import { OpenAIClient } from '@lib/openAiApi';
|
|
16
|
-
import { FeApi } from '@/base/apis/feApi';
|
|
17
|
-
import appRouterConfig from '@config/app.router.json';
|
|
18
|
-
import themeConfigJson from '@config/theme.json';
|
|
19
|
-
import { UserToken } from '@/base/cases/UserToken';
|
|
11
|
+
import { base as baseRoutes } from '@config/app.router.json';
|
|
20
12
|
|
|
21
13
|
export class RegisterControllers implements InversifyRegisterInterface {
|
|
22
14
|
register(container: InversifyRegisterContainer): void {
|
|
23
15
|
const routerController = new RouterController({
|
|
24
|
-
config:
|
|
16
|
+
config: baseRoutes,
|
|
25
17
|
logger
|
|
26
18
|
});
|
|
27
19
|
|
|
28
20
|
const jsonStorageController = new JSONStorageController(localJsonStorage);
|
|
29
|
-
const requestController = new RequestController(
|
|
30
|
-
container.get(OpenAIClient),
|
|
31
|
-
container.get(FeApi)
|
|
32
|
-
);
|
|
33
|
-
const executorController = new ExecutorController(container.get(FeApi));
|
|
34
|
-
const userController = new UserController({
|
|
35
|
-
userToken: container.get(UserToken),
|
|
36
|
-
feApi: container.get(FeApi),
|
|
37
|
-
routerController
|
|
38
|
-
});
|
|
39
|
-
const themeController = new ThemeController({
|
|
40
|
-
...themeConfigJson.override,
|
|
41
|
-
storage: localJsonStorage
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const pageProcesser = new ProcesserService({
|
|
45
|
-
logger
|
|
46
|
-
}).usePlugin(userController);
|
|
47
21
|
|
|
48
22
|
container.bind(RouterController).toConstantValue(routerController);
|
|
49
23
|
container
|
|
50
24
|
.bind(JSONStorageController)
|
|
51
25
|
.toConstantValue(jsonStorageController);
|
|
52
|
-
|
|
53
|
-
container.
|
|
54
|
-
container.bind(UserController).toConstantValue(userController);
|
|
55
|
-
container.bind(ThemeController).toConstantValue(themeController);
|
|
56
|
-
container.bind(ProcesserService).toConstantValue(pageProcesser);
|
|
26
|
+
|
|
27
|
+
container.get(ProcesserService).use(container.get(UserController));
|
|
57
28
|
}
|
|
58
29
|
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
import { JSONSerializer, JSONStorage, Logger } from '@qlover/fe-corekit';
|
|
2
|
+
import type { EnvConfigInterface } from '@qlover/corekit-bridge';
|
|
1
3
|
import type {
|
|
2
4
|
InversifyRegisterInterface,
|
|
3
5
|
InversifyRegisterContainer
|
|
4
6
|
} from '@/base/port/InversifyIocInterface';
|
|
5
7
|
import { JSON, localJsonStorage, logger } from '../globals';
|
|
6
|
-
import {
|
|
7
|
-
import { IOCIdentifier } from '@/base/consts/IOCIdentifier';
|
|
8
|
+
import { IOCIdentifier } from '@/core/IOC';
|
|
8
9
|
|
|
9
10
|
export class RegisterGlobals implements InversifyRegisterInterface {
|
|
11
|
+
constructor(private appConfig: EnvConfigInterface) {}
|
|
12
|
+
|
|
10
13
|
register(container: InversifyRegisterContainer): void {
|
|
14
|
+
// inject AppConfig to IOC
|
|
15
|
+
container.bind(IOCIdentifier.AppConfig).toConstantValue(this.appConfig);
|
|
16
|
+
|
|
11
17
|
container.bind(JSONSerializer).toConstantValue(JSON);
|
|
12
18
|
container.bind(IOCIdentifier.JSON).toConstantValue(JSON);
|
|
13
19
|
|
|
@@ -3,6 +3,7 @@ import { RegisterGlobals } from './RegisterGlobals';
|
|
|
3
3
|
import { RegisterCommon } from './RegisterCommon';
|
|
4
4
|
import { RegisterApi } from './RegisterApi';
|
|
5
5
|
import { RegisterControllers } from './RegisterControllers';
|
|
6
|
+
import AppConfig from '../AppConfig';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Register List
|
|
@@ -10,7 +11,7 @@ import { RegisterControllers } from './RegisterControllers';
|
|
|
10
11
|
* Register List is used to register dependencies in bootstrap
|
|
11
12
|
*/
|
|
12
13
|
export const registerList: InversifyRegisterInterface[] = [
|
|
13
|
-
new RegisterGlobals(),
|
|
14
|
+
new RegisterGlobals(AppConfig),
|
|
14
15
|
new RegisterCommon(),
|
|
15
16
|
new RegisterApi(),
|
|
16
17
|
new RegisterControllers()
|
|
@@ -5,7 +5,10 @@ import { createRoot } from 'react-dom/client';
|
|
|
5
5
|
import App from './App.tsx';
|
|
6
6
|
import startup from './core/bootstrap';
|
|
7
7
|
|
|
8
|
-
startup(
|
|
8
|
+
startup({
|
|
9
|
+
window: window,
|
|
10
|
+
envSource: import.meta.env
|
|
11
|
+
});
|
|
9
12
|
|
|
10
13
|
createRoot(document.getElementById('root')!).render(
|
|
11
14
|
<StrictMode>
|