Skip to content

Commit

Permalink
Started implementing pas2js_build
Browse files Browse the repository at this point in the history
  • Loading branch information
tcs-ulli committed Dec 4, 2018
1 parent fd4d351 commit 6b44bc4
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 18 deletions.
6 changes: 3 additions & 3 deletions pas2js/win32/pas2js.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# -u is the same as #UNDEF
#
# Write always a nice logo ;)
# -l
-l

# Display Hints, Warnings and Notes
-vwnh
Expand All @@ -19,10 +19,10 @@
-Fu$CfgDir\..\packages\fcl-base
-Fu$CfgDir\..\packages\fcl-db
-Fu$CfgDir\..\packages\fpcunit
-Fu$CfgDir\..\packages\widget

#IFDEF nodejs
-Jirtl.js
#ENDIF

# end.
# end.

23 changes: 19 additions & 4 deletions pas2js_build/pas2js_build.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,25 @@
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<CommandLineParams Value="C:\Quellen\Pas2JS_Widget\test\project1.lpr"/>
</local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default"/>
<Mode0 Name="default">
<local>
<CommandLineParams Value="C:\Quellen\Pas2JS_Widget\test\project1.lpr"/>
</local>
</Mode0>
</Modes>
</RunParams>
<RequiredPackages Count="1">
<RequiredPackages Count="2">
<Item1>
<PackageName Value="LCLBase"/>
<PackageName Value="Pas2JS_Designer_Package"/>
</Item1>
<Item2>
<PackageName Value="LCLBase"/>
</Item2>
</RequiredPackages>
<Units Count="1">
<Unit0>
Expand All @@ -44,12 +54,17 @@
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="pas2js_build"/>
<Filename Value="../pas2js/win32/pas2js_build"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<UseExternalDbgSyms Value="True"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
Expand Down
63 changes: 62 additions & 1 deletion pas2js_build/pas2js_build.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,48 @@
{$mode objfpc}{$H+}

uses
Interfaces,
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils, CustApp, CompWriterJS
Classes, SysUtils, CustApp, CompWriterJS, fpjson, jsonparser,LResources,WebCtrls
{ you can add units after this };

type

{ TPas2JSBuild }

TPas2JSBuild = class(TCustomApplication)
private
procedure FindComponentClass(Reader: TReader; const aClassName: string;
var ComponentClass: TComponentClass);
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure ConvertLFM(aName : string);
procedure WriteHelp; virtual;
end;

{ TPas2JSBuild }

procedure TPas2JSBuild.FindComponentClass(Reader: TReader;
const aClassName: string; var ComponentClass: TComponentClass);
begin
if copy(AClassName,0,6)= 'TWForm' then
ComponentClass := TWForm
else if CompareText(AClassName, 'TWButton') = 0 then
ComponentClass := TWButton;
end;

procedure TPas2JSBuild.DoRun;
var
ErrorMsg: String;
aFile: TStringList;
aParser: TJSONParser;
aOptions: TJSONObject;
searchResult: TRawByteSearchRec;
begin
// quick check parameters
ErrorMsg:=CheckOptions('h','help');
Expand All @@ -43,8 +61,41 @@ procedure TPas2JSBuild.DoRun;
Exit;
end;

{ read config }

if not FileExists(ParamStr(ParamCount)) then
raise(Exception.Create('ERROR: Project File not Found !'));
aFile := TStringList.Create;
aFile.LoadFromFile(ParamStr(ParamCount));
while aFile.Count>0 do
if aFile[0]<>'{@PAS2JS_BEGIN}' then
aFile.Delete(0)
else
begin
aFile.Delete(0);
break;
end;
while aFile.Count>0 do
if aFile[aFile.Count-1]<>'{@PAS2JS_END}' then
aFile.Delete(aFile.Count-1)
else
begin
aFile.Delete(aFile.Count-1);
break;
end;
aParser := TJSONParser.Create(aFile.Text);
aOptions := aParser.Parse as TJSONObject;

{ convert lfm }

//TODO: parse Project Units and not convert only Units from Project Dir
if findfirst(ExtractFileDir(ParamStr(ParamCount))+DirectorySeparator+'*.lfm', faAnyFile, searchResult) = 0 then
begin
repeat
ConvertLFM(ExtractFileDir(ParamStr(ParamCount))+DirectorySeparator+searchResult.Name);
until FindNext(searchResult) <> 0;
FindClose(searchResult);
end;
// stop program loop
Terminate;
end;
Expand All @@ -60,6 +111,16 @@ destructor TPas2JSBuild.Destroy;
inherited Destroy;
end;

procedure TPas2JSBuild.ConvertLFM(aName: string);
var
aComponent : TComponent;
aStream: TFileStream;
begin
writeln('INFO: Converting "'+aName+'"');
aStream := TFileStream.Create(aName,fmOpenRead);
ReadComponentFromTextStream(aStream,aComponent,@FindComponentClass);
end;

procedure TPas2JSBuild.WriteHelp;
begin
{ add your help code here }
Expand Down
2 changes: 1 addition & 1 deletion pas2js_designer/source/pas2js_ide_descriptor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ function TPas2JSWFrame.GetLocalizedName: string;

function TPas2JSWFrame.GetLocalizedDescription: string;
begin
Result := 'Create a Pas2JS Web Fram';
Result := 'Create a Pas2JS Web Frame';
end;

{ TPas2JSWDataModule }
Expand Down
10 changes: 1 addition & 9 deletions pas2js_designer/source/pas2js_ide_options.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object OptionsForm: TOptionsForm
ClientHeight = 450
ClientWidth = 526
Position = poScreenCenter
LCLVersion = '1.8.4.0'
LCLVersion = '2.0.0.2'
object ButtonsPanel: TButtonPanel
Left = 6
Height = 37
Expand Down Expand Up @@ -203,14 +203,10 @@ object OptionsForm: TOptionsForm
ParentColor = False
end
object CompilerDialog: TOpenDialog
Width = 1332
Height = 765
Title = 'Builder Excutable'
left = 288
end
object TemplateDialog: TOpenDialog
Width = 1332
Height = 765
Title = 'HTML page template'
DefaultExt = '.*.html'
Filter = 'HTML File|*.html'
Expand All @@ -222,15 +218,11 @@ object OptionsForm: TOptionsForm
top = 120
end
object BrowseriDialog: TOpenDialog
Width = 1332
Height = 765
Title = 'Browser Excutable'
left = 288
top = 240
end
object BuilderDialog: TOpenDialog
Width = 1332
Height = 765
Title = 'Builder Excutable'
left = 288
top = 64
Expand Down

0 comments on commit 6b44bc4

Please sign in to comment.