Skip to content

Commit 5ff4298

Browse files
authored
Merge pull request #157 from TNG/add-formatting-and-linting-for-typescript
Add formatting and linting for typescript
2 parents a662318 + 4435bc4 commit 5ff4298

File tree

123 files changed

+14062
-11128
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+14062
-11128
lines changed

.github/workflows/eslint-prettier.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Lint TS
2+
on: [push, pull_request]
3+
jobs:
4+
lint-ts:
5+
runs-on: ubuntu-latest
6+
defaults:
7+
run:
8+
working-directory: ./WebUI
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-node@v4
12+
with:
13+
node-version: 20
14+
- run: npm ci
15+
- run: npm run lint:ci
16+
- run: npm run format:ci

WebUI/.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue}]
2+
charset = utf-8
3+
indent_size = 2
4+
indent_style = space
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+
8+
end_of_line = lf
9+
max_line_length = 100

WebUI/.prettierrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://json.schemastore.org/prettierrc",
3+
"semi": false,
4+
"singleQuote": true,
5+
"printWidth": 100
6+
}

WebUI/build/README.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22

33
## Fetch remote dependencies for build
44

5-
1. run ```npm install```
5+
1. run `npm install`
66
2. aquire windows libuv dlls, e.g. via miniforge:
77
- Install miniforge: https://github.com/conda-forge/miniforge
88
- Create a reference conda environment with libuv installed
9-
```
10-
conda create -n cp311_libuv python=3.11 libuv -y
11-
# copy the path to this conda env
12-
conda env list | findstr cp311_libuv
13-
```
14-
3. run ```npm run fetch-build-resources -- --conda_env_dir=$PATH_TO_CONDA_ENV```
9+
```
10+
conda create -n cp311_libuv python=3.11 libuv -y
11+
# copy the path to this conda env
12+
conda env list | findstr cp311_libuv
13+
```
14+
3. run `npm run fetch-build-resources -- --conda_env_dir=$PATH_TO_CONDA_ENV`
1515

1616
## decide for offline or online installer
1717

1818
### online installer
1919

20-
run
20+
run
21+
2122
```
2223
npm run prepare-build
2324
npm run build
@@ -28,6 +29,7 @@ npm run build
2829
**FIXME: offline scripts are missing**
2930

3031
run
32+
3133
```
3234
npm run prepare-build:${PLATFORM}-offline
3335
npm run build:${PLATFORM}-offline

WebUI/build/build-config.json

