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

feat: add local test script #217

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Sysweb3

### [Testing locally with Pali-Wallet](./scripts/README.md)
55 changes: 55 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Project Build Scripts



## Prerequisites
- Before running the script, make sure the following tools are installed on your system:

- yarn: Used to manage dependencies and execute build scripts.
- jq: Used to programmatically manipulate JSON files.

You can install these requirements using the following commands:

```bash
sudo apt-get install jq
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
nvm install node
npm install -g yarn
```

## Build local development
- This script automates the process of building specified local packages and updating their paths in the `package.json` of the pali-wallet project.
### Usage

To run the script, you need to provide the path to the `package.json` file of the pali-wallet project. You can optionally specify which packages you want to build and update. If no packages are specified, all packages will be processed.

#### Syntax

```bash
./build-local-test.sh <path_to_destination_package_json> [package_names...]
```

#### Examples

##### To update all packages:
```bash
./build-local-test.sh /path/to/pali-wallet/package.json
```

##### To update specific packages (e.g., sysweb3-keyring and sysweb3-network):
```bash
./build-local-test.sh /path/to/pali-wallet/package.json sysweb3-keyring sysweb3-network
```

## Build manifest v3 local development
- This script automates the process of building the local development using manifest v3
### Usage

To run the script, you need to provide the path to the `pali-wallet` project.

#### Syntax

```bash
./build-local-mv3.sh <path_to_pali>
```

104 changes: 104 additions & 0 deletions scripts/build-local-mv3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/bash

# Check if yarn and jq are available
if ! command -v yarn &> /dev/null; then
echo "yarn could not be found, please install it."
exit 1
fi

if ! command -v jq &> /dev/null; then
echo "jq could not be found, please install it."
exit 1
fi

if [ "$#" -lt 1 ]; then
echo "Usage: $0 <pali-wallet-path>"
exit 1
fi

PALI_PATH=$1

# Variables
PACKAGES_DIR="$PWD/packages"
CORE_PACKAGE="sysweb3-core"
KEYRING_PACKAGE="sysweb3-keyring"
CORE_PACKAGE_PATH="$PACKAGES_DIR/$CORE_PACKAGE"
KEYRING_PACKAGE_JSON="$PACKAGES_DIR/$KEYRING_PACKAGE/package.json"
PALI_PACKAGE_JSON="$PALI_PATH/package.json"

# Ensure the Core package directory exists
if [ ! -d "$CORE_PACKAGE_PATH" ]; then
echo "Core package path $CORE_PACKAGE_PATH does not exist."
exit 1
fi

# Build the Core package
echo "Building $CORE_PACKAGE at $CORE_PACKAGE_PATH..."
(cd "$CORE_PACKAGE_PATH" && yarn && yarn localTest) || exit 1

# Generate the local path for the Core package
CORE_DIST_PATH="$CORE_PACKAGE_PATH/dist"

# Check if the Keyring package.json exists
if [ ! -f "$KEYRING_PACKAGE_JSON" ]; then
echo "Keyring package.json not found at $KEYRING_PACKAGE_JSON"
exit 1
fi

# Update the Keyring package.json with the Core dist path
TEMP_FILE=$(mktemp)
jq --arg path "$CORE_DIST_PATH" \
'.dependencies["@pollum-io/sysweb3-core"] = $path' "$KEYRING_PACKAGE_JSON" > "$TEMP_FILE" && mv "$TEMP_FILE" "$KEYRING_PACKAGE_JSON"

if [ $? -eq 0 ]; then
echo "sysweb3-core path updated in sysweb3-keyring package.json to $CORE_DIST_PATH"
else
echo "Failed to update sysweb3-core in sysweb3-keyring package.json."
[ -f "$TEMP_FILE" ] && rm "$TEMP_FILE"
exit 1
fi

# Update the Pali package.json with the Keyring dist path
PACKAGE_PATH="$PACKAGES_DIR/$KEYRING_PACKAGE"
echo "Building Core at Keyring..."

# Ensure the directory exists
if [ ! -d "$PACKAGE_PATH" ]; then
echo "Package path $PACKAGE_PATH does not exist."
continue
fi

