Skip to content

Commit

Permalink
fix the actual bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgrain committed Nov 8, 2023
1 parent 0fd9f17 commit b5efde9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tools/@aws-cdk/spec2cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Options:
--pattern [string] [default: %moduleName%/%serviceShortName%.generated.ts]
File and path pattern for generated files
--service [string]
Generate files only for a specific service, e.g. aws-lambda
Generate files only for a specific service, e.g. AWS::S3

Path patterns can use the following variables:

Expand Down
19 changes: 14 additions & 5 deletions tools/@aws-cdk/spec2cdk/lib/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const config = {
},
'service': {
type: 'string',
description: 'Generate files only for a specific service, e.g. aws-lambda',
description: 'Generate files only for a specific service, e.g. AWS::S3',
},
'clear-output': {
type: 'boolean',
Expand Down Expand Up @@ -83,7 +83,7 @@ async function main(argv: string[]) {

const outputDir = positionals[0];
if (!outputDir) {
throw new Error('Please specify the output-path');
throw new EvalError('Please specify the output-path');
}

const pss: Record<PatternKeys, true> = { moduleName: true, serviceName: true, serviceShortName: true };
Expand Down Expand Up @@ -117,7 +117,10 @@ async function main(argv: string[]) {
};

if (options.service && typeof options.service === 'string') {
const moduleMap = { [options.service]: { services: [options.service] } };
if (!options.service.includes('::')) {
throw new EvalError('Service must be in the form `<Partition>::<Service>, e.g. AWS::S3');
}
const moduleMap = { [options.service.toLocaleLowerCase().split('::').join('-')]: { services: [options.service] } };
await generate(moduleMap, generatorOptions);
return;
}
Expand All @@ -126,9 +129,15 @@ async function main(argv: string[]) {
}

main(process.argv.splice(2)).catch((e) => {
log.error(`Error: ${e.message}\n`);
showHelp(command, args);
process.exitCode = 1;

if (e instanceof EvalError) {
log.error(`Error: ${e.message}\n`);
showHelp(command, args);
} else {
log.error(e);
}

});

function stringOr(pat: unknown, def: string) {
Expand Down
2 changes: 1 addition & 1 deletion tools/@aws-cdk/spec2cdk/lib/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async function generator(

const result = {
modules: moduleMap,
resources: Object.values(moduleMap).flat().map(pick('resources')).reduce(mergeObjects),
resources: Object.values(moduleMap).flat().map(pick('resources')).reduce(mergeObjects, {}),
outputFiles: Object.values(moduleMap).flat().flatMap(pick('outputFiles')),
};

Expand Down

0 comments on commit b5efde9

Please sign in to comment.