Skip to content

Commit

Permalink
refactor: 切换为单项目-拆分部分类库,减小打包体积
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 20, 2023
1 parent 57297ab commit ee2e562
Show file tree
Hide file tree
Showing 10 changed files with 4,509 additions and 13,391 deletions.
18 changes: 9 additions & 9 deletions public/libs/zhi-publisher-sdk/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var r = Object.defineProperty;
var g = (i, t, s) => t in i ? r(i, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : i[t] = s;
var n = (i, t, s) => (g(i, typeof t != "symbol" ? t + "" : t, s), s);
(function(i, t) {
!i || i.getElementById("livereloadscript") || (t = i.createElement("script"), t.async = 1, t.src = "//" + (self.location.host || "localhost").split(":")[0] + ":35730/livereload.js?snipver=1", t.id = "livereloadscript", i.getElementsByTagName("head")[0].appendChild(t));
var g = (n, t, s) => t in n ? r(n, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[t] = s;
var i = (n, t, s) => (g(n, typeof t != "symbol" ? t + "" : t, s), s);
(function(n, t) {
!n || n.getElementById("livereloadscript") || (t = n.createElement("script"), t.async = 1, t.src = "//" + (self.location.host || "localhost").split(":")[0] + ":35729/livereload.js?snipver=1", t.id = "livereloadscript", n.getElementsByTagName("head")[0].appendChild(t));
})(self.document);
class a {
static init(t) {
this.Env = t.Env, this.BlogConstants = t.BlogConstants, this.BlogTypeEnum = t.BlogTypeEnum, this.SiyuanConstants = t.SiyuanConstants, this.SiyuanConfig = t.SiyuanConfig, this.SiYuanApiAdaptor = t.SiYuanApiAdaptor, this.BlogApi = t.BlogApi;
this.appInstance = t.appInstance, this.Env = t.Env, this.BlogConstants = t.BlogConstants, this.BlogTypeEnum = t.BlogTypeEnum, this.SiyuanConstants = t.SiyuanConstants, this.SiyuanConfig = t.SiyuanConfig, this.SiYuanApiAdaptor = t.SiYuanApiAdaptor, this.BlogApi = t.BlogApi;
}
/**
* 获取 siyuan-kernel-api 实例
Expand All @@ -23,10 +23,10 @@ class a {
break;
default: {
if (t instanceof this.Env) {
const p = t.getEnvOrDefault(this.SiyuanConstants.VITE_SIYUAN_API_URL_KEY, "http://127.0.0.1:6806"), c = t.getStringEnv(this.SiyuanConstants.VITE_SIYUAN_AUTH_TOKEN_KEY), l = new this.SiyuanConfig(p, c);
l.fixTitle = !0, e = new this.SiYuanApiAdaptor(l);
const c = t.getEnvOrDefault(this.SiyuanConstants.VITE_SIYUAN_API_URL_KEY, "http://127.0.0.1:6806"), l = t.getStringEnv(this.SiyuanConstants.VITE_SIYUAN_AUTH_TOKEN_KEY), p = new this.SiyuanConfig(c, l);
p.fixTitle = !0, e = new this.SiYuanApiAdaptor(p);
} else
e = new this.SiYuanApiAdaptor(s);
e = new this.SiYuanApiAdaptor(s), e.init(this.appInstance);
break;
}
}
Expand All @@ -41,7 +41,7 @@ class a {
* BlogApi
* @private
*/
n(a, "bApi"), n(a, "Env"), n(a, "BlogConstants"), n(a, "BlogTypeEnum"), n(a, "SiyuanConstants"), n(a, "SiyuanConfig"), n(a, "SiYuanApiAdaptor"), n(a, "BlogApi");
i(a, "appInstance"), i(a, "bApi"), i(a, "Env"), i(a, "BlogConstants"), i(a, "BlogTypeEnum"), i(a, "SiyuanConstants"), i(a, "SiyuanConfig"), i(a, "SiYuanApiAdaptor"), i(a, "BlogApi");
export {
a as PublishSdk
};
2 changes: 2 additions & 0 deletions public/libs/zhi-publisher-sdk/publish-sdk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare class PublishSdk {
* BlogApi
* @private
*/
private static appInstance;
private static bApi;
private static Env;
private static BlogConstants;
Expand All @@ -19,6 +20,7 @@ declare class PublishSdk {
private static SiYuanApiAdaptor;
private static BlogApi;
static init(options: {
appInstance: any;
Env: any;
BlogConstants: any;
BlogTypeEnum: any;
Expand Down
17,779 changes: 4,432 additions & 13,347 deletions public/libs/zhi-siyuan-api/index.js

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions public/libs/zhi-siyuan-api/lib/ZhiSiyuanApiUtil.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
import { Env } from "zhi-env";
import { ZhiUtil } from "zhi-common";
/**
* 工具类统一入口,每个应用自己实现
*
* @public
* @author terwer
* @since 1.0.0
*/
declare class ZhiSiyuanApiUtil extends ZhiUtil {
static zhiEnv(): Env;
declare class ZhiSiyuanApiUtil {
private static env;
/**
* 通用环境变量
*
* @param appInstance - 插件实例
*/
static zhiEnv(appInstance: any): any;
/**
* 通用日志
*
* @param appInstance - 应用实例
* @param loggerName - 日志名称
*/
static zhiLog(appInstance: any, loggerName: string): any;
/**
* 通用工具入口
*
* @param appInstance - 应用实例
*/
static zhiCommon(appInstance: any): any;
}
export default ZhiSiyuanApiUtil;
5 changes: 3 additions & 2 deletions public/libs/zhi-siyuan-api/lib/siYuanApiAdaptor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import SiyuanConfig from "./siyuanConfig";
* @since 1.0.0
*/
declare class SiYuanApiAdaptor implements IBlogApi {
private readonly logger;
private readonly common;
private logger;
private common;
private readonly siyuanKernelApi;
private readonly cfg;
/**
Expand All @@ -19,6 +19,7 @@ declare class SiYuanApiAdaptor implements IBlogApi {
* @param cfg - 环境变量 或者 配置项
*/
constructor(cfg: Env | SiyuanConfig);
init(appInstance: any): void;
deletePost(postid: string): Promise<boolean>;
editPost(postid: string, post: Post, publish?: boolean): Promise<boolean>;
getCategories(): Promise<CategoryInfo[]>;
Expand Down
7 changes: 4 additions & 3 deletions public/libs/zhi-siyuan-api/lib/siyuanKernelApi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ declare class SiyuanKernelApi implements ISiyuanKernelApi {
* 思源笔记服务端API版本号
*/
readonly VERSION: string;
private readonly logger;
private readonly env;
private readonly common;
private logger;
private env;
private common;
readonly siyuanConfig: SiyuanConfig;
/**
* 初始化思源服务端 API
*
* @param cfg - 环境变量 或者 配置项
*/
constructor(cfg: Env | SiyuanConfig);
init(appInstance: any): void;
/**
* 分页获取根文档
*
Expand Down
1 change: 0 additions & 1 deletion public/libs/zhi-siyuan-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"dependencies": {
"zhi-env": "workspace:*",
"zhi-log": "workspace:*",
"zhi-common": "workspace:*",
"zhi-blog-api": "workspace:*"
}
}
30 changes: 5 additions & 25 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Plugin } from "siyuan"
import "./index.styl"
import { initLibs } from "~/src/loader"
import { Utils } from "~/src/utils/utils"
import { initTools } from "~/src/tools"

export default class PublisherPlugin extends Plugin {
public fs
Expand All @@ -26,7 +26,7 @@ export default class PublisherPlugin extends Plugin {
ZhiCommon
ZhiUtil
}
public zhiElectron
// public zhiElectron
public zhiBlogApi: {
BlogConstants
BlogTypeEnum
Expand All @@ -43,17 +43,16 @@ export default class PublisherPlugin extends Plugin {

// 初始化常用工具类
// private env
private logger
public logger
// private common
private blogApi
public blogApi

// lifecycle
async onload() {
// 初始化基础类库
await initLibs(this)

// 初始化常用工具类
await this.initUtils()
await initTools(this)

// 业务逻辑
const posts = await this.blogApi.getRecentPosts(10)
Expand All @@ -72,23 +71,4 @@ export default class PublisherPlugin extends Plugin {
// ======================
// private functions
// ======================
private async initUtils() {
// this.env = Utils.zhiEnv(this)
this.logger = Utils.zhiLog(this, "publisher-index")
// this.common = Utils.zhiCommon(this)

// blogApi
const publishSdk = this.zhiPublisherSdk.PublishSdk
publishSdk.init({
Env: this.zhiEnv.Env,
BlogConstants: this.zhiBlogApi.BlogConstants,
BlogTypeEnum: this.zhiBlogApi.BlogTypeEnum,
SiyuanConstants: this.zhiSiyuanApi.SiyuanConstants,
SiyuanConfig: this.zhiSiyuanApi.SiyuanConfig,
SiYuanApiAdaptor: this.zhiSiyuanApi.SiYuanApiAdaptor,
BlogApi: this.zhiBlogApi.BlogApi,
})
const cfg = new this.zhiSiyuanApi.SiyuanConfig("", "")
this.blogApi = publishSdk.blogApi(this.zhiBlogApi.BlogTypeEnum.BlogTypeEnum_Siyuan, cfg)
}
}
16 changes: 16 additions & 0 deletions src/tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Utils } from "~/src/utils/utils"
import PublisherPlugin from "~/src/index"

/**
* 初始化工具类
*
* @param appInstance - 应用实例
*/
export const initTools = async (appInstance: PublisherPlugin) => {
// this.env = Utils.zhiEnv(this)
appInstance.logger = Utils.zhiLog(appInstance, "publisher-index")
// this.common = Utils.zhiCommon(appInstance)

// blogApi
appInstance.blogApi = Utils.blogApi(appInstance)
}
17 changes: 17 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,21 @@ export class Utils {
public static zhiCommon(pluginInstance: PublisherPlugin) {
return pluginInstance.zhiCommon.ZhiUtil.zhiCommon()
}

public static blogApi(appInstance: PublisherPlugin, blogType?: any, blogCfg?: any) {
const publishSdk = appInstance.zhiPublisherSdk.PublishSdk
publishSdk.init({
appInstance: appInstance,
Env: appInstance.zhiEnv.Env,
BlogConstants: appInstance.zhiBlogApi.BlogConstants,
BlogTypeEnum: appInstance.zhiBlogApi.BlogTypeEnum,
SiyuanConstants: appInstance.zhiSiyuanApi.SiyuanConstants,
SiyuanConfig: appInstance.zhiSiyuanApi.SiyuanConfig,
SiYuanApiAdaptor: appInstance.zhiSiyuanApi.SiYuanApiAdaptor,
BlogApi: appInstance.zhiBlogApi.BlogApi,
})
const type = blogType ?? appInstance.zhiBlogApi.BlogTypeEnum.BlogTypeEnum_Siyuan
const cfg = blogCfg ?? new appInstance.zhiSiyuanApi.SiyuanConfig("", "")
return publishSdk.blogApi(type, cfg)
}
}

0 comments on commit ee2e562

Please sign in to comment.