@offckb/cli 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,7 +23,9 @@ Start building on Nervos blockchain, right now, right away!
23
23
  - [Install](#install)
24
24
  - [Usage](#usage)
25
25
  - [Get started](#get-started)
26
- - [Run A dApp Example](#run-a-dapp-example)
26
+ - [Create a full-stack Project](#create-a-full-stack-project)
27
+ - [Create a script-only Project](#create-a-script-only-project)
28
+ - [Run A dApp Example](#run-a-dapp-example)
27
29
  - [Step 1: Select A dApp To Init](#step-1-select-a-dapp-to-init)
28
30
  - [Step 2: Start the Devnet](#step-2-start-the-devnet)
29
31
  - [Step 3: Access Pre-funded Accounts](#step-3-access-pre-funded-accounts)
@@ -64,25 +66,45 @@ Commands:
64
66
  accounts Print account list info
65
67
  list-hashes Use the CKB to list blockchain scripts hashes
66
68
  inject-config Add offckb.config.ts to your workspace
67
- update-config Update offckb.config.ts in your workspace
69
+ sync-config sync offckb.config.ts in your workspace
68
70
  deposit [options] [toAddress] [amountInShannon] Deposit CKB tokens to address, only devnet and testnet
69
71
  transfer [options] [toAddress] [amountInShannon] Transfer CKB tokens to address, only devnet and testnet
70
72
  balance [options] [toAddress] Check account balance, only devnet and testnet
71
73
  deploy [options] Deploy contracts to different networks, only supports devnet and testnet
74
+ deployed-scripts [options] Show deployed contracts info on networks, only supports devnet and testnet
72
75
  help [command] display help for command
73
76
  ```
74
77
 
75
78
  *Use `offckb [command] -h` to learn more about a specific command.*
76
79
 
80
+ Sometimes you might encounter sudo permission problems. Granting the current user write access to the node_modules directory can resolve the problem.
81
+
82
+ ```sh
83
+ sudo chown -R $(whoami) /usr/local/lib/node_modules
84
+ npm install -g @offckb/cli
85
+ ```
86
+
77
87
  ## Get started
78
88
 
89
+ ### Create a full-stack Project
90
+
79
91
  Create a new project from predefined boilerplates.
80
92
 
81
93
  ```sh
82
94
  offckb create <your-project-name, eg:my-first-ckb-project>
83
95
  ```
84
96
 
85
- The boilerplate can be targeting on different CKB networks. Check README.md in the project to get started.
97
+ The boilerplate can be targeting on different CKB networks. Check [README.md](https://github.com/nervosnetwork/docs.nervos.org/blob/develop/examples/remix-vite-template/readme.md) in the project to get started.
98
+
99
+ ### Create a script-only Project
100
+
101
+ You can create a new script project without a frontend. This is useful when you only want to develop smart contracts for CKB.
102
+
103
+ ```sh
104
+ offckb create <your-project-name> --script
105
+ ```
106
+
107
+ Note: you need to have rust/cargo/cargo-generate/clang 16+ installed in your environment to use this command. offckb doesn't do anything really, it just call [ckb-script-template](https://github.com/cryptape/ckb-script-tempaltes) to do all the magic.
86
108
 
87
109
  ## Run A dApp Example
88
110
 
package/dist/cli.js CHANGED
@@ -24,11 +24,12 @@ const encoding_1 = require("./util/encoding");
24
24
  const inject_config_1 = require("./cmd/inject-config");
25
25
  const deposit_1 = require("./cmd/deposit");
26
26
  const deploy_1 = require("./cmd/deploy");
27
- const update_config_1 = require("./cmd/update-config");
27
+ const sync_config_1 = require("./cmd/sync-config");
28
28
  const transfer_1 = require("./cmd/transfer");
29
29
  const balance_1 = require("./cmd/balance");
30
30
  const build_account_1 = require("./cmd/develop/build-account");
31
31
  const create_1 = require("./cmd/create");
32
+ const deployed_scripts_1 = require("./cmd/deployed-scripts");
32
33
  const version = require('../package.json').version;
33
34
  const description = require('../package.json').description;
34
35
  // fix windows terminal encoding of simplified chinese text
@@ -46,8 +47,12 @@ program
46
47
  program
47
48
  .command('create [your-project-name]')
48
49
  .description('Create a new dApp from bare templates')
49
- .action((projectName) => __awaiter(void 0, void 0, void 0, function* () {
50
+ .option('-s, --script', 'Only create the script project')
51
+ .action((projectName, option) => __awaiter(void 0, void 0, void 0, function* () {
50
52
  const name = projectName !== null && projectName !== void 0 ? projectName : 'my-first-ckb-project';
53
+ if (option.script) {
54
+ return yield (0, create_1.createScriptProject)(name);
55
+ }
51
56
  const template = yield (0, create_1.selectBareTemplate)();
52
57
  return (0, create_1.create)(name, template);
53
58
  }));
@@ -56,7 +61,7 @@ program.command('clean').description('Clean the devnet data, need to stop runnin
56
61
  program.command('accounts').description('Print account list info').action(accounts_1.accounts);
57
62
  program.command('list-hashes').description('Use the CKB to list blockchain scripts hashes').action(list_hashes_1.listHashes);
58
63
  program.command('inject-config').description('Add offckb.config.ts to your workspace').action(inject_config_1.injectConfig);
59
- program.command('update-config').description('Update offckb.config.ts in your workspace').action(update_config_1.updateConfig);
64
+ program.command('sync-config').description('Sync offckb.config.ts in your workspace').action(sync_config_1.syncConfig);
60
65
  program
61
66
  .command('deposit [toAddress] [amountInShannon]')
62
67
  .description('Deposit CKB tokens to address, only devnet and testnet')
@@ -86,6 +91,11 @@ program
86
91
  .option('--target <target>', 'Specify the relative bin target folder to deploy to')
87
92
  .option('--privkey <privkey>', 'Specify the private key to deploy scripts')
88
93
  .action((options) => (0, deploy_1.deploy)(options));
94
+ program
95
+ .command('deployed-scripts')
96
+ .description('Show deployed contracts info on different networks, only supports devnet and testnet')
97
+ .option('--network <network>', 'Specify the network to deploy to', 'devnet')
98
+ .action((options) => (0, deployed_scripts_1.deployedScripts)(options));
89
99
  // Add commands meant for developers
90
100
  if (process.env.NODE_ENV === 'development') {
91
101
  // Define the CLI commands and options
@@ -1,3 +1,7 @@
1
1
  import { BareTemplateOption } from '../util/template';
2
+ export interface CreateOption {
3
+ script: boolean;
4
+ }
5
+ export declare function createScriptProject(name: string): void;
2
6
  export declare function create(name: string, template: BareTemplateOption): Promise<void>;
3
7
  export declare function selectBareTemplate(): Promise<BareTemplateOption>;
@@ -12,14 +12,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.selectBareTemplate = exports.create = void 0;
15
+ exports.selectBareTemplate = exports.create = exports.createScriptProject = void 0;
16
16
  const path_1 = __importDefault(require("path"));
17
17
  const const_1 = require("../cfg/const");
18
18
  const fs_1 = require("../util/fs");
19
19
  const template_1 = require("../util/template");
20
20
  const git_1 = require("../util/git");
21
21
  const prompts_1 = require("@inquirer/prompts");
22
+ const child_process_1 = require("child_process");
22
23
  const version = require('../../package.json').version;
24
+ function createScriptProject(name) {
25
+ const cmd = `cargo generate gh:cryptape/ckb-script-templates workspace --name ${name}`;
26
+ try {
27
+ (0, child_process_1.execSync)(cmd, { encoding: 'utf-8', stdio: 'inherit' });
28
+ }
29
+ catch (error) {
30
+ console.error('create script project failed, ', error.message);
31
+ }
32
+ }
33
+ exports.createScriptProject = createScriptProject;
23
34
  function create(name, template) {
24
35
  return __awaiter(this, void 0, void 0, function* () {
25
36
  const targetPath = path_1.default.resolve(const_1.currentExecPath, name);
@@ -0,0 +1,4 @@
1
+ import { NetworkOption } from '../util/type';
2
+ export interface DeployedScriptOption extends NetworkOption {
3
+ }
4
+ export declare function deployedScripts(option?: DeployedScriptOption): void;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deployedScripts = void 0;
4
+ const config_1 = require("../util/config");
5
+ const type_1 = require("../util/type");
6
+ const validator_1 = require("../util/validator");
7
+ function deployedScripts(option = { network: type_1.Network.devnet }) {
8
+ const network = option.network;
9
+ (0, validator_1.validateNetworkOpt)(network);
10
+ const scritpsInfo = (0, config_1.readUserDeployedScriptsInfo)(network);
11
+ console.log(`User deployed scripts on ${network}`);
12
+ console.log(JSON.stringify(scritpsInfo, null, 2));
13
+ }
14
+ exports.deployedScripts = deployedScripts;
@@ -35,11 +35,12 @@ const config_1 = require("../util/config");
35
35
  const validator_1 = require("../util/validator");
36
36
  const type_1 = require("../util/type");
37
37
  function injectConfig() {
38
- const targetPath = const_1.currentExecPath;
39
38
  (0, validator_1.validateTypescriptWorkspace)();
40
39
  // inject the offckb.config.ts file into users workspace
41
40
  // copy config template
42
- (0, fs_1.copyFileSync)(const_1.predefinedOffCKBConfigTsPath, targetPath);
41
+ (0, fs_1.copyFileSync)(const_1.predefinedOffCKBConfigTsPath, const_1.userOffCKBConfigPath);
42
+ // update the version in the offckb.config.ts
43
+ (0, config_1.updateOffCKBConfigVersion)(const_1.userOffCKBConfigPath);
43
44
  // update the config
44
45
  const devnetFullLumosConfig = (0, config_1.buildFullLumosConfig)(type_1.Network.devnet);
45
46
  const testnetFullLumosConfig = (0, config_1.buildFullLumosConfig)(type_1.Network.testnet);
@@ -59,7 +60,7 @@ function injectConfig() {
59
60
  const indexer = offCKB.indexer;
60
61
  const rpc = offCKB.rpc;
61
62
 
62
- Check example at https://github.com/nervosnetwork/docs.nervos.org/tree/develop-v2/examples/create-dob
63
+ Check example at https://github.com/nervosnetwork/docs.nervos.org/tree/develop/examples/simple-transfer
63
64
  `);
64
65
  }
65
66
  exports.injectConfig = injectConfig;
@@ -0,0 +1 @@
1
+ export declare function syncConfig(): void;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateConfig = void 0;
3
+ exports.syncConfig = void 0;
4
4
  const const_1 = require("../cfg/const");
5
5
  const config_1 = require("../util/config");
6
6
  const type_1 = require("../util/type");
7
7
  const validator_1 = require("../util/validator");
8
- function updateConfig() {
8
+ function syncConfig() {
9
9
  (0, validator_1.validateExecDappEnvironment)();
10
10
  // update the offckb.config.ts file in users workspace
11
11
  const devnetFullLumosConfig = (0, config_1.buildFullLumosConfig)(type_1.Network.devnet);
@@ -16,4 +16,4 @@ function updateConfig() {
16
16
  (0, config_1.updateScriptInfoInOffCKBConfigTs)(mainnetFullLumosConfig, const_1.userOffCKBConfigPath, type_1.Network.mainnet);
17
17
  console.log('offCKB config updated.');
18
18
  }
19
- exports.updateConfig = updateConfig;
19
+ exports.syncConfig = syncConfig;
@@ -1,5 +1,6 @@
1
1
  import { config } from '@ckb-lumos/lumos';
2
2
  import { Network } from './type';
3
+ export declare function updateOffCKBConfigVersion(filePath: string): void;
3
4
  export declare function updateScriptInfoInOffCKBConfigTs(newConfig: config.Config, filePath: string, network: Network): void;
4
5
  export declare function readUserDeployedScriptsInfo(network: Network): Record<string, config.ScriptConfig>;
5
6
  export declare function readPredefinedDevnetLumosConfig(): config.Config;
@@ -23,12 +23,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.buildFullLumosConfig = exports.readPredefinedTestnetLumosConfig = exports.readPredefinedMainnetLumosConfig = exports.readPredefinedDevnetLumosConfig = exports.readUserDeployedScriptsInfo = exports.updateScriptInfoInOffCKBConfigTs = void 0;
26
+ exports.buildFullLumosConfig = exports.readPredefinedTestnetLumosConfig = exports.readPredefinedMainnetLumosConfig = exports.readPredefinedDevnetLumosConfig = exports.readUserDeployedScriptsInfo = exports.updateScriptInfoInOffCKBConfigTs = exports.updateOffCKBConfigVersion = void 0;
27
27
  const fs = __importStar(require("fs"));
28
28
  const path = __importStar(require("path"));
29
29
  const const_1 = require("../cfg/const");
30
30
  const lumos_1 = require("@ckb-lumos/lumos");
31
31
  const type_1 = require("./type");
32
+ const version = require('../../package.json').version;
33
+ function updateOffCKBConfigVersion(filePath) {
34
+ const versionTarget = 'update-me-offckb-config-version';
35
+ let fileContent = fs.readFileSync(filePath, 'utf-8');
36
+ fileContent = fileContent.replace(versionTarget, version);
37
+ // Write the updated content back to the file
38
+ fs.writeFileSync(filePath, fileContent, 'utf-8');
39
+ }
40
+ exports.updateOffCKBConfigVersion = updateOffCKBConfigVersion;
32
41
  function updateScriptInfoInOffCKBConfigTs(newConfig, filePath, network) {
33
42
  // Read the content of the offckb.config.ts file
34
43
  let fileContent = fs.readFileSync(filePath, 'utf-8');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@offckb/cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "ckb development network for your first try",
5
5
  "author": "Retric Su <retric@cryptape.com>",
6
6
  "license": "MIT",
@@ -1 +0,0 @@
1
- export declare function updateConfig(): void;