@offckb/cli 0.3.0-rc8 → 0.3.0-rc9
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 +14 -2
- package/dist/cmd/deploy.d.ts +2 -1
- package/dist/cmd/deploy.js +14 -11
- 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 +7 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -212,12 +212,18 @@ To build the script, in the root of the project, run:
|
|
|
212
212
|
make build
|
|
213
213
|
```
|
|
214
214
|
|
|
215
|
-
To deploy the script, cd into the frontend folder and run:
|
|
215
|
+
To deploy the script, cd into the frontend folder where the default `offckb.config.ts` file is located and run:
|
|
216
216
|
|
|
217
217
|
```sh
|
|
218
218
|
cd frontend && offckb deploy --network <devnet/testnet>
|
|
219
219
|
```
|
|
220
220
|
|
|
221
|
+
Or specific the `offckb.config.ts` file path for deploy command to locate:
|
|
222
|
+
|
|
223
|
+
```sh
|
|
224
|
+
offckb deploy --network <devnet/testnet> --config <file-path-to-your-offckb.config.ts-file>
|
|
225
|
+
```
|
|
226
|
+
|
|
221
227
|
Pass `--type-id` option if you want Scripts to be upgradable
|
|
222
228
|
|
|
223
229
|
```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')
|
|
@@ -136,6 +147,7 @@ program
|
|
|
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
149
|
.option('--target <target>', 'Specify the relative bin target folder to deploy to')
|
|
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,6 +31,7 @@ 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
37
|
const binFolder = (0, fs_1.isAbsolutePath)(targetFolder) ? targetFolder : path_1.default.resolve(process.cwd(), targetFolder);
|
|
@@ -37,21 +39,22 @@ function deploy(opt = { network: base_1.Network.devnet, typeId: false, target: n
|
|
|
37
39
|
const binPaths = bins.map((bin) => path_1.default.resolve(binFolder, bin));
|
|
38
40
|
const results = yield (0, deploy_1.deployBinaries)(binPaths, privateKey, enableTypeId, ckb);
|
|
39
41
|
// record the deployed contract infos
|
|
40
|
-
(0, deploy_1.recordDeployResult)(results, network
|
|
42
|
+
(0, deploy_1.recordDeployResult)(results, network); // we don't update my-scripts.json since we don't know where the file is
|
|
41
43
|
return;
|
|
42
44
|
}
|
|
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
45
|
// read contract bin folder
|
|
51
|
-
const
|
|
46
|
+
const userOffCKBConfigPath = configPath
|
|
47
|
+
? (0, fs_1.isAbsolutePath)(configPath)
|
|
48
|
+
? configPath
|
|
49
|
+
: path_1.default.resolve(process.cwd(), configPath)
|
|
50
|
+
: path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
51
|
+
if (!fs_2.default.existsSync(userOffCKBConfigPath)) {
|
|
52
|
+
throw new Error(`config file not exits: ${userOffCKBConfigPath}, tips: use --config to specific the offckb.config.ts file`);
|
|
53
|
+
}
|
|
54
|
+
const bins = (0, deploy_1.getToDeployBinsPath)(userOffCKBConfigPath);
|
|
52
55
|
const results = yield (0, deploy_1.deployBinaries)(bins, privateKey, enableTypeId, ckb);
|
|
53
56
|
// record the deployed contract infos
|
|
54
|
-
(0, deploy_1.recordDeployResult)(results, network);
|
|
57
|
+
(0, deploy_1.recordDeployResult)(results, network, userOffCKBConfigPath);
|
|
55
58
|
});
|
|
56
59
|
}
|
|
57
60
|
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,15 +21,14 @@ 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
29
|
const binFolderPath = (0, fs_1.isAbsolutePath)(contractBinFolderValue)
|
|
31
30
|
? contractBinFolderValue
|
|
32
|
-
: path_1.default.resolve(
|
|
31
|
+
: path_1.default.resolve(userOffCKBConfigPath, contractBinFolderValue);
|
|
33
32
|
const bins = (0, fs_1.listBinaryFilesInFolder)(binFolderPath);
|
|
34
33
|
return bins.map((bin) => path_1.default.resolve(binFolderPath, bin));
|
|
35
34
|
}
|
|
@@ -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');
|