Skip to content

Commit d9d492f

Browse files
uioleeRitsuka314
andauthored
refactor: drop old interface and fix test code (#58)
* refactor * test code * eslint * gitignore * update package.json * sort package.json * docs: update * ci: add linter, tester --------- Signed-off-by: Ritsuka <[email protected]> Co-authored-by: Ritsuka <[email protected]>
1 parent 61a55dd commit d9d492f

19 files changed

+1812
-415
lines changed

.eslintrc.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"root": true,
3+
"env": {
4+
"commonjs": true,
5+
"es2021": true,
6+
"node": true
7+
},
8+
"parserOptions": {
9+
"ecmaVersion": "latest"
10+
},
11+
"extends": ["hexo"],
12+
"overrides": [
13+
{
14+
"files": ["test/**"],
15+
"extends": ["hexo", "hexo/test"]
16+
}
17+
],
18+
"rules": {
19+
"linebreak-style": ["error", "unix"]
20+
}
21+
}

.github/workflows/install-pandoc.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
const { exec } = require('node:child_process');
4+
5+
const platform = process.env.runner_os;
6+
let cmdStr = '';
7+
8+
const installPandoc = cmdStr => {
9+
exec(
10+
cmdStr.trim(),
11+
{
12+
cwd: process.cwd(),
13+
env: process.env,
14+
encoding: 'utf8',
15+
timeout: 300000
16+
},
17+
(error, stdout, stderr) => {
18+
console.log(`install stdout: ${stdout}`);
19+
console.error(`install stderr: ${stderr}`);
20+
if (error) {
21+
console.error(`install error: ${error}`);
22+
throw Error(`install error: ${error}`);
23+
}
24+
}
25+
);
26+
};
27+
28+
switch (String(platform).trim().toLowerCase()) {
29+
case 'linux':
30+
console.info(`Install pandoc for ${platform}`);
31+
cmdStr = 'sudo apt install pandoc -y';
32+
installPandoc(cmdStr);
33+
break;
34+
case 'windows':
35+
console.info(`Install pandoc for ${platform}`);
36+
cmdStr
37+
= 'choco install -y --no-progress --timeout 270 pandoc';
38+
installPandoc(cmdStr);
39+
break;
40+
case 'macos':
41+
console.info(`Install pandoc for ${platform}`);
42+
cmdStr = 'brew install pandoc';
43+
installPandoc(cmdStr);
44+
break;
45+
default:
46+
console.error(`Unsupport platform: ${platform}`);
47+
throw Error(`Unsupport platform: ${platform}`);
48+
}

.github/workflows/linter.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: linter
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
paths:
7+
- "lib/**"
8+
- "test/**"
9+
- ".github/workflows/linter.yml"
10+
pull_request:
11+
paths:
12+
- "lib/**"
13+
- "test/**"
14+
- ".github/workflows/linter.yml"
15+
16+
env:
17+
CI: true
18+
19+
jobs:
20+
linter:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v3
24+
25+
- uses: actions/setup-node@v3
26+
with:
27+
node-version: "lts/*"
28+
29+
- name: Get npm cache directory
30+
id: npm-cache-dir
31+
shell: bash
32+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
33+
34+
- uses: actions/cache@v3
35+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
36+
with:
37+
path: ${{ steps.npm-cache-dir.outputs.dir }}
38+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
39+
restore-keys: |
40+
${{ runner.os }}-node-
41+
42+
- name: Install Dependencies
43+
run: npm i
44+
45+
- name: Test
46+
run: npm run lint

.github/workflows/tester.yml

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: tester
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
paths:
7+
- "lib/**"
8+
- "test/**"
9+
- "package.json"
10+
- ".github/workflows/tester.yml"
11+
pull_request:
12+
paths:
13+
- "lib/**"
14+
- "test/**"
15+
- "package.json"
16+
- ".github/workflows/tester.yml"
17+
18+
env:
19+
CI: true
20+
21+
jobs:
22+
tester:
23+
runs-on: ${{ matrix.os }}
24+
strategy:
25+
matrix:
26+
os: [ubuntu-latest, windows-latest, macos-latest]
27+
node-version: [14, 16, 18]
28+
fail-fast: false
29+
30+
steps:
31+
- uses: actions/checkout@v3
32+
33+
- uses: actions/setup-node@v3
34+
with:
35+
node-version: ${{ matrix.node-version }}
36+
37+
- name: Install pandoc
38+
env:
39+
runner_os: ${{runner.os}}
40+
run: node .github/workflows/install-pandoc.js
41+
42+
- name: Get npm cache directory
43+
id: npm-cache-dir
44+
shell: bash
45+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
46+
47+
- uses: actions/cache@v3
48+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
49+
with:
50+
path: ${{ steps.npm-cache-dir.outputs.dir }}
51+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
52+
restore-keys: |
53+
${{ runner.os }}-node-
54+
55+
- name: Install Dependencies
56+
run: npm i
57+
58+
- name: Test
59+
run: npm run test
60+
61+
coverage:
62+
runs-on: ${{ matrix.os }}
63+
strategy:
64+
matrix:
65+
os: [ubuntu-latest]
66+
node-version: ["lts/*"]
67+
68+
steps:
69+
- uses: actions/checkout@v3
70+
71+
- uses: actions/setup-node@v3
72+
with:
73+
node-version: ${{ matrix.node-version }}
74+
75+
- name: Install pandoc
76+
env:
77+
runner_os: ${{runner.os}}
78+
run: node .github/workflows/install-pandoc.js
79+
80+
- name: Get npm cache directory
81+
id: npm-cache-dir
82+
shell: bash
83+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
84+
85+
- uses: actions/cache@v3
86+
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
87+
with:
88+
path: ${{ steps.npm-cache-dir.outputs.dir }}
89+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
90+
restore-keys: |
91+
${{ runner.os }}-node-
92+
93+
- name: Install Dependencies
94+
run: npm i
95+
96+
- name: Test
97+
run: npm run test-cov
98+
99+
- uses: coverallsapp/github-action@v2
100+
with:
101+
github-token: ${{ secrets.github_token }}

