Skip to content

Commit a446771

Browse files
committed
Add deletePackage command with confirmation and error handling; update version to 2.1.0 and enhance localization for delete operations
1 parent cd89034 commit a446771

File tree

6 files changed

+65
-3
lines changed

6 files changed

+65
-3
lines changed

cli.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@
6262
}
6363
}
6464
},
65+
"deletePackage": {
66+
"options": {
67+
"appId": {
68+
"hasValue": true
69+
}
70+
}
71+
},
6572
"publish": {
6673
"options": {
6774
"platform": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-update-cli",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "command line tool for react-native-update (remote updates for react native)",
55
"main": "index.js",
66
"bin": {

src/locales/en.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,10 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
131131
unnamed: '(Unnamed)',
132132
dryRun: 'Below is the dry-run result, no actual operation will be performed:',
133133
usingCustomVersion: 'Using custom version: {{version}}',
134+
confirmDeletePackage:
135+
'Confirm delete native package {{packageId}}? This operation cannot be undone (Y/N):',
136+
deletePackageSuccess: 'Native package {{packageId}} deleted successfully',
137+
deletePackageError:
138+
'Failed to delete native package {{packageId}}: {{error}}',
139+
usageDeletePackage: 'Usage: cresc deletePackage [packageId] --appId [appId]',
134140
};

src/locales/zh.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,9 @@ export default {
124124
unnamed: '(未命名)',
125125
dryRun: '以下是 dry-run 模拟运行结果,不会实际执行任何操作:',
126126
usingCustomVersion: '使用自定义版本:{{version}}',
127+
confirmDeletePackage: '确认删除原生包 {{packageId}}? 此操作不可撤销 (Y/N):',
128+
deletePackageSuccess: '原生包 {{packageId}} 删除成功',
129+
deletePackageError: '删除原生包 {{packageId}} 失败: {{error}}',
130+
usageDeletePackage:
131+
'使用方法: pushy deletePackage [packageId] --appId [appId]',
127132
};

src/package.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { get, getAllPackages, post, uploadFile } from './api';
1+
import { get, getAllPackages, post, uploadFile, doDelete } from './api';
22
import { question, saveToLocal } from './utils';
33
import { t } from './utils/i18n';
44

@@ -212,4 +212,47 @@ export const packageCommands = {
212212
const { appId } = await getSelectedApp(platform);
213213
await listPackage(appId);
214214
},
215+
deletePackage: async ({
216+
args,
217+
options,
218+
}: {
219+
args: string[];
220+
options: { appId?: string };
221+
}) => {
222+
let packageId = args[0];
223+
let { appId } = options;
224+
225+
if (!appId) {
226+
const platform = await getPlatform();
227+
appId = (await getSelectedApp(platform)).appId as string;
228+
}
229+
230+
// If no packageId provided as argument, let user choose from list
231+
if (!packageId) {
232+
const selectedPackage = await choosePackage(appId);
233+
packageId = selectedPackage.id;
234+
}
235+
236+
// Confirm deletion
237+
// const confirmDelete = await question(
238+
// t('confirmDeletePackage', { packageId }),
239+
// );
240+
241+
// if (
242+
// confirmDelete.toLowerCase() !== 'y' &&
243+
// confirmDelete.toLowerCase() !== 'yes'
244+
// ) {
245+
// console.log(t('cancelled'));
246+
// return;
247+
// }
248+
249+
try {
250+
await doDelete(`/app/${appId}/package/${packageId}`);
251+
console.log(t('deletePackageSuccess', { packageId }));
252+
} catch (error: any) {
253+
throw new Error(
254+
t('deletePackageError', { packageId, error: error.message }),
255+
);
256+
}
257+
},
215258
};

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
55
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
66
"lib": [
7-
"ESNext"
7+
"ESNext",
8+
"DOM"
89
] /* Specify library files to be included in the compilation. */,
910
"allowJs": true /* Allow javascript files to be compiled. */,
1011
// "checkJs": true /* Report errors in .js files. */,

0 commit comments

Comments
 (0)