feat: migrated packages to ts

This commit is contained in:
Haoyu Xu
2025-05-02 02:27:42 +08:00
parent 0af0c785d4
commit 8f6f537c81
111 changed files with 3166 additions and 1155 deletions

View File

@@ -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: '^_' },
],
},
}
)

View File

@@ -4,13 +4,22 @@ import operators, {
OPERATOR_SOURCE_FOLDER,
generateAssetsJson,
} from '@aklive2d/operator'
import type { OperatorConfig } from '@aklive2d/operator/types'
import { DIST_DIR as ASSETS_DIST_DIR } from '@aklive2d/assets'
import { file, env } from '@aklive2d/libs'
import { files as backgroundFiles } from '@aklive2d/background'
import { mapping as musicMapping } from '@aklive2d/music'
import { defaultRegion } from '@aklive2d/charword-table'
import type { ProjectJSON } from '@aklive2d/project-json/types'
export const copyShowcaseData = (name, { dataDir, publicAssetsDir }) => {
interface DirectoryOperatorConfig extends OperatorConfig {
workshopId: string | null
}
export const copyShowcaseData = (
name: string,
{ dataDir, publicAssetsDir }: { dataDir: string; publicAssetsDir: string }
) => {
file.mkdir(publicAssetsDir)
const operatorAssetsDir = path.join(
ASSETS_DIST_DIR,
@@ -131,7 +140,10 @@ export const copyShowcaseData = (name, { dataDir, publicAssetsDir }) => {
return buildConfig
}
export const copyProjectJSON = (name, { releaseDir }) => {
export const copyProjectJSON = (
name: string,
{ releaseDir }: { releaseDir: string }
) => {
file.cpSync(
path.resolve(ASSETS_DIST_DIR, config.module.assets.project_json, name),
path.resolve(releaseDir),
@@ -141,7 +153,13 @@ export const copyProjectJSON = (name, { releaseDir }) => {
)
}
export const copyDirectoryData = async ({ dataDir, publicDir }) => {
export const copyDirectoryData = async ({
dataDir,
publicDir,
}: {
dataDir: string
publicDir: string
}) => {
file.mkdir(publicDir)
const extractedFolder = path.join(
OPERATOR_SOURCE_FOLDER,
@@ -151,32 +169,40 @@ export const copyDirectoryData = async ({ dataDir, publicDir }) => {
const sourceFolder = path.join(ASSETS_DIST_DIR)
const filesToCopy = Object.keys(operators)
const operatorConfig = Object.values(
Object.values(operators).reduce((acc, cur) => {
const date = cur.date
if (acc[date]) {
acc[date].push(cur)
} else {
acc[date] = [cur]
}
Object.values(operators).reduce(
(acc, cur) => {
const curD = cur as DirectoryOperatorConfig
const date = curD.date
cur.workshopId = null
try {
cur.workshopId = JSON.parse(
file.readSync(
path.join(
ASSETS_DIST_DIR,
config.module.assets.project_json,
cur.link,
config.module.project_json.project_json
)
curD.workshopId = null
const text = file.readSync(
path.join(
ASSETS_DIST_DIR,
config.module.assets.project_json,
cur.link,
config.module.project_json.project_json
)
).workshopid
} catch (e) {
console.log(`No workshop id for ${cur.link}!`, e)
}
)
if (!text) {
console.log(`No workshop id for ${cur.link}!`)
} else {
curD.workshopId = (
JSON.parse(text) as ProjectJSON
).workshopid
}
return acc
}, {})
if (acc[date]) {
acc[date].push(curD)
} else {
acc[date] = [curD]
}
return acc
},
{} as {
[date: string]: DirectoryOperatorConfig[]
}
)
).sort((a, b) => Date.parse(b[0].date) - Date.parse(a[0].date))
await Promise.all(
config.directory.error.files.map(async (key) => {

View File

@@ -3,7 +3,7 @@
"private": true,
"version": "0.0.0",
"license": "MIT",
"main": "index.js",
"main": "index.ts",
"type": "module",
"dependencies": {
"@aklive2d/eslint-config": "workspace:*",
@@ -16,7 +16,12 @@
"@aklive2d/prettier-config": "workspace:*",
"@aklive2d/charword-table": "workspace:*"
},
"peerDependencies": {
"globals": ">=16.0.0",
"typescript-eslint": ">=8.31.1",
"typescript": ">=5.8.2"
},
"scripts": {
"lint": "eslint \"*.js\" \"**/*.js\" && prettier --check ."
"lint": "eslint && prettier --check ."
}
}

View 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/**/*"]
}