Skip to content

Commit

Permalink
feat: #374 使用python重构项目构建脚本-抽取python工具类
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Feb 2, 2023
1 parent 5d37cef commit 80c9898
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 46 deletions.
25 changes: 0 additions & 25 deletions components.d.ts
@@ -1,28 +1,3 @@
/*
* 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.
*/

// generated by unplugin-vue-components
// We suggest you to commit this file into source control
// Read more: https://github.com/vuejs/core/pull/3399
Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -11,8 +11,7 @@
"docs": "jsdoc -c jsdoc.json utils/api.ts",
"prettier": "prettier --write .",
"prepare": "husky install",
"widget": "bash scripts/widget.sh",
"widgetWin": "pwsh scripts/widget.ps1",
"widget": "python scripts/widget.py",
"ext": "bash scripts/ext.sh",
"extWin": "pwsh scripts/ext.ps1",
"extDev": "bash scripts/extDev.sh",
Expand Down
91 changes: 91 additions & 0 deletions scripts/scriptutils.py
@@ -0,0 +1,91 @@
# 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.
#
# 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 distutils
import glob
import os
import sys
from distutils import file_util


def switch_workdir():
cwd = "./"
if os.getcwd().endswith("scripts"):
cwd = "../"

# 打印当前python版本
print("当前python版本:" + sys.version)
# 打印当前路径
print("当前路径:" + os.getcwd())

print("切换路径")
os.chdir(cwd)
print("当前路径:" + os.getcwd())


def cp_file(f, t):
"""
拷贝文件
:param f: 源路径
:param t: 目的地
"""
distutils.file_util.copy_file(f, t)


def rm_file(filename):
"""
删除文件
:param filename:文件名
"""
if os.path.exists(filename):
os.remove(filename)


def rm_files(regex):
"""
正则删除文件
:param regex: 正则
"""
file_list = glob.glob(regex)
for file in file_list:
rm_file(file)
12 changes: 0 additions & 12 deletions scripts/widget.ps1

This file was deleted.

65 changes: 65 additions & 0 deletions scripts/widget.py
@@ -0,0 +1,65 @@
# 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.
#
# 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 scriptutils

if __name__ == "__main__":
scriptutils.switch_workdir()

# 构建项目到 dist 目录
# 在 node 里面可以通过 process.env.BUILD_TYPE 读取
# os.environ["BUILD_TYPE"] = "siyuan"
# os.system("vue-tsc --noEmit && vite build")

# 复制挂件需要的其他文件
scriptutils.cp_file("./LICENSE", "./dist/")
scriptutils.cp_file("./README.md", "./dist/")
scriptutils.cp_file("./policy.md", "./dist/")
print("复制挂件需要的其他文件.")

# 删除Chrome插件专属文件
scriptutils.rm_file("./dist/background.js")
scriptutils.rm_files("./dist/manifest*.json")
print("删除Chrome插件专属文件.")

print("发布完毕.")
7 changes: 0 additions & 7 deletions scripts/widget.sh
Expand Up @@ -23,13 +23,6 @@
# questions.
#

pwd
vue-tsc --noEmit && BUILD_TYPE=siyuan vite build
cp ./LICENSE ./dist/
cp ./README.md ./dist/
cp ./policy.md ./dist/
cp ./.gitignore ./dist/

# 删除Chrome插件专属文件
rm ./dist/background.js
rm ./dist/manifest*.json
Expand Down

0 comments on commit 80c9898

Please sign in to comment.