Merge branch 'master' into publish

This commit is contained in:
Haishan 2023-01-30 21:53:22 +08:00
commit 69b070da91
9 changed files with 329 additions and 262 deletions

View file

@ -35,6 +35,10 @@ jobs:
- name: Lint - name: Lint
run: pnpm lint run: pnpm lint
- name: Set git commit sha
id: revparse
run: |
echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Build - name: Build
run: pnpm build run: pnpm build
@ -67,7 +71,7 @@ jobs:
- name: Push to gh-pages - name: Push to gh-pages
if: github.event_name == 'push' && (startsWith(github.event.ref, 'refs/tags/') || github.event.ref == 'refs/heads/publish') if: github.event_name == 'push' && (startsWith(github.event.ref, 'refs/tags/') || github.event.ref == 'refs/heads/publish')
env: env:
GITHUB_TOKEN: ${{ secrets.TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PUBLISH_DIR: public PUBLISH_DIR: public
BRANCH: gh-pages BRANCH: gh-pages
run: | run: |
@ -95,6 +99,10 @@ jobs:
if: github.event_name == 'push' && (startsWith(github.event.ref, 'refs/tags/') || startsWith(github.event.ref, 'refs/heads/v0.') || github.event.ref == 'refs/heads/master' || github.event.ref == 'refs/heads/test') if: github.event_name == 'push' && (startsWith(github.event.ref, 'refs/tags/') || startsWith(github.event.ref, 'refs/heads/v0.') || github.event.ref == 'refs/heads/master' || github.event.ref == 'refs/heads/test')
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Set git commit sha
id: revparse
run: |
echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Cache Docker layers - name: Cache Docker layers
uses: actions/cache@v3 uses: actions/cache@v3
@ -149,6 +157,8 @@ jobs:
labels: ${{ steps.docker_meta.outputs.labels }} labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=gha cache-from: type=gha
cache-to: type=gha cache-to: type=gha
build-args: |
COMMIT_HASH=${{ env.COMMIT_HASH }}
- name: Image digest - name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }} run: echo ${{ steps.docker_build.outputs.digest }}

View file

@ -1,3 +1,5 @@
ARG COMMIT_SHA=""
FROM --platform=$BUILDPLATFORM node:alpine AS builder FROM --platform=$BUILDPLATFORM node:alpine AS builder
WORKDIR /app WORKDIR /app

View file

