Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
[refactor] simplify Souce Code based on Web Utility, KoAJAX & MobX
Browse files Browse the repository at this point in the history
[migrate] replace NPM + React scripts + Travis CI with PNPM + Parcel + GitHub actions
[optimize] upgrade Upstream packages & ReadMe document
[fix] some detail bugs
  • Loading branch information
TechQuery committed Oct 7, 2023
1 parent 2aa165a commit dec54b4
Show file tree
Hide file tree
Showing 31 changed files with 9,480 additions and 621 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI & CD
on:
push:
branches:
- master
jobs:
Build-and-Deploy:
runs-on: ubuntu-latest
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v3
if: ${{ !env.VERCEL_TOKEN || !env.VERCEL_ORG_ID || !env.VERCEL_PROJECT_ID }}
with:
node-version: 18
cache: pnpm
- name: Install Dependencies
if: ${{ !env.VERCEL_TOKEN || !env.VERCEL_ORG_ID || !env.VERCEL_PROJECT_ID }}
run: pnpm i --frozen-lockfile

- name: Build Production
if: ${{ !env.VERCEL_TOKEN || !env.VERCEL_ORG_ID || !env.VERCEL_PROJECT_ID }}
run: pnpm build

- name: Deploy Production
uses: peaceiris/actions-gh-pages@v3
if: ${{ !env.VERCEL_TOKEN || !env.VERCEL_ORG_ID || !env.VERCEL_PROJECT_ID }}
with:
publish_dir: ./dist
personal_token: ${{ secrets.GITHUB_TOKEN }}
force_orphan: true

- name: Deploy to Vercel
uses: amondnet/vercel-action@v25
if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }}
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
working-directory: ./dist
vercel-args: --prod
27 changes: 27 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Pull Request
on:
push:
branches-ignore:
- master
jobs:
Build-and-Deploy:
runs-on: ubuntu-latest
permissions:
contents: write
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
steps:
- uses: actions/checkout@v3
if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }}

- name: Deploy to Vercel
uses: amondnet/vercel-action@v25
if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }}
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
working-directory: ./dist
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ yarn.lock

# production
/build
.parcel-cache/
dist/
.leancloud

# misc
Expand All @@ -24,3 +26,10 @@ yarn.lock
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# IDE
.vscode/settings.json
.idea/

# Cloud
.vercel
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh

. "$(dirname -- "$0")/_/husky.sh"

npm test
5 changes: 5 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh

. "$(dirname -- "$0")/_/husky.sh"

npm run build
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
registry=https://registry.npm.taobao.org
auto-install-peers = false
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

62 changes: 29 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
# Git Pager

