1.0.8 โ€ข Published 2 years ago

@thegrotesk/scripterra v1.0.8

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
2 years ago
------------------------------------------------------------------
  _________            .__        __
 /   _____/ ___________|__|______/  |_  _______________________
 \_____  \_/ ___\_  __ \  \____ \   __\/ __ \_  __ \_  __ \__  \
 /        \  \___|  | \/  |  |_> >  | \  ___/|  | \/|  | \// __ \_
/_______  /\___  >__|  |__|   __/|__|  \___  >__|   |__|  (____  /
        \/     \/         |__|             \/                  \/
-------------------------------------------------------------------

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

โš™๏ธ 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

๐Ÿค 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.

1.0.8

2 years ago

1.0.7

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

0.1.1

2 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.1.0

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago