@offckb/cli 0.1.0-rc6 → 0.1.0-rc8

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
@@ -26,6 +26,11 @@ Start building on Nervos blockchain, right now, right away!
26
26
  - [Step 1: Create A Project](#step-1-create-a-project)
27
27
  - [Step 2: Start the Devnet](#step-2-start-the-devnet)
28
28
  - [Step 3: Access Pre-funded Accounts](#step-3-access-pre-funded-accounts)
29
+ - [Dapp Templates](#dapp-templates)
30
+ - [View and transfer balance](#view-and-transfer-balance)
31
+ - [Write \& read on-chain messages](#write--read-on-chain-messages)
32
+ - [Issue custom token via xUDT scripts](#issue-custom-token-via-xudt-scripts)
33
+ - [Create on-chain digital object via Spore protocol](#create-on-chain-digital-object-via-spore-protocol)
29
34
  - [Built-in scripts](#built-in-scripts)
30
35
  - [Accounts](#accounts)
31
36
  - [About Lumos](#about-lumos)
@@ -121,6 +126,36 @@ Print account list, each account is funded with 42_000_000_00000000 capacity in
121
126
 
122
127
  Copy some private keys and visit http://localhost:1234 to play your first CKB Dapp!
123
128
 
129
+ ## Dapp Templates
130
+
131
+ `offckb` packs some basic minimal Dapp templates for you to learn and get started with. By running `offckb init`, you can select the different Dapp templates to quickly set up a local Dapp project targeting the local blockchain with built-in scripts and accounts.
132
+
133
+ The Dapp templates often involve interaction with some most useful smart contracts on CKB like xUDT/Spore/Omnilock. The best thing is those Dapp examples also come with detailed tutorial documents from [docs.nervos.org](https://docs.nervos.org/). The source codes of these templates are also maintained [here](https://github.com/nervosnetwork/docs.nervos.org/tree/develop-v2/examples).
134
+
135
+ ### View and transfer balance
136
+
137
+ A simple Dapp to check CKB balance and transfer CKB.
138
+
139
+ [Tutorial](https://nervos-ckb-docs-git-develop-v2-cryptape.vercel.app/docs/dapp/view-and-transfer-balance)
140
+
141
+ ### Write & read on-chain messages
142
+
143
+ A simple Dapp to issue your own token via XUDT scripts.
144
+
145
+ [Tutorial](https://nervos-ckb-docs-git-develop-v2-cryptape.vercel.app/docs/dapp/write-and-read-on-chain-message)
146
+
147
+ ### Issue custom token via xUDT scripts
148
+
149
+ A simple Dapp to store & retrieve data from a Cell.
150
+
151
+ [Tutorial](https://nervos-ckb-docs-git-develop-v2-cryptape.vercel.app/docs/dapp/issue-custom-token)
152
+
153
+ ### Create on-chain digital object via Spore protocol
154
+
155
+ A simple Dapp to create on-chain digital objects with spore scripts.
156
+
157
+ [Tutorial](https://nervos-ckb-docs-git-develop-v2-cryptape.vercel.app/docs/dapp/create-nft)
158
+
124
159
  ## Built-in scripts
125
160
 
126
161
  - [x] xUDT https://github.com/nervosnetwork/rfcs/pull/428
@@ -10,3 +10,8 @@ export declare const ckbFolderPath: string;
10
10
  export declare const ckbBinPath: string;
11
11
  export declare const accountTargetDir: string;
12
12
  export declare const minimalRequiredCKBVersion = "0.113.1";
13
+ export declare const dappTemplateGitRepoUserAndName = "nervosnetwork/docs.nervos.org";
14
+ export declare const dappTemplateGitUrl = "https://github.com/nervosnetwork/docs.nervos.org";
15
+ export declare const dappTemplateGitBranch = "develop-v2";
16
+ export declare const dappTemplateGitFolder = "examples";
17
+ export declare const dappTemplateGitSelectOptionFile = "options.json";
package/dist/cfg/const.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.minimalRequiredCKBVersion = exports.accountTargetDir = exports.ckbBinPath = exports.ckbFolderPath = exports.devnetDataPath = exports.devnetPath = exports.devnetSourcePath = exports.targetEnvironmentPath = exports.dappTemplatePath = exports.packageRootPath = exports.packageSrcPath = exports.currentExecPath = void 0;
26
+ exports.dappTemplateGitSelectOptionFile = exports.dappTemplateGitFolder = exports.dappTemplateGitBranch = exports.dappTemplateGitUrl = exports.dappTemplateGitRepoUserAndName = exports.minimalRequiredCKBVersion = exports.accountTargetDir = exports.ckbBinPath = exports.ckbFolderPath = exports.devnetDataPath = exports.devnetPath = exports.devnetSourcePath = exports.targetEnvironmentPath = exports.dappTemplatePath = exports.packageRootPath = exports.packageSrcPath = exports.currentExecPath = void 0;
27
27
  const path = __importStar(require("path"));
28
28
  // path
29
29
  exports.currentExecPath = process.cwd();
@@ -39,3 +39,9 @@ exports.ckbBinPath = path.resolve(exports.ckbFolderPath, 'ckb');
39
39
  exports.accountTargetDir = path.join(exports.packageRootPath, `account`);
40
40
  // Version
41
41
  exports.minimalRequiredCKBVersion = '0.113.1';
42
+ // url
43
+ exports.dappTemplateGitRepoUserAndName = 'nervosnetwork/docs.nervos.org';
44
+ exports.dappTemplateGitUrl = `https://github.com/${exports.dappTemplateGitRepoUserAndName}`;
45
+ exports.dappTemplateGitBranch = 'develop-v2';
46
+ exports.dappTemplateGitFolder = 'examples';
47
+ exports.dappTemplateGitSelectOptionFile = 'options.json';
package/dist/cli.js CHANGED
@@ -19,7 +19,6 @@ const init_chain_1 = require("./cmd/init-chain");
19
19
  const build_lumos_config_1 = require("./cmd/build-lumos-config");
20
20
  const init_1 = require("./cmd/init");
21
21
  const accounts_1 = require("./cmd/accounts");
22
- const select_1 = require("./cfg/select");
23
22
  const clean_1 = require("./cmd/clean");
24
23
  const version = require('../package.json').version;
25
24
  const program = new commander_1.Command();
@@ -32,7 +31,7 @@ program
32
31
  .description('init dapp project with lumos')
33
32
  .action((str) => __awaiter(void 0, void 0, void 0, function* () {
34
33
  const name = str !== null && str !== void 0 ? str : 'my-awesome-ckb-dapp';
35
- const template = yield (0, select_1.selectTemplate)();
34
+ const template = yield (0, init_1.selectTemplate)();
36
35
  return (0, init_1.init)(name, template);
37
36
  }));
38
37
  program.command('node').description('Use the CKB to start devnet').action(node_1.node);
@@ -59,6 +59,41 @@ export declare function devnetLumosConfigTemplate(cellBaseTxHashInGenesisBlock:
59
59
  INDEX: string;
60
60
  DEP_TYPE: string;
61
61
  };
62
+ SPORE: {
63
+ CODE_HASH: string;
64
+ HASH_TYPE: string;
65
+ TX_HASH: string;
66
+ INDEX: string;
67
+ DEP_TYPE: string;
68
+ };
69
+ SPORE_CLUSTER: {
70
+ CODE_HASH: string;
71
+ HASH_TYPE: string;
72
+ TX_HASH: string;
73
+ INDEX: string;
74
+ DEP_TYPE: string;
75
+ };
76
+ SPORE_CLUSTER_AGENT: {
77
+ CODE_HASH: string;
78
+ HASH_TYPE: string;
79
+ TX_HASH: string;
80
+ INDEX: string;
81
+ DEP_TYPE: string;
82
+ };
83
+ SPORE_CLUSTER_PROXY: {
84
+ CODE_HASH: string;
85
+ HASH_TYPE: string;
86
+ TX_HASH: string;
87
+ INDEX: string;
88
+ DEP_TYPE: string;
89
+ };
90
+ SPORE_LUA: {
91
+ CODE_HASH: string;
92
+ HASH_TYPE: string;
93
+ TX_HASH: string;
94
+ INDEX: string;
95
+ DEP_TYPE: string;
96
+ };
62
97
  };
63
98
  };
64
99
  export declare function buildLumosConfig(): Promise<void>;
@@ -79,6 +79,41 @@ function devnetLumosConfigTemplate(cellBaseTxHashInGenesisBlock, secondTxHashInG
79
79
  INDEX: '0x9',
80
80
  DEP_TYPE: 'code',
81
81
  },
82
+ SPORE: {
83
+ CODE_HASH: '0x7e8bf78a62232caa2f5d47e691e8db1a90d05e93dc6828ad3cb935c01ec6d208',
84
+ HASH_TYPE: 'data1',
85
+ TX_HASH: cellBaseTxHashInGenesisBlock,
86
+ INDEX: '0xa',
87
+ DEP_TYPE: 'code',
88
+ },
89
+ SPORE_CLUSTER: {
90
+ CODE_HASH: '0x7366a61534fa7c7e6225ecc0d828ea3b5366adec2b58206f2ee84995fe030075',
91
+ HASH_TYPE: 'data1',
92
+ TX_HASH: cellBaseTxHashInGenesisBlock,
93
+ INDEX: '0xb',
94
+ DEP_TYPE: 'code',
95
+ },
96
+ SPORE_CLUSTER_AGENT: {
97
+ CODE_HASH: '0xc986099b41d79ca1b2a56ce5874bcda8175440a17298ea5e2bbc3897736b8c21',
98
+ HASH_TYPE: 'data1',
99
+ TX_HASH: cellBaseTxHashInGenesisBlock,
100
+ INDEX: '0xc',
101
+ DEP_TYPE: 'code',
102
+ },
103
+ SPORE_CLUSTER_PROXY: {
104
+ CODE_HASH: '0xbe8b9ce3d05a32c4bb26fe71cd5fc1407ce91e3a8b9e8719be2ab072cef1454b',
105
+ HASH_TYPE: 'data1',
106
+ TX_HASH: cellBaseTxHashInGenesisBlock,
107
+ INDEX: '0xd',
108
+ DEP_TYPE: 'code',
109
+ },
110
+ SPORE_LUA: {
111
+ CODE_HASH: '0x94a9b875911ace20f1f0d063a26495d14e4b04e32fd218261bb747f34e71ae47',
112
+ HASH_TYPE: 'data1',
113
+ TX_HASH: cellBaseTxHashInGenesisBlock,
114
+ INDEX: '0xe',
115
+ DEP_TYPE: 'code',
116
+ },
82
117
  },
83
118
  };
84
119
  return devnetConfig;
package/dist/cmd/clean.js CHANGED
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.clean = void 0;
4
7
  const const_1 = require("../cfg/const");
5
8
  const util_1 = require("../util");
9
+ const fs_1 = __importDefault(require("fs"));
6
10
  function clean() {
7
11
  if ((0, util_1.isFolderExists)(const_1.devnetDataPath)) {
8
12
  try {
9
- (0, util_1.removeFolderSync)(const_1.devnetDataPath);
13
+ fs_1.default.rmSync(const_1.devnetDataPath, { recursive: true });
10
14
  console.log(`Chain data cleaned.`);
11
15
  }
12
16
  catch (error) {
@@ -1 +1,2 @@
1
1
  export declare function init(name: string, template: string): void;
2
+ export declare function selectTemplate(): Promise<string>;
package/dist/cmd/init.js CHANGED
@@ -1,16 +1,27 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.init = void 0;
15
+ exports.selectTemplate = exports.init = void 0;
7
16
  const const_1 = require("../cfg/const");
8
17
  const path_1 = __importDefault(require("path"));
9
18
  const util_1 = require("../util");
19
+ const select_1 = __importDefault(require("@inquirer/select"));
20
+ const util_2 = require("../util");
10
21
  function init(name, template) {
11
22
  const targetPath = path_1.default.resolve(const_1.currentExecPath, name);
12
- const sourcePath = path_1.default.resolve(const_1.dappTemplatePath, template);
13
- (0, util_1.copyFolderSync)(sourcePath, targetPath);
23
+ const dappTemplateFolderPath = `${const_1.dappTemplateGitFolder}/${template}`;
24
+ (0, util_1.gitCloneAndDownloadFolderSync)(const_1.dappTemplateGitUrl, const_1.dappTemplateGitBranch, dappTemplateFolderPath, targetPath);
14
25
  // add some common code files
15
26
  const ckbDotTs = path_1.default.resolve(const_1.dappTemplatePath, 'ckb.ts');
16
27
  const configJson = path_1.default.resolve(const_1.dappTemplatePath, 'config.json');
@@ -19,3 +30,14 @@ function init(name, template) {
19
30
  console.log(`init CKB dapp project: ${targetPath}`);
20
31
  }
21
32
  exports.init = init;
33
+ function selectTemplate() {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const opts = yield (0, util_2.loadTemplateOpts)();
36
+ const answer = yield (0, select_1.default)({
37
+ message: 'Select a Dapp template',
38
+ choices: opts,
39
+ });
40
+ return answer;
41
+ });
42
+ }
43
+ exports.selectTemplate = selectTemplate;
@@ -1 +1,15 @@
1
1
  export declare function installDependency(): Promise<void>;
2
+ export declare function downloadBinaryAndUnzip(): Promise<void>;
3
+ export declare function downloadAndSaveCKBBinary(tempFilePath: string): Promise<void>;
4
+ export declare function unZipFile(filePath: string, extractDir: string, useTar?: boolean): Promise<void>;
5
+ export declare function decompressTarGzAsync(tarballPath: string, destinationDir: string): Promise<void>;
6
+ export declare function getInstalledVersion(): string | null;
7
+ export declare function isVersionOutdated(installedVersion: string): boolean;
8
+ export declare function getOS(): string;
9
+ export declare function getArch(): string;
10
+ export declare function getExtension(): 'tar.gz' | 'zip';
11
+ export declare function buildDownloadUrl(version: string, opt?: {
12
+ os?: string;
13
+ arch?: string;
14
+ ext?: string;
15
+ }): string;
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.installDependency = void 0;
38
+ exports.buildDownloadUrl = exports.getExtension = exports.getArch = exports.getOS = exports.isVersionOutdated = exports.getInstalledVersion = exports.decompressTarGzAsync = exports.unZipFile = exports.downloadAndSaveCKBBinary = exports.downloadBinaryAndUnzip = exports.installDependency = void 0;
39
39
  const axios_1 = __importDefault(require("axios"));
40
40
  const child_process_1 = require("child_process");
41
41
  const fs = __importStar(require("fs"));
@@ -43,6 +43,7 @@ const path = __importStar(require("path"));
43
43
  const semver_1 = __importDefault(require("semver"));
44
44
  const os_1 = __importDefault(require("os"));
45
45
  const adm_zip_1 = __importDefault(require("adm-zip"));
46
+ const tar = __importStar(require("tar"));
46
47
  const const_1 = require("../cfg/const");
47
48
  const BINARY = const_1.ckbBinPath;
48
49
  const MINIMAL_VERSION = const_1.minimalRequiredCKBVersion;
@@ -53,7 +54,6 @@ function installDependency() {
53
54
  if (version) {
54
55
  if (isVersionOutdated(version)) {
55
56
  console.log(`${BINARY} version ${version} is outdated, download and install the new version ${MINIMAL_VERSION}..`);
56
- console.log(buildDownloadUrl(MINIMAL_VERSION));
57
57
  }
58
58
  else {
59
59
  return;
@@ -62,22 +62,24 @@ function installDependency() {
62
62
  else {
63
63
  console.log(`${BINARY} not found, download and install the new version ${MINIMAL_VERSION}..`);
64
64
  }
65
+ yield downloadBinaryAndUnzip();
66
+ });
67
+ }
68
+ exports.installDependency = installDependency;
69
+ function downloadBinaryAndUnzip() {
70
+ return __awaiter(this, void 0, void 0, function* () {
65
71
  const arch = getArch();
66
72
  const osname = getOS();
73
+ const ext = getExtension();
67
74
  const ckbVersionOSName = `ckb_v${MINIMAL_VERSION}_${arch}-${osname}`;
68
75
  try {
69
- const downloadURL = buildDownloadUrl(MINIMAL_VERSION);
70
- const response = yield axios_1.default.get(downloadURL, {
71
- responseType: 'arraybuffer',
72
- });
73
- const tempFilePath = path.join(os_1.default.tmpdir(), `${ckbVersionOSName}.zip`);
74
- fs.writeFileSync(tempFilePath, response.data);
76
+ const tempFilePath = path.join(os_1.default.tmpdir(), `${ckbVersionOSName}.${ext}`);
77
+ yield downloadAndSaveCKBBinary(tempFilePath);
75
78
  // Unzip the file
76
- const zip = new adm_zip_1.default(tempFilePath);
77
79
  const extractDir = path.join(const_1.targetEnvironmentPath, `ckb_v${MINIMAL_VERSION}`);
78
- zip.extractAllTo(extractDir, /*overwrite*/ true);
79
- const sourcePath = path.join(extractDir, ckbVersionOSName);
80
+ yield unZipFile(tempFilePath, extractDir, ext === 'tar.gz');
80
81
  // Install the extracted files
82
+ const sourcePath = path.join(extractDir, ckbVersionOSName);
81
83
  fs.renameSync(sourcePath, const_1.ckbFolderPath); // Move binary to desired location
82
84
  fs.chmodSync(const_1.ckbBinPath, '755'); // Make the binary executable
83
85
  console.log('CKB installed successfully.');
@@ -87,7 +89,53 @@ function installDependency() {
87
89
  }
88
90
  });
89
91
  }
90
- exports.installDependency = installDependency;
92
+ exports.downloadBinaryAndUnzip = downloadBinaryAndUnzip;
93
+ function downloadAndSaveCKBBinary(tempFilePath) {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ const downloadURL = buildDownloadUrl(MINIMAL_VERSION);
96
+ const response = yield axios_1.default.get(downloadURL, {
97
+ responseType: 'arraybuffer',
98
+ });
99
+ fs.writeFileSync(tempFilePath, response.data);
100
+ });
101
+ }
102
+ exports.downloadAndSaveCKBBinary = downloadAndSaveCKBBinary;
103
+ function unZipFile(filePath, extractDir, useTar = false) {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ // Ensure the destination directory exists, if not create it
106
+ if (!fs.existsSync(extractDir)) {
107
+ fs.mkdirSync(extractDir);
108
+ }
109
+ if (useTar === true) {
110
+ return yield decompressTarGzAsync(filePath, extractDir);
111
+ }
112
+ const zip = new adm_zip_1.default(filePath);
113
+ zip.extractAllTo(extractDir, true);
114
+ });
115
+ }
116
+ exports.unZipFile = unZipFile;
117
+ function decompressTarGzAsync(tarballPath, destinationDir) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ return new Promise((resolve, reject) => {
120
+ // Create a readable stream from the .tar.gz file
121
+ const tarballStream = fs.createReadStream(tarballPath);
122
+ // Extract the contents of the .tar.gz file to the destination directory
123
+ tarballStream
124
+ .pipe(tar.x({
125
+ cwd: destinationDir,
126
+ }))
127
+ .on('error', (err) => {
128
+ console.error('Error extracting tarball:', err);
129
+ reject(err); // Reject with error if extraction fails
130
+ })
131
+ .on('finish', () => {
132
+ console.log('Extraction complete.');
133
+ resolve(); // Resolve when extraction completes
134
+ });
135
+ });
136
+ });
137
+ }
138
+ exports.decompressTarGzAsync = decompressTarGzAsync;
91
139
  function getInstalledVersion() {
92
140
  try {
93
141
  const versionOutput = (0, child_process_1.execSync)(`${BINARY} --version`, {
@@ -103,9 +151,11 @@ function getInstalledVersion() {
103
151
  return null;
104
152
  }
105
153
  }
154
+ exports.getInstalledVersion = getInstalledVersion;
106
155
  function isVersionOutdated(installedVersion) {
107
156
  return semver_1.default.lt(installedVersion, MINIMAL_VERSION);
108
157
  }
158
+ exports.isVersionOutdated = isVersionOutdated;
109
159
  function getOS() {
110
160
  const platform = os_1.default.platform();
111
161
  if (platform === 'darwin') {
@@ -121,6 +171,7 @@ function getOS() {
121
171
  throw new Error('Unsupported operating system');
122
172
  }
123
173
  }
174
+ exports.getOS = getOS;
124
175
  function getArch() {
125
176
  const arch = os_1.default.arch();
126
177
  if (arch === 'x64') {
@@ -133,8 +184,19 @@ function getArch() {
133
184
  throw new Error('Unsupported architecture');
134
185
  }
135
186
  }
136
- function buildDownloadUrl(version) {
137
- const os = getOS();
138
- const arch = getArch();
139
- return `https://github.com/nervosnetwork/ckb/releases/download/v${version}/ckb_v${version}_${arch}-${os}.zip`;
187
+ exports.getArch = getArch;
188
+ function getExtension() {
189
+ const platform = os_1.default.platform();
190
+ if (platform === 'linux') {
191
+ return 'tar.gz';
192
+ }
193
+ return 'zip';
194
+ }
195
+ exports.getExtension = getExtension;
196
+ function buildDownloadUrl(version, opt = {}) {
197
+ const os = opt.os || getOS();
198
+ const arch = opt.arch || getArch();
199
+ const extension = opt.ext || getExtension();
200
+ return `https://github.com/nervosnetwork/ckb/releases/download/v${version}/ckb_v${version}_${arch}-${os}.${extension}`;
140
201
  }
202
+ exports.buildDownloadUrl = buildDownloadUrl;
package/dist/util.d.ts CHANGED
@@ -3,4 +3,11 @@ export declare function copyFolderSync(source: string, destination: string): voi
3
3
  export declare function copyFileSync(source: string, target: string): void;
4
4
  export declare function copyFilesWithExclusion(sourceDir: string, destinationDir: string, excludedFolders: string[]): Promise<void>;
5
5
  export declare function copyRecursive(source: string, destination: string, excludedFolders: string[]): Promise<void>;
6
- export declare function removeFolderSync(folderPath: string): void;
6
+ export declare function isGitInstalled(): boolean;
7
+ export declare function gitCloneAndDownloadFolderSync(repoUrl: string, branch: string, subFolderName: string, targetPath: string): undefined;
8
+ export interface TemplateOption {
9
+ name: string;
10
+ value: string;
11
+ description: string;
12
+ }
13
+ export declare function loadTemplateOpts(): Promise<Array<TemplateOption>>;
package/dist/util.js CHANGED
@@ -31,10 +31,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
32
  });
33
33
  };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
34
37
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.removeFolderSync = exports.copyRecursive = exports.copyFilesWithExclusion = exports.copyFileSync = exports.copyFolderSync = exports.isFolderExists = void 0;
38
+ exports.loadTemplateOpts = exports.gitCloneAndDownloadFolderSync = exports.isGitInstalled = exports.copyRecursive = exports.copyFilesWithExclusion = exports.copyFileSync = exports.copyFolderSync = exports.isFolderExists = void 0;
39
+ const child_process_1 = require("child_process");
36
40
  const fs = __importStar(require("fs"));
37
41
  const path = __importStar(require("path"));
42
+ const const_1 = require("./cfg/const");
43
+ const axios_1 = __importDefault(require("axios"));
44
+ const const_2 = require("./cfg/const");
38
45
  function isFolderExists(folderPath) {
39
46
  try {
40
47
  // Check if the path exists
@@ -121,21 +128,70 @@ function copyRecursive(source, destination, excludedFolders) {
121
128
  });
122
129
  }
123
130
  exports.copyRecursive = copyRecursive;
124
- function removeFolderSync(folderPath) {
125
- if (fs.existsSync(folderPath)) {
126
- fs.readdirSync(folderPath).forEach((file) => {
127
- const curPath = path.join(folderPath, file);
128
- if (fs.lstatSync(curPath).isDirectory()) {
129
- // Recursive call for directories
130
- removeFolderSync(curPath);
131
- }
132
- else {
133
- // Delete files
134
- fs.unlinkSync(curPath);
135
- }
136
- });
137
- // Remove the directory itself
138
- fs.rmdirSync(folderPath);
131
+ function isGitInstalled() {
132
+ try {
133
+ (0, child_process_1.execSync)('git --version');
134
+ return true;
135
+ }
136
+ catch (error) {
137
+ return false;
138
+ }
139
+ }
140
+ exports.isGitInstalled = isGitInstalled;
141
+ function gitCloneAndDownloadFolderSync(repoUrl, branch, subFolderName, targetPath) {
142
+ console.log('start cloning the dapp template..');
143
+ const tempFolder = path.resolve(const_1.dappTemplatePath, 'temp-clone-folder');
144
+ if (!isGitInstalled()) {
145
+ console.log('Git is not installed, please check https://git-scm.com/');
146
+ return process.exit(1);
147
+ }
148
+ // Empty the temp folder if it exists
149
+ if (fs.existsSync(tempFolder)) {
150
+ fs.rmSync(tempFolder, { recursive: true });
151
+ }
152
+ // Create the temp folder
153
+ fs.mkdirSync(tempFolder, { recursive: true });
154
+ // Clone the repository
155
+ try {
156
+ const cloneCommand = `git clone -n --depth=1 --single-branch --branch ${branch} --filter=tree:0 ${repoUrl} ${tempFolder}`;
157
+ (0, child_process_1.execSync)(cloneCommand);
158
+ }
159
+ catch (error) {
160
+ console.error('Error:', error);
161
+ process.exit(1);
162
+ }
163
+ // checkout the examples sub folder
164
+ try {
165
+ (0, child_process_1.execSync)(`git sparse-checkout set ${subFolderName}`, { cwd: tempFolder });
166
+ (0, child_process_1.execSync)(`git checkout`, { cwd: tempFolder });
167
+ }
168
+ catch (error) {
169
+ console.error('Error:', error);
170
+ process.exit(1);
171
+ }
172
+ // Ensure targetPath exists and is a directory
173
+ if (!fs.existsSync(targetPath) || !fs.statSync(targetPath).isDirectory()) {
174
+ fs.mkdirSync(targetPath, { recursive: true });
175
+ }
176
+ const source = path.resolve(tempFolder, subFolderName);
177
+ copyFolderSync(source, targetPath);
178
+ // Empty the temp folder if it exists
179
+ if (fs.existsSync(tempFolder)) {
180
+ fs.rmSync(tempFolder, { recursive: true });
139
181
  }
182
+ console.log(`Folder ${subFolderName} downloaded successfully from ${repoUrl} and moved to ${targetPath}`);
183
+ }
184
+ exports.gitCloneAndDownloadFolderSync = gitCloneAndDownloadFolderSync;
185
+ function loadTemplateOpts() {
186
+ return __awaiter(this, void 0, void 0, function* () {
187
+ const githubUrl = `https://raw.githubusercontent.com/${const_2.dappTemplateGitRepoUserAndName}/${const_2.dappTemplateGitBranch}/${const_2.dappTemplateGitFolder}/${const_2.dappTemplateGitSelectOptionFile}`;
188
+ try {
189
+ const response = yield axios_1.default.get(githubUrl);
190
+ return response.data;
191
+ }
192
+ catch (error) {
193
+ throw new Error(`Error fetching JSON: ${error.message}`);
194
+ }
195
+ });
140
196
  }
141
- exports.removeFolderSync = removeFolderSync;
197
+ exports.loadTemplateOpts = loadTemplateOpts;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@offckb/cli",
3
- "version": "0.1.0-rc6",
3
+ "version": "0.1.0-rc8",
4
4
  "description": "ckb development network for your first try",
5
5
  "author": "Retric Su <retric@cryptape.com>",
6
6
  "license": "MIT",
@@ -26,8 +26,8 @@
26
26
  "build": "tsc",
27
27
  "start": "ts-node-dev --transpile-only src/cli.ts",
28
28
  "clean": "rm -rf ./target",
29
- "lint": "eslint \"{src,templates}/**/*.ts\" \"{src,templates}/**/*.tsx\" --ignore-pattern 'node_modules/'",
30
- "lint:fix": "eslint \"{src,templates}/**/*.ts\" \"{src,templates}/**/*.tsx\" --ignore-pattern 'node_modules/' --fix",
29
+ "lint": "eslint \"src/**/*.ts\" \"templates/*.ts\" --ignore-pattern 'node_modules/'",
30
+ "lint:fix": "eslint \"src/**/*.ts\" \"templates/*.ts\" --ignore-pattern 'node_modules/' --fix",
31
31
  "fmt": "prettier --write '{src,templates,account}/**/*.{js,jsx,ts,tsx,md,json}'"
32
32
  },
33
33
  "husky": {
@@ -48,6 +48,7 @@
48
48
  "@types/adm-zip": "^0.5.5",
49
49
  "@types/node": "^20.11.19",
50
50
  "@types/semver": "^7.5.7",
51
+ "@types/tar": "^6.1.11",
51
52
  "@typescript-eslint/eslint-plugin": "^7.0.2",
52
53
  "@typescript-eslint/parser": "^7.0.2",
53
54
  "eslint": "^8.57.0",
@@ -64,6 +65,7 @@
64
65
  "axios": "^1.6.7",
65
66
  "child_process": "^1.0.2",
66
67
  "commander": "^12.0.0",
67
- "semver": "^7.6.0"
68
+ "semver": "^7.6.0",
69
+ "tar": "^6.2.1"
68
70
  }
69
71
  }
@@ -58,6 +58,41 @@
58
58
  "TX_HASH": "0x1dbed8dcfe0f18359c65c5e9546fd15cd69de73ea0a502345be30180649c9467",
59
59
  "INDEX": "0x9",
60
60
  "DEP_TYPE": "code"
61
+ },
62
+ "SPORE": {
63
+ "CODE_HASH": "0x7e8bf78a62232caa2f5d47e691e8db1a90d05e93dc6828ad3cb935c01ec6d208",
64
+ "HASH_TYPE": "data1",
65
+ "TX_HASH": "0x1dbed8dcfe0f18359c65c5e9546fd15cd69de73ea0a502345be30180649c9467",
66
+ "INDEX": "0xa",
67
+ "DEP_TYPE": "code"
68
+ },
69
+ "SPORE_CLUSTER": {
70
+ "CODE_HASH": "0x7366a61534fa7c7e6225ecc0d828ea3b5366adec2b58206f2ee84995fe030075",
71
+ "HASH_TYPE": "data1",
72
+ "TX_HASH": "0x1dbed8dcfe0f18359c65c5e9546fd15cd69de73ea0a502345be30180649c9467",
73
+ "INDEX": "0xb",
74
+ "DEP_TYPE": "code"
75
+ },
76
+ "SPORE_CLUSTER_AGENT": {
77
+ "CODE_HASH": "0xc986099b41d79ca1b2a56ce5874bcda8175440a17298ea5e2bbc3897736b8c21",
78
+ "HASH_TYPE": "data1",
79
+ "TX_HASH": "0x1dbed8dcfe0f18359c65c5e9546fd15cd69de73ea0a502345be30180649c9467",
80
+ "INDEX": "0xc",
81
+ "DEP_TYPE": "code"
82
+ },
83
+ "SPORE_CLUSTER_PROXY": {
84
+ "CODE_HASH": "0xbe8b9ce3d05a32c4bb26fe71cd5fc1407ce91e3a8b9e8719be2ab072cef1454b",
85
+ "HASH_TYPE": "data1",
86
+ "TX_HASH": "0x1dbed8dcfe0f18359c65c5e9546fd15cd69de73ea0a502345be30180649c9467",
87
+ "INDEX": "0xd",
88
+ "DEP_TYPE": "code"
89
+ },
90
+ "SPORE_LUA": {
91
+ "CODE_HASH": "0x94a9b875911ace20f1f0d063a26495d14e4b04e32fd218261bb747f34e71ae47",
92
+ "HASH_TYPE": "data1",
93
+ "TX_HASH": "0x1dbed8dcfe0f18359c65c5e9546fd15cd69de73ea0a502345be30180649c9467",
94
+ "INDEX": "0xe",
95
+ "DEP_TYPE": "code"
61
96
  }
62
97
  }
63
98
  }
@@ -1 +0,0 @@
1
- export declare function selectTemplate(): Promise<string>;