template.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. export const TEMPLATE_HEADER =
  2. "/** Generated file, do not edit. See scripts/factorio-dump/lua-api/index.ts for generator. */";
  3. export const FULL_API_TEMPLATE = `${TEMPLATE_HEADER}
  4. /**
  5. * Application: {{app}}
  6. * Version: {{appVersion}}
  7. * API Version: {{apiVersion}}
  8. */
  9. {{#interfaces}}
  10. {{#if description}}
  11. /** {{{description}}} */
  12. {{/if}}
  13. {{#unless props.length}}
  14. // eslint-disable-next-line @typescript-eslint/no-empty-interface
  15. {{/unless}}
  16. {{#if export}}export {{/if}}interface {{#if extends}}_{{/if}}{{name}} {
  17. {{#if typeName}}
  18. type: '{{typeName}}';
  19. {{/if}}
  20. {{#props}}
  21. {{#if description}}
  22. /** {{{description}}} */
  23. {{/if}}
  24. {{name}}{{#if optional}}?{{/if}}: {{{type}}};
  25. {{/props}}
  26. }
  27. {{#if extends}}
  28. export type {{name}} = _{{name}} & Omit<{{extends}}, keyof _{{name}}>;
  29. {{/if}}
  30. {{#if isTypeFunction}}
  31. export function is{{name}}(value: unknown): value is {{name}} {
  32. return (value as { type: string }).type === '{{isTypeFunction}}';
  33. }
  34. {{/if}}
  35. {{/interfaces}}
  36. {{#types}}
  37. {{#if description}}
  38. /** {{{description}}} */
  39. {{/if}}
  40. export type {{name}} = {{{value}}};
  41. {{/types}}
  42. type SR<T> = Record<string, T>;
  43. export type FactorioRawData = {
  44. {{#interfaces}}
  45. {{#if typeName}}
  46. "{{typeName}}"?:SR<{{name}}>;
  47. {{/if}}
  48. {{/interfaces}}
  49. }
  50. `;