This repository contains a handy shell function runts()
, which automates the process of compiling and running TypeScript files. It's a simple and effective tool that helps you test your TypeScript code quickly and easily.
Please ensure you have the following installed:
- Node.js: A JavaScript runtime used to execute the compiled TypeScript files. You can download Node.js from here.
- TypeScript: A superset of JavaScript that adds static types. You can install TypeScript globally with npm (Node Package Manager) using the following command:
npm install -g typescript
To add the runts()
function to your ~/.zshrc
file, follow these steps:
-
Open a terminal.
-
Enter the following command to open the
~/.zshrc
file using a text editor (e.g., nano, vim, code):nano ~/.zshrc
This command opens the
~/.zshrc
file in the nano text editor. You can replacenano
with your preferred text editor's command if desired. -
Scroll to the end of the file using the arrow keys or the Page Up/Page Down keys.
-
Append the contents of the
runts.sh
file from the repository to the end of the~/.zshrc
file. -
Save the changes by pressing
Ctrl + O
, then pressEnter
to confirm. -
Exit the text editor by pressing
Ctrl + X
. -
To apply the changes to your current shell session, run the following command:
source ~/.zshrc
This command reloads the
~/.zshrc
file and makes therunts()
function available for use in your terminal.
Now you can use the runts()
function to compile and run your TypeScript files with ease.
The function runts()
is designed to be added to your ~/.zshrc
file (or ~/.bashrc
if you're using bash).
You should open the desired file (~/.zshrc
or ~/.bashrc
) and append the contents of runts.sh
to the end of this file.
To use the runts()
function:
- Save and close your
~/.zshrc
(or~/.bashrc
) file. - Apply the changes to your current shell session using the command
source ~/.zshrc
(orsource ~/.bashrc
for bash). - You can now run the
runts()
function by calling it with the filename (without the extension) as a parameter:
runts filename
Please note: filename
refers to the name of your TypeScript file without the .ts
extension.
The runts()
function does the following:
- It takes the filename of a TypeScript file (without the
.ts
extension) as an argument. - It compiles the TypeScript file into JavaScript using the TypeScript compiler (
tsc
). - If the TypeScript compilation fails, it outputs an error message and exits.
- It then executes the compiled JavaScript file using Node.js (
node
). - If the JavaScript execution fails, it outputs an error message and exits.
With this tool, you can focus more on writing your TypeScript code and spend less time on the repetitive task of compiling and running your TypeScript files.
Happy Coding!
This project is licensed under the MIT License - see the LICENSE.md file for details.