Skip to content

Commit 0ab1a4b

Browse files
authored
docs: segregate api docs url/deployment (#3602)
1 parent 95255c8 commit 0ab1a4b

35 files changed

+166
-115
lines changed

.changeset/khaki-hairs-heal.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
---
3+
4+
docs: segregate api docs url/deployment

.github/workflows/release.yaml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,29 @@ jobs:
125125
HOME: ${{ github.workspace }}
126126
npm_config_registry: "https://npm.pkg.github.com"
127127

128-
# ensure docs are always deployed after merge of changeset PR
128+
# ensure docs API is always deployed after merge of changeset PR
129129
- name: Get the last commit message and set env vars
130130
run: echo LAST_COMMIT_MSG=$(git --no-pager log -1 --pretty=%B) >> $GITHUB_ENV
131131

132-
- name: Decides if Docs should be deployed
132+
- name: Decides if Docs API should be deployed
133133
if: startsWith(env.LAST_COMMIT_MSG, 'ci(release):') && env.RELEASE_VERSION_HIGHER_THAN_LATEST == 'true'
134-
run: echo SHOULD_DEPLOY_DOCS=true >> $GITHUB_ENV
134+
run: echo DEPLOY_STABLE_DOCS_API=true >> $GITHUB_ENV
135+
136+
# nightly docs API gets updated on every merge to master
137+
# and is configured in the vercel dashboard
138+
# stable docs API gets updated only when a new release is published
139+
- name: Update Docs API (stable)
140+
if: github.ref_name == 'master' && env.DEPLOY_STABLE_DOCS_API == 'true'
141+
env:
142+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
143+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_TS_DOCS_API_PROJECT_ID }}
144+
run: |
145+
pnpm install --global vercel@latest
146+
vercel --prod --token=${{ secrets.VERCEL_TOKEN }}
135147
136148
# # Commenting out as we require permissions to trigger across repos
137-
# - name: Update docs (nightly)
138-
# if: github.ref_name == 'master' && env.SHOULD_DEPLOY_DOCS == 'true'
149+
# - name: Update docs
150+
# if: github.ref_name == 'master'
139151
# uses: benc-uk/workflow-dispatch@v1
140152
# with:
141153
# workflow: update-nightly.yml

apps/docs-api/index.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212

1313
# Modules
1414

15-
- [abi-coder](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_abi_coder.html)
16-
- [abi-typegen](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_abi_typegen.html)
17-
- [account](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_account.html)
18-
- [address](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_address.html)
19-
- [crypto](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_crypto.html)
20-
- [errors](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_errors.html)
21-
- [hasher](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_hasher.html)
22-
- [math](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_math.html)
23-
- [program](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_program.html)
24-
- [script](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_script.html)
25-
- [transactions](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_transactions.html)
26-
- [utils](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_utils.html)
15+
- [abi-coder](modules/_fuel_ts_abi_coder.html)
16+
- [abi-typegen](modules/_fuel_ts_abi_typegen.html)
17+
- [account](modules/_fuel_ts_account.html)
18+
- [address](modules/_fuel_ts_address.html)
19+
- [crypto](modules/_fuel_ts_crypto.html)
20+
- [errors](modules/_fuel_ts_errors.html)
21+
- [hasher](modules/_fuel_ts_hasher.html)
22+
- [math](modules/_fuel_ts_math.html)
23+
- [program](modules/_fuel_ts_program.html)
24+
- [script](modules/_fuel_ts_script.html)
25+
- [transactions](modules/_fuel_ts_transactions.html)
26+
- [utils](modules/_fuel_ts_utils.html)

