/src
└── cli.tsx: Calls "yargs.commandDir('./rootCmds')" to configure top-level command
└── /rootCmds:
| └── api.tsx: This cmd calls `yargs.commandDir()` on each of the dirs below
| └── /authCmds
| | └── beginPassReset.tsx: "dappbot api auth/beginPassReset" will send a password reset request
| | └── ...
| └── /privateCmds
| | └── createDapp.tsx: "dappbot api private/createDapp <...args>" will create a Dapp
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
// Stuttering | |
const args: AuthMethods.LoginMethod.LoginArgs = { ... }; | |
// No stuttering | |
const args: Auth.Login.Args = { ... }; |
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
// The type reference is so wordy! This isn't convenient. | |
import Types from '@eximchain/dappbot-types'; | |
const args: Types.Methods.Auth.Login.Args = { ... }; | |
// We can make the reference more compact by importing a | |
// more specific slice of the overall types. | |
import Auth from '@eximchain/dappbot-types/spec/methods'; | |
const args: Auth.Login.Args = { ... }; |
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
yargs.command( | |
'lorem <arg1> <arg2>', | |
'This cmd description is ipsum.', | |
function(yargs) { | |
// Builder: Perform addt'l command configuration | |
}, | |
function(argv) { | |
// Handler: When user correctly calls this cmd, this fxn will receive the parsed opstring | |
} | |
); |
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
export const command = 'lorem <arg1> <arg2>'; | |
export const desc = 'This cmd description is ipsum'; | |
export function builder(yargs) { | |
// Add addt'l command configuration | |
} | |
export function handler(argv) { | |
// Use parsed argv to perform any actions desired |
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
... | |
export function handler(args:ArgShape<DappNameArg>) { | |
const { DappName, hubUrl } = args; | |
const url = `${hubUrl}/${DappName}`; | |
// Each and every handler function has a | |
// render call like this one. | |
render( |
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
{ | |
"name": "@eximchain/dappbot-cli", | |
"bin": { | |
"dappbot": "build/cli.js" | |
}, | |
"..." : "..." | |
} |
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
/** | |
* Middlware: Listen for any options whose name ends in "Path", and if found, | |
* read the file's contents as a string and add it as an argument | |
* whose name ends in "File". For instance, "authPath" will yield | |
* an "authFile" string, which can be JSON.parse()d to get the | |
* actual authData. | |
* @param args | |
*/ | |
export function loadFileFromPath(args:ArgShape): ArgShape { | |
const pathKeys = Object.keys(args).filter(key => key.indexOf('Path') > -1); |
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
import { SuccessBox } from '../ui'; | |
export function handler(args:ArgShape<DappNameArg>) { | |
const { DappName, hubUrl } = args; | |
const url = `${hubUrl}/${DappName}`; | |
render( | |
<SuccessBox result={{ | |
message: `Opening ${url} now!` | |
}} /> |
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
import { AuthData, newAuthData } from '@eximchain/dappbot-types/spec/user'; | |
export const AUTH_FILENAME = 'dappbotAuthData.json'; | |
export const AUTH_FILE_PATH = path.resolve(__dirname, `./${AUTH_FILENAME}`); | |
export function initAuthFile() { | |
if (!fs.existsSync(AUTH_FILE_PATH)) { | |
fs.writeFileSync(AUTH_FILE_PATH, JSON.stringify(newAuthData(), null, 2)); | |
} | |
} |