# Execute yarn localTest
(cd "$PACKAGE_PATH" && yarn && yarn localTest) || continue

# Generate the local path for the package
LOCAL_PATH="$PACKAGE_PATH/dist"

# Update the package.json of the pali-wallet project
TEMP_FILE=$(mktemp)
jq --arg pkg "@pollum-io/$KEYRING_PACKAGE" --arg path "$LOCAL_PATH" \
'.dependencies[$pkg] = $path' "$PALI_PACKAGE_JSON" > "$TEMP_FILE" && mv "$TEMP_FILE" "$PALI_PACKAGE_JSON"

if [ $? -eq 0 ]; then
echo "$PACKAGE path updated in package.json to $LOCAL_PATH"
else
echo "Failed to update $PACKAGE in package.json."
[ -f "$TEMP_FILE" ] && rm "$TEMP_FILE"
fi


# Path to .envrc
ENVRC_PATH="$PALI_PATH/.envrc"
MANIFEST_VAR="MANIFEST_TYPE=MV3"

# Set environment variable MANIFEST_TYPE in the Pali .env file
if grep -q "$MANIFEST_VAR" "$ENVRC_PATH"; then
echo "A variável $MANIFEST_VAR já está definida no $ENVRC_PATH."
else
# Execute direnv to allow the environment
echo "$MANIFEST_VAR" >> "$ENVRC_PATH"
echo "Variável $MANIFEST_VAR adicionada ao $ENVRC_PATH."
(cd "$PALI_PATH" && direnv allow)
fi

echo "All operations completed successfully."
76 changes: 76 additions & 0 deletions scripts/build-local-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash

# Check if the path to package.json was provided as an argument
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <path_to_destination_package_json> [package_names...]"
exit 1
fi

DESTINATION_PACKAGE_JSON=$1

# List of all available packages to build and update
ALL_PACKAGES=("sysweb3-keyring" "sysweb3-network" "sysweb3-utils")
# List of packages to be processed, can be all or a subset
PACKAGES_TO_PROCESS=()

if [ "$#" -eq 1 ]; then
PACKAGES_TO_PROCESS=("${ALL_PACKAGES[@]}")
else
shift # remove the first argument (path to package.json)
while (( "$#" )); do
PACKAGES_TO_PROCESS+=($1)
shift
done
fi

# Verify if the destination package.json exists
if [ ! -f "$DESTINATION_PACKAGE_JSON" ]; then
echo "Destination package.json not found at $DESTINATION_PACKAGE_JSON"
exit 1
fi

# Ensure yarn and jq are available
if ! command -v yarn &> /dev/null; then
echo "yarn could not be found, please install it."
exit 1
fi

if ! command -v jq &> /dev/null; then
echo "jq could not be found, please install it."
exit 1
fi

PACKAGES_DIR="$PWD/packages"

# Iterate over each specified package, build and update the path in package.json
for PACKAGE in "${PACKAGES_TO_PROCESS[@]}"
do
PACKAGE_PATH="$PACKAGES_DIR/$PACKAGE"
echo "Building $PACKAGE at $PACKAGE_PATH..."

# Ensure the directory exists
if [ ! -d "$PACKAGE_PATH" ]; then
echo "Package path $PACKAGE_PATH does not exist."
continue
fi

# Execute yarn localTest
(cd "$PACKAGE_PATH" && yarn && yarn localTest) || continue

# Generate the local path for the package
LOCAL_PATH="$PACKAGE_PATH/dist"

# Update the package.json of the pali-wallet project
TEMP_FILE=$(mktemp)
jq --arg pkg "@pollum-io/$PACKAGE" --arg path "$LOCAL_PATH" \
'.dependencies[$pkg] = $path' "$DESTINATION_PACKAGE_JSON" > "$TEMP_FILE" && mv "$TEMP_FILE" "$DESTINATION_PACKAGE_JSON"

if [ $? -eq 0 ]; then
echo "$PACKAGE path updated in package.json to $LOCAL_PATH"
else
echo "Failed to update $PACKAGE in package.json."
[ -f "$TEMP_FILE" ] && rm "$TEMP_FILE"
fi
done

echo "All packages have been built and paths updated successfully."
Loading