+4-14
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
{
2525
"from": "external/LlamaCPP",
2626
"to": "LlamaCPP",
27-
"filter": [
28-
"!__pycache__/"
29-
]
27+
"filter": ["!__pycache__/"]
3028
},
3129
{
3230
"from": "external/intel_extension_for_pytorch-2.3.110+xpu-cp311-cp311-win_amd64.whl",
@@ -77,27 +75,19 @@
7775
"directories": {
7876
"output": "../release"
7977
},
80-
"files": [
81-
"dist",
82-
"dist-electron"
83-
],
78+
"files": ["dist", "dist-electron"],
8479
"win": {
8580
"target": [
8681
{
8782
"target": "nsis",
88-
"arch": [
89-
"x64"
90-
]
83+
"arch": ["x64"]
9184
}
9285
],
9386
"verifyUpdateCodeSignature": false,
9487
"requestedExecutionLevel": "asInvoker",
9588
"icon": "app.ico",
9689
"artifactName": "${productName}-${version}.${ext}",
97-
"electronLanguages": [
98-
"en-US",
99-
"zh-CN"
100-
]
90+
"electronLanguages": ["en-US", "zh-CN"]
10191
},
10292
"nsis": {
10393
"license": "build/license.rtf",

WebUI/build/scripts/check-i18n.js

+48-48
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
// Usage: node check-i18n.js --i18n-dir=$DIR
22

3-
const fs = require('fs');
4-
const path = require('path');
5-
const argv = require('minimist')(process.argv.slice(2));
3+
const fs = require('fs')
4+
const path = require('path')
5+
const argv = require('minimist')(process.argv.slice(2))
66

7-
const i18nDirArg = argv.i18n_dir;
7+
const i18nDirArg = argv.i18n_dir
88
if (!i18nDirArg) {
9-
console.error('Usage: node check-i18n.js --i18n-dir=$DIR\n');
10-
process.exit(1);
9+
console.error('Usage: node check-i18n.js --i18n-dir=$DIR\n')
10+
process.exit(1)
1111
}
1212

13-
const i18nDir = path.resolve(i18nDirArg);
14-
const enData = JSON.parse(fs.readFileSync(path.join(i18nDir, 'en-US.json')));
15-
const keys = Object.keys(enData);
13+
const i18nDir = path.resolve(i18nDirArg)
14+
const enData = JSON.parse(fs.readFileSync(path.join(i18nDir, 'en-US.json')))
15+
const keys = Object.keys(enData)
1616

17-
const langs = fs.readdirSync(i18nDir).filter(f => f.endsWith('.json'));
18-
const missingKeys = {};
19-
const unusedKeys = {};
17+
const langs = fs.readdirSync(i18nDir).filter((f) => f.endsWith('.json'))
18+
const missingKeys = {}
19+
const unusedKeys = {}
2020

21-
langs.forEach(lang => {
22-
const data = JSON.parse(fs.readFileSync(path.join(i18nDir, lang)));
23-
keys.forEach(key => {
24-
if (!data[key]) {
25-
if (!missingKeys[lang]) {
26-
missingKeys[lang] = [];
27-
}
28-
missingKeys[lang].push(key);
29-
}
30-
});
31-
32-
Object.keys(data).forEach(key => {
33-
if (!keys.includes(key)) {
34-
if (!unusedKeys[lang]) {
35-
unusedKeys[lang] = [];
36-
}
37-
unusedKeys[lang].push(key);
38-
}
39-
});
21+
langs.forEach((lang) => {
22+
const data = JSON.parse(fs.readFileSync(path.join(i18nDir, lang)))
23+
keys.forEach((key) => {
24+
if (!data[key]) {
25+
if (!missingKeys[lang]) {
26+
missingKeys[lang] = []
27+
}
28+
missingKeys[lang].push(key)
29+
}
30+
})
4031

41-
if (missingKeys[lang]) {
42-
// print pretty
43-
// 5 entries per row
44-
const entriesPerRow = 5;
45-
const entries = missingKeys[lang];
46-
const rows = [];
47-
for (let i = 0; i < entries.length; i += entriesPerRow) {
48-
rows.push(entries.slice(i, i + entriesPerRow).join(', '));
49-
}
50-
console.log(`${missingKeys[lang].length} missing keys for ${lang}:`);
51-
console.log(` ${rows.join('\n ')}`);
52-
console.log();
32+
Object.keys(data).forEach((key) => {
33+
if (!keys.includes(key)) {
34+
if (!unusedKeys[lang]) {
35+
unusedKeys[lang] = []
36+
}
37+
unusedKeys[lang].push(key)
5338
}
54-
if (unusedKeys[lang]) {
55-
console.log(`${unusedKeys[lang].length} unused keys for ${lang}:`);
56-
console.log(` ${unusedKeys[lang].join(', ')}`);
57-
console.log();
39+
})
40+
41+
if (missingKeys[lang]) {
42+
// print pretty
43+
// 5 entries per row
44+
const entriesPerRow = 5
45+
const entries = missingKeys[lang]
46+
const rows = []
47+
for (let i = 0; i < entries.length; i += entriesPerRow) {
48+
rows.push(entries.slice(i, i + entriesPerRow).join(', '))
5849
}
59-
});
50+
console.log(`${missingKeys[lang].length} missing keys for ${lang}:`)
51+
console.log(` ${rows.join('\n ')}`)
52+
console.log()
53+
}
54+
if (unusedKeys[lang]) {
55+
console.log(`${unusedKeys[lang].length} unused keys for ${lang}:`)
56+
console.log(` ${unusedKeys[lang].join(', ')}`)
57+
console.log()
58+
}
59+
})
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,99 @@
11
// Usage: node fetch-python-package-resources.js --target-dir=$DIR --conda_env_dir=$DIR
2-
const https = require('https');
3-
const fs = require('fs');
4-
const path = require('path');
5-
const { HttpsProxyAgent } = require('https-proxy-agent');
2+
const https = require('https')
3+
const fs = require('fs')
4+
const path = require('path')
5+
const { HttpsProxyAgent } = require('https-proxy-agent')
66

7-
8-
const argv = require('minimist')(process.argv.slice(2));
7+
const argv = require('minimist')(process.argv.slice(2))
98
const targetDirArg = argv.target_dir
109
const condaEnvDirArg = argv.conda_env_dir
1110

1211
if (!targetDirArg || !condaEnvDirArg) {
13-
console.error('Usage: node fetch-python-package-resources.js --target_dir=$DIR --conda_env_dir=$DIR\n');
14-
process.exit(1);
12+
console.error(
13+
'Usage: node fetch-python-package-resources.js --target_dir=$DIR --conda_env_dir=$DIR\n',
14+
)
15+
process.exit(1)
1516
}
1617

17-
const targetDir = path.resolve(targetDirArg);
18+
const targetDir = path.resolve(targetDirArg)
1819
const condaTargetDir = path.join(targetDir, 'conda-env-lib')
19-
const condaEnvLibraryDir = path.resolve(path.join(condaEnvDirArg, 'Library'));
20+
const condaEnvLibraryDir = path.resolve(path.join(condaEnvDirArg, 'Library'))
2021

21-
const embeddablePythonUrl = 'https://raw.githubusercontent.com/adang1345/PythonWindows/master/3.11.10/python-3.11.10-embed-amd64.zip';
22+
const embeddablePythonUrl =
23+
'https://raw.githubusercontent.com/adang1345/PythonWindows/master/3.11.10/python-3.11.10-embed-amd64.zip'
2224
const getPipScriptUrl = 'https://bootstrap.pypa.io/get-pip.py'
2325
const sevenZrExeUrl = 'https://www.7-zip.org/a/7zr.exe'
2426

2527
function fetchFileIfNotPresent(url) {
26-
const expectedFilePath = path.join(targetDir, getBaseFileName(url))
27-
if (fs.existsSync(expectedFilePath)) {
28-
console.log(`omitting fetching of ${url} as ${expectedFilePath} already exists`)
29-
} else {
30-
fetchFile(url)
31-
}
28+
const expectedFilePath = path.join(targetDir, getBaseFileName(url))
29+
if (fs.existsSync(expectedFilePath)) {
30+
console.log(`omitting fetching of ${url} as ${expectedFilePath} already exists`)
31+
} else {
32+
fetchFile(url)
33+
}
3234
}
3335

3436
function fetchFile(url) {
35-
const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy;
36-
const options = proxy ? { agent: new HttpsProxyAgent(proxy) } : {};
37-
https.get(url, options, (response) => {
38-
const filePath = path.join(targetDir, getBaseFileName(url))
39-
const file = fs.createWriteStream(filePath);
40-
response.pipe(file);
37+
const proxy =
38+
process.env.HTTPS_PROXY ||
39+
process.env.https_proxy ||
40+
process.env.HTTP_PROXY ||
41+
process.env.http_proxy
42+
const options = proxy ? { agent: new HttpsProxyAgent(proxy) } : {}
43+
https
44+
.get(url, options, (response) => {
45+
const filePath = path.join(targetDir, getBaseFileName(url))
46+
const file = fs.createWriteStream(filePath)
47+
response.pipe(file)
4148

42-
file.on('finish', () => {
43-
file.close();
44-
console.log(`Downloaded ${filePath} successfully!`);
45-
});
46-
}).on('error', (err) => {
47-
console.error(`Error downloading ${embeddablePythonUrl}: ${err}`);
48-
});
49+
file.on('finish', () => {
50+
file.close()
51+
console.log(`Downloaded ${filePath} successfully!`)
52+
})
53+
})
54+
.on('error', (err) => {
55+
console.error(`Error downloading ${embeddablePythonUrl}: ${err}`)
56+
})
4957
}
5058

51-
5259
function getBaseFileName(url) {
53-
const urlPathSegments = url.split('/');
54-
const baseFileName = urlPathSegments[urlPathSegments.length - 1]
55-
return baseFileName;
60+
const urlPathSegments = url.split('/')
61+
const baseFileName = urlPathSegments[urlPathSegments.length - 1]
62+
return baseFileName
5663
}
5764

5865
function prepareTargetPath() {
59-
if (!fs.existsSync(condaTargetDir)) {
60-
fs.mkdirSync(targetDir, { recursive: true });
61-
}
66+
if (!fs.existsSync(condaTargetDir)) {
67+
fs.mkdirSync(targetDir, { recursive: true })
68+
}
6269
}
6370

6471
function copyLibuvDllsIfNotPresent() {
65-
if (fs.existsSync(path.join(condaTargetDir, 'Library', 'bin', 'uv.dll'))) {
66-
console.log(`omitting fetching copying of libuv DLLs, as they already exist`)
67-
} else {
68-
if (!path.join(condaEnvLibraryDir, 'bin', 'uv.dll')) {
69-
console.log(`provided conda env at ${condaEnvLibraryDir} is missing uv.dll. Aborting`)
70-
process.exit(1);
71-
}
72-
fs.cp(condaEnvLibraryDir, path.join(condaTargetDir, 'Library'), { recursive: true }, (err) => {
73-
if (err) {
74-
console.error(err);
75-
console.log('Failed to copy directory');
76-
process.exit(1)
77-
} else {
78-
console.log('Directory copied successfully');
79-
}
80-
});
72+
if (fs.existsSync(path.join(condaTargetDir, 'Library', 'bin', 'uv.dll'))) {
73+
console.log(`omitting fetching copying of libuv DLLs, as they already exist`)
74+
} else {
75+
if (!path.join(condaEnvLibraryDir, 'bin', 'uv.dll')) {
76+
console.log(`provided conda env at ${condaEnvLibraryDir} is missing uv.dll. Aborting`)
77+
process.exit(1)
8178
}
79+
fs.cp(condaEnvLibraryDir, path.join(condaTargetDir, 'Library'), { recursive: true }, (err) => {
80+
if (err) {
81+
console.error(err)
82+
console.log('Failed to copy directory')
83+
process.exit(1)
84+
} else {
85+
console.log('Directory copied successfully')
86+
}
87+
})
88+
}
8289
}
8390

84-
8591
function main() {
86-
prepareTargetPath()
87-
fetchFileIfNotPresent(embeddablePythonUrl)
88-
fetchFileIfNotPresent(getPipScriptUrl)
89-
fetchFileIfNotPresent(sevenZrExeUrl)
90-
copyLibuvDllsIfNotPresent()
92+
prepareTargetPath()
93+
fetchFileIfNotPresent(embeddablePythonUrl)
94+
fetchFileIfNotPresent(getPipScriptUrl)
95+
fetchFileIfNotPresent(sevenZrExeUrl)
96+
copyLibuvDllsIfNotPresent()
9197
}
9298

9399
main()

0 commit comments

Comments
 (0)