feat: migrated packages to ts
This commit is contained in:
@@ -1,3 +1,27 @@
|
||||
import baseConfig from '@aklive2d/eslint-config'
|
||||
import { tsConfig } from '@aklive2d/eslint-config'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import globals from 'globals'
|
||||
|
||||
/** @type {import('eslint').Config} */
|
||||
export default [...baseConfig]
|
||||
export default tseslint.config(
|
||||
...tsConfig,
|
||||
{
|
||||
ignores: ['dist', 'data'],
|
||||
},
|
||||
{
|
||||
files: ['**/*.js', '**/*.ts'],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2022,
|
||||
globals: {
|
||||
...globals.node,
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'error',
|
||||
{ argsIgnorePattern: '^_' },
|
||||
],
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -5,7 +5,16 @@ import { pipeline } from 'node:stream/promises'
|
||||
import pThrottle from 'p-throttle'
|
||||
import { file as fileLib } from '@aklive2d/libs'
|
||||
|
||||
export const githubDownload = async (history_url, raw_url, filepath) => {
|
||||
export type UnzipDownloadItem = {
|
||||
name: string
|
||||
url: string
|
||||
}
|
||||
|
||||
export const githubDownload = async (
|
||||
history_url: string,
|
||||
raw_url: string,
|
||||
filepath: string
|
||||
) => {
|
||||
const historyResponse = await fetch(history_url)
|
||||
const historyData = await historyResponse.json()
|
||||
const lastCommit = historyData[0]
|
||||
@@ -21,7 +30,8 @@ export const githubDownload = async (history_url, raw_url, filepath) => {
|
||||
|
||||
if (fileLib.exists(filepath)) {
|
||||
console.log(`${basename} is the latest version.`)
|
||||
return JSON.parse(fileLib.readSync(filepath))
|
||||
const content = fileLib.readSync(filepath)
|
||||
return content ? JSON.parse(content) : null
|
||||
}
|
||||
const response = await fetch(raw_url)
|
||||
const data = await response.json()
|
||||
@@ -39,9 +49,12 @@ export const githubDownload = async (history_url, raw_url, filepath) => {
|
||||
}
|
||||
|
||||
export const unzipDownload = async (
|
||||
filesToDownload,
|
||||
targetDir,
|
||||
opts = {
|
||||
filesToDownload: UnzipDownloadItem[],
|
||||
targetDir: string,
|
||||
opts: {
|
||||
defaultRegex: RegExp | null
|
||||
matchRegExps: RegExp[]
|
||||
} = {
|
||||
defaultRegex: null,
|
||||
matchRegExps: [],
|
||||
}
|
||||
@@ -52,7 +65,7 @@ export const unzipDownload = async (
|
||||
interval: 1000,
|
||||
})
|
||||
while (retry.length > 0) {
|
||||
const newRetry = []
|
||||
const newRetry: UnzipDownloadItem[] = []
|
||||
await Promise.all(
|
||||
retry.map(
|
||||
throttle(async (item) => {
|
||||
@@ -72,7 +85,9 @@ export const unzipDownload = async (
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
return null
|
||||
})
|
||||
if (!zip) return
|
||||
try {
|
||||
for await (const entry of zip) {
|
||||
if (
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "@aklive2d/downloader",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"main": "index.js",
|
||||
"main": "index.ts",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@aklive2d/eslint-config": "workspace:*",
|
||||
@@ -11,6 +11,6 @@
|
||||
"p-throttle": "^7.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint \"*.js\" \"**/*.js\" && prettier --check ."
|
||||
"lint": "eslint && prettier --check ."
|
||||
}
|
||||
}
|
||||
|
||||
25
packages/downloader/tsconfig.json
Normal file
25
packages/downloader/tsconfig.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2024",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2024", "DOM", "DOM.Iterable"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["**/*"],
|
||||
"exclude": ["dist/**/*", "data/**/*"]
|
||||
}
|
||||
Reference in New Issue
Block a user