Skip to content

Commit

Permalink
linted file export and example output
Browse files Browse the repository at this point in the history
  • Loading branch information
gotjoshua committed Dec 16, 2021
1 parent 6eba386 commit 1fd3353
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/commands/const/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {Command, Flags} from '@oclif/core'
import {constantCase} from 'change-case'
import recursive from 'recursive-readdir'
import path from 'node:path'
import fs from 'node:fs'
import {exec} from 'node:child_process'
export default class Const extends Command {
static description = 'Say const'

Expand All @@ -13,6 +15,7 @@ const friend from oclif! (./src/commands/const/index.ts)

static flags = {
include: Flags.string({char: 'i', description: 'Includes array in json default ["v1/tx.ts","v1alpha2/tx.ts"]', required: false}),
write: Flags.boolean({char: 'w', description: 'Write an output file default false', required: false}),
}

static args = [{name: 'dir', description: 'Directory to crawl', required: false}]
Expand All @@ -23,6 +26,7 @@ const friend from oclif! (./src/commands/const/index.ts)
let dir = args.dir ?? 'src/generated/regen/'
dir = path.resolve(dir)

const isWriteFile = flags.write
const filterFlag: string[] = JSON.parse(flags.include ?? 'false')
const includesArray = filterFlag || ['v1/tx.ts', 'v1alpha2/tx.ts']
const files = await recursive(dir)
Expand Down Expand Up @@ -55,9 +59,19 @@ const friend from oclif! (./src/commands/const/index.ts)
}
}

