@qlover/create-app 0.6.0 → 0.6.2
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 +37 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/templates/react-app/config/IOCIdentifier.ts +13 -0
- package/dist/templates/react-app/docs/zh/bootstrap.md +555 -0
- package/dist/templates/react-app/docs/zh/env.md +480 -0
- package/dist/templates/react-app/docs/zh/global.md +510 -0
- package/dist/templates/react-app/docs/zh/ioc.md +410 -0
- package/dist/templates/react-app/package.json +1 -1
- package/dist/templates/react-app/src/base/apis/AiApi.ts +10 -5
- package/dist/templates/react-app/src/base/apis/feApi/FeApiAdapter.ts +1 -1
- package/dist/templates/react-app/src/base/apis/feApi/FeApiBootstarp.ts +1 -1
- package/dist/templates/react-app/src/base/apis/userApi/UserApi.ts +10 -17
- package/dist/templates/react-app/src/base/apis/userApi/UserApiAdapter.ts +1 -1
- package/dist/templates/react-app/src/base/apis/userApi/UserApiBootstarp.ts +2 -1
- package/dist/templates/react-app/src/base/apis/userApi/UserApiType.ts +7 -5
- package/dist/templates/react-app/src/base/cases/I18nKeyErrorPlugin.ts +3 -2
- package/dist/templates/react-app/src/base/cases/InversifyContainer.ts +33 -0
- package/dist/templates/react-app/src/base/cases/RequestLogger.ts +1 -1
- package/dist/templates/react-app/src/base/cases/RequestStatusCatcher.ts +2 -2
- package/dist/templates/react-app/src/base/services/ProcesserExecutor.ts +1 -1
- package/dist/templates/react-app/src/base/services/RouteService.ts +5 -2
- package/dist/templates/react-app/src/base/services/UserService.ts +8 -10
- package/dist/templates/react-app/src/core/IOC.ts +73 -83
- package/dist/templates/react-app/src/core/bootstraps/BootstrapApp.ts +52 -4
- package/dist/templates/react-app/src/core/bootstraps/{index.ts → BootstrapsRegistry.ts} +2 -3
- package/dist/templates/react-app/src/core/registers/IocRegisterImpl.ts +25 -0
- package/dist/templates/react-app/src/core/registers/RegisterCommon.ts +11 -17
- package/dist/templates/react-app/src/core/registers/RegisterControllers.ts +10 -4
- package/dist/templates/react-app/src/core/registers/RegisterGlobals.ts +6 -15
- package/dist/templates/react-app/src/main.tsx +2 -5
- package/dist/templates/react-app/src/uikit/controllers/JSONStorageController.ts +1 -1
- package/dist/templates/react-app/tsconfig.app.json +2 -1
- package/dist/templates/react-app/tsconfig.node.json +2 -1
- package/dist/templates/react-app/vite.config.ts +1 -1
- package/package.json +2 -2
- package/dist/templates/react-app/src/base/port/ApiTransactionInterface.ts +0 -7
- package/dist/templates/react-app/src/base/port/RequestCatcherInterface.ts +0 -12
- package/dist/templates/react-app/src/core/bootstrap.ts +0 -58
- package/dist/templates/react-app/src/core/registers/RegisterApi.ts +0 -5
- package/dist/templates/react-app/src/core/registers/index.ts +0 -32
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
import { ExecutorPlugin, type SyncStorageInterface } from '@qlover/fe-corekit';
|
|
2
2
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
UserApiLoginTransaction,
|
|
4
|
+
UserInfo
|
|
5
5
|
} from '@/base/apis/userApi/UserApiType';
|
|
6
6
|
import { RouteService } from './RouteService';
|
|
7
7
|
import {
|
|
8
|
-
LoginResponseData,
|
|
9
8
|
type UserAuthApiInterface,
|
|
9
|
+
type UserAuthState,
|
|
10
|
+
LoginResponseData,
|
|
10
11
|
UserAuthService,
|
|
11
|
-
UserAuthState,
|
|
12
12
|
UserAuthStore
|
|
13
13
|
} from '@qlover/corekit-bridge';
|
|
14
14
|
import { inject, injectable } from 'inversify';
|
|
15
15
|
import { UserApi } from '@/base/apis/userApi/UserApi';
|
|
16
16
|
import { AppError } from '@/base/cases/AppError';
|
|
17
17
|
import * as errKeys from '@config/Identifier/common.error';
|
|
18
|
-
import { IOCIdentifier } from '
|
|
18
|
+
import { IOCIdentifier } from '@config/IOCIdentifier';
|
|
19
19
|
import { AppConfig } from '../cases/AppConfig';
|
|
20
|
-
import { UserApiState } from '../apis/userApi/UserApi';
|
|
21
20
|
|
|
22
|
-
export
|
|
23
|
-
UserApiGetUserInfoTransaction['response']['data'];
|
|
21
|
+
export interface UserApiState extends UserAuthState<UserInfo> {}
|
|
24
22
|
|
|
25
23
|
export interface RegisterFormData {
|
|
26
24
|
username: string;
|
|
@@ -32,7 +30,7 @@ export interface RegisterFormData {
|
|
|
32
30
|
|
|
33
31
|
@injectable()
|
|
34
32
|
export class UserService
|
|
35
|
-
extends UserAuthService<
|
|
33
|
+
extends UserAuthService<UserInfo>
|
|
36
34
|
implements ExecutorPlugin
|
|
37
35
|
{
|
|
38
36
|
readonly pluginName = 'UserService';
|
|
@@ -40,7 +38,7 @@ export class UserService
|
|
|
40
38
|
constructor(
|
|
41
39
|
@inject(RouteService) protected routerService: RouteService,
|
|
42
40
|
@inject(UserApi)
|
|
43
|
-
userApi: UserAuthApiInterface<
|
|
41
|
+
userApi: UserAuthApiInterface<UserInfo>,
|
|
44
42
|
@inject(IOCIdentifier.AppConfig) appConfig: AppConfig,
|
|
45
43
|
@inject(IOCIdentifier.LocalStorageEncrypt)
|
|
46
44
|
storage: SyncStorageInterface<string, string>
|
|
@@ -1,104 +1,94 @@
|
|
|
1
1
|
// ! dont't import tsx, only ts file
|
|
2
|
-
import {
|
|
3
|
-
ApiMockPlugin,
|
|
4
|
-
EnvConfigInterface,
|
|
5
|
-
RequestCommonPlugin,
|
|
6
|
-
ApiCatchPlugin,
|
|
7
|
-
IOCContainerInterface,
|
|
8
|
-
createIOCFunction,
|
|
9
|
-
ServiceIdentifier,
|
|
10
|
-
TokenStorage,
|
|
11
|
-
CookieStorage
|
|
12
|
-
} from '@qlover/corekit-bridge';
|
|
13
|
-
import type { JSONSerializer, ObjectStorage } from '@qlover/fe-corekit';
|
|
14
|
-
import type { LoggerInterface } from '@qlover/logger';
|
|
15
2
|
import type { AppConfig } from '@/base/cases/AppConfig';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
3
|
+
import type { IOCRegisterInterface } from '@qlover/corekit-bridge';
|
|
4
|
+
import { createIOCFunction } from '@qlover/corekit-bridge';
|
|
5
|
+
import { InversifyContainer } from '@/base/cases/InversifyContainer';
|
|
6
|
+
import { IOCIdentifier } from '@config/IOCIdentifier';
|
|
19
7
|
|
|
8
|
+
/**
|
|
9
|
+
* IOC identifier map
|
|
10
|
+
*
|
|
11
|
+
* Define the implementation class corresponding to the string identifier
|
|
12
|
+
*/
|
|
13
|
+
export interface IOCIdentifierMap {
|
|
14
|
+
[IOCIdentifier.JSON]: import('@qlover/fe-corekit').JSONSerializer;
|
|
15
|
+
[IOCIdentifier.LocalStorage]: import('@qlover/fe-corekit').ObjectStorage<
|
|
16
|
+
string,
|
|
17
|
+
string
|
|
18
|
+
>;
|
|
19
|
+
[IOCIdentifier.LocalStorageEncrypt]: import('@qlover/fe-corekit').ObjectStorage<
|
|
20
|
+
string,
|
|
21
|
+
string
|
|
22
|
+
>;
|
|
23
|
+
[IOCIdentifier.CookieStorage]: import('@qlover/corekit-bridge').CookieStorage;
|
|
24
|
+
[IOCIdentifier.Logger]: import('@qlover/logger').LoggerInterface;
|
|
25
|
+
[IOCIdentifier.FeApiToken]: import('@qlover/corekit-bridge').TokenStorage<string>;
|
|
26
|
+
[IOCIdentifier.FeApiCommonPlugin]: import('@qlover/corekit-bridge').RequestCommonPlugin;
|
|
27
|
+
[IOCIdentifier.AppConfig]: import('@qlover/corekit-bridge').EnvConfigInterface;
|
|
28
|
+
[IOCIdentifier.ApiMockPlugin]: import('@qlover/corekit-bridge').ApiMockPlugin;
|
|
29
|
+
[IOCIdentifier.ApiCatchPlugin]: import('@qlover/corekit-bridge').ApiCatchPlugin;
|
|
30
|
+
[IOCIdentifier.DialogHandler]: import('@/base/cases/DialogHandler').DialogHandler;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* IOC register options
|
|
35
|
+
*/
|
|
20
36
|
export type IocRegisterOptions = {
|
|
37
|
+
/**
|
|
38
|
+
* The pathname of the current page
|
|
39
|
+
*/
|
|
21
40
|
pathname: string;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The app config
|
|
44
|
+
*/
|
|
22
45
|
appConfig: AppConfig;
|
|
23
46
|
};
|
|
24
47
|
|
|
25
|
-
export type InversifyRegisterContainer = Container;
|
|
26
48
|
/**
|
|
27
|
-
*
|
|
49
|
+
* IOC container
|
|
50
|
+
*
|
|
51
|
+
* This is a alias of IOCContainerInterface, use it without care about the implementation.
|
|
52
|
+
*
|
|
53
|
+
* Need to achieve the effect: when the implementation class on the right side of the equal sign changes, the IOCContainer will change automatically
|
|
28
54
|
*/
|
|
29
|
-
export
|
|
30
|
-
extends IOCRegisterInterface<InversifyContainer, IocRegisterOptions> {}
|
|
31
|
-
|
|
32
|
-
export class InversifyContainer implements IOCContainerInterface {
|
|
33
|
-
private container: Container;
|
|
34
|
-
|
|
35
|
-
constructor() {
|
|
36
|
-
this.container = new Container({
|
|
37
|
-
// allow `@injectable` decorator, auto bind injectable classes
|
|
38
|
-
autobind: true,
|
|
39
|
-
// use singleton scope
|
|
40
|
-
defaultScope: 'Singleton'
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
bind<T>(key: ServiceIdentifier<T>, value: T): void {
|
|
45
|
-
this.container.bind<T>(key).toConstantValue(value);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
get<K extends keyof IOCIdentifierMap>(
|
|
49
|
-
serviceIdentifier: K
|
|
50
|
-
): IOCIdentifierMap[K];
|
|
51
|
-
get<T>(serviceIdentifier: ServiceIdentifier<T>): T;
|
|
52
|
-
get<T, K extends keyof IOCIdentifierMap>(
|
|
53
|
-
serviceIdentifier: ServiceIdentifier<T> | K
|
|
54
|
-
): T | IOCIdentifierMap[K] {
|
|
55
|
-
return this.container.get<T>(serviceIdentifier);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
55
|
+
export type IOCContainer = InversifyContainer;
|
|
58
56
|
|
|
59
57
|
/**
|
|
60
|
-
* IOC
|
|
58
|
+
* IOC register interface.
|
|
61
59
|
*
|
|
62
|
-
*
|
|
63
|
-
* IOC identifier is used to identify the service in the IOC container.
|
|
60
|
+
* This is shortcut interface, implement this interface, you can use any IOC container.
|
|
64
61
|
*
|
|
65
|
-
*
|
|
66
|
-
* ```ts
|
|
67
|
-
* const a = IOC(IOCIdentifier.JSON);
|
|
68
|
-
* const b = IOC('JSON');
|
|
69
|
-
* ```
|
|
62
|
+
* Need to achieve the effect: when the implementation class on the right side of the equal sign changes, the IOCContainer will change automatically
|
|
70
63
|
*/
|
|
71
|
-
export
|
|
72
|
-
|
|
73
|
-
LocalStorage: 'LocalStorage',
|
|
74
|
-
LocalStorageEncrypt: 'LocalStorageEncrypt',
|
|
75
|
-
CookieStorage: 'CookieStorage',
|
|
76
|
-
Logger: 'Logger',
|
|
77
|
-
FeApiToken: 'FeApiToken',
|
|
78
|
-
FeApiCommonPlugin: 'FeApiCommonPlugin',
|
|
79
|
-
AppConfig: 'AppConfig',
|
|
80
|
-
ApiMockPlugin: 'ApiMockPlugin',
|
|
81
|
-
ApiCatchPlugin: 'ApiCatchPlugin',
|
|
82
|
-
DialogHandler: 'DialogHandler'
|
|
83
|
-
});
|
|
64
|
+
export interface IOCRegister
|
|
65
|
+
extends IOCRegisterInterface<IOCContainer, IocRegisterOptions> {}
|
|
84
66
|
|
|
85
67
|
/**
|
|
86
|
-
* IOC
|
|
68
|
+
* IOC function
|
|
69
|
+
*
|
|
70
|
+
* This is the only and main exported content of the file
|
|
71
|
+
*
|
|
72
|
+
* @example use A class
|
|
73
|
+
* ```ts
|
|
74
|
+
* const userService = IOC(UserService);
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example use A string identifier
|
|
78
|
+
*
|
|
79
|
+
* string identifier is shortcut for `IOCIdentifierMap` type, string key of `IOCIdentifier`
|
|
80
|
+
*
|
|
81
|
+
* ```ts
|
|
82
|
+
* const logger = IOC('Logger'); // Logger instance
|
|
83
|
+
*
|
|
84
|
+
* // or
|
|
85
|
+
* const logger = IOC(IOCIdentifier.Logger);
|
|
86
|
+
* ```
|
|
87
87
|
*/
|
|
88
|
-
export interface IOCIdentifierMap {
|
|
89
|
-
[IOCIdentifier.JSON]: JSONSerializer;
|
|
90
|
-
[IOCIdentifier.LocalStorage]: ObjectStorage<string, string>;
|
|
91
|
-
[IOCIdentifier.LocalStorageEncrypt]: ObjectStorage<string, string>;
|
|
92
|
-
[IOCIdentifier.CookieStorage]: CookieStorage;
|
|
93
|
-
[IOCIdentifier.Logger]: LoggerInterface;
|
|
94
|
-
[IOCIdentifier.FeApiToken]: TokenStorage<string>;
|
|
95
|
-
[IOCIdentifier.FeApiCommonPlugin]: RequestCommonPlugin;
|
|
96
|
-
[IOCIdentifier.AppConfig]: EnvConfigInterface;
|
|
97
|
-
[IOCIdentifier.ApiMockPlugin]: ApiMockPlugin;
|
|
98
|
-
[IOCIdentifier.ApiCatchPlugin]: ApiCatchPlugin;
|
|
99
|
-
[IOCIdentifier.DialogHandler]: DialogHandler;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
88
|
export const IOC = createIOCFunction<IOCIdentifierMap>(
|
|
89
|
+
/**
|
|
90
|
+
* If not inversify, you can use any IOC container,
|
|
91
|
+
* then replace the InversifyContainer with your own IOC container
|
|
92
|
+
*/
|
|
103
93
|
new InversifyContainer()
|
|
104
94
|
);
|
|
@@ -1,7 +1,55 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Bootstrap } from '@qlover/corekit-bridge';
|
|
2
|
+
import { envBlackList, envPrefix, browserGlobalsName } from '@config/common';
|
|
3
|
+
import { IOC } from '../IOC';
|
|
4
|
+
import * as globals from '../globals';
|
|
5
|
+
import { GLOBAL_NO_WINDOW } from '@config/Identifier/common.error';
|
|
6
|
+
import { IocRegisterImpl } from '../registers/IocRegisterImpl';
|
|
7
|
+
import { BootstrapsRegistry } from './BootstrapsRegistry';
|
|
2
8
|
|
|
3
|
-
export class BootstrapApp
|
|
4
|
-
|
|
9
|
+
export class BootstrapApp {
|
|
10
|
+
static async main(): Promise<void> {
|
|
11
|
+
const root = window;
|
|
5
12
|
|
|
6
|
-
|
|
13
|
+
if (!(typeof root !== 'undefined' && root instanceof Window)) {
|
|
14
|
+
throw new Error(GLOBAL_NO_WINDOW);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { logger, appConfig } = globals;
|
|
18
|
+
const { pathname } = root.location;
|
|
19
|
+
|
|
20
|
+
const bootstrap = new Bootstrap({
|
|
21
|
+
root,
|
|
22
|
+
logger,
|
|
23
|
+
ioc: {
|
|
24
|
+
manager: IOC,
|
|
25
|
+
register: new IocRegisterImpl({ pathname, appConfig })
|
|
26
|
+
},
|
|
27
|
+
envOptions: {
|
|
28
|
+
target: appConfig,
|
|
29
|
+
source: {
|
|
30
|
+
...import.meta.env,
|
|
31
|
+
[envPrefix + 'BOOT_HREF']: root.location.href
|
|
32
|
+
},
|
|
33
|
+
prefix: envPrefix,
|
|
34
|
+
blackList: envBlackList
|
|
35
|
+
},
|
|
36
|
+
globalOptions: {
|
|
37
|
+
sources: globals,
|
|
38
|
+
target: browserGlobalsName
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
logger.info('bootstrap start...');
|
|
44
|
+
|
|
45
|
+
// init bootstrap
|
|
46
|
+
await bootstrap.initialize();
|
|
47
|
+
|
|
48
|
+
const bootstrapsRegistry = new BootstrapsRegistry(IOC);
|
|
49
|
+
|
|
50
|
+
await bootstrap.use(bootstrapsRegistry.register()).start();
|
|
51
|
+
} catch (error) {
|
|
52
|
+
logger.error(`${appConfig.appName} starup error:`, error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
7
55
|
}
|
|
@@ -4,14 +4,14 @@ import type {
|
|
|
4
4
|
IOCContainerInterface,
|
|
5
5
|
IOCFunctionInterface
|
|
6
6
|
} from '@qlover/corekit-bridge';
|
|
7
|
-
import { BootstrapApp } from './BootstrapApp';
|
|
8
7
|
import { UserApiBootstarp } from '@/base/apis/userApi/UserApiBootstarp';
|
|
9
8
|
import { FeApiBootstarp } from '@/base/apis/feApi/FeApiBootstarp';
|
|
10
9
|
import { AiApiBootstarp } from '@/base/apis/AiApi';
|
|
11
10
|
import { printBootstrap } from './PrintBootstrap';
|
|
12
|
-
import { IOCIdentifier
|
|
11
|
+
import { IOCIdentifier } from '@config/IOCIdentifier';
|
|
13
12
|
import { I18nService } from '@/base/services/I18nService';
|
|
14
13
|
import { I18nKeyErrorPlugin } from '@/base/cases/I18nKeyErrorPlugin';
|
|
14
|
+
import { IOCIdentifierMap } from '../IOC';
|
|
15
15
|
|
|
16
16
|
export class BootstrapsRegistry {
|
|
17
17
|
constructor(
|
|
@@ -30,7 +30,6 @@ export class BootstrapsRegistry {
|
|
|
30
30
|
new UserApiBootstarp(),
|
|
31
31
|
new FeApiBootstarp(),
|
|
32
32
|
AiApiBootstarp,
|
|
33
|
-
new BootstrapApp(),
|
|
34
33
|
IOC(I18nKeyErrorPlugin)
|
|
35
34
|
];
|
|
36
35
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IOCContainer, IOCRegister, IocRegisterOptions } from '../IOC';
|
|
2
|
+
import type { IOCManagerInterface } from '@qlover/corekit-bridge';
|
|
3
|
+
import { RegisterGlobals } from './RegisterGlobals';
|
|
4
|
+
import { RegisterCommon } from './RegisterCommon';
|
|
5
|
+
import { RegisterControllers } from './RegisterControllers';
|
|
6
|
+
|
|
7
|
+
export class IocRegisterImpl implements IOCRegister {
|
|
8
|
+
constructor(protected options: IocRegisterOptions) {}
|
|
9
|
+
|
|
10
|
+
getRegisterList(): IOCRegister[] {
|
|
11
|
+
return [RegisterGlobals, RegisterCommon, new RegisterControllers()];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @override
|
|
16
|
+
*/
|
|
17
|
+
register(
|
|
18
|
+
ioc: IOCContainer,
|
|
19
|
+
manager: IOCManagerInterface<IOCContainer>
|
|
20
|
+
): void {
|
|
21
|
+
this.getRegisterList().forEach((Register) => {
|
|
22
|
+
Register.register(ioc, manager, this.options);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import { FetchAbortPlugin } from '@qlover/fe-corekit';
|
|
2
|
-
import { Logger } from '@qlover/logger';
|
|
3
1
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from '@/core/IOC';
|
|
2
|
+
FetchAbortPlugin,
|
|
3
|
+
type SyncStorageInterface
|
|
4
|
+
} from '@qlover/fe-corekit';
|
|
5
|
+
import { Logger } from '@qlover/logger';
|
|
9
6
|
import {
|
|
10
7
|
RequestCommonPlugin,
|
|
11
8
|
ApiMockPlugin,
|
|
12
9
|
ApiCatchPlugin,
|
|
13
10
|
ThemeService,
|
|
14
|
-
IOCManagerInterface,
|
|
15
11
|
TokenStorage
|
|
16
12
|
} from '@qlover/corekit-bridge';
|
|
17
13
|
import mockDataJson from '@config/feapi.mock.json';
|
|
@@ -22,13 +18,11 @@ import { I18nService } from '@/base/services/I18nService';
|
|
|
22
18
|
import { RouteService } from '@/base/services/RouteService';
|
|
23
19
|
import { baseRoutes } from '@config/app.router';
|
|
24
20
|
import { UserService } from '@/base/services/UserService';
|
|
21
|
+
import { IOCRegister } from '../IOC';
|
|
22
|
+
import { IOCIdentifier } from '@config/IOCIdentifier';
|
|
25
23
|
|
|
26
|
-
export
|
|
27
|
-
register(
|
|
28
|
-
container: InversifyContainer,
|
|
29
|
-
_: IOCManagerInterface<InversifyContainer>,
|
|
30
|
-
options: IocRegisterOptions
|
|
31
|
-
): void {
|
|
24
|
+
export const RegisterCommon: IOCRegister = {
|
|
25
|
+
register(container, _, options): void {
|
|
32
26
|
const AppConfig = container.get(IOCIdentifier.AppConfig);
|
|
33
27
|
|
|
34
28
|
const feApiToken = new TokenStorage(AppConfig.userTokenStorageKey, {
|
|
@@ -61,7 +55,7 @@ export class RegisterCommon implements InversifyRegisterInterface {
|
|
|
61
55
|
ThemeService,
|
|
62
56
|
new ThemeService({
|
|
63
57
|
...themeConfig,
|
|
64
|
-
storage: localStorage
|
|
58
|
+
storage: localStorage as SyncStorageInterface<string, string>
|
|
65
59
|
})
|
|
66
60
|
);
|
|
67
61
|
|
|
@@ -73,6 +67,6 @@ export class RegisterCommon implements InversifyRegisterInterface {
|
|
|
73
67
|
})
|
|
74
68
|
);
|
|
75
69
|
|
|
76
|
-
container.bind(I18nService, new I18nService(options
|
|
70
|
+
container.bind(I18nService, new I18nService(options!.pathname));
|
|
77
71
|
}
|
|
78
|
-
}
|
|
72
|
+
};
|
|
@@ -2,12 +2,18 @@ import { localStorage } from '../globals';
|
|
|
2
2
|
import { JSONStorageController } from '@/uikit/controllers/JSONStorageController';
|
|
3
3
|
import { ProcesserExecutor } from '@/base/services/ProcesserExecutor';
|
|
4
4
|
import { UserService } from '@/base/services/UserService';
|
|
5
|
-
import { InversifyRegisterInterface } from '../IOC';
|
|
6
|
-
import { InversifyContainer } from '../IOC';
|
|
7
5
|
import { I18nKeyErrorPlugin } from '@/base/cases/I18nKeyErrorPlugin';
|
|
6
|
+
import { IOCContainer, IOCRegister } from '../IOC';
|
|
7
|
+
import { IOCManagerInterface } from '@qlover/corekit-bridge';
|
|
8
8
|
|
|
9
|
-
export class RegisterControllers implements
|
|
10
|
-
|
|
9
|
+
export class RegisterControllers implements IOCRegister {
|
|
10
|
+
/**
|
|
11
|
+
* @override
|
|
12
|
+
*/
|
|
13
|
+
register(
|
|
14
|
+
container: IOCContainer,
|
|
15
|
+
_: IOCManagerInterface<IOCContainer>
|
|
16
|
+
): void {
|
|
11
17
|
const jsonStorageController = new JSONStorageController(localStorage);
|
|
12
18
|
|
|
13
19
|
container.bind(JSONStorageController, jsonStorageController);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { JSONSerializer } from '@qlover/fe-corekit';
|
|
2
|
-
import type { IOCManagerInterface } from '@qlover/corekit-bridge';
|
|
3
2
|
import {
|
|
4
3
|
cookieStorage,
|
|
5
4
|
dialogHandler,
|
|
@@ -8,22 +7,14 @@ import {
|
|
|
8
7
|
localStorageEncrypt,
|
|
9
8
|
logger
|
|
10
9
|
} from '../globals';
|
|
11
|
-
import {
|
|
12
|
-
type InversifyContainer,
|
|
13
|
-
type InversifyRegisterInterface,
|
|
14
|
-
IOCIdentifier,
|
|
15
|
-
IocRegisterOptions
|
|
16
|
-
} from '@/core/IOC';
|
|
10
|
+
import { IOCRegister } from '@/core/IOC';
|
|
17
11
|
import { Logger } from '@qlover/logger';
|
|
12
|
+
import { IOCIdentifier } from '@config/IOCIdentifier';
|
|
18
13
|
|
|
19
|
-
export
|
|
20
|
-
register(
|
|
21
|
-
container: InversifyContainer,
|
|
22
|
-
_: IOCManagerInterface<InversifyContainer>,
|
|
23
|
-
options: IocRegisterOptions
|
|
24
|
-
): void {
|
|
14
|
+
export const RegisterGlobals: IOCRegister = {
|
|
15
|
+
register(container, _, options): void {
|
|
25
16
|
// inject AppConfig to IOC
|
|
26
|
-
container.bind(IOCIdentifier.AppConfig, options
|
|
17
|
+
container.bind(IOCIdentifier.AppConfig, options!.appConfig);
|
|
27
18
|
container.bind(IOCIdentifier.DialogHandler, dialogHandler);
|
|
28
19
|
|
|
29
20
|
container.bind(JSONSerializer, JSON);
|
|
@@ -36,4 +27,4 @@ export class RegisterGlobals implements InversifyRegisterInterface {
|
|
|
36
27
|
container.bind(IOCIdentifier.LocalStorageEncrypt, localStorageEncrypt);
|
|
37
28
|
container.bind(IOCIdentifier.CookieStorage, cookieStorage);
|
|
38
29
|
}
|
|
39
|
-
}
|
|
30
|
+
};
|
|
@@ -3,12 +3,9 @@ import 'reflect-metadata';
|
|
|
3
3
|
import { StrictMode } from 'react';
|
|
4
4
|
import { createRoot } from 'react-dom/client';
|
|
5
5
|
import App from './App.tsx';
|
|
6
|
-
import
|
|
6
|
+
import { BootstrapApp } from './core/bootstraps/BootstrapApp';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
root: window,
|
|
10
|
-
envSource: import.meta.env
|
|
11
|
-
});
|
|
8
|
+
BootstrapApp.main();
|
|
12
9
|
|
|
13
10
|
createRoot(document.getElementById('root')!).render(
|
|
14
11
|
<StrictMode>
|
|
@@ -17,7 +17,7 @@ export class JSONStorageController extends StoreInterface<JSONStoragePageState>
|
|
|
17
17
|
requestTimeout: (state: JSONStoragePageState) => state.requestTimeout
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
constructor(private storage: SyncStorageInterface<string,
|
|
20
|
+
constructor(private storage: SyncStorageInterface<string, unknown>) {
|
|
21
21
|
super(() => ({
|
|
22
22
|
testKey1: storage.getItem('testKey1') ?? 0,
|
|
23
23
|
testKey2: storage.getItem('testKey2') ?? 0,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from './config/common';
|
|
9
9
|
import { name, version } from './package.json';
|
|
10
10
|
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
11
|
-
import envConfig from '@qlover/corekit-bridge/vite-env-config
|
|
11
|
+
import envConfig from '@qlover/corekit-bridge/vite-env-config';
|
|
12
12
|
import ts2Locales from '@brain-toolkit/ts2locales/vite';
|
|
13
13
|
import i18nConfig from './config/i18n';
|
|
14
14
|
import tailwindcss from '@tailwindcss/vite';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qlover/create-app",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Create a new app with a single command",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"commander": "^13.1.0",
|
|
40
40
|
"inquirer": "^12.3.2",
|
|
41
|
-
"@qlover/scripts-context": "0.
|
|
41
|
+
"@qlover/scripts-context": "1.0.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsup",
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Bootstrap } from '@qlover/corekit-bridge';
|
|
2
|
-
import { envBlackList, envPrefix, browserGlobalsName } from '@config/common';
|
|
3
|
-
import { IOC } from './IOC';
|
|
4
|
-
import * as globals from '@/core/globals';
|
|
5
|
-
import { IocRegister } from './registers';
|
|
6
|
-
import { BootstrapsRegistry } from './bootstraps';
|
|
7
|
-
import { GLOBAL_NO_WINDOW } from '@config/Identifier/common.error';
|
|
8
|
-
|
|
9
|
-
export default async function startup({
|
|
10
|
-
root,
|
|
11
|
-
envSource
|
|
12
|
-
}: {
|
|
13
|
-
root: unknown;
|
|
14
|
-
envSource: Record<string, unknown>;
|
|
15
|
-
}) {
|
|
16
|
-
if (!(typeof root !== 'undefined' && root instanceof Window)) {
|
|
17
|
-
throw new Error(GLOBAL_NO_WINDOW);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const { logger, appConfig } = globals;
|
|
21
|
-
|
|
22
|
-
const iocRegister = new IocRegister({
|
|
23
|
-
pathname: root.location.pathname,
|
|
24
|
-
appConfig
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const bootstrap = new Bootstrap({
|
|
28
|
-
root,
|
|
29
|
-
logger,
|
|
30
|
-
ioc: {
|
|
31
|
-
manager: IOC,
|
|
32
|
-
register: iocRegister
|
|
33
|
-
},
|
|
34
|
-
envOptions: {
|
|
35
|
-
target: appConfig,
|
|
36
|
-
source: { ...envSource, [envPrefix + 'BOOT_HREF']: root.location.href },
|
|
37
|
-
prefix: envPrefix,
|
|
38
|
-
blackList: envBlackList
|
|
39
|
-
},
|
|
40
|
-
globalOptions: {
|
|
41
|
-
sources: globals,
|
|
42
|
-
target: browserGlobalsName
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
logger.info('bootstrap start...');
|
|
48
|
-
|
|
49
|
-
// init bootstrap
|
|
50
|
-
await bootstrap.initialize();
|
|
51
|
-
|
|
52
|
-
const bootstrapsRegistry = new BootstrapsRegistry(IOC);
|
|
53
|
-
|
|
54
|
-
await bootstrap.use(bootstrapsRegistry.register()).start();
|
|
55
|
-
} catch (error) {
|
|
56
|
-
logger.error(`${appConfig.appName} starup error:`, error);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { RegisterGlobals } from './RegisterGlobals';
|
|
2
|
-
import { RegisterCommon } from './RegisterCommon';
|
|
3
|
-
import { RegisterApi } from './RegisterApi';
|
|
4
|
-
import { RegisterControllers } from './RegisterControllers';
|
|
5
|
-
import {
|
|
6
|
-
InversifyContainer,
|
|
7
|
-
InversifyRegisterInterface,
|
|
8
|
-
IocRegisterOptions
|
|
9
|
-
} from '../IOC';
|
|
10
|
-
import { IOCManagerInterface } from '@qlover/corekit-bridge';
|
|
11
|
-
|
|
12
|
-
export class IocRegister implements InversifyRegisterInterface {
|
|
13
|
-
constructor(protected options: IocRegisterOptions) {}
|
|
14
|
-
|
|
15
|
-
getRegisterList(): InversifyRegisterInterface[] {
|
|
16
|
-
return [
|
|
17
|
-
new RegisterGlobals(),
|
|
18
|
-
new RegisterCommon(),
|
|
19
|
-
new RegisterApi(),
|
|
20
|
-
new RegisterControllers()
|
|
21
|
-
];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
register(
|
|
25
|
-
ioc: InversifyContainer,
|
|
26
|
-
manager: IOCManagerInterface<InversifyContainer>
|
|
27
|
-
): void {
|
|
28
|
-
this.getRegisterList().forEach((register) => {
|
|
29
|
-
register.register(ioc, manager, this.options);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|