@offckb/cli 0.3.0-rc9 → 0.3.1

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/dist/cli.js CHANGED
@@ -146,7 +146,7 @@ program
146
146
  .command('deploy')
147
147
  .description('Deploy contracts to different networks, only supports devnet and testnet')
148
148
  .option('--network <network>', 'Specify the network to deploy to', 'devnet')
149
- .option('--target <target>', 'Specify the relative bin target folder to deploy to')
149
+ .option('--target <target>', 'Specify the script binaries file/folder path to deploy')
150
150
  .option('--config <config>', 'Specify the offckb.config.ts file path for deployment', undefined)
151
151
  .option('-t, --type-id', 'Specify if use upgradable type id to deploy the script')
152
152
  .option('--privkey <privkey>', 'Specify the private key to deploy scripts')
@@ -34,9 +34,8 @@ function deploy(opt = { network: base_1.Network.devnet, typeId: false, target: u
34
34
  const configPath = opt.config;
35
35
  const targetFolder = opt.target;
36
36
  if (targetFolder) {
37
- const binFolder = (0, fs_1.isAbsolutePath)(targetFolder) ? targetFolder : path_1.default.resolve(process.cwd(), targetFolder);
38
- const bins = (0, fs_1.listBinaryFilesInFolder)(binFolder);
39
- 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);
40
39
  const results = yield (0, deploy_1.deployBinaries)(binPaths, privateKey, enableTypeId, ckb);
41
40
  // record the deployed contract infos
42
41
  (0, deploy_1.recordDeployResult)(results, network); // we don't update my-scripts.json since we don't know where the file is
@@ -26,11 +26,11 @@ function getToDeployBinsPath(userOffCKBConfigPath) {
26
26
  const match = fileContent.match(/contractBinFolder:\s*['"]([^'"]+)['"]/);
27
27
  if (match && match[1]) {
28
28
  const contractBinFolderValue = match[1];
29
- const binFolderPath = (0, fs_1.isAbsolutePath)(contractBinFolderValue)
29
+ const binFileOrFolderPath = (0, fs_1.isAbsolutePath)(contractBinFolderValue)
30
30
  ? contractBinFolderValue
31
31
  : path_1.default.resolve(userOffCKBConfigPath, contractBinFolderValue);
32
- const bins = (0, fs_1.listBinaryFilesInFolder)(binFolderPath);
33
- return bins.map((bin) => path_1.default.resolve(binFolderPath, bin));
32
+ const bins = (0, fs_1.getBinaryFilesFromPath)(binFileOrFolderPath);
33
+ return bins;
34
34
  }
35
35
  else {
36
36
  console.log('contractBinFolder value not found in offckb.config.ts');
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@offckb/cli",
3
- "version": "0.3.0-rc9",
3
+ "version": "0.3.1",
4
4
  "description": "ckb development network for your first try",
5
5
  "author": "CKB EcoFund",
6
6
  "license": "MIT",