Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add events support #315

Merged
merged 1 commit into from Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion libs/Universal-PicGo-Core/src/core/UniversalPicGo.ts
Expand Up @@ -8,17 +8,19 @@
*/

import { simpleLogger } from "zhi-lib-base"
import { EventEmitter } from "../utils/nodePolyfill"

/*
* 思源笔记内部 PicGO 对象定义
*
* @version 1.6.0
* @since 1.4.5
*/
class UniversalPicGo {
class UniversalPicGo extends EventEmitter {
private logger = simpleLogger("universal-picgo-api", "universal-picgo", false)

constructor() {
super()
this.logger.info("UniversalPicGo inited")
}
}
Expand Down
5 changes: 1 addition & 4 deletions libs/Universal-PicGo-Core/src/index.ts
@@ -1,6 +1,3 @@
import { UniversalPicGo } from "./core/UniversalPicGo"

/**
* 思源笔记 PicGO API 入口
*/
export default UniversalPicGo
export { UniversalPicGo }
11 changes: 11 additions & 0 deletions libs/Universal-PicGo-Core/src/utils/nodePolyfill.ts
@@ -0,0 +1,11 @@
/*
* GNU GENERAL PUBLIC LICENSE
* Version 3, 29 June 2007
*
* Copyright (C) 2024 Terwer, Inc. <https://terwer.space/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
import { EventEmitter } from "node:events"

export { EventEmitter }
6 changes: 6 additions & 0 deletions libs/Universal-PicGo-Core/vite.config.ts
Expand Up @@ -6,6 +6,7 @@ import { viteStaticCopy } from "vite-plugin-static-copy"
import dts from "vite-plugin-dts"
import minimist from "minimist"
import livereload from "rollup-plugin-livereload"
import { nodePolyfills, PolyfillOptions } from "vite-plugin-node-polyfills"

const args = minimist(process.argv.slice(2))
const isWatch = args.watch || args.w || false
Expand All @@ -20,6 +21,11 @@ export default defineConfig({
plugins: [
dts(),

nodePolyfills({
// Whether to polyfill `node:` protocol imports.
protocolImports: true,
}) as any,

viteStaticCopy({
targets: [
{
Expand Down
6 changes: 3 additions & 3 deletions packages/picgo-plugin-app/src/pages/PicGoIndex.vue
Expand Up @@ -8,14 +8,14 @@
-->

<script setup lang="ts">
import SyPicgo from "../../../../libs/Universal-PicGo-Core"
import { UniversalPicGo } from "universal-picgo"
import { createAppLogger } from "@/utils/appLogger.ts"

const logger = createAppLogger("picgo-index")

const handleTest = () => {
const api = new SyPicgo()
logger.debug("api =>", api)
const picgo = new UniversalPicGo()
logger.debug("picgo =>", picgo)
}
</script>

Expand Down