From b613d1dce778a78cef642db17bfec1e267bcef12 Mon Sep 17 00:00:00 2001 From: Michal Rus Date: Thu, 17 Mar 2022 15:21:45 +0100 Subject: [PATCH] [DDW-1027] Allow specifying initial command for `yarn nix:testnet ` and the like --- README.md | 7 +++++++ nix/yarn-nix-shell.sh | 33 +++++++++++++++++++++++++++++++++ package.json | 14 +++++++------- 3 files changed, 47 insertions(+), 7 deletions(-) create mode 100755 nix/yarn-nix-shell.sh diff --git a/README.md b/README.md index 8645f6c2de..58330abddf 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ If you get SSL error when running `nix-shell` (SSL peer certificate or SSH remot 1. Run `yarn nix:selfnode` from `daedalus`. 2. Run `yarn dev` from the subsequent `nix-shell` (use `KEEP_LOCAL_CLUSTER_RUNNING` environment variable to keep the local cluster running after Daedalus exits: `KEEP_LOCAL_CLUSTER_RUNNING=true yarn dev`) + 1. Alternatively: run `yarn nix:selfnode yarn dev` to achieve the same thing in a single command. Note: after `yarn dev` exits, you will still remain in the `nix-shell`. 3. Once Daedalus has started and has gotten past the loading screen run the following commands from a new terminal window if you wish to import funded wallets: - Byron wallets: `yarn byron:wallet:importer` - Shelley wallets: `yarn shelley:wallet:importer` @@ -94,31 +95,37 @@ If you get SSL error when running `nix-shell` (SSL peer certificate or SSH remot 1. Run `yarn nix:mainnet` from `daedalus`. 2. Run `yarn dev` from the subsequent `nix-shell` +3. Or in one command: `yarn nix:mainnet yarn dev` #### Flight 1. Run `yarn nix:flight` from `daedalus`. 2. Run `yarn dev` from the subsequent `nix-shell` +3. Or in one command: `yarn nix:flight yarn dev` #### Testnet 1. Run `yarn nix:testnet` from `daedalus`. 2. Run `yarn dev` from the subsequent `nix-shell` +3. Or in one command: `yarn nix:testnet yarn dev` #### Staging 1. Run `yarn nix:staging` from `daedalus`. 2. Run `yarn dev` from the subsequent `nix-shell` +3. Or in one command: `yarn nix:staging yarn dev` #### Shelley QA 1. Run `yarn nix:shelley_qa` from `daedalus`. 2. Run `yarn dev` from the subsequent `nix-shell` +3. Or in one command: `yarn nix:shelley_qa yarn dev` #### Alonzo Purple 1. Run `yarn nix:alonzo_purple` from `daedalus`. 2. Run `yarn dev` from the subsequent `nix-shell` +3. Or in one command: `yarn nix:alonzo_purple yarn dev` #### Native token metadata server diff --git a/nix/yarn-nix-shell.sh b/nix/yarn-nix-shell.sh new file mode 100755 index 0000000000..bccb6bf67e --- /dev/null +++ b/nix/yarn-nix-shell.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +# This small wrapper over `nix-shell`, called from package.json +# (e.g. `yarn nix:testnet`) allows to specify an initial command to be +# run inside the `nix-shell` once its ready, e.g.: +# +# $ yarn nix:testnet yarn dev +# +# After the command finishes, you will still be left inside the +# nix-shell. + +if [ $# -lt 2 ] ; then + echo >&2 'fatal: usage: '"$0"' [ ...]' + exit 1 +fi + +NETWORK="$1" ; shift +cluster="$1" ; shift + +# Unfortunately, we need to shell-escape the command: +# cf. +command='' +while [ $# -gt 0 ] ; do + command="$command '""${1//\'/\'\\\'\'}""'" ; shift +done + +if [ -z "$command" ] ; then + command=':' # no-op, if no command +fi + +export NETWORK +# `return` will make the user stay in `nix-shell` after the initial command finishes: +exec nix-shell --argstr nodeImplementation cardano --argstr cluster "$cluster" --command "$command ; return" diff --git a/package.json b/package.json index 971688adba..7c994f729d 100644 --- a/package.json +++ b/package.json @@ -49,13 +49,13 @@ "themes:update": "gulp build:themes && ts-node -r esm ./dist/scripts/update.js && yarn prettier --loglevel warn --write source/renderer/app/themes/daedalus/*.ts", "themes:copy": "ts-node -r @babel/register -r @babel/polyfill source/renderer/app/themes/utils/copyTheme.ts && yarn prettier --loglevel warn --write source/renderer/app/themes/daedalus/*.ts", "clear:cache": "gulp clear:cache", - "nix:alonzo_purple": "NETWORK=alonzo_purple nix-shell --argstr nodeImplementation cardano --argstr cluster alonzo_purple", - "nix:mainnet": "NETWORK=mainnet nix-shell --argstr nodeImplementation cardano --argstr cluster mainnet", - "nix:flight": "NETWORK=mainnet nix-shell --argstr nodeImplementation cardano --argstr cluster mainnet_flight", - "nix:selfnode": "NETWORK=selfnode nix-shell --argstr nodeImplementation cardano --argstr cluster selfnode", - "nix:shelley_qa": "NETWORK=shelley_qa nix-shell --argstr nodeImplementation cardano --argstr cluster shelley_qa", - "nix:staging": "NETWORK=staging nix-shell --argstr nodeImplementation cardano --argstr cluster staging", - "nix:testnet": "NETWORK=testnet nix-shell --argstr nodeImplementation cardano --argstr cluster testnet", + "nix:alonzo_purple": "./nix/yarn-nix-shell.sh alonzo_purple alonzo_purple", + "nix:mainnet": "./nix/yarn-nix-shell.sh mainnet mainnet", + "nix:flight": "./nix/yarn-nix-shell.sh mainnet mainnet_flight", + "nix:selfnode": "./nix/yarn-nix-shell.sh selfnode selfnode", + "nix:shelley_qa": "./nix/yarn-nix-shell.sh shelley_qa shelley_qa", + "nix:staging": "./nix/yarn-nix-shell.sh staging staging", + "nix:testnet": "./nix/yarn-nix-shell.sh testnet testnet", "byron:wallet:importer": "ts-node utils/api-importer/byron-wallet-importer.ts", "shelley:wallet:importer": "ts-node utils/api-importer/shelley-wallet-importer.ts", "mary:wallet:importer": "ts-node utils/api-importer/mary-wallet-importer.ts",