Skip to content

Commit a11986c

Browse files
committed
added snippets to test-env-js readme intro
1 parent f23c36e commit a11986c

12 files changed

Lines changed: 147 additions & 147 deletions

File tree

packages/js/client/tsconfig.build.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "build"
5+
},
36
"include": [
47
"./src/**/*.ts"
58
],

packages/js/client/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"es5",
88
"dom"
99
],
10-
"outDir": "build"
1110
},
1211
"include": [
13-
"./src/**/*.ts"
12+
"./src/**/*.ts",
13+
"./examples/**/*.ts"
1414
],
1515
"exclude": []
1616
}

packages/js/core-client/tsconfig.build.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "build"
5+
},
36
"include": [
47
"./src/**/*.ts"
58
],

packages/js/core-client/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"es5",
88
"dom"
99
],
10-
"outDir": "build"
1110
},
1211
"include": [
13-
"./src/**/*.ts"
12+
"./src/**/*.ts",
13+
"./examples/**/*.ts"
1414
],
1515
"exclude": []
1616
}

packages/js/test-env/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/examples/**/*.d.ts
2+
/examples/**/*.js
3+
/examples/**/*.js.map

packages/js/test-env/README.md

Lines changed: 41 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,46 @@ It allows user to initiate the test environment through a javascript function (i
88

99
# Usage
1010

11-
Initialization with the simple-storage wrapper.
11+
## Init test env
12+
13+
Spin up docker containers for Ganache and IPFS.
1214

1315
``` typescript
14-
import path from "path";
15-
import { PolywrapClient } from "@polywrap/client-js";
16-
import {
17-
buildWrapper,
18-
initTestEnvironment,
19-
stopTestEnvironment,
20-
providers,
21-
ensAddresses
22-
} from "@polywrap/test-env-js";
23-
import * as App from "../types/wrap";
24-
25-
// test wrapper in a test environment
26-
export async function foo({
27-
// spin up docker containers for Ganache and IPFS.
2816
await initTestEnvironment();
29-
const CONNECTION = { networkNameOrChainId: "testnet" };
17+
```
18+
19+
## Stop test env
20+
21+
Stop docker containers for Ganache and IPFS.
22+
23+
``` typescript
24+
await stopTestEnvironment();
25+
```
26+
27+
## Build a wrapper
3028

29+
Build a local wrapper project.
30+
31+
``` typescript
3132
// get path to the wrapper in testing
3233
const wrapperPath: string = path.join(path.resolve(__dirname), "..");
3334

3435
// build current wrapper with CLI, invoking codegen before build
3536
await buildWrapper(wrapperPath, undefined, true);
3637

3738
// get URI to the local wrapper build
38-
const wrapperUri = `fs/${wrapperPath}/build`;
39-
40-
// invoke the wrapper to deploy a contract to the test env
41-
const deployContractResponse = await App.SimpleStorage_Module.deployContract(
42-
{ connection: CONNECTION },
43-
client,
44-
wrapperUri
45-
);
46-
const contractAddress = deployContractResponse.data as string;
47-
48-
// invoke the wrapper to query a contract in the test env
49-
const response = await App.SimpleStorage_Module.getData(
50-
{
51-
address: contractAddr,
52-
connection: CONNECTION,
53-
},
54-
client,
55-
wrapperUri
56-
);
57-
});
58-
39+
const wrapperUri = `wrap://fs/${wrapperPath}/build`;
5940
```
6041

61-
# API Outline
42+
## Execute the CLI
6243

63-
- ensAddresses, providers - constant addresses and urls
64-
- runCLI - run arbitrary Polywrap CLI commands
65-
- initTestEnvironment - spin up Ganache and IPFS Docker instances
66-
- stopTestEnvironment - stop Docker
67-
- buildWrapper - compile wasm and bindings
68-
- buildAndDeployWrapper - deploy wrapper to the testnet ENS
44+
Execute a command with the Polywrap CLI.
45+
46+
``` typescript
47+
const { exitCode, stderr, stdout } = await runCLI({
48+
args: ["infra", "up", "--verbose"],
49+
});
50+
```
6951

7052
## Constants
7153

@@ -138,11 +120,13 @@ export const stopTestEnvironment = async (
138120
* Build the wrapper located at the given path
139121
*
140122
* @param wrapperAbsPath - absolute path of wrapper to build
141-
* @param manifestPathOverride? - path to p
123+
* @param manifestPathOverride? - path to polywrap manifest
124+
* @param codegen? - run codegen before build
142125
*/
143126
export async function buildWrapper(
144127
wrapperAbsPath: string,
145-
manifestPathOverride?: string
128+
manifestPathOverride?: string,
129+
codegen?: boolean
146130
): Promise<void>
147131
```
148132

@@ -157,6 +141,7 @@ export async function buildWrapper(
157141
* @param ipfsProvider - ipfs provider to use for deployment
158142
* @param ethereumProvider - ethereum provider to use for ENS registration
159143
* @param ensName? - an ENS domain name to register and assign to the wrapper
144+
* @param codegen? - run codegen before build
160145
*
161146
* @returns registered ens domain name and IPFS hash
162147
*/
@@ -165,28 +150,19 @@ export async function buildAndDeployWrapper({
165150
ipfsProvider,
166151
ethereumProvider,
167152
ensName,
153+
codegen,
168154
}: {
169155
wrapperAbsPath: string;
170156
ipfsProvider: string;
171157
ethereumProvider: string;
172158
ensName?: string;
159+
codegen?: boolean;
173160
}): Promise<{
174161
ensDomain: string;
175162
ipfsCid: string;
176163
}>
177164
```
178165

179-
```typescript title="Example: buildAndDeployWrapper with default infrastructure module"
180-
import { buildAndDeployWrapper, providers } from "@polywrap/test-env-js";
181-
182-
const { ensDomain, ipfsCid } = await buildAndDeployWrapper({
183-
wrapperAbsPath: "...",
184-
ipfsProvider: providers.ipfs,
185-
ethereumProvider: providers.ethereum,
186-
});
187-
const ensUri = `ens/testnet/${ensDomain}`;
188-
```
189-
190166
### buildAndDeployWrapperToHttp
191167

192168
```typescript
@@ -197,17 +173,20 @@ const ensUri = `ens/testnet/${ensDomain}`;
197173
* @param wrapperAbsPath - absolute path of wrapper to build
198174
* @param httpProvider - http provider used for deployment and domain registration
199175
* @param name? - a domain name to register and assign to the wrapper
176+
* @param codegen? - run codegen before build
200177
*
201178
* @returns http uri
202179
*/
203180
export async function buildAndDeployWrapperToHttp({
204181
wrapperAbsPath,
205182
httpProvider,
206183
name,
184+
codegen,
207185
}: {
208186
wrapperAbsPath: string;
209187
httpProvider: string;
210188
name?: string;
189+
codegen?: boolean;
211190
}): Promise<{ uri: string }>
212191
```
213192

@@ -217,10 +196,11 @@ export async function buildAndDeployWrapperToHttp({
217196
/**
218197
* Runs the polywrap CLI programmatically.
219198
*
220-
* @param args - an array of command line arguments
221-
* @param cwd? - a current working directory
222-
* @param cli? - a path to a Polywrap CLI binary
223-
* @param env? - a map of environmental variables
199+
* @param options - an object containing:
200+
* args - an array of command line arguments
201+
* cwd? - a current working directory
202+
* cli? - a path to a Polywrap CLI binary
203+
* env? - a map of environmental variables
224204
*
225205
* @returns exit code, standard output, and standard error logs
226206
*/
@@ -234,10 +214,4 @@ export const runCLI = async (options: {
234214
stdout: string;
235215
stderr: string;
236216
}>
237-
```
238-
239-
```typescript title="Example: runCLI calling the 'infra' command"
240-
const { exitCode, stderr, stdout } = await runCLI({
241-
args: ["infra", "up", "--modules=eth-ens-ipfs", "--verbose"]
242-
});
243217
```
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {
2+
buildWrapper,
3+
initTestEnvironment,
4+
runCLI,
5+
stopTestEnvironment,
6+
} from "../build";
7+
8+
import path from "path";
9+
10+
export async function init(): Promise<void> {
11+
// $start: quickstart-init
12+
await initTestEnvironment();
13+
// $end
14+
}
15+
16+
export async function stop(): Promise<void> {
17+
// $start: quickstart-stop
18+
await stopTestEnvironment();
19+
// $end
20+
}
21+
22+
export async function build(): Promise<string> {
23+
// $start: quickstart-build
24+
// get path to the wrapper in testing
25+
const wrapperPath: string = path.join(path.resolve(__dirname), "..");
26+
27+
// build current wrapper with CLI, invoking codegen before build
28+
await buildWrapper(wrapperPath, undefined, true);
29+
30+
// get URI to the local wrapper build
31+
const wrapperUri = `wrap://fs/${wrapperPath}/build`;
32+
// $end
33+
34+
return wrapperUri;
35+
}
36+
37+
export async function cli(): Promise<{
38+
exitCode: number;
39+
stdout: string;
40+
stderr: string;
41+
}> {
42+
// $start: quickstart-runCLI
43+
const { exitCode, stderr, stdout } = await runCLI({
44+
args: ["infra", "up", "--verbose"],
45+
});
46+
// $end
47+
48+
return { exitCode, stderr, stdout };
49+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": [
4+
"./**/*.ts"
5+
],
6+
}

packages/js/test-env/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
"build"
1313
],
1414
"scripts": {
15-
"build": "rimraf ./build && tsc --project tsconfig.build.json && yarn copy:wrappers",
15+
"build": "yarn build:fast && yarn build:snippets && yarn build:readme",
16+
"build:fast": "rimraf ./build && tsc --project tsconfig.build.json && yarn copy:wrappers",
1617
"lint": "eslint --color -c ../../../.eslintrc.js src/",
1718
"copy:wrappers": "copyfiles ./src/wrappers/**/**/* ./build/wrappers/ -u 2",
19+
"build:snippets": "tsc --project ./examples/tsconfig.examples.json",
1820
"build:readme": "yarn doc-snippets combine"
1921
},
2022
"dependencies": {
@@ -37,13 +39,16 @@
3739
},
3840
"doc-snippets": {
3941
"extract": {
40-
"include": "./**/*.{ts,tsx,json,yaml,txt,md,graphql,cue}",
42+
"include": [
43+
"./src/**/*.{ts,tsx,json,yaml,txt,md,graphql,cue}",
44+
"./examples/**/*.{ts,tsx,json,yaml,txt,md,graphql,cue}"
45+
],
4146
"ignore": [
4247
"./**/node_modules/**",
4348
"./**/.polywrap/**",
4449
"./**/__tests__/**"
4550
],
46-
"dir": "./src"
51+
"dir": "./"
4752
},
4853
"inject": {
4954
"dir": "./readme",

0 commit comments

Comments
 (0)