-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
4,125 additions
and
1,050 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@lens-protocol/cli": minor | ||
--- | ||
|
||
**feat:** Initial version of Lens CLI - a CLI tool for Lens developers. Initial commands: `create-profile` and `investigate`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
root: true, | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: './tsconfig.json', | ||
}, | ||
extends: ['@lens-protocol/eslint-config'], | ||
rules: { | ||
'no-console': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Lens CLI | ||
|
||
CLI tool for Lens developers. | ||
|
||
**Please note, this is an experimental tool and it may undergo significant changes in the future.** | ||
|
||
## Usage | ||
|
||
Install the Lens CLI from npm. | ||
|
||
```bash | ||
npm install -g @lens-protocol/cli | ||
``` | ||
|
||
See the available commands. The first level command decides the environment: `development` or `production`. | ||
You can use shorthand `dev` and `prod` instead. | ||
|
||
```bash | ||
lens development --help | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
lens production --help | ||
``` | ||
|
||
## Local Setup | ||
|
||
First install dependencies. Run all commands from the monorepo root directory. | ||
|
||
```bash | ||
pnpm install | ||
``` | ||
|
||
Start the development mode. It will watch for changes and rebuild the CLI. | ||
|
||
```bash | ||
pnpm --dir packages/cli dev | ||
``` | ||
|
||
Then link the package globally. | ||
|
||
```bash | ||
pnpm --dir packages/cli link --global | ||
``` | ||
|
||
Now you can run the CLI from anywhere. | ||
|
||
```bash | ||
lens --help | ||
``` | ||
|
||
Delete the global link when you're done. | ||
|
||
```bash | ||
pnpm remove --global @lens-protocol/cli | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "@lens-protocol/cli", | ||
"version": "0.0.0", | ||
"description": "Lens CLI", | ||
"repository": { | ||
"directory": "packages/cli", | ||
"type": "git", | ||
"url": "git://github.com/lens-protocol/lens-sdk.git" | ||
}, | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"bin": { | ||
"lens": "./dist/index.js" | ||
}, | ||
"scripts": { | ||
"build": "tsup src/index.ts --format esm", | ||
"dev": "tsup src/index.ts --format esm --watch", | ||
"lens": "ts-node --esm ./src/index.ts", | ||
"eslint:fix": "pnpm run eslint --fix", | ||
"eslint": "eslint src", | ||
"lint": "pnpm run prettier && pnpm run eslint && pnpm run tsc", | ||
"lint:fix": "pnpm run prettier:fix && pnpm run eslint:fix && pnpm run tsc", | ||
"prettier:fix": "prettier --write .", | ||
"prettier": "prettier --check .", | ||
"test": "echo \"Not in scope for this example\"", | ||
"tsc": "tsc --noEmit" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"@commander-js/extra-typings": "^12.0.1", | ||
"@ethersproject/address": "^5.7.0", | ||
"@lens-protocol/client": "*", | ||
"@lens-protocol/shared-kernel": "*", | ||
"chalk": "^5.3.0", | ||
"commander": "^12.0.0", | ||
"nanospinner": "^1.1.0", | ||
"tslib": "^2.6.2" | ||
}, | ||
"devDependencies": { | ||
"@lens-protocol/eslint-config": "workspace:*", | ||
"@lens-protocol/prettier-config": "workspace:*", | ||
"@lens-protocol/tsconfig": "workspace:*", | ||
"@types/node": "^18.19.31", | ||
"eslint": "^8.57.0", | ||
"prettier": "^3.2.5", | ||
"ts-node": "^10.9.2", | ||
"tsup": "^8.0.2", | ||
"typescript": "5.2.2" | ||
}, | ||
"engines": { | ||
"node": ">=18 <21" | ||
}, | ||
"prettier": "@lens-protocol/prettier-config" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Command } from '@commander-js/extra-typings'; | ||
import { isAddress } from '@ethersproject/address'; | ||
import { isRelaySuccess, isValidHandle } from '@lens-protocol/client'; | ||
import { createSpinner } from 'nanospinner'; | ||
|
||
import { ensureParentCommand, initLensClient } from '../lib/commandToEnvironment.js'; | ||
import { output } from '../lib/output.js'; | ||
|
||
export function createTestProfile() { | ||
const cmd = 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 validation = createSpinner(`Validating input data`).start(); | ||
|
||
if (!isValidHandle(options.handle)) { | ||
validation.error(); | ||
output.error(`Invalid handle: ${options.handle}`); | ||
process.exit(1); | ||
} | ||
|
||
if (!isAddress(options.address)) { | ||
validation.error(); | ||
output.error(`Invalid address: ${options.address}`); | ||
process.exit(1); | ||
} | ||
|
||
const parentCommandName = ensureParentCommand(cmd); | ||
const client = initLensClient(parentCommandName); | ||
|
||
// check if the requested handle is available | ||
const handleOwnerAddress = await client.handle.resolveAddress({ | ||
handle: `lens/${options.handle}`, | ||
}); | ||
|
||
if (handleOwnerAddress) { | ||
validation.error(); | ||
output.error(`The requested handle "${options.handle}" is not available.`); | ||
process.exit(1); | ||
} | ||
validation.success(); | ||
|
||
const creation = createSpinner( | ||
`Creating new test profile with handle "${options.handle}" for address "${options.address}"`, | ||
).start(); | ||
|
||
try { | ||
const profileCreateResult = await client.wallet.createProfileWithHandle({ | ||
handle: options.handle, | ||
to: options.address, | ||
}); | ||
|
||
if (!isRelaySuccess(profileCreateResult)) { | ||
creation.error(); | ||
output.error(`Something went wrong:`, profileCreateResult); | ||
process.exit(1); | ||
} | ||
|
||
await client.transaction.waitUntilComplete({ forTxId: profileCreateResult.txId }); | ||
|
||
creation.success(); | ||
output.success(`Profile created successfully`); | ||
} catch (error) { | ||
creation.error(); | ||
output.error(error); | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
return cmd; | ||
} |
Oops, something went wrong.