Explorar el Código

* Node command-line demos

michael hace 5 años
padre
commit
dddcdbb4d2
Se han modificado 3 ficheros con 141 adiciones y 0 borrados
  1. 10 0
      demo/jspdf/basic.html
  2. 77 0
      demo/rtl/demonodecmdlineoptions.lpi
  3. 54 0
      demo/rtl/demonodecmdlineoptions.pas

+ 10 - 0
demo/jspdf/basic.html

@@ -40,6 +40,16 @@
           </div>
         </div>
       </div>
+      <div class="row">
+    <div class="source">
+      <div class="source-inner">
+        <div>
+          Created using &nbsp; <a target="_blank" href="https://wiki.freepascal.org/pas2js">pas2js.</a> &nbsp;&nbsp;Sources: &nbsp; <a target="new" href="basic.lpr">Program
+          sources</a>.
+        </div>
+      </div>
+    </div>
+      </div>
     </div>
     <script>
       rtl.run();

+ 77 - 0
demo/rtl/demonodecmdlineoptions.lpi

@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+  <ProjectOptions>
+    <Version Value="12"/>
+    <General>
+      <Flags>
+        <MainUnitHasCreateFormStatements Value="False"/>
+        <MainUnitHasTitleStatement Value="False"/>
+        <MainUnitHasScaledStatement Value="False"/>
+        <Runnable Value="False"/>
+      </Flags>
+      <SessionStorage Value="InProjectDir"/>
+      <Title Value="demonodecmdlineoptions"/>
+      <UseAppBundle Value="False"/>
+      <ResourceType Value="res"/>
+    </General>
+    <BuildModes>
+      <Item Name="Default" Default="True"/>
+    </BuildModes>
+    <PublishOptions>
+      <Version Value="2"/>
+      <UseFileFilters Value="True"/>
+    </PublishOptions>
+    <RunParams>
+      <FormatVersion Value="2"/>
+    </RunParams>
+    <Units>
+      <Unit>
+        <Filename Value="demonodecmdlineoptions.pas"/>
+        <IsPartOfProject Value="True"/>
+      </Unit>
+    </Units>
+  </ProjectOptions>
+  <CompilerOptions>
+    <Version Value="11"/>
+    <Target FileExt=".js">
+      <Filename Value="demonodecmdlineoptions"/>
+    </Target>
+    <SearchPaths>
+      <IncludeFiles Value="$(ProjOutDir)"/>
+      <UnitOutputDirectory Value="js"/>
+    </SearchPaths>
+    <Parsing>
+      <SyntaxOptions>
+        <AllowLabel Value="False"/>
+        <CPPInline Value="False"/>
+        <UseAnsiStrings Value="False"/>
+      </SyntaxOptions>
+    </Parsing>
+    <CodeGeneration>
+      <TargetOS Value="nodejs"/>
+    </CodeGeneration>
+    <Linking>
+      <Debugging>
+        <GenerateDebugInfo Value="False"/>
+        <UseLineInfoUnit Value="False"/>
+      </Debugging>
+    </Linking>
+    <Other>
+      <CustomOptions Value="-Jeutf-8 -Jminclude -Jirtl.js"/>
+      <CompilerPath Value="$(pas2js)"/>
+    </Other>
+  </CompilerOptions>
+  <Debugging>
+    <Exceptions>
+      <Item>
+        <Name Value="EAbort"/>
+      </Item>
+      <Item>
+        <Name Value="ECodetoolError"/>
+      </Item>
+      <Item>
+        <Name Value="EFOpenError"/>
+      </Item>
+    </Exceptions>
+  </Debugging>
+</CONFIG>

+ 54 - 0
demo/rtl/demonodecmdlineoptions.pas

@@ -0,0 +1,54 @@
+program demonodecmdlineoptions;
+
+{$mode objfpc}
+
+uses
+  nodejsapp, JS, Classes, SysUtils, nodeJS;
+
+type
+
+  { TMyApplication }
+
+  TMyApplication = class(TNodeJSApplication)
+    procedure doRun; override;
+  private
+    procedure Usage(Msg: string);
+  end;
+
+procedure TMyApplication.Usage(Msg : string);
+
+begin
+  if Msg<>'' then
+    Writeln('Error :',Msg);
+  Writeln('Usage:');
+  Writeln(ExeName,' [options]');
+  Writeln('Where options is one or more of');
+  Writeln('-h --help    this help message');
+  Writeln('-e --echo    echo option');
+  ExitCode:=Ord(Msg<>'');
+end;
+
+procedure TMyApplication.doRun;
+
+Var
+  S : String;
+begin
+  S:=CheckOptions('he:',['help','echo']);
+  if (S<>'') or HasOption('h','help') then
+    Usage(S);
+  if HasOption('e','echo') then
+    Writeln(GetoptionValue('e','echo'));
+  for S in GetNonOptions('he:',['help','echo']) do
+    Writeln(s);
+  Terminate;
+end;
+
+var
+  Application : TMyApplication;
+
+begin
+  Application:=TMyApplication.Create(nil);
+  Application.Initialize;
+  Application.Run;
+  Application.Free;
+end.