Skip to content

Commit

Permalink
fix: change build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Mar 14, 2024
1 parent d090d80 commit 9545e57
Show file tree
Hide file tree
Showing 14 changed files with 383 additions and 131 deletions.
1 change: 0 additions & 1 deletion .prettierignore
Expand Up @@ -6,7 +6,6 @@ node_modules

# Ignore all dts files:
*.d.ts
vite.config.ts

# lib
/pnpm-lock.yaml
6 changes: 3 additions & 3 deletions DEVELOPMENT.md
Expand Up @@ -11,19 +11,19 @@ pnpm install
serve

```bash
pnpm serve -F app
pnpm serve -F siyuan-plugin-picgo
```

dev

```bash
pnpm dev
pnpm dev -F siyuan-plugin-picgo
```

## Build

```bash
pnpm package
pnpm build
```

artifacts structure
Expand Down
3 changes: 1 addition & 2 deletions packages/siyuan-plugin-picgo/.gitignore
Expand Up @@ -26,5 +26,4 @@ components.d.ts
*.njsproj
*.sln
*.sw?
coverage
vite.config.ts
coverage
26 changes: 5 additions & 21 deletions packages/siyuan-plugin-picgo/common/Constants.ts
@@ -1,26 +1,10 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* GNU GENERAL PUBLIC LICENSE
* Version 3, 29 June 2007
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
* Copyright (C) 2022-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.
*/

