Skip to content

Commit

Permalink
feat: 更新挂件版 siyuanhook
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 14, 2023
1 parent e6754fa commit 4764b0c
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 8 deletions.
5 changes: 4 additions & 1 deletion libs/publisher-hook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@terwer/publisher-hook",
"version": "0.0.1",
"version": "0.0.3",
"type": "module",
"description": "siyuanhook for sy-post-publisher widget",
"main": "./dist/index.js",
Expand Down Expand Up @@ -31,5 +31,8 @@
"dependencies": {
"zhi-device": "^0.5.0",
"zhi-log": "^1.13.0"
},
"publishConfig": {
"access": "public"
}
}
3 changes: 3 additions & 0 deletions libs/publisher-hook/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
import PublishHook from "./publish-hook"
import { SiyuanDevice, BrowserUtil, DeviceTypeEnum } from "zhi-device"

export default PublishHook
export { SiyuanDevice, BrowserUtil, DeviceTypeEnum }
5 changes: 4 additions & 1 deletion plugins/publisher-main/.env.development.local.example
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
VITE_DEBUG_MODE=true
# 是否开启info日志,true | false,建议生产环境设置为false
VITE_LOG_INFO_ENABLED=true
# 是否开始调试模式
VITE_DEBUG_MODE=true
4 changes: 4 additions & 0 deletions plugins/publisher-main/.env.production.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 是否开启info日志,true | false,建议生产环境设置为false
VITE_LOG_INFO_ENABLED=true
# 是否开始调试模式
VITE_DEBUG_MODE=false
3 changes: 2 additions & 1 deletion plugins/publisher-main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"svelte": "^3.57.0"
},
"dependencies": {
"zhi-device": "^0.5.0"
"zhi-device": "^0.5.0",
"zhi-log": "^1.13.0"
}
}
13 changes: 9 additions & 4 deletions plugins/publisher-main/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Dialog, isMobile, Menu, Plugin } from "siyuan"
import App from "./App.svelte"
import { DeviceDetection, DeviceTypeEnum } from "zhi-device"
import { Env } from "zhi-env"

const STORAGE_NAME = "menu-config"
const SETTING_CONTAINER = "publish-tool-setting"

// https://github.com/sveltejs/svelte-preprocess/issues/91#issuecomment-548527600
export default class PublishTool extends Plugin {
private env: Env = new Env(import.meta.env)

// lifecycle
public onload() {
this._addTopBar()
Expand Down Expand Up @@ -126,10 +129,12 @@ export default class PublishTool extends Plugin {

const publisherIndex = `/widgets/sy-post-publisher/index.html`

console.log(this.env)
console.log(this.env.isDev())
if (deviceType == DeviceTypeEnum.DeviceType_Siyuan_MainWin) {
import("/plugins/publish-tool/lib/bridge/index.js" as any).then((hook) => {
const publisherHook = new hook.default()
publisherHook.init().then(() => {
import("/plugins/publish-tool/lib/bridge/index.js" as any).then((bridge) => {
const publisherBridge = new bridge.default()
publisherBridge.init().then(() => {
// 发布首页
// const pageId: any = "111111"
// const pageUrl = "index.html"
Expand All @@ -142,7 +147,7 @@ export default class PublishTool extends Plugin {
// const widgetId = "1111111"
// const pageUrl = "detail/index.html"

win.syp.renderPublishHelper(pageId, pageUrl, win, true)
win.syp.renderPublishHelper(pageId, pageUrl, win, this.env.isDev())
console.log("publisherHook inited")
})
})
Expand Down
27 changes: 26 additions & 1 deletion plugins/publisher-main/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
/// <reference types="vitest" />

import { resolve } from "path"
import { defineConfig } from "vite"
import { defineConfig, loadEnv } from "vite"
import minimist from "minimist"
import { viteStaticCopy } from "vite-plugin-static-copy"
import livereload from "rollup-plugin-livereload"
import { svelte } from "@sveltejs/vite-plugin-svelte"

const mode = process.env.NODE_ENV
const args = minimist(process.argv.slice(2))
const isWatch = args.watch || args.w
const devDistDir = "/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/data/plugins/publish-tool"
const distDir = isWatch ? devDistDir : "./dist"

const defineEnv = () => {
const env = loadEnv(mode, process.cwd())
return {
"process.env": Object.entries(env).reduce((prev, [key, val]) => {
return {
...prev,
[key]: val,
}
}, {}),
}
}
const env = {
...defineEnv(),
// 下面可以自定义添加需要注入的环境变量
"process.env.NODE_ENV": mode,
}

console.log("mode=>", mode)
console.log("env=>", env)
console.log("isWatch=>", isWatch)
console.log("distDir=>", distDir)

Expand All @@ -38,6 +58,11 @@ export default defineConfig({
// 静态资源服务文件夹
// publicDir: "public",

// https://github.com/vitejs/vite/issues/1930
// https://vitejs.dev/guide/env-and-mode.html#env-files
// 在这里自定义变量
define: env,

build: {
// 浏览器兼容性 ‘esnext’ | 'modules'
// https://vitejs.dev/config/build-options.html#build-target
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4764b0c

Please sign in to comment.