pascal-utils
Version:
Utility functions for compilation of simple pascal programs, with the Free Pascal compiler, in Node.js.
69 lines (50 loc) • 1.94 kB
Markdown

[](https://badge.fury.io/js/pascal-utils)

[](https://codecov.io/gh/synthetic-borealis/pascal-utils.js)
Utility functions for compilation of simple pascal programs with the Free Pascal compiler in
Node.js.
1. [Requirements](
2. [Installation](
3. [Usage](
1. [Compiler Detection](
2. [Compilation](
4. [Examples](
* The Free Pascal compiler.
* Node.js v16.x or above.
Run `yarn add pascal-utils -D` or `npm i pascal-utils --save-dev`.
The documentation can be found [here](./docs/API.md).
Run `checkCompiler().then(({ version }) => ...)` to check if the Free Pascal compiler is installed
and is in the system path.
Run `compile(inputFile, outputFile).then(...)` to compile a program.
```javascript
const fs = require('fs/promises');
const pascalUtils = require('pascal-utils');
describe('Compiler detection', () => {
it('Detects compiler', () => pascalUtils.checkCompiler()
.then(() => {
expect(true).toBeTruthy();
}));
});
describe('Compilation', () => {
const exeExtension = process.platform === 'win32' ? '.exe' : '';
const sourceFile = './assets/hello.pas';
const exeName = `./hello${exeExtension}`;
it('Compiles and links', () => pascalUtils.compile(sourceFile, exeName)
.then(() => {
expect(true).toBeTruthy();
}));
afterAll(() => Promise.all([
fs.unlink('./hello.o'),
fs.unlink(exeName),
]));
});
```