-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
141 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { Command } from "commander"; | ||
import { getJwt, setJwt } from "../services/pinata"; | ||
import { PinataSDK } from "pinata-web3"; | ||
|
||
export const pinataCommands = new Command(); | ||
|
||
// ############################################################### | ||
// CLI init setup | ||
// ############################################################### | ||
|
||
pinataCommands | ||
.name("pinata") | ||
.description("This is a CLI for pinata") | ||
.version("1.0.0"); | ||
|
||
/** | ||
* PinataのJWTを設定するコマンド | ||
*/ | ||
pinataCommands | ||
.command("setJwt") | ||
.description("Set a jwt of Pinata") | ||
.requiredOption("--jwt <JWT>") | ||
.action(({ jwt }) => { | ||
setJwt(jwt); | ||
}); | ||
|
||
/** | ||
* Hatのメタデータをipfs上にアップロードするコマンド | ||
*/ | ||
interface Responsibility { | ||
label: string; | ||
description?: string; | ||
link?: string; | ||
} | ||
interface Eligibility { | ||
manual: boolean; | ||
criteria: string[]; | ||
} | ||
interface Toggle { | ||
manual: boolean; | ||
criteria: string[]; | ||
} | ||
|
||
pinataCommands | ||
.command("uploadMetadata") | ||
.description("Upload the hat metadata on ipfs.") | ||
.requiredOption("-n, --name <name>", "Hat Name") | ||
.requiredOption("-d, --description <description>", "Hat Details") | ||
.option( | ||
"-r, --responsibilities <label>,<description>,<link>", | ||
"Responsibilities (may be specified multiple times to define multiple responsibilities)", | ||
(value, previous: Responsibility[]) => { | ||
const [label, description, link] = value.split(","); | ||
return previous | ||
? previous.concat([{ label, description, link }]) | ||
: [{ label, description, link }]; | ||
}, | ||
[] | ||
) | ||
.option( | ||
"-a, --authorities <authorities>", | ||
"Authority (may be specified multiple times to define multiple authorities)", | ||
(value, previous: string[]) => | ||
previous ? previous.concat([value]) : [value], | ||
[] | ||
) | ||
.option( | ||
"-e, --eligibility <manual>,<criteria...>", | ||
"Eligibility (<manual> is a boolean value, <criteria... > can be specified multiple times, separated by commas, to define multiple criteria.)", | ||
(value) => { | ||
const [manual, ...criteria] = value.split(","); | ||
return { manual: manual === "true", criteria } satisfies Eligibility; | ||
} | ||
) | ||
.option( | ||
"-t, --toggle <manual> <criteria...>", | ||
"Toggle (<manual> is a boolean value, <criteria... > can be specified multiple times, separated by spaces, to define multiple criteria.)", | ||
(value) => { | ||
const [manual, ...criteria] = value.split(","); | ||
return { manual: manual === "true", criteria } satisfies Toggle; | ||
} | ||
) | ||
.action( | ||
async ({ | ||
name, | ||
description, | ||
responsibilities, | ||
authorities, | ||
eligibility, | ||
toggle, | ||
}) => { | ||
const { jwt } = getJwt(); | ||
|
||
const pinata = new PinataSDK({ pinataJwt: jwt }); | ||
|
||
const upload = await pinata.upload.json({ | ||
type: "1.0", | ||
data: { | ||
name, | ||
description, | ||
responsibilities, | ||
authorities: authorities, | ||
eligibility, | ||
toggle, | ||
}, | ||
}); | ||
|
||
console.log("CID:", upload.IpfsHash); | ||
console.log("URI:", `ipfs://${upload.IpfsHash}`); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters