Skip to content

Commit

Permalink
Quality of life improvements (#127)
Browse files Browse the repository at this point in the history
* Fix formatting errors in some error messages

* Wrap all error-messaging operations in the same method

* Some code simplification, grammar fixes

* Introduce terminal link lib, start adding conf message

* Start using new nicely-formatting feedback mechanism.

* Start getting error messages to work

* Add in remaining cofirmation messages.

* I live to make Jon happy

* Jon's wish is my command
  • Loading branch information
creativedrewy authored Jan 9, 2023
1 parent 5871673 commit 07466d8
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 90 deletions.
3 changes: 3 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@
"@types/commander": "^2.12.2",
"@types/debug": "^4.1.7",
"@types/js-yaml": "^4.0.5",
"@types/terminal-link": "^1.2.0",
"@types/update-notifier": "^6.0.1",
"shx": "^0.3.4"
},
"dependencies": {
"@solana-mobile/dapp-store-publishing-tools": "workspace:0.1.7",
"@solana/web3.js": "1.68.0",
"ajv": "^8.11.0",
"boxen": "^7.0.1",
"commander": "^9.4.1",
"debug": "^4.3.4",
"dotenv": "^16.0.3",
"esm": "^3.2.25",
"image-size": "^1.0.2",
"js-yaml": "^4.1.0",
"terminal-link": "^3.0.0",
"tweetnacl": "1.0.3",
"update-notifier": "^6.0.2"
}
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/create/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ export const createAppCommand = async ({
{ dryRun }
);

// TODO(sdlaver): dry-run should not modify config
saveToConfig({ app: { address: appAddress } });
if (!dryRun) {
saveToConfig({ app: { address: appAddress } });
}

return { appAddress };
};
150 changes: 68 additions & 82 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
publishSupportCommand,
publishUpdateCommand
} from "./commands/publish/index.js";
import { checkForSelfUpdate, getConfigFile, parseKeypair, showUserErrorMessage } from "./utils.js";
import { checkForSelfUpdate, generateNetworkSuffix, getConfigFile, parseKeypair, showMessage } from "./utils.js";
import terminalLink from "terminal-link";
import boxen from "boxen";

import * as dotenv from "dotenv";

Expand All @@ -34,6 +36,16 @@ function resolveBuildToolsPath(buildToolsPath: string | undefined) {
return;
}

async function tryWithErrorMessage(block: () => Promise<any>) {
try {
await block()
} catch (e) {
const errorMsg = (e as Error | null)?.message ?? "";

showMessage("Error", errorMsg, true);
}
}

