Skip to content

Commit

Permalink
Update: change tye parser type name and json file name
Browse files Browse the repository at this point in the history
  • Loading branch information
zengxinhai committed May 12, 2023
1 parent 2bde9e9 commit dae5a6f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions example/publish-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
*/
import * as path from "path";
import * as dotenv from "dotenv";
import { SuiKit } from "@scallop-dao/sui-kit";
import { SuiKit } from "@scallop-io/sui-kit";
import { SuiPackagePublisher } from "../src";
dotenv.config();

(async() => {
const secretKey = process.env.SECRET_KEY;
const suiKit = new SuiKit({ secretKey, networkType: 'localhost' });
const suiKit = new SuiKit({ secretKey, networkType: 'devnet' });

const packagePath = path.join(__dirname, './sample_move/package_a');
const publisher = new SuiPackagePublisher();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/advance/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { SuiAdvancePackagePublisher } from "./sui-advance-package-publisher"
export type { PackageBatch } from "./publish-package-batch"
export type { NetworkType } from "./network-type"
export type { PublishPackageOption as AdvancePublishOption, ObjectIdsParser } from "./publish-package-empower"
export type { PublishPackageOption as AdvancePublishOption, PublishResultParser } from "./publish-package-empower"

4 changes: 2 additions & 2 deletions src/lib/advance/publish-package-batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export const publishPackageBatch = async (

const normalizePackageBatch = (packageBatch: PackageBatch) => {
return packageBatch.map((pkg) => {
const defaultOption: PublishPackageOption = { enforce: false, writeToml: true, objectIdsParser: defaultObjectIdsParser }
const defaultOption: PublishPackageOption = { enforce: false, writeToml: true, publishResultParser: defaultPublishResultParser }
return { packagePath: pkg.packagePath, option: pkg.option || defaultOption }
})
}

const defaultObjectIdsParser = (publishResult: PackagePublishResult) => {
const defaultPublishResultParser = (publishResult: PackagePublishResult) => {
const packageId = publishResult.packageId;
const upgradeCapId = publishResult.upgradeCapId;
return { packageId, upgradeCapId }
Expand Down
18 changes: 9 additions & 9 deletions src/lib/advance/publish-package-empower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import type { PackagePublishResult } from "../publish-package"
import { parseMoveToml, writeMoveToml } from "./toml";
import { writeAsJson } from './write-as-json'

export type ObjectIdsParser = (publishResult: PackagePublishResult) => Record<string, any>;
export type PublishResultParser = (publishResult: PackagePublishResult) => Record<string, any>;
export type PublishPackageOption = {
// if true, the package will be published even if it's already published for the networkType
enforce?: boolean
// if true, it will write a `Move.${networkType}.toml` file for the package
writeToml?: boolean
// if true, it will write a `Move.${networkType}.json` file with the parsed objectIds
objectIdsParser?: ObjectIdsParser
// if true, it will write a `publish-result.${networkType}.json` file with the parsed objectIds
publishResultParser?: PublishResultParser
}

/**
Expand All @@ -26,18 +26,18 @@ export type PublishPackageOption = {
* @param option
* option.enforce: if true, the package will be published even if it's already published for the networkType
* option.writeToml: if true, it will write a `Move.${networkType}.toml` file for the package
* option.objectIdsParser: if provided, it will write a `object-ids.${networkType}.json` file with the parsed objectIds
* option.publishResultParser: if provided, it will write a `publish-result.${networkType}.json` file with the parsed objectIds
*/
export const publishPackageEmpower = async (
packagePublisher: SuiPackagePublisher,
pkgPath: string,
signer: RawSigner,
networkType: NetworkType,
option: PublishPackageOption = { enforce: false, writeToml: false, objectIdsParser: undefined }
option: PublishPackageOption = { enforce: false, writeToml: false, publishResultParser: undefined }
) => {
const enforce = option.enforce || false;
const writeToml = option.writeToml || false;
const objectIdsParser = option.objectIdsParser || undefined;
const publishResultParser = option.publishResultParser || undefined;

const moveTomlPathForNetworkType = path.join(pkgPath, `Move.${networkType}.toml`);
const shouldPublish = !fs.existsSync(moveTomlPathForNetworkType) || enforce;
Expand All @@ -46,9 +46,9 @@ export const publishPackageEmpower = async (
if (writeToml) {
writeTomlForNetworkType(pkgPath, res.packageId, networkType);
}
if (objectIdsParser) {
const objIds = objectIdsParser(res);
writeAsJson(objIds, path.join(pkgPath, `object-ids.${networkType}.json`));
if (publishResultParser) {
const parsedPublishResult = publishResultParser(res);
writeAsJson(parsedPublishResult, path.join(pkgPath, `publish-result.${networkType}.json`));
}
return res;
} else {
Expand Down

0 comments on commit dae5a6f

Please sign in to comment.