.gitignore

+6-121
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
# Vim files
2-
*.swo
3-
*.swp
4-
5-
# Created by https://www.toptal.com/developers/gitignore/api/node,webstorm
6-
# Edit at https://www.toptal.com/developers/gitignore?templates=node,webstorm
1+
# Created by https://www.toptal.com/developers/gitignore/api/node
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=node
73

84
### Node ###
95
# Logs
@@ -145,118 +141,7 @@ dist
145141
# SvelteKit build / generate output
146142
.svelte-kit
147143

148-
### WebStorm ###
149-
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
150-
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
151-
152-
# User-specific stuff
153-
.idea/**/workspace.xml
154-
.idea/**/tasks.xml
155-
.idea/**/usage.statistics.xml
156-
.idea/**/dictionaries
157-
.idea/**/shelf
158-
159-
# AWS User-specific
160-
.idea/**/aws.xml
161-
162-
# Generated files
163-
.idea/**/contentModel.xml
164-
165-
# Sensitive or high-churn files
166-
.idea/**/dataSources/
167-
.idea/**/dataSources.ids
168-
.idea/**/dataSources.local.xml
169-
.idea/**/sqlDataSources.xml
170-
.idea/**/dynamic.xml
171-
.idea/**/uiDesigner.xml
172-
.idea/**/dbnavigator.xml
173-
174-
# Gradle
175-
.idea/**/gradle.xml
176-
.idea/**/libraries
177-
178-
# Gradle and Maven with auto-import
179-
# When using Gradle or Maven with auto-import, you should exclude module files,
180-
# since they will be recreated, and may cause churn. Uncomment if using
181-
# auto-import.
182-
# .idea/artifacts
183-
# .idea/compiler.xml
184-
# .idea/jarRepositories.xml
185-
# .idea/modules.xml
186-
# .idea/*.iml
187-
# .idea/modules
188-
# *.iml
189-
# *.ipr
190-
191-
# CMake
192-
cmake-build-*/
193-
194-
# Mongo Explorer plugin
195-
.idea/**/mongoSettings.xml
196-
197-
# File-based project format
198-
*.iws
199-
200-
# IntelliJ
201-
out/
202-
203-
# mpeltonen/sbt-idea plugin
204-
.idea_modules/
205-
206-
# JIRA plugin
207-
atlassian-ide-plugin.xml
208-
209-
# Cursive Clojure plugin
210-
.idea/replstate.xml
211-
212-
# SonarLint plugin
213-
.idea/sonarlint/
214-
215-
# Crashlytics plugin (for Android Studio and IntelliJ)
216-
com_crashlytics_export_strings.xml
217-
crashlytics.properties
218-
crashlytics-build.properties
219-
fabric.properties
220-
221-
# Editor-based Rest Client
222-
.idea/httpRequests
223-
224-
# Android studio 3.1+ serialized cache file
225-
.idea/caches/build_file_checksums.ser
226-
227-
### WebStorm Patch ###
228-
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
229-
230-
# *.iml
231-
# modules.xml
232-
# .idea/misc.xml
233-
# *.ipr
234-
235-
# Sonarlint plugin
236-
# https://plugins.jetbrains.com/plugin/7973-sonarlint
237-
.idea/**/sonarlint/
238-
239-
# SonarQube Plugin
240-
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
241-
.idea/**/sonarIssues.xml
242-
243-
# Markdown Navigator plugin
244-
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
245-
.idea/**/markdown-navigator.xml
246-
.idea/**/markdown-navigator-enh.xml
247-
.idea/**/markdown-navigator/
248-
249-
# Cache file creation bug
250-
# See https://youtrack.jetbrains.com/issue/JBR-2257
251-
.idea/$CACHE_FILE$
252-
253-
# CodeStream plugin
254-
# https://plugins.jetbrains.com/plugin/12206-codestream
255-
.idea/codestream.xml
256-
257-
# Azure Toolkit for IntelliJ plugin
258-
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
259-
.idea/**/azureSettings.xml
260-
261-
# End of https://www.toptal.com/developers/gitignore/api/node,webstorm
262-
144+
# End of https://www.toptal.com/developers/gitignore/api/node
145+
146+
.idea
147+
.vscode

.idea/.gitignore

-5
This file was deleted.

.idea/hexo-renderer-pandoc.iml

-13
This file was deleted.

.idea/modules.xml

-8
This file was deleted.

.idea/vcs.xml

-6
This file was deleted.

.mocharc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
timeout: 10000

0 commit comments

Comments
 (0)