|
| 1 | +#!/usr/bin/env sh |
| 2 | + |
| 3 | +tarball_dir=$(pwd) |
| 4 | + |
| 5 | +case "$1" in |
| 6 | +create) |
| 7 | + if [ -d etc/playgrounds/"$2" ]; then |
| 8 | + echo "Playground '$2' already exists; do you want to delete and recreate it? [y/N]" |
| 9 | + read -r response |
| 10 | + |
| 11 | + if [ "$response" != "y" ]; then |
| 12 | + echo "You can use 'update' to update the playground instead with the latest local build of \`astra-db-ts\`" |
| 13 | + exit 1 |
| 14 | + fi |
| 15 | + fi |
| 16 | + |
| 17 | + if [ -z "$2" ]; then |
| 18 | + echo "Usage: $0 create <name>" |
| 19 | + exit 1 |
| 20 | + fi |
| 21 | + |
| 22 | + npm run build |
| 23 | + npm pack |
| 24 | + |
| 25 | + rm -rf etc/playgrounds/"$2" |
| 26 | + mkdir -p etc/playgrounds/"$2" |
| 27 | + cd etc/playgrounds/"$2" || exit 1 |
| 28 | + |
| 29 | + npm init -y |
| 30 | + npm i -D typescript tsx dotenv |
| 31 | + cp ../../../tsconfig.json . |
| 32 | + |
| 33 | + npm i "${tarball_dir}"/datastax-astra-db-ts-*.tgz |
| 34 | + rm "${tarball_dir}"/datastax-astra-db-ts-*.tgz |
| 35 | + |
| 36 | + echo "import * as $ from '@datastax/astra-db-ts'; |
| 37 | +import dotenv from 'dotenv'; |
| 38 | +
|
| 39 | +dotenv.configDotenv({ path: '../../../.env' }); |
| 40 | +
|
| 41 | +const client = new $.DataAPIClient(process.env.CLIENT_DB_TOKEN, { environment: process.env.CLIENT_DB_ENVIRONMENT as any }); |
| 42 | +const db = client.db(process.env.CLIENT_DB_URL!); |
| 43 | +const admin = client.admin(); |
| 44 | +const dbAdmin = db.admin({ environment: process.env.CLIENT_DB_ENVIRONMENT as any }); |
| 45 | +const coll = db.collection('test_coll'); |
| 46 | +const table = db.table('test_table'); |
| 47 | +
|
| 48 | +(async () => { |
| 49 | +
|
| 50 | +})();" > index.ts |
| 51 | + ;; |
| 52 | +update) |
| 53 | + if [ -z "$2" ]; then |
| 54 | + echo "Usage: $0 update <name>" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + |
| 58 | + if [ ! -d etc/playgrounds/"$2" ]; then |
| 59 | + echo "Playground '$2' not found" |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + |
| 63 | + npm run build |
| 64 | + npm pack |
| 65 | + |
| 66 | + cd etc/playgrounds/"$2" || exit 1 |
| 67 | + |
| 68 | + npm i "${tarball_dir}"/datastax-astra-db-ts-*.tgz |
| 69 | + rm "${tarball_dir}"/datastax-astra-db-ts-*.tgz |
| 70 | + ;; |
| 71 | +destroy) |
| 72 | + if [ -z "$2" ]; then |
| 73 | + echo "Usage: $0 destroy <name>" |
| 74 | + exit 1 |
| 75 | + fi |
| 76 | + |
| 77 | + if [ ! -d etc/playgrounds/"$2" ]; then |
| 78 | + echo "Playground '$2' not found" |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | + |
| 82 | + rm -rf etc/playgrounds/"$2" |
| 83 | + ;; |
| 84 | +*) |
| 85 | + if [ -z "$1" ]; then |
| 86 | + echo "Usage: $0 <name>" |
| 87 | + exit 1 |
| 88 | + fi |
| 89 | + |
| 90 | + if [ ! -d etc/playgrounds/"$1" ]; then |
| 91 | + echo "Playground '$1' not found" |
| 92 | + exit 1 |
| 93 | + fi |
| 94 | + |
| 95 | + cd etc/playgrounds/"$1" || exit 1 |
| 96 | + npx tsx index.ts |
| 97 | +esac |
0 commit comments