Skip to content

Commit

Permalink
another try
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysu committed Apr 9, 2024
1 parent 52bb9ac commit a0561c4
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 18 deletions.
4 changes: 3 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"private": true,
"main": "dist/lens-protocol-cli.cjs.js",
"module": "dist/lens-protocol-cli.esm.js",
"type": "module",
"bin": {
"lens": "./dist/lens-protocol-cli.cjs.js"
"lens": "./dist/lens-protocol-cli.esm.js"
},
"scripts": {
"build": "preconstruct build && pnpm run postbuild",
Expand All @@ -32,6 +33,7 @@
"@ethersproject/address": "^5.7.0",
"@lens-protocol/client": "workspace:*",
"@lens-protocol/shared-kernel": "workspace:*",
"chalk": "^5.3.0",
"commander": "^12.0.0",
"nanospinner": "^1.1.0",
"tslib": "^2.6.2"
Expand Down
25 changes: 12 additions & 13 deletions packages/cli/src/commands/createTestProfile.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { Command } from '@commander-js/extra-typings';
import { isAddress } from '@ethersproject/address';
import { isRelaySuccess, isValidHandle } from '@lens-protocol/client';
import { assertError } from '@lens-protocol/shared-kernel';
import pkg from '@lens-protocol/client';
const { isRelaySuccess, isValidHandle } = pkg;
import { createSpinner } from 'nanospinner';

import {
ensureParentCommand,
getHandlePrefix,
initLensClient,
} from '../utils/commandToEnvironment';
} from '../utils/commandToEnvironment.js';

const createTestProfile = new Command('create-profile')
.description('Create a new test profile, possible only in the development environment')
.requiredOption('-h, --handle <handle>', 'Test profile handle')
.requiredOption('-a, --address <address>', 'Wallet address')
.action(async (options) => {
const validatorSpinner = createSpinner(`Validating input data`).start();
const validation = createSpinner(`Validating input data`).start();

if (!isValidHandle(options.handle)) {
validatorSpinner.error();
validation.error();
console.error(`Invalid handle: ${options.handle}`);
process.exit(1);
}

if (!isAddress(options.address)) {
validatorSpinner.error();
validation.error();
console.error(`Invalid address: ${options.address}`);
process.exit(1);
}
Expand All @@ -38,13 +38,13 @@ const createTestProfile = new Command('create-profile')
});

if (handleOwnerAddress) {
validatorSpinner.error();
validation.error();
console.error(`The requested handle "${options.handle}" is not available.`);
process.exit(1);
}
validatorSpinner.success();
validation.success();

const spinner = createSpinner(
const creation = createSpinner(
`Creating new test profile with handle "${options.handle}" for address "${options.address}"`,
).start();

Expand All @@ -55,18 +55,17 @@ const createTestProfile = new Command('create-profile')
});

if (!isRelaySuccess(profileCreateResult)) {
creation.error();
console.error(`Something went wrong`, profileCreateResult);
spinner.error();
process.exit(1);
}

await client.transaction.waitUntilComplete({ forTxId: profileCreateResult.txId });

spinner.success();
creation.success();
console.log(`Profile created successfully`);
} catch (error) {
assertError(error);
spinner.error();
creation.error();
console.error(error);
process.exit(1);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import { program, Command } from '@commander-js/extra-typings';

import { createTestProfile } from './commands/createTestProfile';
import { createTestProfile } from './commands/createTestProfile.js';
import './utils/logger.js';

program.name('lens').description('Lens CLI');

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/utils/commandToEnvironment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Command } from '@commander-js/extra-typings';
import { LensClient, development, production } from '@lens-protocol/client';
import pkg from '@lens-protocol/client';
const { LensClient, production, development } = pkg;

const commandToEnvironmentMap = {
production: production,
Expand Down
12 changes: 12 additions & 0 deletions packages/cli/src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import chalk from 'chalk';

const log = console.log;
const error = console.error;

console.log = (...args: Parameters<typeof console.log>) => {
log(chalk.green(...args));
};

console.error = (...args: Parameters<typeof console.error>) => {
error(chalk.red(...args));
};
4 changes: 2 additions & 2 deletions packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"extends": "@lens-protocol/tsconfig/base.json",
"compilerOptions": {
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "node",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "dist"
},
"include": ["./src"]
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a0561c4

Please sign in to comment.