( plugin: QuickAdd, params: CliData, )
| 832 | } |
| 833 | |
| 834 | async function previewPackageHandler( |
| 835 | plugin: QuickAdd, |
| 836 | params: CliData, |
| 837 | ): Promise<string> { |
| 838 | try { |
| 839 | const path = |
| 840 | typeof params.path === "string" ? params.path.trim() : ""; |
| 841 | if (!path) { |
| 842 | return serialize({ |
| 843 | ok: false, |
| 844 | command: CLI_COMMANDS.preview, |
| 845 | error: "Missing package path. Provide path=<vault-path>.", |
| 846 | }); |
| 847 | } |
| 848 | |
| 849 | const { pkg } = await readQuickAddPackage(plugin.app, path); |
| 850 | const preview = await analysePackagePreview( |
| 851 | plugin.app, |
| 852 | plugin.settings.choices, |
| 853 | pkg, |
| 854 | ); |
| 855 | |
| 856 | const response: PackagePreviewCliResponse = { |
| 857 | ok: true, |
| 858 | command: CLI_COMMANDS.preview, |
| 859 | preview, |
| 860 | }; |
| 861 | |
| 862 | if (isTruthy(params.decode)) { |
| 863 | response.contents = preview.files.map((file) => ({ |
| 864 | path: file.originalPath, |
| 865 | ...decodeAssetPreview(pkg, file.originalPath), |
| 866 | })); |
| 867 | } |
| 868 | |
| 869 | return serialize(response); |
| 870 | } catch (error) { |
| 871 | return serialize({ |
| 872 | ok: false, |
| 873 | command: CLI_COMMANDS.preview, |
| 874 | error: error instanceof Error ? error.message : String(error), |
| 875 | }); |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | export function registerQuickAddCliHandlers(plugin: QuickAdd): boolean { |
| 880 | const cliTarget = plugin as unknown as RegisterCliHandlerTarget; |
no test coverage detected