tsc.gni 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. ]
  25. type_roots = "node_modules/@types,typings"
  26. if (defined(invoker.type_root)) {
  27. type_roots += "," + invoker.type_root
  28. }
  29. base_out_path = invoker.output_gen_dir + "/electron/"
  30. args = [
  31. "-p",
  32. rebase_path(invoker.tsconfig),
  33. "--outDir",
  34. rebase_path("$base_out_path" + invoker.output_dir_name),
  35. "--typeRoots",
  36. type_roots,
  37. ]
  38. outputs = []
  39. foreach(invoker_source, invoker.sources) {
  40. # The output of TSC is all inputs but with JS instead of TS as the extension
  41. outputs += [ "$base_out_path" + get_path_info(invoker_source, "dir") +
  42. "/" + get_path_info(invoker_source, "name") + ".js" ]
  43. }
  44. }
  45. }