apps/docs/.vitepress/config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,21 @@ export default defineConfig({
1414
md.use(snippetPlugin);
1515
md.use(codeInContextPlugin);
1616
md.block.ruler.disable('snippet');
17+
md.core.ruler.before('normalize', 'replace-docs-api-url', (state) => {
18+
const apiUrl = process.env.NODE_ENV === 'development' ? 'http://localhost:5174' : '/api';
19+
state.src = state.src.replace(/DOCS_API_URL/g, apiUrl);
20+
});
1721
},
1822
},
23+
transformHtml: (code) => {
24+
// make the API links open in a new tab
25+
// because opening in the same tab doesn't work in the preview
26+
return code.replace(/(<a\s+[^>]*href="\/api\/[^"]*")/g, '$1 target="_blank" rel="noreferrer"');
27+
},
28+
// Finds dead DOCS_API_URL links and fails,
29+
// but they get replaced later in the markdown transformer.
30+
// We have the md link checker workflow which covers this.
31+
ignoreDeadLinks: true,
1932
head: [
2033
['link', { rel: 'icon', href: '/fuels-ts/favicon.ico', type: 'image/png' }],
2134
['meta', { property: 'og:type', content: 'website' }],

apps/docs/package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
"description": "",
66
"type": "module",
77
"scripts": {
8-
"dev": "nodemon --config nodemon.config.json -x 'run-s build:snippets dev:docs'",
8+
"dev": "nodemon --config nodemon.config.json -x 'run-s build:snippets build:docs-api dev:docs'",
99
"build": "run-s build:snippets build:docs",
10-
"preview": "run-s build:snippets preview:docs",
10+
"preview": "run-s build:snippets build:docs-api preview:docs",
1111
"test": "cd ../.. && pnpm run test:filter apps/docs",
1212
"build:snippets": "run-s wrap:snippets build:forc",
13-
"build:docs": "vitepress build",
13+
"build:docs": "run-s build:docs-app build:docs-api",
14+
"build:docs-app": "vitepress build",
15+
"build:docs-api": "cd ../docs-api && pnpm build && cp -r ./src/api ../docs/dist",
1416
"preview:docs": "vitepress preview",
15-
"dev:docs": "vitepress dev",
17+
"preview:docs-api": "pnpm vite preview --port 5174 --outDir ../docs-api/src/api",
18+
"dev:docs": "run-p docs:dev preview:docs-api",
19+
"docs:dev": "vitepress dev",
1620
"wrap:snippets": "tsx ./scripts/wrap-snippets.ts",
1721
"build:forc": "pnpm fuels build --deploy",
1822
"type:check": "pnpm tsc --noEmit --project tsconfig.emit.json"

apps/docs/src/guide/contracts/contract-balance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Contract Balance
22

3-
When working with contracts, it's crucial to be aware of the available contract balance of an asset while paying for costly operations. This guide will explain the `getBalance` method in the [Contract](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_program.Contract.html) class, which allows you to check a contract's available balance.
3+
When working with contracts, it's crucial to be aware of the available contract balance of an asset while paying for costly operations. This guide will explain the `getBalance` method in the [Contract](DOCS_API_URL/classes/_fuel_ts_program.Contract.html) class, which allows you to check a contract's available balance.
44

55
## The `getBalance` Method
66

7-
The [`Contract.getBalance`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_program.Contract.html#getBalance) method retrieves the available balance of a specific asset on your contract. This method is particularly useful for determining the remaining balance after sending assets to a contract and executing contract calls.
7+
The [`Contract.getBalance`](DOCS_API_URL/classes/_fuel_ts_program.Contract.html#getBalance) method retrieves the available balance of a specific asset on your contract. This method is particularly useful for determining the remaining balance after sending assets to a contract and executing contract calls.
88

99
It is important to note that this method returns the total available contract balance, regardless of how often assets have been sent to it or spent.
1010

apps/docs/src/guide/contracts/cost-estimation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Estimating Contract Call Cost
22

3-
The [`FunctionInvocationScope.getTransactionCost`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_program.FunctionInvocationScope.html#getTransactionCost) method allows you to estimate the cost of a specific contract call. The return type, `TransactionCost`, is an object containing relevant information for the estimation:
3+
The [`FunctionInvocationScope.getTransactionCost`](DOCS_API_URL/classes/_fuel_ts_program.FunctionInvocationScope.html#getTransactionCost) method allows you to estimate the cost of a specific contract call. The return type, `TransactionCost`, is an object containing relevant information for the estimation:
44

55
<<< @/../../../packages/account/src/providers/provider.ts#cost-estimation-1{ts:line-numbers}
66

apps/docs/src/guide/contracts/dependency-estimation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ In [variable outputs](./variable-outputs.md), we mention that a contract call mi
44

55
However, by default the SDK always automatically estimates these dependencies and double-checks if everything is in order whenever you invoke a contract function or attempt to send a transaction.
66

7-
The SDK uses the [Provider.estimateTxDependencies](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_account.Provider.html#estimateTxDependencies) method to set any missing dependencies identified during the estimation process. This requires simulating the transaction a few times in the background.
7+
The SDK uses the [Provider.estimateTxDependencies](DOCS_API_URL/classes/_fuel_ts_account.Provider.html#estimateTxDependencies) method to set any missing dependencies identified during the estimation process. This requires simulating the transaction a few times in the background.
88

99
While relying on the SDK's automatic estimation is a decent default behavior, we recommend manually specifying the dependencies if they are known in advance to avoid the performance impact of the estimation process.

apps/docs/src/guide/contracts/deploying-contracts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Now that the contract is deployed, you can interact with it by submitting a cont
5353

5454
## Deploying a Large Contract as Blobs
5555

56-
In the above guide we use the recommended `deploy` method. If you are working with a contract that is too large to be deployed in a single transaction, then the SDK will chunk the contract for you and submit it as blobs, to then be accessed later by a create transaction. This process is handled by the [`ContractFactory.deployAsBlobTx`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_contract.index.ContractFactory.html#deployAsBlobTx) method.
56+
In the above guide we use the recommended `deploy` method. If you are working with a contract that is too large to be deployed in a single transaction, then the SDK will chunk the contract for you and submit it as blobs, to then be accessed later by a create transaction. This process is handled by the [`ContractFactory.deployAsBlobTx`](DOCS_API_URL/classes/_fuel_ts_contract.index.ContractFactory.html#deployAsBlobTx) method.
5757

5858
<<< @./snippets/deploying-contracts/deployment.ts#blobs{ts:line-numbers}
5959

apps/docs/src/guide/contracts/managing-deployed-contracts.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ To interact with a deployed contract using the SDK without redeploying it, you o
44

55
## Contract ID
66

7-
The `contractId` property from the [`Contract`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_program.Contract.html) class is an instance of the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class.
7+
The `contractId` property from the [`Contract`](DOCS_API_URL/classes/_fuel_ts_program.Contract.html) class is an instance of the [`Address`](DOCS_API_URL/classes/_fuel_ts_address.Address.html) class.
88

9-
The [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class also provides a set of utility functions for easy manipulation and conversion between address formats along with one property; `b256Address`, which is a string encoded in [`B256`](../types/b256.md) format.
9+
The [`Address`](DOCS_API_URL/classes/_fuel_ts_address.Address.html) class also provides a set of utility functions for easy manipulation and conversion between address formats along with one property; `b256Address`, which is a string encoded in [`B256`](../types/b256.md) format.
1010

1111
When you log the `contractId` property of an instantiated Contract using `console.log`, the output appears as follows:
1212

@@ -22,10 +22,10 @@ If you have already an instantiated and deployed contract in hands you can creat
2222

2323
<<< @./snippets/managing-deployed-contracts.ts#with-contractId{ts:line-numbers}
2424

25-
The previous example assumes that you have a [`Contract`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_program.Contract.html) instance at hand. However, some Fuel tools and Sway use the [`B256`](../types/b256.md) type format, a hex-encoded string-like type, for contract IDs.
25+
The previous example assumes that you have a [`Contract`](DOCS_API_URL/classes/_fuel_ts_program.Contract.html) instance at hand. However, some Fuel tools and Sway use the [`B256`](../types/b256.md) type format, a hex-encoded string-like type, for contract IDs.
2626

2727
You might have this format instead, for example, if you have deployed your contract with `forc deploy`.
2828

29-
The process of instantiating a [`Contract`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_program.Contract.html) remains the same when using a contract ID of type `B256`:
29+
The process of instantiating a [`Contract`](DOCS_API_URL/classes/_fuel_ts_program.Contract.html) remains the same when using a contract ID of type `B256`:
3030

3131
<<< @./snippets/managing-deployed-contracts.ts#with-b256{ts:line-numbers}

0 commit comments

Comments
 (0)