Skip to content

Commit

Permalink
docs: clearer instructions (LIT-Protocol#146)
Browse files Browse the repository at this point in the history
* docs: clearer instructions

* Update README.md

Signed-off-by: Anson <[email protected]>

* chore: review changes

---------

Signed-off-by: Anson <[email protected]>
  • Loading branch information
Ansonhkg authored Jun 17, 2023
1 parent 3195cf7 commit 534d87e
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 96 deletions.
163 changes: 76 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,29 @@ This new V2 SDK is written in Typescript and is a complete rewrite of the old SD

# Quick Start

### NodeJS Only
### NodeJS Exclusive

Removed browser related methods eg. checkAndSignAuthSig
Removed browser-specific methods, e.g., checkAndSignAuthSig

```
yarn add @lit-protocol/lit-node-client-nodejs
```

### (Isomorphic) works on Node.js/browser
or..

### Isomorphic Implementation

Operable in both Node.js and the browser

```
yarn add @lit-protocol/lit-node-client
```

### Vanilla JS (UMD)
or..

### Vanilla JavaScript (UMD)

For usage directly in the browser with a script tag

```js
<script src="https://cdn.jsdelivr.net/npm/@lit-protocol/lit-node-client-vanilla/lit-node-client.js"></script>
Expand All @@ -55,16 +63,21 @@ yarn add @lit-protocol/lit-node-client

# Packages

> 📝 If you're looking to use the Lit SDK, you're probably all set with just the lit-node-client <link>. It's got everything most folks need. However, if you're the type who likes to keep things super lean and mean, and you need to keep an eagle eye on your bundle size, we've got individual packages too.
Individual packages are below so that you can import the minimum required packages for your use case.
📝 If you're looking to use the Lit SDK, you're probably all set with just the lit-node-client <link>. <br/>Get started with interacting with Lit network!

<!-- autogen:package:start -->

Package | Category | Version | Download
--- | --- | --- | ---
| [@lit-protocol/lit-node-client-nodejs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client-nodejs) | ![lit-node-client-nodejs](https://img.shields.io/badge/-nodejs-2E8B57 "lit-node-client-nodejs") | 2.2.25 | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/lit-node-client-nodejs">npm</a><br/><a href="https://cdn.jsdelivr.net/npm/@lit-protocol/lit-node-client-nodejs-vanilla/lit-node-client-nodejs.min.js">Vanilla JS (UMD)</a>
| [@lit-protocol/lit-node-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client) | ![lit-node-client](https://img.shields.io/badge/-universal-8A6496 "lit-node-client") | 2.2.25 | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/lit-node-client">npm</a><br/><a href="https://cdn.jsdelivr.net/npm/@lit-protocol/lit-node-client-vanilla/lit-node-client.min.js">Vanilla JS (UMD)</a>


Lit provides additional packages tailored for your specific use cases.


Package | Category | Version | Download
--- | --- | --- | ---
| [@lit-protocol/access-control-conditions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions) | ![access-control-conditions](https://img.shields.io/badge/-universal-8A6496 "access-control-conditions") | 2.2.25 | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/access-control-conditions">npm</a><br/><a href="https://cdn.jsdelivr.net/npm/@lit-protocol/access-control-conditions-vanilla/access-control-conditions.min.js">Vanilla JS (UMD)</a>
| [@lit-protocol/auth-helpers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-helpers) | ![auth-helpers](https://img.shields.io/badge/-universal-8A6496 "auth-helpers") | 2.2.25 | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/auth-helpers">npm</a><br/><a href="https://cdn.jsdelivr.net/npm/@lit-protocol/auth-helpers-vanilla/auth-helpers.min.js">Vanilla JS (UMD)</a>
| [@lit-protocol/bls-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/bls-sdk) | ![bls-sdk](https://img.shields.io/badge/-universal-8A6496 "bls-sdk") | 2.2.25 | <a target="_blank" href="https://www.npmjs.com/package/@lit-protocol/bls-sdk">npm</a><br/><a href="https://cdn.jsdelivr.net/npm/@lit-protocol/bls-sdk-vanilla/bls-sdk.min.js">Vanilla JS (UMD)</a>
Expand Down Expand Up @@ -108,70 +121,70 @@ http://docs.lit-js-sdk-v2.litprotocol.com/ <br/>
# Contributing and developing to this SDK

## Recommended VSCode Extensions
## Prerequisite

<details>
<summary>Nx Console</summary>
Download: <a href="https://nx.dev/core-features/integrate-with-editors">https://nx.dev/core-features/integrate-with-editors</a>
</details>
<details>
<summary>Restore Terminal</summary>
- node (v18.0.0)

Download: <a href="https://marketplace.visualstudio.com/items?itemName=EthanSK.restore-terminals">https://marketplace.visualstudio.com/items?itemName=EthanSK.restore-terminals</a>
See [Video](https://streamable.com/e/5g52m4)
## Recommended

```js
"restoreTerminals.terminals": [
{See [Video](https://streamable.com/e/5g52m4)
"splitTerminals": [
// {
// "name": "nx graph",
// "commands": ["yarn graph"]
// },
{
"name": "nodejs",
"commands": ["yarn nx run nodejs:serve"]
},
{
"name": "html",
"commands": ["yarn nx run html:serve"]
},
{
"name": "react",
"commands": ["yarn nx run react:serve"]
},
{
"name": "custom",
"commands": ["clear"]
}
]
}
]
```
- NX Console: https://nx.dev/core-features/integrate-with-editors

</details>
# Quick Start

# Workflow
The following commands will help you start developing with this repository.

## CLI (WIP)
First, install the dependencies via yarn:

```
yarn tools
yarn
```

## Dev
## Building

You can build the project with the following command:

```
yarn build
```

## Running Test Apps

The test apps are configured to automatically import all modules and expose all module functions. For browsers, you can access these functions using `window.LitJsSdk_<package_name>.<function_name>`

```jsx
// this will open
// Running apps...
// html: http://localhost:4002
// react: http://localhost:4003
// nodejs: in this terminal
yarn tools --dev --apps
// nodejs: in the terminal
yarn apps
```

or runniny individually

```
// html
yarn nx run html:serve
// react
yarn nx run react:serve
// nodejs
yarn nx run nodejs:serve
```

## Run unit tests

// usually i will open another temrinal to watch the package
// i'm developing
yarn tools --watch --target <package-name>
```
yarn test:unit
```

## Run E2E tests

```
yarn test:e2e
```

# (WIP) Advanced

## Creating a new library

Expand All @@ -188,45 +201,27 @@ yarn gen:lib <package-name> <tag>
yarn tools --create --react contracts-sdk --demo
```

## Deleting a library
## Deleting a package or app

```
yarn tool:delete (--package OR --app) <project-name>
// delete an app from ./app/<app-name>
yarn delete:app <app-name>
// delete a package from ./packages/<package-name>
yarn delete:package <package-name>
```


## Building

```jsx
yarn build

// or
yarn tools --build
```

### Building target package

```jsx
yarn nx run <project-name>:build

// or
yarn tools --build --target <project-name>

// or targeted env
yarn nx run <project-name>:_buildTsc
yarn nx run <project-name>:_buildWeb
```
## Watching
```jsx
// watch all packages change
yarn tools --watch

// watch a target package
yarn tools --watch <package-name>

// watch a target package with all its monorepo dependencies
yarn tools --watch <package-name>--deps
```

## Building Local Changes
Expand Down Expand Up @@ -264,12 +259,6 @@ yarn tools --clone <project-name> <clone-project-name> <(?) --publish> <(?) --re
yarn tools --clone lit-node-client @litprotocol/dev --publish --remove-after
```
### HTML Test app to Vercel
```
yarn tool:buildHtml
```
## Testing
### Quick Start on E2E Testing
Expand Down Expand Up @@ -399,6 +388,6 @@ Object.defineProperty(globalThis, 'crypto', {
<details>
<summary>error Command failed with exit code 13.</summary>
Make sure your node version is above v16.16.0
Make sure your node version is above v18.0.0
</details>
35 changes: 26 additions & 9 deletions tools/scripts/gen-readme.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,25 @@ libs.map((lib) => {
});

let rows = [...bundled, ...universals, ...browsers, ...nodejs];
let mainModules = [
'@lit-protocol/lit-node-client',
'@lit-protocol/lit-node-client-nodejs',
];
let mainRows = [];
let otherRows = [];

// separate the rows into main and others
rows.forEach((row) => {
const name = row.split('|')[1].trim();
if (mainModules.some((module) => name.includes(module))) {
mainRows.push(row);
} else {
otherRows.push(row);
}
});

// sort rows always to have @lit-protocol/lit-node-client at the top
rows = rows.sort((a, b) => {
// sort main rows to have @lit-protocol/lit-node-client at the top
mainRows = mainRows.sort((a, b) => {
const aName = a.split('|')[1].trim();
const bName = b.split('|')[1].trim();
if (aName.includes('@lit-protocol/lit-node-client')) {
Expand All @@ -108,14 +124,12 @@ rows = rows.sort((a, b) => {

const tables = {
headers: ['Package', 'Category', 'Version', 'Download'],
rows: rows,
mainRows: mainRows,
otherRows: otherRows,
};

// console.log(rows);

// make table to github markdown
const table = (tables) => {
const { headers, rows } = tables;
const table = (headers, rows) => {
const header = headers.join(' | ');
const divider = headers.map(() => '---').join(' | ');
const body = rows.join('\n');
Expand All @@ -126,12 +140,15 @@ ${body}
`;
};

let content = table(tables);
let mainContent = table(tables.headers, tables.mainRows);
let otherContent =
"If you're a tech-savvy user and wish to utilize only specific submodules that our main module relies upon, you can find individual packages listed below. This way, you can import only the necessary packages that cater to your specific use case::\n\n" +
table(tables.headers, tables.otherRows);

// use regex to replace the content between the comments <!-- autogen:package:start --> and <!-- autogen:package:end -->
const newReadme = readme.replace(
/<!-- autogen:package:start -->[\s\S]*<!-- autogen:package:end -->/m,
`<!-- autogen:package:start -->\n${content}\n<!-- autogen:package:end -->`
`<!-- autogen:package:start -->\n${mainContent}\n\n${otherContent}\n<!-- autogen:package:end -->`
);

// console.log(newReadme);
Expand Down

0 comments on commit 534d87e

Please sign in to comment.