[![NPM Dependency](https://david-dm.org/kaiyuanshe/git-pager.svg)](https://david-dm.org/kaiyuanshe/git-pager)
[![Build Status](https://travis-ci.com/kaiyuanshe/git-pager.svg?branch=master)](https://travis-ci.com/kaiyuanshe/git-pager)
[![CI & CD](https://github.com/kaiyuanshe/git-pager/actions/workflows/main.yml/badge.svg)][1]

## 技术架构

- 前端技术栈:[`npm init react-app . --typescript`](https://github.com/facebook/create-react-app)
- 前端技术栈:

- 后端技术栈:
- 编程语言: [TypeScript v5][2]
- 组件引擎: [React v17][3]
- 组件套件: [Bootstrap v4][4]
- 状态管理: [MobX v5][5]
- PWA 框架: [Workbox v7][6]
- CI / CD: [GitHub Actions][7] + [Vercel][8]

- [Koa](http://koa.bootcss.com/)
- 后端技术栈:

- [LeanCloud](https://leancloud.cn/)
- [Koa][9]
- [LeanCloud][10]

## 本地开发

### 单独启动前端开发环境

1. 执行命令 `npm run front`

2. 浏览器访问 http://localhost:3000/?repository=your-repo&token=your-token
1. 执行命令 `npm run front`
2. 浏览器访问 http://localhost:3000/?repository=your-repo&token=your-token

### 前端生产环境 + 后端调试环境

1. 执行命令 `lean up`(需装好 [LeanCloud 命令行工具](https://leancloud.cn/docs/leanengine_cli.html)

2. 浏览器访问 http://localhost:3000/?repository=your-repo
1. 执行命令 `lean up`(需装好 [LeanCloud 命令行工具][11]
2. 浏览器访问 http://localhost:3000/?repository=your-repo

## 远程部署

Expand All @@ -37,31 +40,24 @@ npm run deploy

### `npm test`

Launches the test runner in the interactive watch mode.<br>
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
Launches the test runner in the interactive watch mode.

### `npm run build`

Builds the app for production to the `build` folder.<br>
Builds the app for production to the `build` folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br>
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
[1]: https://github.com/kaiyuanshe/git-pager/actions/workflows/main.yml
[2]: https://www.typescriptlang.org/
[3]: https://react.dev/
[4]: https://getbootstrap.com/docs/4.6/
[5]: https://github.com/mobxjs/mobx/tree/mobx4and5/docs
[6]: https://developers.google.com/web/tools/workbox
[7]: https://github.com/features/actions
[8]: https://vercel.com/
[9]: http://koa.bootcss.com/
[10]: https://leancloud.cn/
[11]: https://leancloud.cn/docs/leanengine_cli.html
18 changes: 18 additions & 0 deletions fix-bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { readFileSync, readdirSync, writeFileSync } from 'fs';
import { join } from 'path';

const [root = 'dist'] = process.argv.slice(2);

console.time();

for (const name of readdirSync(root))
if (name.endsWith('.js')) {
const path = join(root, name);
const data = readFileSync(path, { encoding: 'utf-8' });

writeFileSync(path, data.replace(/\$\w+\$import\$\w+\W/, ''));

console.log(`[fix] ${path}`);
}

console.timeEnd();
114 changes: 54 additions & 60 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,90 +1,84 @@
{
"name": "git-pager",
"version": "0.9.0",
"version": "1.0.0",
"private": true,
"author": "shiy2008@gmail.com",
"engines": {
"node": ">=8.0.0"
"node": ">=18"
},
"dependencies": {
"@octokit/rest": "^16.28.7",
"@octokit/rest": "^20.0.2",
"browser-unhandled-rejection": "^1.0.2",
"classnames": "^2.2.6",
"clipboard-polyfill": "^2.8.1",
"core-js": "^3.2.0",
"classnames": "^2.3.2",
"core-js": "^3.33.0",
"hostname-is-private": "^2.0.8",
"koa": "^2.7.0",
"koa": "^2.14.2",
"koa-logger": "^3.2.1",
"koa-mount": "^4.0.0",
"koa-route": "^3.2.0",
"koa-static": "^5.0.0",
"koajax": "^0.9.4",
"leancloud-storage": "^3.15.0",
"leanengine": "^3.4.0",
"leanengine": "^3.8.0",
"markdown-ime": "^1.0.3",
"marked": "^0.7.0",
"mobx": "^5.13.0",
"mobx-react": "^6.1.1",
"node-fetch": "^2.6.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"turndown": "^5.0.3",
"marked": "^9.1.0",
"mobx": "^5.15.7",
"mobx-react": "^6.3.1",
"node-fetch": "^2.7.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"turndown": "^7.1.2",
"turndown-plugin-gfm": "^1.0.2",
"yaml": "^1.6.0"
"web-utility": "^4.1.3",
"yaml": "^2.3.2"
},
"devDependencies": {
"@types/classnames": "^2.2.9",
"@types/jest": "24.0.17",
"@types/marked": "^0.6.5",
"@types/node": "12.6.9",
"@types/react": "16.8.24",
"@types/react-dom": "16.8.5",
"@types/turndown": "^5.0.0",
"@types/yaml": "^1.0.2",
"husky": "^3.0.2",
"lint-staged": "^9.2.1",
"prettier": "^1.18.2",
"react-scripts": "3.0.1",
"typescript": "3.5.3"
"@parcel/packager-raw-url": "~2.9.3",
"@parcel/transformer-less": "~2.9.3",
"@parcel/transformer-webmanifest": "~2.9.3",
"@types/classnames": "^2.3.1",
"@types/jest": "29.5.5",
"@types/node": "^18.18.4",
"@types/react": "^17.0.67",
"@types/react-dom": "^17.0.21",
"@types/turndown": "^5.0.2",
"@types/yaml": "^1.9.7",
"buffer": "^6.0.3",
"husky": "^8.0.3",
"jest": "^29.7.0",
"lint-staged": "^14.0.1",
"parcel": "~2.9.3",
"prettier": "^3.0.3",
"process": "^0.11.10",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "~5.2.2",
"workbox-cli": "^7.0.0"
},
"scripts": {
"front": "react-scripts start",
"format": "lint-staged",
"build": "lint-staged && react-scripts build",
"start": "node ./server ./build LEANCLOUD_APP_PORT",
"dev": "npm run build && node --inspect ./server ./build LEANCLOUD_APP_PORT",
"test": "react-scripts test",
"deploy": "npm run build && lean deploy",
"eject": "react-scripts eject"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm test -- --watchAll=false && npm run build"
}
"prepare": "husky install",
"parcel": "rm -rf .parcel-cache/ dist/ && parcel",
"front": "npm run parcel -- public/index.html",
"pack": "npm run parcel -- build public/index.html --public-url . --no-source-maps && ts-node fix-bundle",
"build": "npm run pack && workbox generateSW",
"start": "node ./server ./dist LEANCLOUD_APP_PORT",
"dev": "npm run build && node --inspect ./server ./dist LEANCLOUD_APP_PORT",
"test": "lint-staged && jest",
"deploy": "npm run build && lean deploy"
},
"lint-staged": {
"*.{html,md,css,less,js,json,ts,jsx,tsx}": [
"prettier --write",
"git add"
]
"*.{html,md,css,less,js,json,ts,jsx,tsx}": "prettier --write"
},
"eslintConfig": {
"extends": "react-app"
},
"prettier": {
"singleQuote": true
"singleQuote": true,
"trailingComma": "none",
"arrowParens": "avoid"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 2 chrome version",
"last 2 firefox version",
"last 2 safari version",
"last 2 edge version"
]
"browserslist": "> 0.5%, last 2 versions, not dead, IE 11",
"jest": {
"preset": "ts-jest"
}
}
Loading

0 comments on commit dec54b4

Please sign in to comment.