@offckb/cli 0.3.0-canary-e88a9d6.0 → 0.3.0-canary-1f8bab4.0
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 +7 -1
- package/dist/cli.js +15 -3
- package/dist/cmd/deploy.d.ts +2 -1
- package/dist/cmd/deploy.js +16 -14
- package/dist/cmd/inject-config.d.ts +4 -1
- package/dist/cmd/inject-config.js +29 -7
- package/dist/cmd/sync-scripts.d.ts +4 -1
- package/dist/cmd/sync-scripts.js +11 -4
- package/dist/deploy/index.d.ts +2 -2
- package/dist/deploy/index.js +10 -9
- package/dist/util/fs.d.ts +1 -0
- package/dist/util/fs.js +17 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -210,12 +210,18 @@ To build the script, in the root of the project, run:
|
|
|
210
210
|
make build
|
|
211
211
|
```
|
|
212
212
|
|
|
213
|
-
To deploy the script, cd into the frontend folder and run:
|
|
213
|
+
To deploy the script, cd into the frontend folder where the default `offckb.config.ts` file is located and run:
|
|
214
214
|
|
|
215
215
|
```sh
|
|
216
216
|
cd frontend && offckb deploy --network <devnet/testnet>
|
|
217
217
|
```
|
|
218
218
|
|
|
219
|
+
Or specific the `offckb.config.ts` file path for deploy command to locate:
|
|
220
|
+
|
|
221
|
+
```sh
|
|
222
|
+
offckb deploy --network <devnet/testnet> --config <file-path-to-your-offckb.config.ts-file>
|
|
223
|
+
```
|
|
224
|
+
|
|
219
225
|
Pass `--type-id` option if you want Scripts to be upgradable
|
|
220
226
|
|
|
221
227
|
```sh
|
package/dist/cli.js
CHANGED
|
@@ -96,8 +96,19 @@ program
|
|
|
96
96
|
.command('list-hashes [CKB-Version]')
|
|
97
97
|
.description('Use the CKB to list blockchain scripts hashes')
|
|
98
98
|
.action(list_hashes_1.printDevnetListHashes);
|
|
99
|
-
program
|
|
100
|
-
|
|
99
|
+
program
|
|
100
|
+
.command('inject-config')
|
|
101
|
+
.description('Add offckb.config.ts to your frontend workspace')
|
|
102
|
+
.option('--target <target>', 'Specify the custom file path of the new injected config')
|
|
103
|
+
.action(inject_config_1.injectConfig);
|
|
104
|
+
program
|
|
105
|
+
.command('sync-scripts')
|
|
106
|
+
.description('Sync scripts json files in your frontend workspace')
|
|
107
|
+
.option('--config <config>', 'Specify the offckb.config.ts file path', undefined)
|
|
108
|
+
.action((opt) => {
|
|
109
|
+
const configPath = opt.config;
|
|
110
|
+
return (0, sync_scripts_1.syncScripts)({ configPath });
|
|
111
|
+
});
|
|
101
112
|
program
|
|
102
113
|
.command('deposit [toAddress] [amountInCKB]')
|
|
103
114
|
.description('Deposit CKB tokens to address, only devnet and testnet')
|
|
@@ -135,7 +146,8 @@ program
|
|
|
135
146
|
.command('deploy')
|
|
136
147
|
.description('Deploy contracts to different networks, only supports devnet and testnet')
|
|
137
148
|
.option('--network <network>', 'Specify the network to deploy to', 'devnet')
|
|
138
|
-
.option('--target <target>', 'Specify the
|
|
149
|
+
.option('--target <target>', 'Specify the script binaries file/folder path to deploy')
|
|
150
|
+
.option('--config <config>', 'Specify the offckb.config.ts file path for deployment', undefined)
|
|
139
151
|
.option('-t, --type-id', 'Specify if use upgradable type id to deploy the script')
|
|
140
152
|
.option('--privkey <privkey>', 'Specify the private key to deploy scripts')
|
|
141
153
|
.option('-r, --proxy-rpc', 'Use Proxy RPC to connect to blockchain')
|
package/dist/cmd/deploy.d.ts
CHANGED
package/dist/cmd/deploy.js
CHANGED
|
@@ -20,7 +20,8 @@ const fs_1 = require("../util/fs");
|
|
|
20
20
|
const validator_1 = require("../util/validator");
|
|
21
21
|
const deploy_1 = require("../deploy");
|
|
22
22
|
const ckb_1 = require("../sdk/ckb");
|
|
23
|
-
|
|
23
|
+
const fs_2 = __importDefault(require("fs"));
|
|
24
|
+
function deploy(opt = { network: base_1.Network.devnet, typeId: false, target: undefined, proxyRpc: false }) {
|
|
24
25
|
var _a;
|
|
25
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
27
|
const network = opt.network;
|
|
@@ -30,28 +31,29 @@ function deploy(opt = { network: base_1.Network.devnet, typeId: false, target: n
|
|
|
30
31
|
// we use deployerAccount to deploy contract by default
|
|
31
32
|
const privateKey = opt.privkey || account_1.deployerAccount.privkey;
|
|
32
33
|
const enableTypeId = (_a = opt.typeId) !== null && _a !== void 0 ? _a : false;
|
|
34
|
+
const configPath = opt.config;
|
|
33
35
|
const targetFolder = opt.target;
|
|
34
36
|
if (targetFolder) {
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const binPaths = bins.map((bin) => path_1.default.resolve(binFolder, bin));
|
|
37
|
+
const binFilesOrFolder = (0, fs_1.isAbsolutePath)(targetFolder) ? targetFolder : path_1.default.resolve(process.cwd(), targetFolder);
|
|
38
|
+
const binPaths = (0, fs_1.getBinaryFilesFromPath)(binFilesOrFolder);
|
|
38
39
|
const results = yield (0, deploy_1.deployBinaries)(binPaths, privateKey, enableTypeId, ckb);
|
|
39
40
|
// record the deployed contract infos
|
|
40
|
-
(0, deploy_1.recordDeployResult)(results, network
|
|
41
|
+
(0, deploy_1.recordDeployResult)(results, network); // we don't update my-scripts.json since we don't know where the file is
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
43
|
-
// check if target workspace is valid
|
|
44
|
-
try {
|
|
45
|
-
(0, validator_1.validateExecDappEnvironment)();
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
return console.debug('Not a valid offCKB dapp workspace.');
|
|
49
|
-
}
|
|
50
44
|
// read contract bin folder
|
|
51
|
-
const
|
|
45
|
+
const userOffCKBConfigPath = configPath
|
|
46
|
+
? (0, fs_1.isAbsolutePath)(configPath)
|
|
47
|
+
? configPath
|
|
48
|
+
: path_1.default.resolve(process.cwd(), configPath)
|
|
49
|
+
: path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
50
|
+
if (!fs_2.default.existsSync(userOffCKBConfigPath)) {
|
|
51
|
+
throw new Error(`config file not exits: ${userOffCKBConfigPath}, tips: use --config to specific the offckb.config.ts file`);
|
|
52
|
+
}
|
|
53
|
+
const bins = (0, deploy_1.getToDeployBinsPath)(userOffCKBConfigPath);
|
|
52
54
|
const results = yield (0, deploy_1.deployBinaries)(bins, privateKey, enableTypeId, ckb);
|
|
53
55
|
// record the deployed contract infos
|
|
54
|
-
(0, deploy_1.recordDeployResult)(results, network);
|
|
56
|
+
(0, deploy_1.recordDeployResult)(results, network, userOffCKBConfigPath);
|
|
55
57
|
});
|
|
56
58
|
}
|
|
57
59
|
exports.deploy = deploy;
|
|
@@ -1,22 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
4
24
|
};
|
|
5
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
26
|
exports.injectConfig = void 0;
|
|
7
27
|
const fs_1 = require("fs");
|
|
8
|
-
const
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
28
|
+
const path_1 = __importStar(require("path"));
|
|
10
29
|
const gen_1 = require("../scripts/gen");
|
|
11
30
|
const offckb_config_1 = require("../template/offckb-config");
|
|
12
31
|
const setting_1 = require("../cfg/setting");
|
|
13
32
|
const version = require('../../package.json').version;
|
|
14
|
-
function injectConfig() {
|
|
15
|
-
(0, validator_1.validateTypescriptWorkspace)();
|
|
33
|
+
function injectConfig({ target }) {
|
|
16
34
|
// inject the offckb.config.ts file into users workspace
|
|
17
35
|
// copy config template
|
|
36
|
+
const userOffCKBConfigPath = target
|
|
37
|
+
? (0, path_1.isAbsolute)(target)
|
|
38
|
+
? target
|
|
39
|
+
: path_1.default.resolve(process.cwd(), target)
|
|
40
|
+
: path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
18
41
|
const predefinedOffCKBConfigTsPath = path_1.default.resolve(setting_1.packageRootPath, 'templates/v3/offckb.config.example.ts');
|
|
19
|
-
const userOffCKBConfigPath = path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
20
42
|
(0, fs_1.copyFileSync)(predefinedOffCKBConfigTsPath, userOffCKBConfigPath);
|
|
21
43
|
// update the version in the offckb.config.ts
|
|
22
44
|
offckb_config_1.OffCKBConfigFile.updateVersion(version, userOffCKBConfigPath);
|
package/dist/cmd/sync-scripts.js
CHANGED
|
@@ -5,12 +5,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.syncScripts = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const validator_1 = require("../util/validator");
|
|
9
8
|
const gen_1 = require("../scripts/gen");
|
|
10
9
|
const offckb_config_1 = require("../template/offckb-config");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const fs_1 = require("../util/fs");
|
|
11
|
+
const fs_2 = __importDefault(require("fs"));
|
|
12
|
+
function syncScripts({ configPath }) {
|
|
13
|
+
const userOffCKBConfigPath = configPath
|
|
14
|
+
? (0, fs_1.isAbsolutePath)(configPath)
|
|
15
|
+
? configPath
|
|
16
|
+
: path_1.default.resolve(process.cwd(), configPath)
|
|
17
|
+
: path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
18
|
+
if (!fs_2.default.existsSync(userOffCKBConfigPath)) {
|
|
19
|
+
throw new Error(`config file not exits: ${userOffCKBConfigPath}, tips: use --config to specific the offckb.config.ts file`);
|
|
20
|
+
}
|
|
14
21
|
const contractInfoFolder = offckb_config_1.OffCKBConfigFile.readContractInfoFolder(userOffCKBConfigPath);
|
|
15
22
|
if (!contractInfoFolder) {
|
|
16
23
|
throw new Error('No contract info folder found in offckb.config.ts!');
|
package/dist/deploy/index.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { HexString } from '../type/base';
|
|
|
6
6
|
export type DeployBinaryReturnType = ReturnType<typeof deployBinary>;
|
|
7
7
|
export type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
|
|
8
8
|
export type DeployedInterfaceType = UnwrapPromise<DeployBinaryReturnType>;
|
|
9
|
-
export declare function getToDeployBinsPath(): string[];
|
|
10
|
-
export declare function recordDeployResult(results: DeployedInterfaceType[], network: Network,
|
|
9
|
+
export declare function getToDeployBinsPath(userOffCKBConfigPath: string): string[];
|
|
10
|
+
export declare function recordDeployResult(results: DeployedInterfaceType[], network: Network, userOffCKBConfigPath?: string): Promise<void>;
|
|
11
11
|
export declare function deployBinaries(binPaths: string[], privateKey: HexString, enableTypeId: boolean, ckb: CKB): Promise<{
|
|
12
12
|
deploymentRecipe: DeploymentRecipe;
|
|
13
13
|
deploymentOptions: DeploymentOptions;
|
package/dist/deploy/index.js
CHANGED
|
@@ -21,17 +21,16 @@ const fs_1 = require("../util/fs");
|
|
|
21
21
|
const path_1 = __importDefault(require("path"));
|
|
22
22
|
const fs_2 = __importDefault(require("fs"));
|
|
23
23
|
const core_1 = require("@ckb-ccc/core");
|
|
24
|
-
function getToDeployBinsPath() {
|
|
25
|
-
const userOffCKBConfigPath = path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
24
|
+
function getToDeployBinsPath(userOffCKBConfigPath) {
|
|
26
25
|
const fileContent = fs_2.default.readFileSync(userOffCKBConfigPath, 'utf-8');
|
|
27
26
|
const match = fileContent.match(/contractBinFolder:\s*['"]([^'"]+)['"]/);
|
|
28
27
|
if (match && match[1]) {
|
|
29
28
|
const contractBinFolderValue = match[1];
|
|
30
|
-
const
|
|
29
|
+
const binFileOrFolderPath = (0, fs_1.isAbsolutePath)(contractBinFolderValue)
|
|
31
30
|
? contractBinFolderValue
|
|
32
|
-
: path_1.default.resolve(
|
|
33
|
-
const bins = (0, fs_1.
|
|
34
|
-
return bins
|
|
31
|
+
: path_1.default.resolve(userOffCKBConfigPath, contractBinFolderValue);
|
|
32
|
+
const bins = (0, fs_1.getBinaryFilesFromPath)(binFileOrFolderPath);
|
|
33
|
+
return bins;
|
|
35
34
|
}
|
|
36
35
|
else {
|
|
37
36
|
console.log('contractBinFolder value not found in offckb.config.ts');
|
|
@@ -39,7 +38,7 @@ function getToDeployBinsPath() {
|
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
exports.getToDeployBinsPath = getToDeployBinsPath;
|
|
42
|
-
function recordDeployResult(results, network,
|
|
41
|
+
function recordDeployResult(results, network, userOffCKBConfigPath) {
|
|
43
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
43
|
if (results.length === 0) {
|
|
45
44
|
return;
|
|
@@ -49,8 +48,10 @@ function recordDeployResult(results, network, isUpdateMyScriptsJsonFile = true)
|
|
|
49
48
|
(0, migration_1.generateDeploymentMigrationFile)(result.deploymentOptions.name, result.deploymentRecipe, network);
|
|
50
49
|
}
|
|
51
50
|
// update my-scripts.json
|
|
52
|
-
if (
|
|
53
|
-
|
|
51
|
+
if (userOffCKBConfigPath) {
|
|
52
|
+
if (!fs_2.default.existsSync(userOffCKBConfigPath)) {
|
|
53
|
+
throw new Error(`config file not exits: ${userOffCKBConfigPath}`);
|
|
54
|
+
}
|
|
54
55
|
const folder = offckb_config_1.OffCKBConfigFile.readContractInfoFolder(userOffCKBConfigPath);
|
|
55
56
|
if (folder) {
|
|
56
57
|
const myScriptsFilePath = path_1.default.resolve(folder, 'my-scripts.json');
|
package/dist/util/fs.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ 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
6
|
export declare function readFileToUint8Array(filePath: string): Promise<Uint8Array>;
|
|
7
|
+
export declare function getBinaryFilesFromPath(fileOrFolderPath: string): string[];
|
|
7
8
|
export declare function listBinaryFilesInFolder(folderPath: string): string[];
|
|
8
9
|
export declare function isBinaryFile(filePath: string): boolean;
|
|
9
10
|
export declare function isAbsolutePath(filePath: string): boolean;
|
package/dist/util/fs.js
CHANGED
|
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.getSubfolders = exports.findFileInFolder = exports.isAbsolutePath = exports.isBinaryFile = exports.listBinaryFilesInFolder = exports.readFileToUint8Array = exports.copyRecursive = exports.copyFilesWithExclusion = exports.copyFileSync = exports.copyFolderSync = exports.isFolderExists = void 0;
|
|
35
|
+
exports.getSubfolders = exports.findFileInFolder = exports.isAbsolutePath = exports.isBinaryFile = exports.listBinaryFilesInFolder = exports.getBinaryFilesFromPath = exports.readFileToUint8Array = exports.copyRecursive = exports.copyFilesWithExclusion = exports.copyFileSync = exports.copyFolderSync = exports.isFolderExists = void 0;
|
|
36
36
|
const fs = __importStar(require("fs"));
|
|
37
37
|
const path = __importStar(require("path"));
|
|
38
38
|
function isFolderExists(folderPath) {
|
|
@@ -135,19 +135,29 @@ function readFileToUint8Array(filePath) {
|
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
137
|
exports.readFileToUint8Array = readFileToUint8Array;
|
|
138
|
+
function getBinaryFilesFromPath(fileOrFolderPath) {
|
|
139
|
+
if (!fs.existsSync(fileOrFolderPath)) {
|
|
140
|
+
throw new Error(`File or Folder not exits ${fileOrFolderPath}`);
|
|
141
|
+
}
|
|
142
|
+
// Check if the provided path is a directory
|
|
143
|
+
if (fs.lstatSync(fileOrFolderPath).isDirectory()) {
|
|
144
|
+
return listBinaryFilesInFolder(fileOrFolderPath);
|
|
145
|
+
}
|
|
146
|
+
if (fs.lstatSync(fileOrFolderPath).isFile() && isBinaryFile(fileOrFolderPath)) {
|
|
147
|
+
return [fileOrFolderPath];
|
|
148
|
+
}
|
|
149
|
+
throw new Error(`${fileOrFolderPath} is not a valid path to deploy scripts.`);
|
|
150
|
+
}
|
|
151
|
+
exports.getBinaryFilesFromPath = getBinaryFilesFromPath;
|
|
138
152
|
function listBinaryFilesInFolder(folderPath) {
|
|
139
153
|
// Check if the provided path is a directory
|
|
140
154
|
if (!fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) {
|
|
141
155
|
throw new Error(`${folderPath} is not a valid directory.`);
|
|
142
156
|
}
|
|
143
157
|
// Read the contents of the directory
|
|
144
|
-
const files = fs.readdirSync(folderPath);
|
|
158
|
+
const files = fs.readdirSync(folderPath).map((f) => path.join(folderPath, f));
|
|
145
159
|
// Filter out only the binary files (assuming they have extensions like .exe, .bin, .dll, etc.)
|
|
146
|
-
const binaryFiles = files.filter((file) =>
|
|
147
|
-
const filePath = path.join(folderPath, file);
|
|
148
|
-
// Check if the file is a regular file and not a directory
|
|
149
|
-
return fs.statSync(filePath).isFile() && isBinaryFile(filePath);
|
|
150
|
-
});
|
|
160
|
+
const binaryFiles = files.filter((file) => fs.statSync(file).isFile() && isBinaryFile(file));
|
|
151
161
|
return binaryFiles;
|
|
152
162
|
}
|
|
153
163
|
exports.listBinaryFilesInFolder = listBinaryFilesInFolder;
|