tsc.gni 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import("npm.gni")
  2. template("typescript_build") {
  3. assert(defined(invoker.tsconfig), "Need tsconfig name to run")
  4. assert(defined(invoker.sources), "Need tsc sources to run")
  5. assert(defined(invoker.output_dir_name),
  6. "Need output_dir_name to run, should be 'lib' or other top level dir")
  7. assert(defined(invoker.output_gen_dir),
  8. "Need output_gen_dir to run, should be relative to the root gen dir")
  9. npm_action(target_name) {
  10. forward_variables_from(invoker,
  11. [
  12. "deps",
  13. "public_deps",
  14. "outputs",
  15. ])
  16. script = "tsc"
  17. sources = invoker.sources
  18. inputs = [
  19. invoker.tsconfig,
  20. "//electron/tsconfig.json",
  21. "//electron/yarn.lock",
  22. "//electron/typings/internal-ambient.d.ts",
  23. "//electron/typings/internal-electron.d.ts",
  24. "//electron/typings/internal-helpers.d.ts",
  25. ]
  26. type_roots = "node_modules/@types,typings"
  27. if (defined(invoker.type_root)) {
  28. type_roots += "," + invoker.type_root
  29. }
  30. base_out_path = invoker.output_gen_dir + "/electron/"
  31. args = [
  32. "-p",
  33. rebase_path(invoker.tsconfig),
  34. "--outDir",
  35. rebase_path("$base_out_path" + invoker.output_dir_name),
  36. "--typeRoots",
  37. type_roots,
  38. ]
  39. outputs = []
  40. foreach(invoker_source, invoker.sources) {
  41. # The output of TSC is all inputs but with JS instead of TS as the extension
  42. outputs += [ "$base_out_path" + get_path_info(invoker_source, "dir") +
  43. "/" + get_path_info(invoker_source, "name") + ".js" ]
  44. }
  45. }
  46. }