nodepas2js.pp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. program nodepas2js;
  2. {$mode objfpc}
  3. {$I pas2js_defines.inc}
  4. uses
  5. JS, NodeJSApp,
  6. Classes, SysUtils,
  7. Pas2jsFileUtils, Pas2jsLogger,
  8. Pas2jsCompiler, Pas2JSFSCompiler, Pas2JSCompilerCfg;
  9. type
  10. { TPas2jsCLI }
  11. TPas2jsCLI = class(TNodeJSApplication)
  12. private
  13. FCompiler: TPas2jsFSCompiler;
  14. protected
  15. procedure DoRun; override;
  16. public
  17. constructor Create(TheOwner: TComponent); override;
  18. destructor Destroy; override;
  19. property Compiler: TPas2jsFsCompiler read FCompiler;
  20. end;
  21. procedure TPas2jsCLI.DoRun;
  22. var
  23. ParamList: TStringList;
  24. i: Integer;
  25. begin
  26. ParamList:=TStringList.Create;
  27. try
  28. for i:=1 to ParamCount do
  29. ParamList.Add(Params[i]);
  30. try
  31. Compiler.Run(ParamStr(0),GetCurrentDirPJ,ParamList);
  32. except
  33. on E: ECompilerTerminate do ;
  34. on E: Exception do
  35. begin
  36. {AllowWriteln}
  37. writeln(E.Message);
  38. {AllowWriteln-}
  39. if ExitCode=0 then
  40. ExitCode:=ExitCodeErrorInternal;
  41. end
  42. else begin
  43. {AllowWriteln}
  44. writeln('ERROR value: ',JSExceptValue);
  45. {AllowWriteln-}
  46. if ExitCode=0 then
  47. ExitCode:=ExitCodeErrorInternal;
  48. end;
  49. end;
  50. finally
  51. ParamList.Free;
  52. Compiler.Log.CloseOutputFile;
  53. end;
  54. // stop program loop
  55. Terminate; // Keep ExitCode!
  56. end;
  57. constructor TPas2jsCLI.Create(TheOwner: TComponent);
  58. begin
  59. inherited Create(TheOwner);
  60. StopOnException:=True;
  61. FCompiler:=TPas2jsFSCompiler.Create;
  62. FCompiler.ConfigSupport:=TPas2JSFileConfigSupport.Create(FCompiler);
  63. end;
  64. destructor TPas2jsCLI.Destroy;
  65. begin
  66. FreeAndNil(FCompiler);
  67. inherited Destroy;
  68. end;
  69. var
  70. Application: TPas2jsCLI;
  71. begin
  72. Application:=TPas2jsCLI.Create(nil);
  73. Application.Run;
  74. Application.Free;
  75. end.