Sign in Join
Wiki copytemporary

lazarus pas2js integration: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11# Lazarus pas2JS integration
22
33Requires **Lazarus 1.9+** and **pas2js** ([[pas2js|see here]]). Installation procedure:
44
551\. Click on menu Package - Install/Uninstall Packages
66
77
88![](/wiki-images/e/ee/Pas2jsdsgn_install_package.png)
99
10102\. Choose the package **pas2jsdsgn** then restart the IDE.
1111
1212
1313![](/wiki-images/e/ee/Pas2jsdsgn-install.png)
1414
1515The Lazarus [[pas2js]] integration has 3 parts to it:
1616
1717- [[lazarus pas2js integration|Global options]]
1818- [[lazarus pas2js integration|Project wizards]]
1919- [[lazarus pas2js integration|A debug window]]
2020
2121## Global options
2222
2323In the Tools/Options... dialog, the Pas2JS section allows you to set some options that affect the IDE integration. It looks like this:
2424
2525![](/wiki-images/5/52/Pas2jsdsgn_globaloptions.png)
2626
2727The following settings are available:
2828
2929Path of pas2js
3030This is the compiler binary used when setting up a new project.\
3131It will be searched in the PATH if no absolute path is set. Corresponds to IDE macro *Pas2JSJS*.
3232
3333Change **Path of pas2js** to **C:\lazarus\pas2js\bin\win64-x86_64\pas2js.exe**
3434
3535Path of simpleserver (Lazarus 2.3+ configure this in *Simple Web Server*)
3636This is the webserver that is started when a project is run that needs a webserver.\
3737This is by default the simpleserver application from the FPC project. The program can be found in the FPC sources in the directory *fpcsrc\packages\fcl-web\examples\simpleserver* and has to be compiled manually.
3838
3939You may also use any other webserver, as long as it accepts the -p option to set the path, and it serves files from the directory in which it was started.
4040
4141Change **\$MakeExe(IDE,simpleserver)** to **C:\lazarus\pas2js\bin\compileserver.exe**
4242
4343Port number to start allocating from
4444Every time you create a new webserver project, a new port number is allocated for the webserver. (you can still edit this in the new project dialog).
4545
4646Browser to use when opening HTML page (Lazarus 2.3+ configure this in *Simple Web Server*)
4747The IDE will use this browser to open your HTML page.\
4848It will be searched in the PATH if no absolute path is set. Corresponds to IDE macro *Pas2JSBrowser*.
4949
5050Node.js executable
5151The IDE will use this Node.js executable to start a Node.js project.\
5252It will be searched in the PATH if no absolute path is set. Corresponds to IDE macro *Pas2JSNodeJS*.
5353
5454Electron executable (since Lazarus 2.3)
5555The IDE will use the electron.exe to start an Electron project.\
5656It will be searched in the PATH if no absolute path is set. Corresponds to IDE macro *Pas2JSElectron*.
5757
5858Atom package template directory
5959The IDE will use some files in this directory when creating an Atom package skeleton.\
6060There is no default for this.
6161
6262VS Code extension template directory
6363The IDE will use some files in this directory when creating a VS Code extension skeleton.\
6464There is no default for this.
6565
6666## Project Wizards
6767
6868The pas2js support is in the pas2jsdsgn.lpk package, which you can find in the components/pas2js directory. It registers 2 wizards in the 'New project' dialog:
6969
7070- Web Browser Application
7171- Node.js Application
7272
7373![](/wiki-images/1/1c/Pas2jsdsgn_projects.png)
7474
7575Besides creating an initial project source, both options will also
7676
7777- Set up the compiler command for compiling with pas2js
7878- change the 'Run' command so the 'Run without debugging' option works: it will open a project in the browser or run it with nodejs.
7979
8080## Web Browser application
8181
8282This wizard will ask for some options before generating a new project. The dialog is shown below.
8383
8484![](/wiki-images/5/5b/Webbrowserappoptions.png)
8585
8686The following options are available:
8787
8888- **Create initial HTML page**. This is self-explanatory,\
8989 the IDE will generate a template HTML page which includes all that is necessary to run the pas2js code.\
9090 The page is included in the project description, so you can open and edit it from within the IDE.
9191 - **Maintain HTML page**.\
9292 If you change the name of the project, the IDE will update the references in the HTML File.\
9393 (all your changes will be lost)
9494 - **Run RTL when all page resources are fully loaded**: By default the script tag that starts the ball rolling will call `rtl.run()`.\
9595 Checking this option changes the script, so the `rtl.run` is run in the HTML `document.onReady` event instead.\
9696 This is necessary if your code contains startup code that references elements in the HTML.\
9797 The elements will only be available after the onReady event.
9898 - **Let RTL show uncaught exceptions**: catch exceptions and show a dialog instead of normal browser behavior, which needs the developer tools to see an uncaught exception.
9999 - **Use Browser Console unit.**\
100100 Checking this will simply include the browserconsole unit in the uses clause.\
101101 This hooks into the system units writeln command: any output will be appended to the HTML.\
102102 the generated HTML has a div with the correct ID to which the output is appended.
103103- **Use Browser Application object.**\
104104 This changes the code to use the `TBrowserApplication` object.\
105105 This is a `TCustomApplication` descendent which offers support for query parameters etc. as if they were command-line parameters.
106106 - **Run webassembly program**\
107107- **Run**\
108108 What to do on **Run**
109109 - **Start HTTP server on port**\
110110 the IDE starts a browser at this port and opens a browser with the URL of the html file
111111 - **Use this URL to start application**\
112112 the IDE opens a browser with this URL.
113113 - **Execute Run parameters**\
114114 default Lazarus behavior
115115
116116## Progressive Web Application
117117
118118Since Lazarus 2.3 and pas2js 2.2.1
119119
120120The **PWA** is like a *Web Browser Application*, except this wizard creates two projects, the *'ServiceWorker.lpi* and *'YourPWA.lpi*, a project group, a manifest and some icons. After the options dialog it asks for the file name of the webapp program source filename (usually a *.lpr or *.pas).
121121
122122To run it you must compile both projects to create the two needed js files. The project group window helps you to switch easily and compile the projects.
123123
124124## Electron Web Application
125125
126126Since Lazarus 2.3 and pas2js 2.2.1.
127127
128128See [[pas2js Electron Web Application]]
129129
130130The **Electron** web app is like a *Web Browser Application*, except this wizard creates three projects, the **preload.lpi**, the **render.lpi** and **YourApp.lpi**, and a project group. After the options dialog it asks for the file name of the webapp program source filename (usually a *.lpr or *.pas).
131131
132132To run it you must compile all three projects to create the three needed js files. The project group window helps you to switch easily and compile all projects.
133133
134134## Atom package options
135135
136136![](/wiki-images/1/1f/Pas2jsatomintegration.png)
137137
138138The New Atom Package wizard will create a template for an atom package.
139139
140140You must enter the following information:
141141
142142- Directory (it will be created if it does not exist)
143143- A description
144144- A package name (must contain letters and can contain dashes)
145145- A package class name. This is the name of the application class.
146146
147147The following information is optional:
148148
149149- Commands: a series of command names and command functions. They will be inserted in the application class and code will be created to register them within atom.
150150- License: The license to be used. This is inserted in the package.json file.
151151- Keywords: Keywords to insert in the package.json file.
152152- Activation commands: keystrokes and commands that activate the package.
153153
154154- The generated code can be configured, with the following files:
155155
156-` * `**`glue.js`**` contains the glue code for the Atom package. This is the file that starts the Atom package.`\
157-` * `**`keymap.json`**` contains the default JSON file with the keymap.`\
158-` * `**`menu.json`**` contains the default menu file with the menu entries.`\
159-` * `**`package.less`**` contains the default css file for your package.`\
160-` * `**`project.lpr`**` contains the default project code.`
156+```text
157+ * glue.js contains the glue code for the Atom package. This is the file that starts the Atom package.
158+ * keymap.json contains the default JSON file with the keymap.
159+ * menu.json contains the default menu file with the menu entries.
160+ * package.less contains the default css file for your package.
161+ * project.lpr contains the default project code.
162+```
161163
162164The location for the default files can be set in the global pas2js options dialog.
163165
164166In these files, the following placeholders will be substituted:
165167
166168- **%PACKAGENAME%** will be replaced with the package name.
167169- **%PACKAGEPROJECTNAME%** will be replaced with the project file name.
168170- **%PACKAGEHANDLERINTFS%** the line containing this will be removed and replaced with the declarations of command functions;
169171- **%PACKAGEHANDLERINTFS%** the line containing this will be removed and replaced with the implementations of command functions;
170172- **%PACKAGEHANDLERREGS%** the line containing this will be removed and replaced with the registration of command functions in Atom or VS Code;
171173
172174## VS Code extension options
173175
174176![](/wiki-images/9/96/Pas2jsvscodeintegration.png)
175177
176178The New VS Code extension wizard will create a template for a VS Code extension.
177179
178180You must enter the following information:
179181
180182- Directory (it will be created if it does not exist)
181183- A description
182184- A package name (must contain letters and can contain dashes)
183185- A publisher name (can only contain letters)
184186- A package class name. This is the name of the application class.
185187
186188The following information is optional:
187189
188190- Commands: a series of command names and command functions that activate the package.
189191- License: The license to be used. This is inserted in the package.json file.
190192- Keywords: Keywords to insert in the package.json file.
191193- Contribution commands: commands that activate the package.
192194
193195- The generated code can be configured, with the following files:
194196
195-` * `**`glue.js`**` contains the glue code for the Atom package. This is the file that starts the Atom package.`\
196-` * `**`tasks.json`**` contains the code to build the package in VS Code. You can add any commands you see fit.`\
197-` * `**`launch.json`**` contains the code to launch VS Code with the new package installed.`\
198-` * `**`project.lpr`**` contains the default project code.`
197+```text
198+ * glue.js contains the glue code for the Atom package. This is the file that starts the Atom package.
199+ * tasks.json contains the code to build the package in VS Code. You can add any commands you see fit.
200+ * launch.json contains the code to launch VS Code with the new package installed.
201+ * project.lpr contains the default project code.
202+```
199203
200204The same substitutions as for the Atom package are made.
201205
202206The location for the default files can be set in the global pas2js options dialog.
203207
204208## Project options
205209
206210You can change the settings chosen in the new project wizard in the Project Settings dialog. It also allows you to convert any existing (simple) project to a web application project.
207211
208212The project options are located at the bottom "Web Project (pas2js)'
209213
210214![](/wiki-images/7/72/Pas2jsprojectoptions.png)
211215
212216The checkbox at the top marks the project as web browser project.
213217
214218All other options have the same meaning as their counter parts in the 'New project' wizard.
215219
216220The \`\`\`Reset compile command\`\`\` and \`\`\`Reset run command\`\`\` set the respective commands to their default values.
217221
218222## Debug window
219223
220224As you start projects from various directories, the IDE will start webservers as needed. After some time, there can be several webservers running. An overview of running webservers can be shown using the the View/Debug Windows/Pas2JS Webservers menu item.
221225
222226It shows a list of processes started by the IDE:
223227
224228![](/wiki-images/f/f7/Webservers.png)
225229
226230Support for stopping/starting processes will still be added, as well as statistics for number of requests etc.
227231
228232## Navigation
229233
230234- Back to [[pas2js]]
231235- Back to [[Pas2JS Version Changes]]
232236
233237---
234238*From the Free Pascal wiki, page "lazarus pas2js integration", as it stood on 2022-04-21 after a change by Mattias2, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history