Skip to content

Instantly share code, notes, and snippets.

View john-osullivan's full-sized avatar
Focusing

John O'Sullivan john-osullivan

Focusing
View GitHub Profile
@john-osullivan
john-osullivan / package-for-custom-name.json
Created November 7, 2019 05:02
Dev Diaries #3 - package.json "bin" syntaxes
{
"name": "@eximchain/dappbot-cli",
"bin": {
"dappbot": "build/cli.js"
},
"..." : "..."
}
@john-osullivan
john-osullivan / goto-handler.tsx
Last active November 7, 2019 06:51
Dev Diaries #3 - CLI goto handler
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!`
}} />
@john-osullivan
john-osullivan / goto-handler.tsx
Created November 7, 2019 04:51
Dev Diaries #3 - CLI goto handler
...
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(
@john-osullivan
john-osullivan / hidden-command.ts
Last active November 12, 2019 17:45
Dev Diaries #3 - Hidden yargs Commands
export const command = "onboarding";
export const desc = false;
@john-osullivan
john-osullivan / project-structure.md
Last active November 7, 2019 01:36
Dev Diaries #3 - Project Structure

/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
@john-osullivan
john-osullivan / yargs-module.ts
Created November 6, 2019 21:33
Dev Diaries #3 - yargs module for cmd config
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
@john-osullivan
john-osullivan / yargs-command.ts
Created November 6, 2019 21:27
Dev Diaries #3 - yargs.command()
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
}
);
@john-osullivan
john-osullivan / no-stutter.ts
Created September 16, 2019 23:32
Dev Diaries #2: Demonstration of stuttering
// Stuttering
const args: AuthMethods.LoginMethod.LoginArgs = { ... };
// No stuttering
const args: Auth.Login.Args = { ... };
@john-osullivan
john-osullivan / package.json
Created September 16, 2019 22:14
Dev Diaries #2 - Sample package.json from the User submodule
{
"main" : "../../build/user/index.js",
"types": "./index.ts"
}
@john-osullivan
john-osullivan / index.ts
Last active September 16, 2019 22:08
Dev Diaries #2 - Sample index file from the User submodule
// This line takes all of the exports from that
// file and wraps them into a single namespace.
// If we didn't do this "* as User" syntax here,
// then a consumer would have to do it in order
// to get a convenient namespace.
import * as User from './user';
// This line directly surfaces all of its non-default
// exports from right here, so that users can just
// grab one item from there, e.g.: