@thegrotesk/scripterra v1.0.8
------------------------------------------------------------------
_________ .__ __
/ _____/ ___________|__|______/ |_ _______________________
\_____ \_/ ___\_ __ \ \____ \ __\/ __ \_ __ \_ __ \__ \
/ \ \___| | \/ | |_> > | \ ___/| | \/| | \// __ \_
/_______ /\___ >__| |__| __/|__| \___ >__| |__| (____ /
\/ \/ |__| \/ \/
-------------------------------------------------------------------
Powerful script engine for Node.js
๐ Homepage
๐งโ๐ซ Motivation
What about the dependencies?
What about the dubbing of the code?
What about the logs?
What if you have many projects that require one script but different configs for it?
๐ Features
- Pretty CLI
- Multiple env files for one scripts
- Schedules
- Custom detached worker
- Logs
- Easy to use
โ Requirments
- redis-stack-server Quick start
- node v16.16.0
โ๏ธ Install
npm i -g @thegrotesk/scripterra
๐ Quick Guide
You can list all available flags by typing this command:
scripterra --help
Step 1. Init project
Create a project directory and initialize the npm.
mkdir ./my-scripterra-project
cd ./my-scripterra-project
npm init -y
Once it completed, let's create scripterra config file!
scripterra --create config
Your project structure should look like this example:
-my-scripterra-project
|__ .scripterra
|__ package.json
|__ package-lock.json
Step 2. Configure
Open .scripterra file. You should see this template:
SCRIPTS_PATH=./scripts/
ENV_PATH=./env/
REDIS=redis://localhost:6379
LOG_PATH=./logs/
You can change configuration if you want.
SCRIPTS_PATH - define the folder in which you want to store scripts
ENV_PATH - define the folder in which you want to store environment files
REDIS - define redis connection string
LOG_PATH - define the folder in which Scripterra Worker will store the logs
Step 3. Create script
scripterra --create script --name Test
Scripterra will automaticaly create SCRIPTS_PATH folder and store Test.js there.
Step 4. Run script
You can run script with different env files from your ENV_PATH.
Let's create one.
nano ./env/.test
And create some values. For example:
HELLO_STRING=Hello world!
Now open Test.js and log this value. All env values stored in process.env
import { Script } from '@thegrotesk/scripterra';
//Generated by Scripterra.
export class Test extends Script {
constructor(console, args) {
super(console, args);
}
async main() {
this.console.consoleInfo(process.env.HELLO_STRING);
}
}
Now, we can run the script.
scripterra --run Test --env .test
You should see this in your terminal:
------------------------------------------------------------------
_________ .__ __
/ _____/ ___________|__|______/ |_ _______________________
\_____ \_/ ___\_ __ \ \____ \ __\/ __ \_ __ \_ __ \__ \
/ \ \___| | \/ | |_> > | \ ___/| | \/| | \// __ \_
/_______ /\___ >__| |__| __/|__| \___ >__| |__| (____ /
\/ \/ |__| \/ \/
-------------------------------------------------------------------
Welcome to Scripterra! Pass --help for more information.
[ 2022-08-12T10:44:37.206Z ]
Info | Current .scripterra config:
[ 2022-08-12T10:44:37.206Z ]
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ (index) โ Values โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ SCRIPTS_PATH โ './scripts/' โ
โ ENV_PATH โ './env/' โ
โ REDIS โ 'redis://localhost:6379' โ
โ LOG_PATH โ './logs/' โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโ
[ 2022-08-12T10:44:37.217Z ]
Info | Compile script...
[Test.js] | Info | Starting...
[Test.js] | Info | Hello world!
[Test.js] | Info | Finished.
Step 5. Schedule script
You can schedule your scripts. Be shure that your redis server is working!
scripterra --schedule Test --env .test --expression '* * * * *'
Check if you schedule was created.
scripterra --listall
You should see this:
Info | List of all schedules:
[ 2022-08-12T10:49:15.474Z ]
โโโโโโโโโโโฌโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโ
โ (index) โ script โ env โ expression โ serialized_task โ
โโโโโโโโโโโผโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโค
โ 0 โ 'Test' โ '.test' โ '* * * * *' โ '' โ
โโโโโโโโโโโดโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโ
To update schedule cron expression, just type the same command as for creation and update expression string
scripterra --schedule Test --env .test --expresion '10 * * * *'
You should see this message:
Warning | This script and env already scheduled. Updating schedule...
Now, we can launch the scripterra worker to process the jobs.
scripterra -w
Or, you can run worker in detach mode
scripterra -w -D
You should see this:
Info | Detached worker was started with pid 25052
To stop worker you need to kill the process with pid 25052.
Worker will write logs in LOG_PATH. All logs sorted by pid.
-/logs
|__ scripterra.pid-25052.log
Step 6. Delete the script or schedule
If you want to delete your script. Type:
scripterra --delete script --name Test
If you want to delete your schedule. Type:
scripterra --delete schedule --name Test --env .test
Warning! To delete schedule you need to specify --env flag. Otherwise all schedules for this script will be deleted.
Enjoy!
๐งพ Documantation
Run tests
npm run test
Author
๐ค Alexander Poberezhnyi
- Github: @TheGrotesk
- LinkedIn: @alexandr-poberezhnyi-90a0a5186
๐ค Contributing
Contributions, issues and feature requests are welcome!Feel free to check issues page. You can also take a look at the contributing guide.
Show your support
Give a โญ๏ธ if this project helped you!
๐ License
Copyright ยฉ 2021 Alexander Poberezhnyi. This project is GPL--3.0--or--later licensed.
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago