escript
v0.1.5
Published
A C-like scripting language, built upon Typescript
Downloads
4
Readme
Overview
Escript is a straightforward scripting language designed to extend TypeScript with a more C-like syntax, enhancing the developer experience. It aims to simplify scripting and provide a more intuitive syntax for common programming tasks.
This CLI tool allows you to compile Escript code to TypeScript and optionally transpile it to JavaScript. You can also execute the resulting JavaScript code directly from the command line.
Example
Here's a simple Escript file, showcasing its syntax:
// app.es
interface Car {
string make;
};
Car myCar = {
make: "Chevrolet"
};
// output: Chevrolet
log myCar.make;
class Vehicle {
private string make;
private string model;
public constructor(string make, string model) {
this.make = make;
this.model = model;
}
public string displayInfo() {
return this.make + " " + this.model;
}
protected void updateModel(string newModel) {
this.model = newModel;
}
}
Vehicle myCar2 = new Vehicle("Ford", "Mustang");
// output: Ford Mustang
log myCar2.displayInfo();
CLI Features
- Compile Escript to TypeScript: Converts Escript code into TypeScript.
- Transpile TypeScript to JavaScript: Converts TypeScript code into JavaScript using the TypeScript compiler (tsc).
- Execute JavaScript: Run the final JavaScript output directly from the command line.
- Interactive Help: Provides help and usage instructions directly via CLI.
Installation
You can install Escript CLI globally using npm or yarn:
npm install -g escript
# or
yarn global add escript
Usage
Basic Command
To compile an Escript file, use the following command:
npx esc -i <input-path> -o <output-path>
-i, --input <file>:
Path to the input Escript file.-o, --output <file>:
Path to the output JavaScript or TypeScript file.
Optional Flags
-t, --transpile:
Transpile the resulting TypeScript code to JavaScript. If this flag is used, the output path should be for a TypeScript file (.ts), and the final output will be a JavaScript file (.js).-r, --run:
Run the final JavaScript file after transpilation. This option requires that the-t
flag is also set.
Examples
Compile Escript to TypeScript:
npx esc -i myscript.es -o output.ts
This command converts myscript.es
to TypeScript and saves it as output.ts
.
Compile and Transpile to JavaScript:
npx esc -i myscript.es -o output.ts -t
This command converts myscript.es
to TypeScript and then transpiles output.ts
to JavaScript, saving it as output.js
.
Compile, Transpile, and Run:
npx esc -i myscript.es -o output.ts -t -r
This command performs the full workflow: compiles myscript.es
to TypeScript, transpiles it to JavaScript, and then runs output.js
.
Commands
start
Get started using the Escript CLI tool with the following command:
npx esc start
This command displays a welcome message and basic usage instructions.
Configuration
TypeScript Compilation
The CLI uses the TypeScript compiler (tsc
) to transpile TypeScript code to JavaScript. Ensure that tsc
is installed and accessible from your environment. You can install it globally via npm:
npm install -g typescript