nodepas2js.pp 1.6 KB

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