Skip to content

Instantly share code, notes, and snippets.

@wonderful-panda
Created November 25, 2016 03:52
Show Gist options
  • Select an option

  • Save wonderful-panda/5611ff4e47dfefbde909da09347c21f5 to your computer and use it in GitHub Desktop.

Select an option

Save wonderful-panda/5611ff4e47dfefbde909da09347c21f5 to your computer and use it in GitHub Desktop.
Generate typescript code by template engine
import * as Electron from "electron";
export const vuexActions = {
<%
VuexActions.methods.forEach((m, index) => {
const paramListWithType = m.parameters.map(p => `, ${p.prefix}${p.name}${p.postfix}: ${p.typeName}`).join("");
const paramList = m.parameters.map(p => `, ${p.prefix}${p.name}`).join("");
const last = index == VuexActions.methods.length - 1;
-%>
<%- m.name %>(target: Electron.WebContents<%- paramListWithType -%>): void {
target.send("action", "<%- m.name %>"<%- paramList -%>);
}<%- last ? "" : "," %>
<%
});
-%>
};
import * as Electron from "electron";
export const vuexActions = {
{{#each VuexActions.methods}}
{{{name}}}(target: Electron.WebContents
{{~#each parameters~}} , {{{concat prefix name postfix ": " typeName}}} {{~/each~}}
): void {
target.send("action", "{{name}}"
{{~#each parameters~}} , {{{concat prefix name}}} {{~/each~}}
);
}
{{~#unless @last~}} , {{~/unless}}
{{/each}}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment