CLI scripts to be run locally or as CRON jobs
Run a script using serve
and the script's path under lib
:
pnpm serve lib/index.js
If you need to pass arguments to a script, don't forget to use --
to tell pnpm
to pass-thru:
pnpm serve lib/path/to/some-script.js -- --some-param=123
TL;DR: Don't forget:
lib
(notsrc
).js
(not.ts
)--
before script arguments
The default environment is declared in .env
, committed to Git, and shared with the team. Scripts will run using:
- LOCAL - Bio DB
- NO - Arbimon DB
- NO - Core DB/APIs
You can override the default environment locally by editing .env.local
All secrets must be declared in .env.local
, not in .env
To avoid repeatedly editing/changing environment files (which creates uncertainty and risk, ex: forgetting you're connected to production), you are encouraged to define standard modes.
You can specify a "mode" to import additional predefined env:
pnpm serve lib/path/to/some/script.js -- --mode=testing
The following env files will be imported based on the mode (with later files overriding earlier files):
.env
.env.local
.env.${mode}
(ex:.env.testing
).env.${mode}.local
(ex:.env.testing.local
)
With no explicit mode set, scripts will start with a banner:
_ Biodiversity CLI _
Running in default mode
When using a mode that has the config option PROTECTION=warn
, you will see the following banner:
_ Biodiversity CLI _
Running in TESTING mode
This is a protected mode - are you sure you want to continue? (y|N)
Note: You will need to add secrets in respective .env.${mode}.local
files
Parallel deployments:
production
- PRODUCTION Bio/Arbimon/Corestaging
- STAGING Bio/Arbimon/Coretesting
- TESTING Bio/Arbimon/Core (or STAGING if no TESTING)
Bio local + remote external:
locpro
- LOCAL Bio; PRODUCTION Arbimon/Corelocsta
- LOCAL Bio; STAGING Arbimon/Core
You can create whatever modes you want!
If you wanted a new shared mode abc
, you would create:
.env.abc
(config; secret keys; committed).env.abc.local
(secret values; NOT committed)
If you wanted a new private mode, def
, you would create:
.env.def.local
(config & secrets; NOT committed)
You could use these modes like:
pnpm serve lib/path/to/some/script.js -- --mode=abc
pnpm serve lib/path/to/some/script.js -- --mode=def
Get all data (incremental) from Arbimon and write it to a bio
pnpm serve lib/ingest/sync/incremental.js
pnpm serve lib/sync/reset-and-resync.js -- --slug=rfcx-th --mode=staging
If you're targeting a local database, you must first start it:
pnpm --filter=db serve
(local dev DB)pnpm --filter=db serve-int
(local integration test DB)
Completely reset the database (deletes all tables & wipes migration log):
pnpm db-reset
Run migrations (creates tables, views, etc)
pnpm db-migrate -- --verbose
Run seeders (inserts fake data)
pnpm db-seed -- --verbose
Run reset, migrate, and seed (as 1 script):
pnpm db-rms
pnpm db-rms-int-local