Skip to content

Commit

Permalink
Merge pull request #87 from terwer/dev
Browse files Browse the repository at this point in the history
feat: 在线分享第一版-完善打包流程
  • Loading branch information
terwer authored Jun 16, 2023
2 parents 31c9110 + dff7064 commit aae6b74
Show file tree
Hide file tree
Showing 18 changed files with 702 additions and 10 deletions.
39 changes: 39 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: 2
updates:
# Fetch and update latest `npm` packages
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
time: "00:00"
open-pull-requests-limit: 10
reviewers:
- terwer
assignees:
- terwer
commit-message:
prefix: fix
prefix-development: chore
include: scope
labels:
- "npm dependencies"
- "npm"

# Fetch and update latest `github-actions` pkgs
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
time: "00:00"
open-pull-requests-limit: 10
reviewers:
- terwer
assignees:
- terwer
commit-message:
prefix: fix
prefix-development: chore
include: scope
labels:
- "github actions"
- "ci"
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
push:
branches:
- dev

jobs:
build:
name: Build
timeout-minutes: 15
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 2

- uses: pnpm/action-setup@v2.2.4
with:
version: 8

- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build

- name: Package
run: pnpm package
103 changes: 103 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
on:
push:
branches:
- main

name: release-please
jobs:
release-please:
runs-on: ubuntu-latest
steps:
# Create release
- name: Create release
uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: node
package-name: release-please-action
## branch to open pull release PR against (detected by default)
default-branch: main
## Should breaking changes before 1.0.0 produce minor bumps? Default false
bump-minor-pre-major: false
## Should feat changes before 1.0.0 produce patch bumps instead of minor bumps? Default false
bump-patch-for-minor-pre-major: false
## If set, create releases that are pre-major or pre-release version marked as pre-release on GitHub. Defaults false
prerelease: false
## header used within the release PR body, defaults to using :robot: I have created a release *beep* *boop*
pull-request-header: ':robot: A new release will be created'
## A JSON formatted String containing to override the outputted changelog sections
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"refactor","section":"Code Refactoring","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false},{"type":"perf","section":"Performance Improvements","hidden":false}]'

# Checkout
- name: Checkout
if: ${{ steps.release.outputs.release_created }}
uses: actions/checkout@v3

# Install Node.js
- name: Install Node.js
if: ${{ steps.release.outputs.release_created }}
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'

# Install pnpm
- name: Install pnpm
if: ${{ steps.release.outputs.release_created }}
uses: pnpm/action-setup@v2
id: pnpm-install
with:
version: 8
run_install: false

# Get pnpm store directory
- name: Get pnpm store directory
if: ${{ steps.release.outputs.release_created }}
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
# Setup pnpm cache
- name: Setup pnpm cache
if: ${{ steps.release.outputs.release_created }}
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
# Install dependencies
- name: Install dependencies
if: ${{ steps.release.outputs.release_created }}
run: pnpm install

# Prepare new version
# https://github.com/google-github-actions/release-please-action#outputs
- name: Prepare new version
if: ${{ steps.release.outputs.release_created }}
run: |
pnpm prepareRelease
# Build for production
- name: Build for production
if: ${{ steps.release.outputs.release_created }}
run: pnpm build

# Archive package
- name: Archive package
if: ${{ steps.release.outputs.release_created }}
run: pnpm package