export const isDev = process.env.DEV_MODE === "true"
28 changes: 6 additions & 22 deletions packages/siyuan-plugin-picgo/common/appLogger.ts
@@ -1,26 +1,10 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* GNU GENERAL PUBLIC LICENSE
* Version 3, 29 June 2007
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
* Copyright (C) 2023-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 { isDev } from "./Constants"
Expand All @@ -36,7 +20,7 @@ window.console = isDev ? win?.eruda?.get("console") : window.console
/**
* 简单的日志接口
*/
interface ILogger {
export interface ILogger {
debug: (msg: string, obj?: any) => void
info: (msg: string, obj?: any) => void
warn: (msg: string, obj?: any) => void
Expand Down
5 changes: 1 addition & 4 deletions packages/siyuan-plugin-picgo/index.html
Expand Up @@ -5,10 +5,7 @@
<link rel="icon" type="image/x-icon" href="/images/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PicGO 插件</title>
<script src="./libs/eruda/eruda.js"></script>
<script>
eruda.init()
</script>
<%- injectScript %>
</head>
<body>
<div id="app"></div>
Expand Down
8 changes: 5 additions & 3 deletions packages/siyuan-plugin-picgo/package.json
Expand Up @@ -5,18 +5,20 @@
"type": "module",
"scripts": {
"serve": "python -u scripts/serve.py && vite",
"dev": "python -u scripts/dev.py &&vue-tsc && vite build --wach",
"build": "vue-tsc && vite build",
"preview": "vite preview"
"dev": "python -u scripts/dev.py",
"build": "python -u scripts/build.py"
},
"devDependencies": {
"@terwer/esbuild-config-custom": "2.0.0",
"@terwer/eslint-config-custom": "^1.3.6",
"@vitejs/plugin-vue": "^5.0.4",
"fast-glob": "^3.3.2",
"minimist": "^1.2.5",
"rollup-plugin-livereload": "^2.0.5",
"typescript": "^5.2.2",
"vite": "^5.1.6",
"vite-plugin-html": "^3.2.2",
"vitest": "^1.3.1",
"vue-tsc": "^1.8.27"
},
"dependencies": {
Expand Down
14 changes: 14 additions & 0 deletions packages/siyuan-plugin-picgo/scripts/build.py
@@ -0,0 +1,14 @@
import shutil
import sys
import os

# 设置标准输出的编码为 UTF-8
# Windows 必须添加此设置
sys.stdout.reconfigure(encoding="utf-8")

# siyuan-plugin-bootstrap
# os.system("")

# picgo-app
os.system("vue-tsc && vite build")
print"PicGO plugin build success")
9 changes: 3 additions & 6 deletions packages/siyuan-plugin-picgo/scripts/dev.py
@@ -1,16 +1,13 @@
import shutil
import sys
import os

# 设置标准输出的编码为 UTF-8
# Windows 必须添加此设置
sys.stdout.reconfigure(encoding="utf-8")

# siyuan-plugin-bootstrap
os.system("")
# os.system("")

# picgo-app
shutil.copyfile("vite.config.plugin.ts", "vite.config.ts")
print("Config is reset to web, will serve as browser")

# vite
# 会阻塞,最好在 npm 的 scripts 里面,便于及时查看日志
os.system("vue-tsc && vite build --watch")
9 changes: 3 additions & 6 deletions packages/siyuan-plugin-picgo/scripts/serve.py
@@ -1,13 +1,10 @@
import shutil
import sys
import os

# 设置标准输出的编码为 UTF-8
# Windows 必须添加此设置
sys.stdout.reconfigure(encoding="utf-8")

# "serve": "cp index.siyuan-nginx.html index.html && cp vite.config.siyuan-nginx.ts vite.config.ts && vite"
shutil.copyfile("vite.config.web.ts", "vite.config.ts")
print("Config is reset to web, will serve as browser")

# vite
# 会阻塞,最好在 npm 的 scripts 里面,便于及时查看日志
os.environ['IS_SERVE'] = 'true'
os.system("vite")
34 changes: 34 additions & 0 deletions packages/siyuan-plugin-picgo/src/setup.ts
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
*/

import { afterEach, beforeEach } from "vitest"

beforeEach(async () => {
console.log("======test is starting...======")
})

afterEach(() => {
console.log("======test is finished.========")
})
Expand Up @@ -9,16 +9,24 @@

import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import livereload from "rollup-plugin-livereload"
import minimist from "minimist"
import fg from "fast-glob"
import { createHtmlPlugin } from "vite-plugin-html"
import path from "path"

// config
const args = minimist(process.argv.slice(2))
// 开启之后可以同eruda接管日志
const isServe = process.env.IS_SERVE
const isWatch = args.watch || args.w || false
const isDev = isWatch
const isDev = isServe || isWatch
const outDir = args.o || args.outDir

const distDir = outDir || "./dist"

// https://vitejs.dev/config/
export default defineConfig({
export default defineConfig(() => ({
plugins: [
vue(),

Expand Down Expand Up @@ -80,4 +88,58 @@ export default defineConfig({
$composables: path.resolve(__dirname, "./src/composables"),
},
},
})

build: {
// 输出路径
outDir: distDir,
emptyOutDir: false,

// 构建后是否生成 source map 文件
sourcemap: false,

// 设置为 false 可以禁用最小化混淆
// 或是用来指定是应用哪种混淆器
// boolean | 'terser' | 'esbuild'
// 不压缩,用于调试
minify: !isDev,

rollupOptions: {
plugins: [
...(isWatch
? [
livereload(distDir),
{
//监听静态资源文件
name: "watch-external",
async buildStart() {
const files = await fg(["src/assets/*", "./README*.md", "./widget.json"])
for (const file of files) {
const that = this as any
that.addWatchFile(file)
}
},
},
]
: []),
] as any,

// make sure to externalize deps that shouldn't be bundled into your library
external: [],
},
},

test: {
globals: true,
environment: "jsdom",
// environment: "node",
// environment: "happy-dom",
setupFiles: ["./src/setup.ts"],
include: [
"src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}",
"common/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}",
],
server: {
deps: {},
},
},
}))
60 changes: 0 additions & 60 deletions packages/siyuan-plugin-picgo/vite.config.web.ts

This file was deleted.

0 comments on commit 9545e57

Please sign in to comment.