From 5a5a58d94263d4bbb49103c1ac85a076f050b843 Mon Sep 17 00:00:00 2001 From: RetricSu Date: Tue, 7 May 2024 15:03:22 +0800 Subject: [PATCH 1/3] refactor: rename update-config to sync-config (#76) --- README.md | 6 ++++-- src/cli.ts | 4 ++-- src/cmd/{update-config.ts => sync-config.ts} | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) rename src/cmd/{update-config.ts => sync-config.ts} (96%) diff --git a/README.md b/README.md index 0289586..a86a6ea 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/src/cli.ts b/src/cli.ts index 1498553..b77bf38 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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'; @@ -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]') diff --git a/src/cmd/update-config.ts b/src/cmd/sync-config.ts similarity index 96% rename from src/cmd/update-config.ts rename to src/cmd/sync-config.ts index 9cdacba..aa9a5ce 100644 --- a/src/cmd/update-config.ts +++ b/src/cmd/sync-config.ts @@ -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 From b94f482fffaced63f44261a262aac4dd175a0ed8 Mon Sep 17 00:00:00 2001 From: RetricSu Date: Tue, 7 May 2024 15:10:21 +0800 Subject: [PATCH 2/3] doc: update readme with usage sudo workaround (#77) --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index a86a6ea..28b8079 100644 --- a/README.md +++ b/README.md @@ -77,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 From d9fd5d437f4c4042b066dbebe46bbab6d3e2d736 Mon Sep 17 00:00:00 2001 From: RetricSu Date: Tue, 7 May 2024 23:52:11 +0800 Subject: [PATCH 3/3] fix: inject config copy failed and invalid version (#78) --- src/cmd/inject-config.ts | 11 ++++++----- src/util/config.ts | 9 +++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/cmd/inject-config.ts b/src/cmd/inject-config.ts index 1484f9f..bdbbaf1 100644 --- a/src/cmd/inject-config.ts +++ b/src/cmd/inject-config.ts @@ -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); @@ -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 `); } diff --git a/src/util/config.ts b/src/util/config.ts index ce29c9f..b34ddfc 100644 --- a/src/util/config.ts +++ b/src/util/config.ts @@ -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