Skip to content

Commit

Permalink
add build and nobuild to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetazzz committed Jul 3, 2023
1 parent 42e7ec6 commit 16b2757
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/parser/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ 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;
}

const pkgMatched = include?.packages?.some(pkgName => {
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) {
Expand All @@ -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) {
Expand Down
47 changes: 46 additions & 1 deletion packages/telescope/src/commands/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -52,6 +64,8 @@ export default async (argv) => {
let {
protoDirs,
outPath,
build,
nobuild,
includeAminos,
includeLCDClients,
includeRPCClients,
Expand All @@ -61,7 +75,7 @@ export default async (argv) => {
protoDirs = [protoDirs];
}

const options = {
const options: any = {
aminoEncoding: {
enabled: includeAminos
},
Expand All @@ -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(
Expand Down

0 comments on commit 16b2757

Please sign in to comment.