@ -28,22 +28,22 @@
"private": true, "private": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@babel/runtime": "7.20.7", "@babel/runtime": "7.20.13",
"@fontsource/roboto-mono": "4.5.8", "@fontsource/roboto-mono": "4.5.10",
"@reach/menu-button": "0.18.0", "@reach/menu-button": "0.18.0",
"@reach/tooltip": "0.18.0", "@reach/tooltip": "0.18.0",
"@reach/visually-hidden": "0.18.0", "@reach/visually-hidden": "0.18.0",
"@tanstack/react-query": "4.22.0", "@tanstack/react-query": "4.24.2",
"chart.js": "4.1.2", "chart.js": "4.2.0",
"clsx": "^1.2.1", "clsx": "^1.2.1",
"core-js": "3.27.1", "core-js": "3.27.2",
"date-fns": "2.29.3", "date-fns": "2.29.3",
"framer-motion": "8.4.6", "framer-motion": "8.5.4",
"history": "5.3.0", "history": "5.3.0",
"i18next": "22.4.9", "i18next": "22.4.9",
"i18next-browser-languagedetector": "7.0.1", "i18next-browser-languagedetector": "7.0.1",
"i18next-http-backend": "2.1.1", "i18next-http-backend": "2.1.1",
"immer": "9.0.18", "immer": "9.0.19",
"invariant": "^2.2.4", "invariant": "^2.2.4",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"memoize-one": "6.0.0", "memoize-one": "6.0.0",
@ -54,8 +54,8 @@
"react-i18next": "12.1.4", "react-i18next": "12.1.4",
"react-icons": "4.7.1", "react-icons": "4.7.1",
"react-modal": "3.16.1", "react-modal": "3.16.1",
"react-router": "6.6.2", "react-router": "6.8.0",
"react-router-dom": "6.6.2", "react-router-dom": "6.8.0",
"react-switch": "^7.0.0", "react-switch": "^7.0.0",
"react-table": "7.8.0", "react-table": "7.8.0",
"react-tabs": "6.0.0", "react-tabs": "6.0.0",
@ -64,7 +64,7 @@
"recoil": "0.7.6", "recoil": "0.7.6",
"regenerator-runtime": "0.13.11", "regenerator-runtime": "0.13.11",
"reselect": "4.1.7", "reselect": "4.1.7",
"tslib": "2.4.1", "tslib": "2.5.0",
"use-asset": "1.0.4", "use-asset": "1.0.4",
"workbox-core": "6.5.4", "workbox-core": "6.5.4",
"workbox-expiration": "6.5.4", "workbox-expiration": "6.5.4",
@ -73,27 +73,27 @@
"workbox-strategies": "6.5.4" "workbox-strategies": "6.5.4"
}, },
"devDependencies": { "devDependencies": {
"@fontsource/inter": "4.5.14", "@fontsource/inter": "4.5.15",
"@types/invariant": "2.2.35", "@types/invariant": "2.2.35",
"@types/lodash-es": "4.17.6", "@types/lodash-es": "4.17.6",
"@types/react": "18.0.26", "@types/react": "18.0.27",
"@types/react-dom": "18.0.10", "@types/react-dom": "18.0.10",
"@types/react-modal": "3.13.1", "@types/react-modal": "3.13.1",
"@types/react-window": "1.8.5", "@types/react-window": "1.8.5",
"@typescript-eslint/eslint-plugin": "5.48.2", "@typescript-eslint/eslint-plugin": "5.49.0",
"@typescript-eslint/parser": "5.48.2", "@typescript-eslint/parser": "5.49.0",
"@vitejs/plugin-react": "3.0.1", "@vitejs/plugin-react": "3.0.1",
"autoprefixer": "10.4.13", "autoprefixer": "10.4.13",
"eslint": "8.32.0", "eslint": "8.33.0",
"eslint-config-airbnb-base": "15.0.0", "eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "8.6.0", "eslint-config-prettier": "8.6.0",
"eslint-config-react-app": "7.0.1", "eslint-config-react-app": "7.0.1",
"eslint-plugin-flowtype": "8.0.3", "eslint-plugin-flowtype": "8.0.3",
"eslint-plugin-import": "2.27.5", "eslint-plugin-import": "2.27.5",
"eslint-plugin-jsx-a11y": "6.7.1", "eslint-plugin-jsx-a11y": "6.7.1",
"eslint-plugin-react": "7.32.1", "eslint-plugin-react": "7.32.2",
"eslint-plugin-react-hooks": "4.6.0", "eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-simple-import-sort": "^9.0.0", "eslint-plugin-simple-import-sort": "^10.0.0",
"postcss": "8.4.21", "postcss": "8.4.21",
"postcss-import": "15.1.0", "postcss-import": "15.1.0",
"postcss-simple-vars": "^7.0.1", "postcss-simple-vars": "^7.0.1",

File diff suppressed because it is too large Load diff

View file

@ -50,3 +50,7 @@ swRegistration.register();
console.log('Checkout the repo: https://github.com/haishanh/yacd'); console.log('Checkout the repo: https://github.com/haishanh/yacd');
// eslint-disable-next-line // eslint-disable-next-line
console.log('Version:', __VERSION__); console.log('Version:', __VERSION__);
if (__COMMIT_HASH__) {
// eslint-disable-next-line
console.log('Commit hash:', __COMMIT_HASH__);
}

3
src/custom.d.ts vendored
View file

@ -16,12 +16,13 @@ interface Window {
i18n: any; i18n: any;
} }
// webpack definePlugin replacing variables
declare const __VERSION__: string; declare const __VERSION__: string;
declare const __COMMIT_HASH__: string;
declare const process = { declare const process = {
env: { env: {
NODE_ENV: string, NODE_ENV: string,
PUBLIC_URL: string, PUBLIC_URL: string,
COMMIT_HASH: string,
}, },
}; };

View file

@ -3,11 +3,6 @@ import LanguageDetector from 'i18next-browser-languagedetector';
import HttpBackend from 'i18next-http-backend'; import HttpBackend from 'i18next-http-backend';
import { initReactI18next } from 'react-i18next'; import { initReactI18next } from 'react-i18next';
const allLocales = {
zh: import('src/i18n/zh'),
en: import('src/i18n/en'),
};
type BackendRequestCallback = (err: null, result: { status: number; data: any }) => void; type BackendRequestCallback = (err: null, result: { status: number; data: any }) => void;
i18next i18next
@ -16,7 +11,6 @@ i18next
.use(LanguageDetector) .use(LanguageDetector)
.init({ .init({
debug: process.env.NODE_ENV === 'development', debug: process.env.NODE_ENV === 'development',
// resources,
backend: { backend: {
loadPath: '/__{{lng}}/{{ns}}.json', loadPath: '/__{{lng}}/{{ns}}.json',
request: function( request: function(
@ -30,11 +24,11 @@ i18next
switch (url) { switch (url) {
case '/__zh/translation.json': case '/__zh/translation.json':
case '/__zh-CN/translation.json': case '/__zh-CN/translation.json':
p = allLocales.zh; p = import('src/i18n/zh');
break; break;
case '/__en/translation.json': case '/__en/translation.json':
default: default:
p = allLocales.en; p = import('src/i18n/en');
break; break;
} }
@ -45,7 +39,6 @@ i18next
} }
}, },
}, },
supportedLngs: ['en', 'zh'],
fallbackLng: 'en', fallbackLng: 'en',
interpolation: { interpolation: {
escapeValue: false, escapeValue: false,

View file

@ -20,5 +20,5 @@
"noEmit": true, "noEmit": true,
"jsx": "react" "jsx": "react"
}, },
"include": ["./src"] "include": ["./src", "vite.config.ts"]
} }

View file

@ -1,13 +1,24 @@
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react'
import * as path from 'path'; import * as path from 'path';
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';
import * as pkg from './package.json'; import * as pkg from './package.json';
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({ export default defineConfig(async ({ mode }) => {
let hash = process.env.COMMIT_HASH;
if (!hash) {
try {
hash = await gitHash();
} catch (e) { }
}
if (!hash) hash = '';
return {
define: { define: {
__VERSION__: JSON.stringify(pkg.version), __VERSION__: JSON.stringify(pkg.version),
__COMMIT_HASH__: JSON.stringify(hash),
'process.env.NODE_ENV': JSON.stringify(mode), 'process.env.NODE_ENV': JSON.stringify(mode),
'process.env.PUBLIC_URL': JSON.stringify('./'), 'process.env.PUBLIC_URL': JSON.stringify('./'),
}, },
@ -36,4 +47,36 @@ export default defineConfig(({ mode }) => ({
base: './', base: './',
}), }),
], ],
})); }
});
// non vite stuff
async function gitHash() {
try {
const mod = await import('node:child_process');
return await run(mod.spawn, 'git', ['rev-parse', '--short', 'HEAD']);
} catch (e) {
return;
}
}
function run(spawn: typeof import('node:child_process').spawn, cmd0: string, args0: string[]): Promise<string> {
const cmd = cmd0;
const args = args0;
return new Promise((resolve, reject) => {
const proc = spawn(cmd, args);
let out = Buffer.from('');
proc.stdout.on('data', (data) => {
out += data;
});
proc.on('error', (err) => {
reject(err);
});
proc.on('exit', (code) => {
if (code !== 0) reject(code);
resolve(out.toString());
});
});
}