mirror of
https://github.com/motajs/template.git
synced 2026-11-23 22:14:30 +08:00
fix: 注释与实现错位问题
This commit is contained in:
1 parent
29c91c10d5
commit
c5b0a255ba
8 files changed
+45
-21
No files matched your search
@@ -7,23 +7,38 @@ export class PrefixedJSONCProcessor<T> implements ILoadTaskProcessor<
|
||||
> {
|
||||
constructor(readonly prefixSplit: string) {}
|
||||
|
||||
process(
|
||||
response: string,
|
||||
/**
|
||||
* 反序列化并输出
|
||||
* @param str JSON 字符串内容
|
||||
* @param task 加载任务对象
|
||||
*/
|
||||
private output(
|
||||
str: string,
|
||||
task: ILoadTask<LoadDataType.Text, T>
|
||||
): Promise<T> {
|
||||
const splitted = response.split(this.prefixSplit);
|
||||
if (splitted.length !== 2) {
|
||||
logger.error(66, task.url, this.prefixSplit);
|
||||
return Promise.resolve({} as T);
|
||||
}
|
||||
|
||||
const raw = splitted[1];
|
||||
try {
|
||||
const obj = JSON.parse(raw);
|
||||
const obj = JSON.parse(str);
|
||||
return Promise.resolve(obj as T);
|
||||
} catch (e) {
|
||||
logger.error(67, task.url, String(e));
|
||||
return Promise.resolve({} as T);
|
||||
}
|
||||
}
|
||||
|
||||
process(
|
||||
response: string,
|
||||
task: ILoadTask<LoadDataType.Text, T>
|
||||
): Promise<T> {
|
||||
const splitted = response.split(this.prefixSplit);
|
||||
if (splitted.length === 1) {
|
||||
return this.output(response, task);
|
||||
}
|
||||
|
||||
if (splitted.length !== 2) {
|
||||
logger.error(66, task.url, this.prefixSplit);
|
||||
return Promise.resolve({} as T);
|
||||
}
|
||||
|
||||
return this.output(splitted[1], task);
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,7 @@ export class MotaDataLoader
|
||||
|
||||
async *start(): AsyncIterable<number> {
|
||||
if (this.loading || this.dataLoaded) return;
|
||||
this.loading = true;
|
||||
|
||||
// 首先加载核心配置
|
||||
const processor = new PrefixedJSONCProcessor<ICoreStateCoreConfig>(
|
||||
@@ -100,14 +101,21 @@ export class MotaDataLoader
|
||||
coreTask.setProcessor(processor);
|
||||
coreTask.setStarter(this.starter);
|
||||
this.manager.addTask(coreTask);
|
||||
coreTask.loaded().then(obj => {
|
||||
if (this.configMap.has(id)) {
|
||||
logger.error(68, id);
|
||||
return;
|
||||
}
|
||||
this.configMap.set(id, obj);
|
||||
});
|
||||
}
|
||||
yield* this.manager.load();
|
||||
|
||||
// 然后加载其他配置文件
|
||||
await Promise.all(
|
||||
this.forEachHook(hook => hook.onCoreConfigLoaded?.(this))
|
||||
);
|
||||
|
||||
// 然后加载其他配置文件
|
||||
for (const [id, url] of this.extraConfigs) {
|
||||
const task = new LoadTask({
|
||||
identifier: id,
|
||||
@@ -138,6 +146,7 @@ export class MotaDataLoader
|
||||
|
||||
yield* this.manager.load();
|
||||
|
||||
this.dataLoaded = true;
|
||||
this.loadResolve();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ export interface IMotaDataLoader extends IHookable<IMotaDataLoaderHooks> {
|
||||
|
||||
/**
|
||||
* 添加核心配置文件,仅允许在加载前调用,之后调用无效。
|
||||
* 文件必须放在 `src/content` 下,并填写相对于 `src/content` 文件夹的路径,文件包含如下要求:
|
||||
* 文件必须放在 `src` 下,并填写相对于 `src` 文件夹的路径,文件包含如下要求:
|
||||
*
|
||||
* - 文件必须为 `jsonc` 格式
|
||||
* - 文件的注释必须全部集中在开头
|
||||
@@ -45,7 +45,7 @@ export interface IMotaDataLoader extends IHookable<IMotaDataLoaderHooks> {
|
||||
|
||||
/**
|
||||
* 添加额外配置文件,仅允许在 `onCoreConfigLoaded` 中调用或在加载前调用,加载中及加载后后调用无效。
|
||||
* 文件必须放在 `src/content` 下,并填写相对于 `src/content` 文件夹的路径,文件包含如下要求:
|
||||
* 文件必须放在 `src` 下,并填写相对于 `src` 文件夹的路径,文件包含如下要求:
|
||||
*
|
||||
* - 文件必须为 `jsonc` 格式
|
||||
* - 文件的注释必须全部集中在开头
|
||||
|
||||
Reference in new issue
Block a user