Skip to content

Commit 1afc0eb

Browse files
MenciEnter-tainer
authored andcommitted
refactor: migrate NPM to Yarn and add TypeScript and Prettier
1 parent 0bcb7c6 commit 1afc0eb

27 files changed

+7791
-23115
lines changed

.bashrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ alias wiki-upd='export LC_ALL=C.UTF-8 && cd /OI-wiki && git pull origin master'
8787
alias wiki-theme='export LC_ALL=C.UTF-8 && cd /OI-wiki && chmod +x ./scripts/build.sh && ./scripts/build.sh'
8888
alias wiki-bld='export LC_ALL=C.UTF-8 && cd /OI-wiki && mkdocs build -v'
8989
alias wiki-svr='export LC_ALL=C.UTF-8 && cd /OI-wiki && mkdocs serve -v'
90-
alias wiki-bld-math='export LC_ALL=C.UTF-8 && cd /OI-wiki && mkdocs build -v && find ./site -type f -name "*.html" -exec node --max_old_space_size=512 ./scripts/render_math.js {} \;'
91-
alias wiki-o='export LC_ALL=C.UTF-8 && cd /OI-wiki && remark ./docs -o --silent'
90+
alias wiki-bld-math='export LC_ALL=C.UTF-8 && cd /OI-wiki && mkdocs build -v && env NODE_OPTIONS="--max_old_space_size=3072" yarn ts-node-esm ./scripts/render_math.ts'
91+
alias wiki-o='export LC_ALL=C.UTF-8 && cd /OI-wiki && yarn remark ./docs -o --silent'
9292

9393
# Alias definitions.
9494
# You may want to put all your additions into a separate file like

.github/CODEOWNERS

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.github/pull_request_template.md @Ir1d
77
.github/workflows/build-pdf.yml @Enter-tainer
88
.github/workflows/build.yml @billchenchina
9+
.github/workflows/build-authors-cache.yml @Menci
910
.github/workflows/celebration.yml @ouuan
1011
.github/workflows/pr-stale.yml @CoelacanthusHex
1112
.github/ISSUE_TEMPLATE/ @Ir1d
@@ -14,12 +15,14 @@
1415
Dockerfile @CoelacanthusHex
1516
docs/intro/docker-deploy.md @CoelacanthusHex
1617
scripts/ @Ir1d @billchenchina
18+
.prettierrc @Menci
1719
.clang-format @Ir1d
1820
.remarkignore @Enter-tainer
1921
.remarkrc @Ir1d @Enter-tainer
2022
CODE_OF_CONDUCT.md @Ir1d
2123
README.md @Ir1d
22-
gulpfile.js @Ir1d @Enter-tainer
24+
gulpfile.cjs @Ir1d @Enter-tainer
2325
package.json @Ir1d @Enter-tainer
2426
requirements.txt @Ir1d
2527
runtime.txt @Irld
28+
tsconfig.json @Menci

.github/workflows/build-authors-cache.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ jobs:
2222
id: cache
2323
with:
2424
path: node_modules
25-
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
25+
key: ${{ runner.os }}-node-${{ hashFiles('yarn.lock') }}
2626
restore-keys: ${{ runner.os }}-node-
2727
- name: Install Dependencies
2828
if: steps.cache.outputs.cache-hit != 'true'
29-
run: npm install
29+
run: yarn --frozen-lockfile --production
3030
- name: Fetch Authors
3131
run: |
3232
rm -rf authors.json
3333
3434
# Fetch authors list with 10 concurrency requests
35-
node scripts/fetch-authors.js 10
35+
yarn ts-node-esm scripts/update-authors-cache.ts 10
3636
env:
3737
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3838
- name: Commit Authors Cache

.github/workflows/build.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,25 @@ jobs:
3131
id: cache-node
3232
with:
3333
path: node_modules
34-
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
34+
key: ${{ runner.os }}-node-${{ hashFiles('yarn.lock') }}
3535
restore-keys: ${{ runner.os }}-node-
3636
- name: Install Node.js dependencies
3737
if: steps.cache-node.outputs.cache-hit != 'true'
38-
run: npm install
38+
run: yarn --frozen-lockfile --production
3939
- name: Page Build
4040
run: |
4141
chmod +x ./scripts/build.sh && ./scripts/build.sh
4242
mkdocs build -v
43-
- name: Render git history info
44-
run: ./scripts/render_git_history_info.sh
43+
- name: Render commits info
44+
run: ./scripts/render-commits-info.sh
4545
env:
4646
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4747
- name: Render math
48-
run: node --max_old_space_size=3072 ./scripts/render_math.js
48+
run: yarn ts-node-esm ./scripts/render_math.ts
49+
env:
50+
NODE_OPTIONS: --max_old_space_size=3072
4951
- name: Gulp minify
50-
run: npx gulp minify
52+
run: yarn gulp -f gulpfile.cjs minify
5153
- name: Generate redirects
5254
run: python scripts/gen_redirect.py
5355
- name: Deploy to gh-pages

.github/workflows/check-scripts.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Check Scripts
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
paths:
8+
- scripts/**
9+
- package.json
10+
- yarn.lock
11+
- .prettierrc
12+
- tsconfig.json
13+
workflow_dispatch:
14+
15+
jobs:
16+
build:
17+
name: Check Scripts
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v2
21+
- uses: actions/setup-node@v2
22+
with:
23+
node-version: '18.x'
24+
check-latest: true
25+
- name: Cache Node.js dependencies
26+
uses: actions/cache@v2
27+
id: cache-node
28+
with:
29+
path: node_modules
30+
key: ${{ runner.os }}-node-${{ hashFiles('yarn.lock') }}
31+
restore-keys: ${{ runner.os }}-node-
32+
- name: Install Node.js dependencies
33+
if: steps.cache-node.outputs.cache-hit != 'true'
34+
run: yarn --frozen-lockfile
35+
- name: Check Prettier Format
36+
run: yarn scripts:format:check
37+
- name: Check TypeScript Compile
38+
run: yarn tsc

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"endOfLine": "lf",
3+
"printWidth": 120,
4+
"arrowParens": "avoid",
5+
"trailingComma": "none"
6+
}

CODE_OF_CONDUCT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ members of the project's leadership.
6767

6868
## Attribution
6969

70-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
70+
This Code of Conduct is adapted from the[Contributor Covenant][homepage], version 1.4,
7171
available at <https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>
7272

7373
[homepage]: https://www.contributor-covenant.org

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ WORKDIR /
66
RUN apt-get update \
77
&& apt-get install -y git wget curl python3 python3-pip gcc g++ make \
88
&& curl https://bootstrap.pypa.io/get-pip.py | python3 \
9-
&& curl -sL https://deb.nodesource.com/setup_10.x | bash - \
9+
&& curl -sL https://deb.nodesource.com/setup_18.x | bash - \
1010
&& apt-get install -y nodejs
1111

1212
# If you can't connect to GitHub, set WIKI_REPO to any mirror repo.
1313
RUN git clone ${WIKI_REPO:-https://github.com/OI-wiki/OI-wiki.git} --depth=1 \
1414
&& cd OI-wiki \
1515
&& pip install -U -r requirements.txt \
16-
&& npm install
16+
&& yarn --frozen-lockfile
1717

1818
ADD .bashrc /root/
1919

gulpfile.js gulpfile.cjs

File renamed without changes.

0 commit comments

Comments
 (0)