pact-toolbox
Version:
A tool to help you build, test and deploy your Pact smart contracts
76 lines (74 loc) • 2.09 kB
JavaScript
import { defineCommand } from "citty";
import { resolveConfig } from "@pact-toolbox/config";
import { logger, writeFile } from "@pact-toolbox/utils";
import { existsSync } from "fs";
import { join } from "pathe";
import { generateGasStation } from "@pact-toolbox/fabricator";
//#region src/commands/generate/station.ts
const stationCommand = defineCommand({
meta: {
name: "station",
description: "Generate gas station contract"
},
args: {
name: {
type: "positional",
description: "Name of the gas station",
valueHint: "my-gas-station",
default: "my-gas-station",
required: false
},
namespace: {
type: "string",
description: "Namespace of the gas station",
valueHint: "free",
default: "free"
},
"admin-keyset": {
type: "string",
description: "Admin keyset for the gas station",
valueHint: "admin-keyset",
default: "admin-keyset"
},
account: {
type: "string",
description: "K account for the gas station",
required: true,
valueHint: "k:3a9dd...."
},
module: {
type: "string",
description: "Module for the gas station",
valueHint: "my-module",
default: "my-module"
},
force: {
type: "boolean",
description: "Force overwrite existing gas station",
default: false,
alias: ["f"]
}
},
run: async ({ args }) => {
const config = await resolveConfig();
const contractDir = config.contractsDir || "pact";
const code = generateGasStation({
namespace: args.namespace,
adminKeyset: args["admin-keyset"],
account: args.account,
module: args.module,
name: args.name
});
const fileName = `${args.module}-${args.name}.pact`;
const path = join(contractDir, fileName);
if (existsSync(path) && !args.force) {
logger.error(`Gas station ${fileName} already exists in ${contractDir} directory.`);
return;
}
await writeFile(path, code);
logger.box(`Gas station ${fileName} generated in ${contractDir} directory.\nPlease review the generated code before deploying it.`);
}
});
//#endregion
export { stationCommand };
//# sourceMappingURL=station-DWTrY4Lb.js.map