From 16b27572fdb9d1c31885436000baddfae76b74c3 Mon Sep 17 00:00:00 2001 From: Zetazzz Date: Mon, 3 Jul 2023 16:40:01 +0800 Subject: [PATCH] add build and nobuild to cli --- packages/parser/src/utils.ts | 6 +-- packages/telescope/src/commands/transpile.ts | 47 +++++++++++++++++++- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/packages/parser/src/utils.ts b/packages/parser/src/utils.ts index 8904e522dc..c01fc934b2 100644 --- a/packages/parser/src/utils.ts +++ b/packages/parser/src/utils.ts @@ -111,7 +111,7 @@ export const isRefIncluded = ( } // TODO consider deprecating `patterns` in favor of packages and protos supporting minimatch - if (include?.patterns?.some(pattern => minimatch(ref.filename, pattern))) { + if (include?.patterns?.some(pattern => Boolean(ref.filename) && minimatch(ref.filename, pattern))) { return true; } @@ -119,7 +119,7 @@ export const isRefIncluded = ( if (!globPattern.test(pkgName)) { return ref.proto.package === pkgName; } - return minimatch(ref.proto.package, pkgName) + return Boolean(ref.proto?.package) && minimatch(ref.proto.package, pkgName) }); if (pkgMatched) { @@ -130,7 +130,7 @@ export const isRefIncluded = ( if (!globPattern.test(protoName)) { return ref.filename === protoName; } - return minimatch(ref.filename, protoName) + return Boolean(ref.filename) && minimatch(ref.filename, protoName) }); if (protoMatched) { diff --git a/packages/telescope/src/commands/transpile.ts b/packages/telescope/src/commands/transpile.ts index 6bd8c8e582..535ba89e0a 100644 --- a/packages/telescope/src/commands/transpile.ts +++ b/packages/telescope/src/commands/transpile.ts @@ -29,6 +29,18 @@ export default async (argv) => { message: 'where is the output directory?', default: './src/codegen' }, + { + _: true, + type: 'path', + name: 'build', + message: 'which files to include. ex: osmosis/**/gamm/**/*.proto or cosmos/bank/v1beta1/bank.proto', + }, + { + _: true, + type: 'path', + name: 'nobuild', + message: 'which files to exclude. ex: osmosis/**/gamm/**/*.proto or cosmos/bank/v1beta1/bank.proto', + }, { type: 'confirm', name: 'includeAminos', @@ -52,6 +64,8 @@ export default async (argv) => { let { protoDirs, outPath, + build, + nobuild, includeAminos, includeLCDClients, includeRPCClients, @@ -61,7 +75,7 @@ export default async (argv) => { protoDirs = [protoDirs]; } - const options = { + const options: any = { aminoEncoding: { enabled: includeAminos }, @@ -73,6 +87,37 @@ export default async (argv) => { } }; + if(build || nobuild){ + if(!options.prototypes){ + options.prototypes = {} + } + + } + + if(build){ + if (!Array.isArray(build)) { + build = [build]; + } + + if(!options.prototypes.includes){ + options.prototypes.includes = {} + } + + options.prototypes.includes.protos = build; + } + + if(nobuild){ + if (!Array.isArray(nobuild)) { + nobuild = [nobuild]; + } + + if(!options.prototypes.excluded){ + options.prototypes.excluded = {} + } + + options.prototypes.excluded.protos = nobuild; + } + writeFileSync( process.cwd() + '/.telescope.json', JSON.stringify(