mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-12 22:24:19 +01:00
pas2js: started nodepas2js
git-svn-id: trunk@40098 -
This commit is contained in:
parent
f8050815ea
commit
bbb5943fef
@ -39,7 +39,7 @@
|
|||||||
<Filename Value="nodepas2js.js" ApplyConventions="False"/>
|
<Filename Value="nodepas2js.js" ApplyConventions="False"/>
|
||||||
</Target>
|
</Target>
|
||||||
<SearchPaths>
|
<SearchPaths>
|
||||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
<IncludeFiles Value="$(ProjOutDir);../../packages/pastojs/src"/>
|
||||||
<OtherUnitFiles Value="../../packages/fcl-js/src;../../packages/fcl-json/src;../../packages/fcl-passrc/src;../../packages/pastojs/src"/>
|
<OtherUnitFiles Value="../../packages/fcl-js/src;../../packages/fcl-json/src;../../packages/fcl-passrc/src;../../packages/pastojs/src"/>
|
||||||
<UnitOutputDirectory Value="js"/>
|
<UnitOutputDirectory Value="js"/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
|
|||||||
@ -1,17 +1,83 @@
|
|||||||
program nodepas2js;
|
program nodepas2js;
|
||||||
|
|
||||||
{$mode objfpc}
|
{$mode objfpc}
|
||||||
|
{$I pas2js_defines.inc}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
JS, NodeJS, NodeJSFS, Math,
|
JS, NodeJSApp,
|
||||||
Classes, SysUtils,
|
Classes, SysUtils,
|
||||||
jsbase, jstree, jswriter, JSSrcMap,
|
Pas2jsFileUtils, Pas2jsLogger, Pas2jsCompiler;
|
||||||
fpjson,
|
|
||||||
PasTree, PScanner, PParser, PasResolveEval, PasResolver, PasUseAnalyzer,
|
|
||||||
FPPas2Js,
|
|
||||||
Pas2jsFileUtils, Pas2jsLogger, Pas2jsPParser, Pas2jsFileCache, Pas2jsCompiler;
|
|
||||||
|
|
||||||
|
type
|
||||||
|
|
||||||
|
{ TPas2jsCLI }
|
||||||
|
|
||||||
|
TPas2jsCLI = class(TNodeJSApplication)
|
||||||
|
private
|
||||||
|
FCompiler: TPas2jsCompiler;
|
||||||
|
protected
|
||||||
|
procedure DoRun; override;
|
||||||
|
public
|
||||||
|
constructor Create(TheOwner: TComponent); override;
|
||||||
|
destructor Destroy; override;
|
||||||
|
property Compiler: TPas2jsCompiler read FCompiler;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TPas2jsCLI.DoRun;
|
||||||
|
var
|
||||||
|
ParamList: TStringList;
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
// Your code here
|
ParamList:=TStringList.Create;
|
||||||
|
try
|
||||||
|
for i:=1 to ParamCount do
|
||||||
|
ParamList.Add(Params[i]);
|
||||||
|
try
|
||||||
|
Compiler.Run(ParamStr(0),GetCurrentDirPJ,ParamList);
|
||||||
|
except
|
||||||
|
on E: ECompilerTerminate do ;
|
||||||
|
on E: Exception do
|
||||||
|
begin
|
||||||
|
{AllowWriteln}
|
||||||
|
writeln(E.Message);
|
||||||
|
{AllowWriteln-}
|
||||||
|
if ExitCode=0 then
|
||||||
|
ExitCode:=ExitCodeErrorInternal;
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
{AllowWriteln}
|
||||||
|
writeln('ERROR value: ',JSExceptValue);
|
||||||
|
{AllowWriteln-}
|
||||||
|
if ExitCode=0 then
|
||||||
|
ExitCode:=ExitCodeErrorInternal;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
ParamList.Free;
|
||||||
|
Compiler.Log.CloseOutputFile;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// stop program loop
|
||||||
|
Terminate; // Keep ExitCode!
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TPas2jsCLI.Create(TheOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited Create(TheOwner);
|
||||||
|
StopOnException:=True;
|
||||||
|
FCompiler:=TPas2jsCompiler.Create;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TPas2jsCLI.Destroy;
|
||||||
|
begin
|
||||||
|
FreeAndNil(FCompiler);
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
Application: TPas2jsCLI;
|
||||||
|
begin
|
||||||
|
Application:=TPas2jsCLI.Create(nil);
|
||||||
|
Application.Run;
|
||||||
|
Application.Free;
|
||||||
end.
|
end.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user