Skip to content

Commit

Permalink
Fix copyCSharpSettingsFromJS based on new names (#750)
Browse files Browse the repository at this point in the history
The templates names changed and 'normalizeName' no longer works. Switch from using 'name' to 'id' as we should've been doing all along. C# templates still work without this PR, but they're just missing a few niceties as described originally here: #458
  • Loading branch information
ejizba authored Oct 22, 2018
1 parent eba0da0 commit 2e32d31
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/templates/FunctionTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class FunctionTemplates {
const jsTemplates: IFunctionTemplate[] = templates.filter((t: IFunctionTemplate) => t.language.toLowerCase() === ProjectLanguage.JavaScript.toLowerCase());
const csharpTemplates: IFunctionTemplate[] = templates.filter((t: IFunctionTemplate) => t.language.toLowerCase() === ProjectLanguage.CSharp.toLowerCase());
for (const csharpTemplate of csharpTemplates) {
const jsTemplate: IFunctionTemplate | undefined = jsTemplates.find((t: IFunctionTemplate) => normalizeName(t.name) === normalizeName(csharpTemplate.name));
const jsTemplate: IFunctionTemplate | undefined = jsTemplates.find((t: IFunctionTemplate) => normalizeId(t.id) === normalizeId(csharpTemplate.id));
if (jsTemplate) {
for (const cSharpSetting of csharpTemplate.userPromptedSettings) {
const jsSetting: IFunctionSetting | undefined = jsTemplate.userPromptedSettings.find((t: IFunctionSetting) => normalizeName(t.name) === normalizeName(cSharpSetting.name));
Expand All @@ -79,6 +79,14 @@ export class FunctionTemplates {
}
}

/**
* Converts ids like "Azure.Function.CSharp.QueueTrigger.2.x" or "QueueTrigger-JavaScript" to "queuetrigger"
*/
function normalizeId(id: string): string {
const match: RegExpMatchArray | null = id.match(/[a-z]+Trigger/i);
return normalizeName(match ? match[0] : id);
}

function normalizeName(name: string): string {
return name.toLowerCase().replace(/\s/g, '');
}
Expand Down

0 comments on commit 2e32d31

Please sign in to comment.