diff --git a/cli.json b/cli.json index 244a3c3..aac3483 100644 --- a/cli.json +++ b/cli.json @@ -62,6 +62,13 @@ } } }, + "deletePackage": { + "options": { + "appId": { + "hasValue": true + } + } + }, "publish": { "options": { "platform": { diff --git a/package.json b/package.json index 10c6d23..1da1c40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-update-cli", - "version": "2.0.1", + "version": "2.1.0", "description": "command line tool for react-native-update (remote updates for react native)", "main": "index.js", "bin": { diff --git a/src/locales/en.ts b/src/locales/en.ts index 68e8f57..844e7b1 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -131,4 +131,10 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks. unnamed: '(Unnamed)', dryRun: 'Below is the dry-run result, no actual operation will be performed:', usingCustomVersion: 'Using custom version: {{version}}', + confirmDeletePackage: + 'Confirm delete native package {{packageId}}? This operation cannot be undone (Y/N):', + deletePackageSuccess: 'Native package {{packageId}} deleted successfully', + deletePackageError: + 'Failed to delete native package {{packageId}}: {{error}}', + usageDeletePackage: 'Usage: cresc deletePackage [packageId] --appId [appId]', }; diff --git a/src/locales/zh.ts b/src/locales/zh.ts index acb5652..a14024a 100644 --- a/src/locales/zh.ts +++ b/src/locales/zh.ts @@ -124,4 +124,9 @@ export default { unnamed: '(未命名)', dryRun: '以下是 dry-run 模拟运行结果,不会实际执行任何操作:', usingCustomVersion: '使用自定义版本:{{version}}', + confirmDeletePackage: '确认删除原生包 {{packageId}}? 此操作不可撤销 (Y/N):', + deletePackageSuccess: '原生包 {{packageId}} 删除成功', + deletePackageError: '删除原生包 {{packageId}} 失败: {{error}}', + usageDeletePackage: + '使用方法: pushy deletePackage [packageId] --appId [appId]', }; diff --git a/src/package.ts b/src/package.ts index bc82fe7..1956d9a 100644 --- a/src/package.ts +++ b/src/package.ts @@ -1,4 +1,4 @@ -import { get, getAllPackages, post, uploadFile } from './api'; +import { get, getAllPackages, post, uploadFile, doDelete } from './api'; import { question, saveToLocal } from './utils'; import { t } from './utils/i18n'; @@ -212,4 +212,47 @@ export const packageCommands = { const { appId } = await getSelectedApp(platform); await listPackage(appId); }, + deletePackage: async ({ + args, + options, + }: { + args: string[]; + options: { appId?: string }; + }) => { + let packageId = args[0]; + let { appId } = options; + + if (!appId) { + const platform = await getPlatform(); + appId = (await getSelectedApp(platform)).appId as string; + } + + // If no packageId provided as argument, let user choose from list + if (!packageId) { + const selectedPackage = await choosePackage(appId); + packageId = selectedPackage.id; + } + + // Confirm deletion + // const confirmDelete = await question( + // t('confirmDeletePackage', { packageId }), + // ); + + // if ( + // confirmDelete.toLowerCase() !== 'y' && + // confirmDelete.toLowerCase() !== 'yes' + // ) { + // console.log(t('cancelled')); + // return; + // } + + try { + await doDelete(`/app/${appId}/package/${packageId}`); + console.log(t('deletePackageSuccess', { packageId })); + } catch (error: any) { + throw new Error( + t('deletePackageError', { packageId, error: error.message }), + ); + } + }, }; diff --git a/tsconfig.json b/tsconfig.json index f0a6d7e..6e99a87 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,8 @@ "target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */, "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, "lib": [ - "ESNext" + "ESNext", + "DOM" ] /* Specify library files to be included in the compilation. */, "allowJs": true /* Allow javascript files to be compiled. */, // "checkJs": true /* Report errors in .js files. */,