Skip to content

Commit

Permalink
Merge pull request ckb-devrel#79 from RetricSu/develop
Browse files Browse the repository at this point in the history
feat: merge v2.2.0 into master
  • Loading branch information
RetricSu authored May 7, 2024
2 parents db25068 + d9fd5d4 commit bacf470
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ Start building on Nervos blockchain, right now, right away!
- [Install](#install)
- [Usage](#usage)
- [Get started](#get-started)
- [Run A dApp Example](#run-a-dapp-example)
- [Create a full-stack Project](#create-a-full-stack-project)
- [Create a script-only Project](#create-a-script-only-project)
- [Run A dApp Example](#run-a-dapp-example)
- [Step 1: Select A dApp To Init](#step-1-select-a-dapp-to-init)
- [Step 2: Start the Devnet](#step-2-start-the-devnet)
- [Step 3: Access Pre-funded Accounts](#step-3-access-pre-funded-accounts)
Expand Down Expand Up @@ -64,7 +66,7 @@ Commands:
accounts Print account list info
list-hashes Use the CKB to list blockchain scripts hashes
inject-config Add offckb.config.ts to your workspace
update-config Update offckb.config.ts in your workspace
sync-config sync offckb.config.ts in your workspace
deposit [options] [toAddress] [amountInShannon] Deposit CKB tokens to address, only devnet and testnet
transfer [options] [toAddress] [amountInShannon] Transfer CKB tokens to address, only devnet and testnet
balance [options] [toAddress] Check account balance, only devnet and testnet
Expand All @@ -75,6 +77,13 @@ Commands:

*Use `offckb [command] -h` to learn more about a specific command.*

Sometimes you might encounter sudo permission problems. Granting the current user write access to the node_modules directory can resolve the problem.

```sh
sudo chown -R $(whoami) /usr/local/lib/node_modules
npm install -g @offckb/cli
```

## Get started

### Create a full-stack Project
Expand Down
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { setUTF8EncodingForWindows } from './util/encoding';
import { injectConfig } from './cmd/inject-config';
import { DepositOptions, deposit } from './cmd/deposit';
import { DeployOptions, deploy } from './cmd/deploy';
import { updateConfig } from './cmd/update-config';
import { syncConfig } from './cmd/sync-config';
import { TransferOptions, transfer } from './cmd/transfer';
import { BalanceOption, balanceOf } from './cmd/balance';
import { buildAccount } from './cmd/develop/build-account';
Expand Down Expand Up @@ -58,7 +58,7 @@ program.command('clean').description('Clean the devnet data, need to stop runnin
program.command('accounts').description('Print account list info').action(accounts);
program.command('list-hashes').description('Use the CKB to list blockchain scripts hashes').action(listHashes);
program.command('inject-config').description('Add offckb.config.ts to your workspace').action(injectConfig);
program.command('update-config').description('Update offckb.config.ts in your workspace').action(updateConfig);
program.command('sync-config').description('Sync offckb.config.ts in your workspace').action(syncConfig);

program
.command('deposit [toAddress] [amountInShannon]')
Expand Down
11 changes: 6 additions & 5 deletions src/cmd/inject-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import path from 'path';
import { predefinedOffCKBConfigTsPath, currentExecPath, userOffCKBConfigPath, defaultLumosVersion } from '../cfg/const';
import { execSync } from 'child_process';
import fs, { copyFileSync } from 'fs';
import { buildFullLumosConfig, updateScriptInfoInOffCKBConfigTs } from '../util/config';
import { buildFullLumosConfig, updateOffCKBConfigVersion, updateScriptInfoInOffCKBConfigTs } from '../util/config';
import { validateTypescriptWorkspace } from '../util/validator';
import { Network } from '../util/type';

export function injectConfig() {
const targetPath = currentExecPath;

validateTypescriptWorkspace();

// inject the offckb.config.ts file into users workspace
// copy config template
copyFileSync(predefinedOffCKBConfigTsPath, targetPath);
copyFileSync(predefinedOffCKBConfigTsPath, userOffCKBConfigPath);
// update the version in the offckb.config.ts
updateOffCKBConfigVersion(userOffCKBConfigPath);

// update the config
const devnetFullLumosConfig = buildFullLumosConfig(Network.devnet);
const testnetFullLumosConfig = buildFullLumosConfig(Network.testnet);
Expand All @@ -35,7 +36,7 @@ export function injectConfig() {
const indexer = offCKB.indexer;
const rpc = offCKB.rpc;
Check example at https://github.com/nervosnetwork/docs.nervos.org/tree/develop-v2/examples/create-dob
Check example at https://github.com/nervosnetwork/docs.nervos.org/tree/develop/examples/simple-transfer
`);
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/update-config.ts → src/cmd/sync-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { buildFullLumosConfig, updateScriptInfoInOffCKBConfigTs } from '../util/
import { Network } from '../util/type';
import { validateExecDappEnvironment } from '../util/validator';

export function updateConfig() {
export function syncConfig() {
validateExecDappEnvironment();

// update the offckb.config.ts file in users workspace
Expand Down
9 changes: 9 additions & 0 deletions src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import * as path from 'path';
import { dappTemplatePath, deployedContractInfoFolderPath } from '../cfg/const';
import { config } from '@ckb-lumos/lumos';
import { Network } from './type';
const version = require('../../package.json').version;

export function updateOffCKBConfigVersion(filePath: string) {
const versionTarget = 'update-me-offckb-config-version';
let fileContent = fs.readFileSync(filePath, 'utf-8');
fileContent = fileContent.replace(versionTarget, version);
// Write the updated content back to the file
fs.writeFileSync(filePath, fileContent, 'utf-8');
}

export function updateScriptInfoInOffCKBConfigTs(newConfig: config.Config, filePath: string, network: Network): void {
// Read the content of the offckb.config.ts file
Expand Down

0 comments on commit bacf470

Please sign in to comment.