async function main() {
program
.name("dapp-store")
Expand All @@ -54,17 +66,19 @@ async function main() {
.option("-u, --url <url>", "RPC URL", "https://devnet.genesysgo.net")
.option("-d, --dry-run", "Flag for dry run. Doesn't mint an NFT")
.action(async ({ keypair, url, dryRun }) => {
try {
tryWithErrorMessage(async () => {
await checkForSelfUpdate();

const signer = parseKeypair(keypair);

if (signer) {
const result = await createPublisherCommand({ signer, url, dryRun });
const result: { publisherAddress: string } = await createPublisherCommand({ signer, url, dryRun });

const displayUrl = `https://solscan.io/token/${result.publisherAddress}${generateNetworkSuffix(url)}`;
const resultText = `Publisher NFT successfully minted:\n${displayUrl}`;

showMessage("Success", resultText);
}
} catch (e) {
showUserErrorMessage((e as Error | null)?.message ?? "");
}
});
});

createCommand
Expand All @@ -81,31 +95,30 @@ async function main() {
.option("-u, --url <url>", "RPC URL", "https://devnet.genesysgo.net")
.option("-d, --dry-run", "Flag for dry run. Doesn't mint an NFT")
.action(async ({ publisherMintAddress, keypair, url, dryRun }) => {
try {
tryWithErrorMessage(async () => {
await checkForSelfUpdate();

const config = await getConfigFile();

if (!hasAddressInConfig(config.publisher) && !publisherMintAddress) {
showUserErrorMessage(
"Either specify an publisher mint address in the config file, or specify as a CLI argument to this command."
);
createCommand.showHelpAfterError();
return;
throw new Error("Either specify a publisher mint address in the config file or specify as a CLI argument to this command.")
}

const signer = parseKeypair(keypair);
if (signer) {
await createAppCommand({
const result = await createAppCommand({
publisherMintAddress: publisherMintAddress,
signer,
url,
dryRun,
});

const displayUrl = `https://solscan.io/token/${result.appAddress}${generateNetworkSuffix(url)}`;
const resultText = `App NFT successfully minted:\n${displayUrl}`;

showMessage("Success", resultText);
}
} catch (e) {
showUserErrorMessage((e as Error | null)?.message ?? "");
}
});
});

createCommand
Expand All @@ -126,30 +139,20 @@ async function main() {
"Path to Android build tools which contains AAPT2"
)
.action(async ({ appMintAddress, keypair, url, dryRun, buildToolsPath }) => {
try {
tryWithErrorMessage(async () => {
await checkForSelfUpdate();

const resolvedBuildToolsPath = resolveBuildToolsPath(buildToolsPath);
if (resolvedBuildToolsPath === undefined) {
showUserErrorMessage(
"Please specify an Android build tools directory in the .env file or via the command line argument."
);
createCommand.showHelpAfterError();
return;
throw new Error("Please specify an Android build tools directory in the .env file or via the command line argument.")
}

const config = await getConfigFile();

if (!hasAddressInConfig(config.app) && !appMintAddress) {
showUserErrorMessage(
"\n\n::: Either specify an app mint address in the config file, or specify as a CLI argument to this command. :::\n\n"
);
createCommand.showHelpAfterError();
return;
throw new Error("Either specify an app mint address in the config file or specify as a CLI argument to this command")
}

const signer = parseKeypair(keypair);

if (signer) {
const result = await createReleaseCommand({
appMintAddress: appMintAddress,
Expand All @@ -158,10 +161,13 @@ async function main() {
url,
dryRun,
});

const displayUrl = `https://solscan.io/token/${result?.releaseAddress}${generateNetworkSuffix(url)}`;
const resultText = `Release NFT successfully minted:\n${displayUrl}`;

showMessage("Success", resultText);
}
} catch (e) {
showUserErrorMessage((e as Error | null)?.message ?? "");
}
});
}
);

Expand All @@ -177,29 +183,24 @@ async function main() {
"Path to Android build tools which contains AAPT2"
)
.action(async ({ keypair, buildToolsPath }) => {
try {
tryWithErrorMessage(async () => {
await checkForSelfUpdate();

const resolvedBuildToolsPath = resolveBuildToolsPath(buildToolsPath);
if (resolvedBuildToolsPath === undefined) {
showUserErrorMessage(
"Please specify an Android build tools directory in the .env file or via the command line argument."
);
createCommand.showHelpAfterError();
return;
throw new Error("Please specify an Android build tools directory in the .env file or via the command line argument.")
}

const signer = parseKeypair(keypair);

if (signer) {
await validateCommand({
signer,
buildToolsPath: resolvedBuildToolsPath,
});

//TODO: Add pretty formatting here, but will require more work than other sections
}
} catch (e) {
showUserErrorMessage((e as Error | null)?.message ?? "");
}
});
});

const publishCommand = program
Expand Down Expand Up @@ -246,17 +247,13 @@ async function main() {
requestorIsAuthorized,
dryRun,
}) => {
try {
tryWithErrorMessage(async () => {
await checkForSelfUpdate();

const config = await getConfigFile();

if (!hasAddressInConfig(config.release) && !releaseMintAddress) {
showUserErrorMessage(
"\n\n::: Either specify an release mint address in the config file, or specify as a CLI argument to this command. :::\n\n"
);
publishCommand.showHelpAfterError();
return;
throw new Error("Either specify a release mint address in the config file or specify as a CLI argument to this command.")
}

const signer = parseKeypair(keypair);
Expand All @@ -270,10 +267,11 @@ async function main() {
compliesWithSolanaDappStorePolicies,
requestorIsAuthorized,
});

const resultText = "Successfully submitted to the Solana Mobile dApp publisher portal";
showMessage("Success", resultText);
}
} catch (e) {
showUserErrorMessage((e as Error | null)?.message ?? "");
}
});
}
);

Expand Down Expand Up @@ -319,21 +317,16 @@ async function main() {
critical,
dryRun,
}) => {
try {
tryWithErrorMessage(async () => {
await checkForSelfUpdate();

const config = await getConfigFile();

if (!hasAddressInConfig(config.release) && !releaseMintAddress) {
showUserErrorMessage(
"\n\n::: Either specify an release mint address in the config file, or specify as a CLI argument to this command. :::\n\n"
);
publishCommand.showHelpAfterError();
return;
throw new Error("Either specify a release mint address in the config file or specify as a CLI argument to this command.")
}

const signer = parseKeypair(keypair);

if (signer) {
await publishUpdateCommand({
appMintAddress,
Expand All @@ -345,10 +338,11 @@ async function main() {
requestorIsAuthorized,
critical,
});

const resultText = "dApp successfully updated on the publisher portal";
showMessage("Success", resultText);
}
} catch (e) {
showUserErrorMessage((e as Error | null)?.message ?? "");
}
});
}
);

Expand Down Expand Up @@ -389,21 +383,16 @@ async function main() {
critical,
dryRun,
}) => {
try {
tryWithErrorMessage(async () => {
await checkForSelfUpdate();

const config = await getConfigFile();

if (!hasAddressInConfig(config.release) && !releaseMintAddress) {
showUserErrorMessage(
"\n\n::: Either specify an release mint address in the config file, or specify as a CLI argument to this command. :::\n\n"
);
publishCommand.showHelpAfterError();
return;
throw new Error("Either specify a release mint address in the config file or specify as a CLI argument to this command.")
}

const signer = parseKeypair(keypair);

if (signer) {
await publishRemoveCommand({
appMintAddress,
Expand All @@ -414,10 +403,11 @@ async function main() {
requestorIsAuthorized,
critical,
});

const resultText = "dApp successfully removed from the publisher portal";
showMessage("Success", resultText);
}
} catch (e) {
showUserErrorMessage((e as Error | null)?.message ?? "");
}
})
}
);

Expand Down Expand Up @@ -452,21 +442,16 @@ async function main() {
requestDetails,
{ appMintAddress, releaseMintAddress, keypair, url, requestorIsAuthorized, dryRun }
) => {
try {
tryWithErrorMessage(async () => {
await checkForSelfUpdate();

const config = await getConfigFile();

if (!hasAddressInConfig(config.release) && !releaseMintAddress) {
showUserErrorMessage(
"\n\n::: Either specify an release mint address in the config file, or specify as a CLI argument to this command. :::\n\n"
);
publishCommand.showHelpAfterError();
return;
throw new Error("Either specify a release mint address in the config file or specify as a CLI argument to this command.")
}

const signer = parseKeypair(keypair);

if (signer) {
await publishSupportCommand({
appMintAddress,
Expand All @@ -477,10 +462,11 @@ async function main() {
requestorIsAuthorized,
requestDetails,
});

const resultText = "Support request sent successfully";
showMessage("Success", resultText);
}
} catch (e) {
showUserErrorMessage((e as Error | null)?.message ?? "");
}
});
}
);

Expand Down
Loading

0 comments on commit 07466d8

Please sign in to comment.