# Upload package to release
# https://github.com/philips-labs/terraform-aws-github-runner/blob/main/.github/workflows/release.yml#L46
- name: Upload package.zip to the release
if: ${{ steps.release.outputs.releases_created }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
ls -l ./build
for f in $(find ./build -name '*.zip'); do
gh release upload ${{ steps.release.outputs.tag_name }} $f
done
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
.cache
dist
.env.docker
build
__pycache__

# Node dependencies
node_modules
Expand Down
12 changes: 8 additions & 4 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import Footer from "~/components/default/Footer.vue"
</script>

<template>
<div>
<el-container>
<Header />
<slot />
<Footer />
</div>
<el-main>
<slot />
</el-main>
<el-footer>
<Footer />
</el-footer>
</el-container>
</template>
2 changes: 2 additions & 0 deletions locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ export default {
"main.opt.warning.tip": "This operation cannot be undone, continue?",
"switch.active.text": "Debug",
"switch.unactive.text": "Normal",
"blog.index.no.home": "Oh, you haven't set up your homepage yet!",
"blog.index.goto.set.home": "Go to set up my homepage now",
}
2 changes: 2 additions & 0 deletions locales/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ export default {
"main.opt.warning.tip": "此操作不可恢复,是否继续?",
"switch.active.text": "调试模式",
"switch.unactive.text": "正常模式",
"blog.index.no.home": "啊哦,您还没设置自己的主页哟!",
"blog.index.goto.set.home": "马上去设置我的主页",
}
4 changes: 4 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from "path"

const getAppBase = (isSiyuanBuild: boolean, isNodeBuild: boolean, isVercelBuild: boolean, isDev: boolean): string => {
if (isSiyuanBuild) {
return "/plugins/siyuan-blog/"
Expand Down Expand Up @@ -111,6 +113,8 @@ export default defineNuxtConfig({
classSuffix: "",
},

builder: "vite",

vite: {
define: { "process.env.DEV_MODE": `"${isDev || debugMode}"` },
plugins: [],
Expand Down
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
"type": "module",
"scripts": {
"serve": "nuxt dev",
"build": "pnpm pluginBuild && pnpm siyuanBuild",
"dev": "rm -rf ./dist && pnpm pluginBuild && DEBUG_MODE=true pnpm siyuanBuild && pnpm siyuanSync",
"dev": "bash scripts/dev.sh",
"build": "bash scripts/build.sh",
"pluginBuild": "zhi-build --production",
"siyuanBuild": "BUILD_TYPE=siyuan nuxt generate",
"vercelBuild": "BUILD_TYPE=vercel nuxt build",
"nodeBuild": "BUILD_TYPE=node nuxt build",
"siyuanBuild": "BUILD_TYPE=siyuan nuxt generate && cp -r .output/public/* ./dist",
"siyuanSync": "cp -r ./dist/* /Users/terwer/Documents/mydocs/SiYuanWorkspace/public/data/plugins/siyuan-blog",
"dockerPackage": "bash scripts/docker.sh",
"syncVersion": "python scripts/version.py",
"parseChangelog": "python scripts/parse_changelog.py",
"prepareRelease": "pnpm syncVersion && pnpm parseChangelog",
"package": "python scripts/package.py",
"postinstall": "nuxt prepare"
},
"devDependencies": {
Expand Down
6 changes: 4 additions & 2 deletions pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<script setup lang="ts">
const { t } = useVueI18n()
const goSetting = async () => {
await navigateTo("/setting")
}
</script>

<template>
<div>
<el-empty description="啊哦,您还没设置自己的主页哟!">
<el-button type="primary" @click="goSetting">马上去设置我的主页</el-button>
<el-empty :description="t('blog.index.no.home')">
<el-button type="primary" @click="goSetting">{{ t("blog.index.goto.set.home") }}</el-button>
</el-empty>
</div>
</template>
Expand Down
7 changes: 7 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# scripts

## Usage

```bash
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
```
19 changes: 19 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/sh

pnpm siyuanBuild
echo "Nuxt build finished."
pnpm pluginBuild
echo "Plugin build finished."

# 拷贝资源
# rsync -av --progress .output/public/ ./dist/
rsync -av .output/public/ ./dist/
echo "Resources are copied."

# 使用 `sed` 命令替换内容
ls ./dist/_nuxt
find ./dist/_nuxt -type f -name 'entry.*.js' -exec \
sed -i -E 's/\/__i18n__\/prerender/\/plugins\/siyuan-blog\/__i18n__\/prerender/g' {} \;
echo "The i18n path has been replaced"

echo "Siyuan build success."
22 changes: 22 additions & 0 deletions scripts/dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/sh

DEBUG_MODE=true pnpm siyuanBuild
echo "Nuxt build finished."
pnpm pluginBuild
echo "Plugin build finished."

# 拷贝资源
# rsync -av --progress .output/public/ ./dist/
rsync -av .output/public/ ./dist/
echo "Resources are copied."

# 使用 `sed` 命令替换内容
find ./dist/_nuxt -type f -name 'entry.*.js' -exec \
sed -i '' -E 's/\/__i18n__\/prerender/\/plugins\/siyuan-blog\/__i18n__\/prerender/g' {} \;
echo "The i18n path has been replaced"

# 复制最终文件
rsync -av ./dist/ /Users/terwer/Documents/mydocs/SiYuanWorkspace/public/data/plugins/siyuan-blog/
echo "All assets are copied."

echo "Siyuan build success."
2 changes: 2 additions & 0 deletions scripts/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pnpm nodeBuild
docker compose up --build
27 changes: 27 additions & 0 deletions scripts/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os

import scriptutils

if __name__ == "__main__":
# 切换工作空间
scriptutils.switch_workdir()

# 获取当前工作空间
cwd = scriptutils.get_workdir()

dist_folder = "./dist"
data = scriptutils.read_json_file(cwd + "package.json")
v = data["version"]

src_folder = dist_folder
tmp_folder_name = "./siyuan-plugin-blog"
build_zip_path = "./build"
build_zip_name = "siyuan-plugin-blog-" + v + ".zip"

try:
# 压缩dist为zip
scriptutils.zip_folder(src_folder, tmp_folder_name, build_zip_path, build_zip_name)
scriptutils.cp_file(os.path.join(build_zip_path, build_zip_name), os.path.join(build_zip_path, "package.zip"))
except Exception as e:
print(f"打包错误,{str(e)}")
print("插件打包完毕.")
Loading

1 comment on commit aae6b74

@vercel
Copy link

@vercel vercel bot commented on aae6b74 Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.