Skip to content

Commit

Permalink
自动更新包版本
Browse files Browse the repository at this point in the history
  • Loading branch information
2234839 committed Jun 5, 2024
1 parent e7eee15 commit da72db7
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 140 deletions.
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "expr",
"version": "0.2.3",
"version": "0.0.1",
"type": "module",
"description": "",
"repository": "",
"repository": "https://github.com/2234839/siyuan_expr",
"homepage": "",
"author": "",
"author": "崮生_子虚",
"license": "GPL-3.0",
"scripts": {
"make-link": "node --no-warnings ./scripts/make_dev_link.js",
Expand All @@ -14,7 +14,6 @@
},
"devDependencies": {
"fast-glob": "^3.3.2",
"glob": "^7.2.3",
"minimist": "^1.2.8",
"rollup-plugin-livereload": "^2.0.5",
"siyuan": "0.8.3",
Expand All @@ -25,6 +24,6 @@
"vite-plugin-zip-pack": "^1.2.3"
},
"dependencies": {
"@llej/js_util":"github:2234839/ts-util"
"@llej/js_util": "^1.0.8"
}
}
44 changes: 24 additions & 20 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
{
"name": "expr",
"author": "崮生_子虚",
"url": "https://github.com/2234839/OceanPress_siyuan_plugin",
"version": "0.0.1",
"minAppVersion": "2.10.3",
"backends": ["all"],
"frontends": ["all"],
"displayName": {
"en_US": "OceanPress siyuan plugin",
"zh_CN": "expr 思源插件"
"type": "module",
"description": "",
"repository": "https://github.com/2234839/siyuan_expr",
"homepage": "",
"author": "崮生_子虚",
"license": "GPL-3.0",
"scripts": {
"make-link": "node --no-warnings ./scripts/make_dev_link.js",
"dev": "vite build --watch",
"build": "vite build"
},
"description": {
"en_US": "To bestow OceanPress with enhanced capabilities.",
"zh_CN": "为 OceanPress 提供更多能力"
"devDependencies": {
"fast-glob": "^3.3.2",
"minimist": "^1.2.8",
"rollup-plugin-livereload": "^2.0.5",
"siyuan": "0.8.3",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"vite": "^4.5.3",
"vite-plugin-static-copy": "^0.15.0",
"vite-plugin-zip-pack": "^1.2.3"
},
"readme": {
"en_US": "README.md",
"zh_CN": "README.md"
"dependencies": {
"@llej/js_util": "github:2234839/ts-util"
},
"funding": {
"custom": [
"https://afdian.net/@llej0"
]
}
}
"url": "https://github.com/2234839/siyuan_expr"
}
231 changes: 116 additions & 115 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,131 +1,132 @@
import { resolve } from "path"
import { defineConfig, loadEnv } from "vite"
import minimist from "minimist"
import { viteStaticCopy } from "vite-plugin-static-copy"
import livereload from "rollup-plugin-livereload"
import { resolve } from "path";
import { defineConfig, loadEnv } from "vite";
import minimist from "minimist";
import { viteStaticCopy } from "vite-plugin-static-copy";
import livereload from "rollup-plugin-livereload";
import zipPack from "vite-plugin-zip-pack";
import fg from 'fast-glob';
import fg from "fast-glob";
import { siyuan } from "@llej/js_util";
/** 自动更新plugin.json */
import { writeFile } from "fs/promises";
import pluginJSON from "./plugin.json";
import pkg from "./package.json";

import pluginJSON from "./plugin.json"
writeFile("./plugin.json", JSON.stringify(siyuan.mergePluginPackage(pkg, pluginJSON), null, 2));

const args = minimist(process.argv.slice(2))
const isWatch = args.watch || args.w || false
const devDistDir = "./dev"
const distDir = isWatch ? devDistDir : "./dev"
const args = minimist(process.argv.slice(2));
const isWatch = args.watch || args.w || false;
const devDistDir = "./dev";
const distDir = isWatch ? devDistDir : "./dev";

console.log("isWatch=>", isWatch)
console.log("distDir=>", distDir)
console.log("isWatch=>", isWatch);
console.log("distDir=>", distDir);

export default defineConfig({
resolve: {
alias: {
"~": resolve(__dirname, "src"),
}
resolve: {
alias: {
"~": resolve(__dirname, "src"),
},
},

plugins: [
viteStaticCopy({
targets: [
{
src: "./README*.md",
dest: "./",
},
{
src: "./icon.png",
dest: "./",
},
{
src: "./preview.png",
dest: "./",
},
{
src: "./plugin.json",
dest: "./",
},
{
src: "./src/i18n/**",
dest: "./i18n/",
},
],
}),
],
plugins: [
viteStaticCopy({
targets: [
{
src: "./README*.md",
dest: "./",
},
{
src: "./icon.png",
dest: "./",
},
{
src: "./preview.png",
dest: "./",
},
{
src: "./plugin.json",
dest: "./",
},
{
src: "./src/i18n/**",
dest: "./i18n/",
},
],
}),
],

// https://github.com/vitejs/vite/issues/1930
// https://vitejs.dev/guide/env-and-mode.html#env-files
// https://github.com/vitejs/vite/discussions/3058#discussioncomment-2115319
// 在这里自定义变量
define: {
"process.env.DEV_MODE": `"${isWatch}"`,
},
// https://github.com/vitejs/vite/issues/1930
// https://vitejs.dev/guide/env-and-mode.html#env-files
// https://github.com/vitejs/vite/discussions/3058#discussioncomment-2115319
// 在这里自定义变量
define: {
"process.env.DEV_MODE": `"${isWatch}"`,
},

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

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

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

lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, "src/index.ts"),
// the proper extensions will be added
fileName: "index",
formats: ["cjs"],
},
rollupOptions: {
plugins: [
...(
isWatch ? [
livereload(devDistDir),
{
//监听静态资源文件
name: 'watch-external',
async buildStart() {
const files = await fg([
'src/i18n/*.json',
'./README*.md',
'./plugin.json'
]);
for (let file of files) {
this.addWatchFile(file);
}
}
}
] : [
zipPack({
inDir: distDir,
outDir: './',
outFileName: 'package.zip'
})
]
)
],
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, "src/index.ts"),
// the proper extensions will be added
fileName: "index",
formats: ["cjs"],
},
rollupOptions: {
plugins: [
...(isWatch
? [
livereload(devDistDir),
{
//监听静态资源文件
name: "watch-external",
async buildStart() {
const files = await fg(["src/i18n/*.json", "./README*.md", "./plugin.json"]);
for (let file of files) {
this.addWatchFile(file);
}
},
},
]
: [
zipPack({
inDir: distDir,
outDir: "./",
outFileName: "package.zip",
}),
]),
],

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

output: {
entryFileNames: "[name].js",
assetFileNames: (assetInfo) => {
if (assetInfo.name === "style.css") {
return "index.css"
}
return assetInfo.name!
},
//TODO 这里使用伺服模式有问题,但我不知道如何解决,反正这个功能也基本就开发者使用,就这样吧。
sourcemapBaseUrl:`http://localhost:6806/plugins/${pluginJSON.name}/`,
sourcemapPathTransform:(sourcePath) => {
return `${pluginJSON.name}/${sourcePath}`
}
},
output: {
entryFileNames: "[name].js",
assetFileNames: (assetInfo) => {
if (assetInfo.name === "style.css") {
return "index.css";
}
return assetInfo.name!;
},
}
})
//TODO 这里使用伺服模式有问题,但我不知道如何解决,反正这个功能也基本就开发者使用,就这样吧。
sourcemapBaseUrl: `http://localhost:6806/plugins/${pluginJSON.name}/`,
sourcemapPathTransform: (sourcePath) => {
return `${pluginJSON.name}/${sourcePath}`;
},
},
},
},
});

0 comments on commit da72db7

Please sign in to comment.