From b24b27d1008d15ddff7f967c70ba6c05ef849ca7 Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Sat, 11 Jan 2025 20:23:25 +0800 Subject: [PATCH] ts --- biome.json | 3 ++- src/{package.js => package.ts} | 21 ++++++++++----------- src/{user.js => user.ts} | 4 ++-- src/utils/{index.js => index.ts} | 7 ++++--- 4 files changed, 18 insertions(+), 17 deletions(-) rename src/{package.js => package.ts} (92%) rename src/{user.js => user.ts} (91%) rename src/utils/{index.js => index.ts} (97%) diff --git a/biome.json b/biome.json index 40e85ab..4dee737 100644 --- a/biome.json +++ b/biome.json @@ -8,7 +8,8 @@ "recommended": true, "suspicious": { "noExplicitAny": "off", - "noAssignInExpressions": "off" + "noAssignInExpressions": "off", + "noDoubleEquals": "off" }, "style": { "noNonNullAssertion": "off" diff --git a/src/package.js b/src/package.ts similarity index 92% rename from src/package.js rename to src/package.ts index a60986e..24cba04 100644 --- a/src/package.js +++ b/src/package.ts @@ -6,7 +6,7 @@ import { checkPlatform, getSelectedApp } from './app'; import { getApkInfo, getIpaInfo, getAppInfo } from './utils'; import Table from 'tty-table'; -export async function listPackage(appId) { +export async function listPackage(appId: string) { const { data } = await get(`/app/${appId}/package/list?limit=1000`); const header = [{ value: '原生包 Id' }, { value: '原生版本' }]; @@ -35,12 +35,12 @@ export async function listPackage(appId) { return data; } -export async function choosePackage(appId) { +export async function choosePackage(appId: string) { const list = await listPackage(appId); while (true) { const id = await question('输入原生包 id:'); - const app = list.find((v) => v.id === (id | 0)); + const app = list.find((v) => v.id === Number(id)); if (app) { return app; } @@ -48,7 +48,7 @@ export async function choosePackage(appId) { } export const commands = { - uploadIpa: async function ({ args }) { + uploadIpa: async ({ args }: { args: string[] }) => { const fn = args[0]; if (!fn || !fn.endsWith('.ipa')) { throw new Error('使用方法: pushy uploadIpa ipa后缀文件'); @@ -85,7 +85,7 @@ export const commands = { `已成功上传ipa原生包(id: ${id}, version: ${versionName}, buildTime: ${buildTime})`, ); }, - uploadApk: async function ({ args }) { + uploadApk: async ({ args }) => { const fn = args[0]; if (!fn || !fn.endsWith('.apk')) { throw new Error('使用方法: pushy uploadApk apk后缀文件'); @@ -122,7 +122,7 @@ export const commands = { `已成功上传apk原生包(id: ${id}, version: ${versionName}, buildTime: ${buildTime})`, ); }, - uploadApp: async function ({ args }) { + uploadApp: async ({ args }) => { const fn = args[0]; if (!fn || !fn.endsWith('.app')) { throw new Error('使用方法: pushy uploadApp app后缀文件'); @@ -134,7 +134,6 @@ export const commands = { appKey: appKeyInPkg, } = await getAppInfo(fn); const { appId, appKey } = await getSelectedApp('harmony'); - if (appIdInPkg && appIdInPkg != appId) { throw new Error( @@ -160,28 +159,28 @@ export const commands = { `已成功上传app原生包(id: ${id}, version: ${versionName}, buildTime: ${buildTime})`, ); }, - parseApp: async function ({ args }) { + parseApp: async ({ args }) => { const fn = args[0]; if (!fn || !fn.endsWith('.app')) { throw new Error('使用方法: pushy parseApp app后缀文件'); } console.log(await getAppInfo(fn)); }, - parseIpa: async function ({ args }) { + parseIpa: async ({ args }) => { const fn = args[0]; if (!fn || !fn.endsWith('.ipa')) { throw new Error('使用方法: pushy parseIpa ipa后缀文件'); } console.log(await getIpaInfo(fn)); }, - parseApk: async function ({ args }) { + parseApk: async ({ args }) => { const fn = args[0]; if (!fn || !fn.endsWith('.apk')) { throw new Error('使用方法: pushy parseApk apk后缀文件'); } console.log(await getApkInfo(fn)); }, - packages: async function ({ options }) { + packages: async ({ options }) => { const platform = checkPlatform( options.platform || (await question('平台(ios/android/harmony):')), ); diff --git a/src/user.js b/src/user.ts similarity index 91% rename from src/user.js rename to src/user.ts index 563d318..9079bd9 100644 --- a/src/user.js +++ b/src/user.ts @@ -2,12 +2,12 @@ import { question } from './utils'; import { post, get, replaceSession, saveSession, closeSession } from './api'; import crypto from 'node:crypto'; -function md5(str) { +function md5(str: string) { return crypto.createHash('md5').update(str).digest('hex'); } export const commands = { - login: async ({ args }) => { + login: async ({ args }: { args: string[] }) => { const email = args[0] || (await question('email:')); const pwd = args[1] || (await question('password:', true)); const { token, info } = await post('/user/login', { diff --git a/src/utils/index.js b/src/utils/index.ts similarity index 97% rename from src/utils/index.js rename to src/utils/index.ts index a27294e..c191263 100644 --- a/src/utils/index.js +++ b/src/utils/index.ts @@ -25,8 +25,9 @@ export function translateOptions(options) { for (const key in options) { const v = options[key]; if (typeof v === 'string') { - ret[key] = v.replace(/\$\{(\w+)\}/g, (v, n) => - options[n] || process.env[n] || v, + ret[key] = v.replace( + /\$\{(\w+)\}/g, + (v, n) => options[n] || process.env[n] || v, ); } else { ret[key] = v; @@ -124,7 +125,7 @@ export async function getAppInfo(fn) { return { versionName, buildTime, ...appCredential }; } -export async function getIpaInfo(fn) { +export async function getIpaInfo(fn: string) { const appInfoParser = new AppInfoParser(fn); const bundleFile = await appInfoParser.parser.getEntry( /payload\/.+?\.app\/main.jsbundle/,