const output = `
const output = `//Autogenerated by 'protots const'
export const MSGS = ${JSON.stringify(PROTO, null, 2)}
`
if (isWriteFile) {
const absPath = `${dir}/consts.ts`
fs.writeFile(absPath, output, function (err) {
if (err) {
return console.log(err)
}
})
exec(`eslint ${absPath} --ext .ts --config .eslintrc --fix`)
}

this.log(output)
}
}
94 changes: 94 additions & 0 deletions src/generated/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Autogenerated by 'protots const'
export const MSGS = {
REGEN: {
DATA: {
ANCHOR_DATA: '/regen.data.v1alpha2.MsgAnchorData',
SIGN_DATA: '/regen.data.v1alpha2.MsgSignData',
CLIENT_IMPL: '/regen.data.v1alpha2.MsgClientImpl',
},
DIVVY: {
CREATE_ALLOCATOR: '/regen.divvy.v1.MsgCreateAllocator',
UPDATE_ALLOCATOR_SETTINGS: '/regen.divvy.v1.MsgUpdateAllocatorSettings',
SET_ALLOCATOR_RECIPIENTS: '/regen.divvy.v1.MsgSetAllocatorRecipients',
REMOVE_ALLOCATOR: '/regen.divvy.v1.MsgRemoveAllocator',
CLAIM_ALLOCATIONS: '/regen.divvy.v1.MsgClaimAllocations',
CREATE_SLOW_RELEASE_STREAM: '/regen.divvy.v1.MsgCreateSlowReleaseStream',
PAUSE_SLOW_RELEASE_STREAM: '/regen.divvy.v1.MsgPauseSlowReleaseStream',
EDIT_SLOW_RELEASE_STREAM: '/regen.divvy.v1.MsgEditSlowReleaseStream',
CLIENT_IMPL: '/regen.divvy.v1.MsgClientImpl',
},
ECOCREDIT: {
CREATE_CLASS: '/regen.ecocredit.v1alpha2.MsgCreateClass',
CREATE_PROJECT: '/regen.ecocredit.v1alpha2.MsgCreateProject',
CREATE_BATCH: '/regen.ecocredit.v1alpha2.MsgCreateBatch',
CREATE_BATCH_BATCH_ISSUANCE: '/regen.ecocredit.v1alpha2.MsgCreateBatch_BatchIssuance',
SEND: '/regen.ecocredit.v1alpha2.MsgSend',
SEND_SEND_CREDITS: '/regen.ecocredit.v1alpha2.MsgSend_SendCredits',
RETIRE: '/regen.ecocredit.v1alpha2.MsgRetire',
RETIRE_RETIRE_CREDITS: '/regen.ecocredit.v1alpha2.MsgRetire_RetireCredits',
CANCEL: '/regen.ecocredit.v1alpha2.MsgCancel',
CANCEL_CANCEL_CREDITS: '/regen.ecocredit.v1alpha2.MsgCancel_CancelCredits',
UPDATE_CLASS_ADMIN: '/regen.ecocredit.v1alpha2.MsgUpdateClassAdmin',
UPDATE_CLASS_ISSUERS: '/regen.ecocredit.v1alpha2.MsgUpdateClassIssuers',
UPDATE_CLASS_METADATA: '/regen.ecocredit.v1alpha2.MsgUpdateClassMetadata',
SELL: '/regen.ecocredit.v1alpha2.MsgSell',
SELL_ORDER: '/regen.ecocredit.v1alpha2.MsgSell_Order',
UPDATE_SELL_ORDERS: '/regen.ecocredit.v1alpha2.MsgUpdateSellOrders',
UPDATE_SELL_ORDERS_UPDATE: '/regen.ecocredit.v1alpha2.MsgUpdateSellOrders_Update',
BUY: '/regen.ecocredit.v1alpha2.MsgBuy',
BUY_ORDER: '/regen.ecocredit.v1alpha2.MsgBuy_Order',
BUY_ORDER_SELECTION: '/regen.ecocredit.v1alpha2.MsgBuy_Order_Selection',
ALLOW_ASK_DENOM: '/regen.ecocredit.v1alpha2.MsgAllowAskDenom',
CREATE_BASKET: '/regen.ecocredit.v1alpha2.MsgCreateBasket',
ADD_TO_BASKET: '/regen.ecocredit.v1alpha2.MsgAddToBasket',
TAKE_FROM_BASKET: '/regen.ecocredit.v1alpha2.MsgTakeFromBasket',
PICK_FROM_BASKET: '/regen.ecocredit.v1alpha2.MsgPickFromBasket',
CLIENT_IMPL: '/regen.ecocredit.v1alpha2.MsgClientImpl',
},
},
COSMOS: {
CRISIS: {
VERIFY_INVARIANT: '/cosmos.crisis.v1beta1.MsgVerifyInvariant',
CLIENT_IMPL: '/cosmos.crisis.v1beta1.MsgClientImpl',
},
BANK: {
SEND: '/cosmos.bank.v1beta1.MsgSend',
MULTI_SEND: '/cosmos.bank.v1beta1.MsgMultiSend',
CLIENT_IMPL: '/cosmos.bank.v1beta1.MsgClientImpl',
},
DISTRIBUTION: {
SET_WITHDRAW_ADDRESS: '/cosmos.distribution.v1beta1.MsgSetWithdrawAddress',
WITHDRAW_DELEGATOR_REWARD: '/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward',
WITHDRAW_VALIDATOR_COMMISSION: '/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission',
FUND_COMMUNITY_POOL: '/cosmos.distribution.v1beta1.MsgFundCommunityPool',
CLIENT_IMPL: '/cosmos.distribution.v1beta1.MsgClientImpl',
},
GOV: {
SUBMIT_PROPOSAL: '/cosmos.gov.v1beta1.MsgSubmitProposal',
VOTE: '/cosmos.gov.v1beta1.MsgVote',
DEPOSIT: '/cosmos.gov.v1beta1.MsgDeposit',
CLIENT_IMPL: '/cosmos.gov.v1beta1.MsgClientImpl',
},
EVIDENCE: {
SUBMIT_EVIDENCE: '/cosmos.evidence.v1beta1.MsgSubmitEvidence',
CLIENT_IMPL: '/cosmos.evidence.v1beta1.MsgClientImpl',
},
SLASHING: {
UNJAIL: '/cosmos.slashing.v1beta1.MsgUnjail',
CLIENT_IMPL: '/cosmos.slashing.v1beta1.MsgClientImpl',
},
STAKING: {
CREATE_VALIDATOR: '/cosmos.staking.v1beta1.MsgCreateValidator',
EDIT_VALIDATOR: '/cosmos.staking.v1beta1.MsgEditValidator',
DELEGATE: '/cosmos.staking.v1beta1.MsgDelegate',
BEGIN_REDELEGATE: '/cosmos.staking.v1beta1.MsgBeginRedelegate',
UNDELEGATE: '/cosmos.staking.v1beta1.MsgUndelegate',
CLIENT_IMPL: '/cosmos.staking.v1beta1.MsgClientImpl',
},
VESTING: {
CREATE_VESTING_ACCOUNT: '/cosmos.vesting.v1beta1.MsgCreateVestingAccount',
CLIENT_IMPL: '/cosmos.vesting.v1beta1.MsgClientImpl',
},
TX: {},
},
}

1 comment on commit 1fd3353

@gotjoshua
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closes #3

Please sign in to comment.