Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ON HOLD] Add CLI support #36

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions CONFIGURATIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@TODO: review and update CLI parameters

# Configuration parameters

| PARAMETER | ALIAS | ENV/JSON | REQUIRED | DESCRIPTION | OPTIONS / EXAMPLE |
| --------- | --------------------- |---------------------- | --------- | ----------- | --------------- |
| -c | --synchronizationMode | CUSTOM_RUN | NO | Set a custom execution to run. | `splitsAndSegments` or `eventsAndImpressions` |
| -s | --wrapper | STORAGE_PATH | YES | Path to the JS file exposing the Storage API. | `path/to/storageAdapter.js` |
| -d | --debug | DEBUG | NO | Set Logger in DEBUG mode enable. | N/A |
| -k | --apikey | APIKEY | YES | Set the Split apikey. | N/A |
| -r | --sdkUrl | API_URL | NO | Set the Split API URL. | N/A |
| -e | --eventsUrl | EVENTS_API_URL | NO | Set a custom execution to run. | N/A |
| -m | --cliMode | | NO | Set where to obtain the Synchronizer configurations. If empty, it implies set via CLI arguments. | `json` or `env` |
| -p | --prefix | PREFIX | NO | Set the Storage's prefix | N/A |
| -n | --eventsPerPost | EVENTS_PER_POST | NO | Set the number of events to send in a POST request | N/A |
| -f | --impressionsPerPost | IMPRESSIONS_PER_POST | NO | Set a custom execution to run | N/A |
| -t | --maxRetries | MAX_RETRIES | NO | Set the number of retries attempt perform an Event or Impression POST request. | N/A |
| -i | --impressionsMode | IMPRESSIONS_MODE | NO | This configuration defines how impressions are queued. | `optimized` or `debug` |

## CLI usage example
```
splitio-node-synchronizer
--apikey <A_VALID_APIKEY>
--storage /path/to/storageAdapter.js
--apiUrl https://sdk.split.io/api
--eventsApiUrl https://events.split.io/api
--prefix myStoragePrefix
--eventsPerPost 2000
--impressionsPerPost 3000
--impressionsMode debug
--maxRetries 5
--debug
```
## `env` mode usage example

```
splitio-node-synchronizer
--mode env
API_KEY=<A_VALID_APIKEY>
STORAGE_PATH=/path/to/storageAdapter.js
API_URL=https://sdk.split.io/api
EVENTS_API_URL=https://events.split.io/api
PREFIX=myStoragePrefix
EVENTS_PER_POST=2000
IMPRESSIONS_PER_POST=3000
IMPRESSIONS_MODE=debug
MAX_RETRIES=5
DEBUG=true
```

## `json` mode usage example

```
splitio-node-synchronizer --mode json --config /path/to/config.json
```

JSON file example:
```
{
"API_KEY": "<A_VALID_APIKEY>",
"STORAGE_PATH": "/path/to/storageAdapter.js",
"API_URL": "https://sdk.split.io/api",
"EVENTS_API_URL": "https://events.split.io/api",
"PREFIX": "myStoragePrefix",
"EVENTS_PER_POST": 2000,
"IMPRESSIONS_PER_POST": 3000,
"IMPRESSIONS_MODE": "debug",
"MAX_RETRIES": 5,
"DEBUG": "true"
}
```
5 changes: 5 additions & 0 deletions CONTRIBUTORS-GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ The different builds can be generated all at once with the command `npm run buil

_Note:_ In order to run build/tests commands, Node 10 or higher is required.

### Building the tools CLI

To create the CLI that will be set as `bin` in the package, run the command `npm run build:cli`. Refer to [package.json](package.json) for more insight on the build scripts.
_Note:_ the CLI capabilities rely on [yargs](https://www.npmjs.com/package/yargs), which requires Node 12 or higher.

### Running tests

The project includes unit as well as integration tests.
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ This package includes a set of Javascript synchronization tools built based on t
[![Twitter Follow](https://img.shields.io/twitter/follow/splitsoftware.svg?style=social&label=Follow&maxAge=1529000)](https://twitter.com/intent/follow?screen_name=splitsoftware)

## Compatibility
Split sync tools supports Node version 8 or higher.
Split sync tools supports:
- Node version 12 or higher to execute the CLI.
- Node version 8 or higher to import the package and use programmatically.

## Getting started
Below is a simple example that describes the execution of the Javascript Synchronizer:

### Install package as global dependency and run CLI
1. Install npm package via `npm install -g @splitsoftware/splitio-sync-tools`
2. Then, execute the CLI `split-sync-tools [...args]`

### Install package as a project dependency to run programmatically
1. Install npm package via `npm install @splitsoftware/splitio-sync-tools`
2. Inside your app, import the `Synchronizer`

Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
"description": "Split Javascript Sync Tools",
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
"bin": {
"splitio-sync-tools": "bin/splitio-sync-tools.js"
},
"files": [
"lib",
"bin",
"types",
"src"
],
Expand All @@ -17,9 +21,10 @@
"check": "npm run check:lint && npm run check:types",
"check:lint": "eslint src --ext .js,.ts",
"check:types": "tsc --noEmit",
"build": "npm run build:esm && npm run build:cjs",
"build": "npm run build:esm && npm run build:cjs && npm run build:cli",
"build:esm": "rimraf lib/esm && tsc -m es2015 --outDir lib/esm --importHelpers && scripts/build_esm_replace_imports.sh && replace @VERSION@ $npm_package_version lib/esm/settings/defaults.js",
"build:cjs": "rimraf lib/cjs && tsc -m CommonJS --outDir lib/cjs --importHelpers && scripts/build_cjs_replace_imports.sh && replace @VERSION@ $npm_package_version lib/cjs/settings/defaults.js",
"build:cli": "rimraf bin && rollup -c && scripts/make_cli.sh",
"json-server": "node ./e2e/server/server.js",
"test:unit": "jest src/",
"test:e2e": "start-server-and-test 'json-server' 3000 './scripts/check_redis.sh && jest e2e/ --runInBand --forceExit'",
Expand Down