Skip to content

Commit

Permalink
feat(tooling): simplify dryrun command (#90)
Browse files Browse the repository at this point in the history
## Describe your changes
If an .env file is added with these contents:
```
NANGO_SECRET_KEY_DEV=aaa-aaa-aaa
NANGO_HOSTPORT=https://api.nango.dev
```
You can now just run 
```
npm run dryrun -- datadog users d
```

The pattern above being `dryrun $INTEGRATION $SCRIPT_NAME
$CONNECTION_NAME`

Instead of 
```
bash scripts/run-integration-template.bash KEY=aaa-aaa-aaa HOST=https://api.nango.dev datadog dryrun users d
```

Note that this is backwards compatible

## Issue ticket number and link

## Checklist before requesting a review (skip if just adding/editing
APIs & templates)
- [ ] I added tests, otherwise the reason is:
- [ ] External API requests have `retries`
- [ ] Pagination is used where appropriate
- [ ] The built in `nango.paginate` call is used instead of a `while
(true)` loop
- [ ] Third party requests are NOT parallelized (this can cause issues
with rate limits)
- [ ] If a sync requires metadata the `nango.yaml` has `auto_start:
false`
- [ ] If the sync is a `full` sync then `track_deletes: true` is set
  • Loading branch information
khaliqgant authored Nov 1, 2024
1 parent 5d68ba9 commit 39cb9dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"move:integrations": "bash scripts/move-all-to-nango-integration-directories.bash $npm_config_integration",
"undo:move:integrations": "bash scripts/undo-move-to-nango-directories.bash",
"lint-moved-integrations": "npm run move:integrations && npm run lint && npm run undo:move:integrations",
"dryrun": "bash scripts/run-integration-template.bash --dryrun",
"generate:zod": "bash scripts/generate-integration-template-zod.bash $npm_config_integration && npm run undo:move:integrations",
"compile": "bash scripts/compile-all-templates.bash $npm_config_integration && npm run undo:move:integrations",
"prettier-format": "prettier --config .prettierrc \"./**/*.{ts,tsx}\" --write",
Expand Down
13 changes: 12 additions & 1 deletion scripts/run-integration-template.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ popd () {
command popd "$@" > /dev/null
}

if [ -f .env ]; then
export $(cat .env | xargs)
fi

TEMP_DIRECTORY=tmp-run-integration-template

NANGO_HOSTPORT_DEFAULT=http://localhost:3003
Expand All @@ -16,6 +20,8 @@ ITERATIONS=1
INPUT_JSON=""
USE_ITERATIONS=false

nango_command=""

# optional arguments
for arg in "$@"; do
case $arg in
Expand All @@ -27,6 +33,10 @@ for arg in "$@"; do
NANGO_HOSTPORT="${arg#*=}"
shift
;;
--dryrun)
nango_command="dryrun"
shift
;;
--iterations=*)
ITERATIONS="${arg#*=}"
USE_ITERATIONS=true
Expand All @@ -35,6 +45,7 @@ for arg in "$@"; do
esac
done


if [ -z "$NANGO_SECRET_KEY_DEV" ]; then
echo "NANGO_SECRET_KEY_DEV must be set"
exit 1
Expand Down Expand Up @@ -72,7 +83,7 @@ for ((i=1; i<=ITERATIONS; i++)); do
sed -i '' -e "s/\${iteration}/$i/g" "$INPUT_JSON"
fi

NANGO_MOCKS_RESPONSE_DIRECTORY="../../integrations/" NANGO_SECRET_KEY_DEV=$NANGO_SECRET_KEY_DEV NANGO_HOSTPORT=$NANGO_HOSTPORT npx nango "$@"
NANGO_MOCKS_RESPONSE_DIRECTORY="../../integrations/" NANGO_SECRET_KEY_DEV=$NANGO_SECRET_KEY_DEV NANGO_HOSTPORT=$NANGO_HOSTPORT npx nango $nango_command "$@"

if $USE_ITERATIONS && [ -n "$INPUT_JSON" ] && [[ "$INPUT_JSON" == *.json ]]; then
echo "$PRE_REPLACE_CONTENTS" > $INPUT_JSON
Expand Down

0 comments on commit 39cb9dc

Please sign in to comment.