-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlebar.ts
62 lines (54 loc) · 2.26 KB
/
handlebar.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
let rawTemplate =
"var f = list('${ output.value.{{resourceId}} }/config/appsettings', '2021-02-01')";
const Handlebars = require("handlebars");
Handlebars.registerHelper("postCurlyBrace", (text: string) => {
var result = text + "}";
return new Handlebars.SafeString(result);
});
let template = Handlebars.compile(rawTemplate);
console.log(template({ resourceId: "Momo" }));
rawTemplate = "{{preDoubleCurlyBraces pluginId}}.path}}";
Handlebars.registerHelper("preDoubleCurlyBraces", (text: string) => {
var result = "{{" + text;
return new Handlebars.SafeString(result);
});
template = Handlebars.compile(rawTemplate);
console.log(template({ pluginId: "ShaMiKo"}));
template = Handlebars.compile(template({ pluginId: "ShaMiKo"}));
console.log(template({ShaMiKo: { path: "Momo" } }));
*/
import * as Handlebars from "handlebars";
Handlebars.registerHelper("contains", (value, array) => {
array = array instanceof Array ? array : [array];
return array.indexOf(value) > -1 ? this : "";
});
Handlebars.registerHelper("notContains", (value, array) => {
array = array instanceof Array ? array : [array];
return array.indexOf(value) == -1 ? this : "";
});
Handlebars.registerHelper("equals", (value, target) => {
return value === target ? this : "";
});
const rawString = `{{#if (contains "aad-app" connections)}}
INITIATE_LOGIN_ENDPOINT: uri({{azure-web-app.outputs.endpoint}}, 'auth-start.html') // The page is used to let users consent required OAuth permissions during bot SSO process
M365_AUTHORITY_HOST: m365OauthAuthorityHost // AAD authority host
M365_CLIENT_ID: m365ClientId // Client id of AAD application
M365_CLIENT_SECRET: m365ClientSecret // Client secret of AAD application
M365_TENANT_ID: m365TenantId // Tenant id of AAD application
M365_APPLICATION_ID_URI: m365ApplicationIdUri // Application ID URI of AAD application
{{/if}}`;
const rawString2 = `{{#if (equals "Tab" scenario)}}
AA
{{else}}
BB
{{/if}}`;
const rawString3 = `\\{{escaped}}
{{escaped}}
`;
let template = Handlebars.compile(rawString);
console.log(template({ connections: ["aad-app", "teams-tab"] }));
template = Handlebars.compile(rawString2);
console.log(template({ scenario: "Tab" }));
template = Handlebars.compile(rawString3);
console.log(template({ escaped: "Tab" }));