Skip to content

Commit

Permalink
fix: 完善开发文档 - 支持 serve、思源笔记插件、nginx 部署开发调试
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Feb 23, 2024
1 parent 179aa47 commit 532d8ed
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ archive.zip
components.d.ts
auto-imports.d.ts

# ginx
nginx

# test
coverage
testdata
6 changes: 5 additions & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ pnpm serve
dev

```bash
pnpm makeLink -p siyuan
pnpm dev -p siyuan

# pnpm makeLink -p widget
# pnpm dev -p widget -t
# pnpm dev -p static

pnpm dev -p nginx -d nginx
```

## Build
Expand Down
2 changes: 1 addition & 1 deletion esbuild.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const { copy } = require("esbuild-plugin-copy")

const args = minimist(process.argv.slice(2))
const isWatch = args.watch || args.w || false
const distDir = "./dist"
const distDir = args.dist || args.d || "./dist"

module.exports = {
esbuildConfig: {
Expand Down
13 changes: 10 additions & 3 deletions scripts/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@

# Parse arguments.
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--dist", required=False, help="the dist for building files")
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output.")
parser.add_argument("-p", "--platform", help="Build for different platforms, like siyuan, widget, static.")
parser.add_argument("-t", "--type", help="Build browser extension for publishing, like chrome, edge, firefox.")
parser.add_argument("-d", "--dist", required=False, help="the dist for building files")
args = parser.parse_args()

if args.verbose:
Expand All @@ -48,5 +48,12 @@
args.platform = 'siyuan'
os.environ['BUILD_TYPE'] = args.platform

os.system("zhi-build --serve --production")
os.system("vue-tsc --noEmit && vite build --watch")
# zhi-build
zhi_build_cmd = "zhi-build --serve --production -d " + args.dist
print(zhi_build_cmd)
os.system(zhi_build_cmd)

# vite-build
vite_cmd = "vue-tsc --noEmit && vite build --watch --outDir " + args.dist
print(vite_cmd)
os.system(vite_cmd)
40 changes: 32 additions & 8 deletions scripts/make_dev_link.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) 2022-2023, terwer . All rights reserved.
# @author terwer on 2023/11/6

import argparse
import json
import os
import sys
Expand All @@ -26,6 +26,7 @@
"Content-Type": "application/json",
}


def get_siyuan_dir():
url = 'http://127.0.0.1:6806/api/system/getWorkspaces'
try:
Expand Down Expand Up @@ -77,12 +78,15 @@ def get_plugin_name():

def make_link(target_dir, plugin_name):
# dev 目录
dev_dir = f'{os.getcwd()}/{devOutDir}'
dev_dir = os.path.join(os.getcwd(), devOutDir)
# 如果不存在则创建
if not os.path.exists(dev_dir):
os.makedirs(dev_dir)

target_path = f'{target_dir}/{plugin_name}'
target_path = target_dir
if plugin_name.strip() != '':
target_path = os.path.join(target_dir, plugin_name)

# 如果已存在,则退出
if os.path.exists(target_path):
is_symbol = os.path.islink(target_path)
Expand Down Expand Up @@ -159,6 +163,30 @@ def _cmp_path(path1, path2):
# 获取当前路径
cwd = scriptutils.get_workdir()

# Parse arguments.
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--dist", required=False, help="the dist for building files")
parser.add_argument("-f", "--forder", required=False, help="the targetDir for building files")
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output.")
parser.add_argument("-p", "--platform", help="Build for different platforms, like siyuan, widget, static.")
args = parser.parse_args()

if args.verbose:
print("Verbose mode enabled.")
# 设置环境变量
if not args.platform:
args.platform = 'siyuan'
if not args.dist:
args.dist = 'dist'
devOutDir = args.dist
if args.forder:
targetDir = args.forder
name = ''
else:
# 获取插件名称
name = get_plugin_name()
_log(f'>>> 成功获取到插件名称: {name}')

# 获取插件目录
_log('>>> 尝试访问 make_dev_link.js 中的常量 "targetDir"...')
if targetDir == '':
Expand All @@ -183,9 +211,5 @@ def _cmp_path(path1, path2):
_error('请在 scripts/make_dev_link.py 中设置插件目录')
sys.exit(1)

# 获取插件名称
name = get_plugin_name()
_log(f'>>> 成功获取到插件名称: {name}')

# 生成软连接
make_link(targetDir, name)
make_link(targetDir, name)
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ const debugMode = process.env.DEBUG_MODE === "true"
const isServe = process.env.IS_SERVE
const isWatch = args.watch || args.w || false
const isDev = isServe || isWatch || debugMode
const outDir = args.o || args.outDir

const isSiyuanBuild = process.env.BUILD_TYPE === "siyuan"
const isWidgetBuild = process.env.BUILD_TYPE === "widget"
const isStaticBuild = process.env.BUILD_TYPE === "static"
// const isChromeBuild = process.env.BUILD_TYPE === "chrome"
const distDir = isWidgetBuild ? "widget" : "./dist"
const distDir = outDir || (isWidgetBuild ? "widget" : "./dist")
const appBase = getAppBase(isSiyuanBuild, isWidgetBuild, isStaticBuild)

console.log("isWatch=>", isWatch)
Expand Down

0 comments on commit 532d8ed

Please sign in to comment.