abner / docker-pas2js

Generate Javascript from Pascal files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pas2js Docker

Allow to compile a pascal file to javascript, using the pas2js compiler.

How to execute

Preparation

In a folder:

  • Create a directory called src and add a script.pas with your pas2js Pascal Code.

  • Create a directory called dist. The script.js will be compiled into the dist directory.

Execution

docker run --rm -it -v $PWD/src:/opt/pas2js/src -v $PWD/dist:/opt/pas2js/dist abner/pas2js:latest

If everything runs ok, you script.js will be read to be used.

The default target is nodejs, but you can change it to browser, passing the PAS2JS_TARGET environment variable to docker.

Example generating to browser

docker run --rm -it -e PAS2JS_TARGET="browser" -v $PWD/src:/opt/pas2js/src  -v $PWD/dist:/opt/pas2js/dist abner/pas2js:latest

You can pass a different script name through an environment variable called PAS2JS_INPUT_NAME

Sample Script

program pas2jsweb;

{$mode objfpc}

uses
  JS,
  Classes,
  SysUtils,
  Web;

type
  TCrypt = class

  public
    function crypt(Src: string): string;
    function decrypt(Src: string): string;
  private
    function cryptDecrypt(Action, Src: string): string;
  end;


  function TCrypt.crypt(Src: string): string;
  begin
    Result := 'ENCRYPTED';
  end;

  function TCrypt.decrypt(Src: string): string;
  begin
    Result := 'DECRYPTED';
  end;

var
  cryptOject: TCrypt;
  crypted: string;
  deCrypted: string;
begin
  cryptOject := TCrypt.Create;
  // Example: (Do not remove this calls bellow, otherwise the compiler will strip out the functions)
  crypted := cryptOject.crypt('LALALALALA');
  deCrypted := cryptOject.decrypt(crypted);
end.

Uses:

https://wiki.freepascal.org/pas2j

About

Generate Javascript from Pascal files


Languages

Language:Pascal 39.3%Language:Dockerfile 36.4%Language:Shell 24.3%