Skip to content

Developer jq-cli

jq-cli is a command-line tool to help with development and deployment.

Warning

jq-cli works only when hosting:system_api on server in settings.json match domain

You can use jq-cli to:

Bash
1
2
3
4
5
6
7
8
# Build  `index.html` for live reload.
./jq-cli.sh --action build --host app.jquery.io --appname myapp --token mytoken 

# Deploy your local copy to the remote server,
./jq-cli.sh --action deploy --host app.jquery.io --appname myapp --token mytoken 

# Get the application from the remote server
./jq-cli.sh --action get --host app.jquery.io --appname myapp --token mytoken 

Token can be saved in user environment variable and then you can use jq-cli without --token argument. Warning you need to close all terminal windows/vs code instances and open new one to use new environment variable.

Environment variable examples :

Text Only
app.jetquery.io  >  app_jetquery_io
How it works

jq-cli --action build performs the following steps: 1. Prepare a list of local assets 2. Send the local assets list and receive a prepared index file

If files are duplicated in the local and remote locations, the following algorithm is applied on the server side to determine which file to use let's say \css\site.css example:

  • Verify if the file \css\site.css exists in the local development folder.
  • Verify if the file \css\site.css exists on the server.
  • If it exists, verify if the minified version \css\site.min.css is available.
  • Verify if the file \css\site.css exists in the application marked as UI.
  • If it exists, check if the minified version \css\site.min.css is available.

First time setup

1. Install jq-cli

To use jq-cli, you need to have the following dependencies installed:

Bash
curl -L -o jq-cli.sh  https://jetquery.io/examples/scripts/jq-cliv3.sh.txt
* This command will download the script to your app directory.

Bash
echo "---------------------------"
echo "./jq-cli.sh v3, jetquery.io"

function printHelp {
  echo "---------------------------"
  echo "Command line reference:"
  echo "Build index.html for local development" 
  echo " jq-cli --action build --host app.host.com --token token --appname name"
  echo "Deploy local assets to server" 
  echo " jq-cli --action deploy --host app.host.com --token token --appname name"
  echo "Get latest version from server" 
  echo " jq-cli --action get --host app.host.com --token token --appname name"
  echo "---------------------------"
  echo "Options:"
  echo " token can be stored in user environment variable app_host_com"
  echo " !Warning you need to close all instances of vs code to reload environment variables"
  echo "---------------------------"
  echo "Script Latest version : https://jetquery.io/examples/scripts/jq-cliv3.sh.txt"
  exit 1
}


# Parse parameters
while (( "$#" )); do
  case "$1" in
    --action | -a)
      action=$2
      shift 2
      ;;
    --host | -h)
      host=$2
      shift 2
      ;;
    --token | -t)
      token=$2
      shift 2
      ;;
    --dirs | -d)
      dirs=$2
      shift 2
      ;;
    --appname | -n)
      appname=$2
      shift 2
      ;;
    *)

      echo "Unknown option: $1"
      printHelp
      ;;
  esac
done


# Check if host is empty
if [[ -z "$host" ]]; then
  printHelp
fi


# Try to get TOKEN from environment variable
if [ -z "$token" ]; then
  temphost=$(echo "$host" | sed 's/\./_/g' | sed 's/-/_/g' | sed 's/^https\?:\/\///')
  token=${!temphost}
fi

echo "host: $host / token: ${token:0:6} / appname: $appname" 
if [ -z "$token" ]; then
  echo "--token not provided"
  exit 1
fi

if [ -z "$appname" ]; then
  echo "--appname not provided"
  exit 1
fi


if [ "$action" = "get" ]; then     # GET current version from server
  if [ "$appname" = "www" ]; then 
    curl -L -o data.zip  -H "Authorization: Token ${token}" ${host}/api/core/dev/client-files --fail-with-body --silent --show-error
  else
    curl -L -o data.zip  -H "Authorization: Token ${token}" ${host}/api/core/storage/zip/${appname} --fail-with-body --silent --show-error
  fi
  unzip -o data.zip -d .
  # delete data.zip 
  rm data.zip -f
fi

if [ "$action" = "build" ] || [ "$action" = "" ] || [ "$action" = "get" ]; then
  # delete index.html
  rm index.html -f
  # GET local assets list
  find -type f -name "*.js" -o -name "*.css" > list.txt
  # SEND local assets list and build index file
  curl -F "data=@list.txt" -H "Authorization: Token ${token}" ${host}/api/core/dev/client-index -o index.html --fail-with-body --silent --show-error
  if [ -f "index.html" ]; then
    echo "DONE, index.html created"
  else
    echo "ERROR, index.html not created"
  fi
  rm list.txt -f
  rm data.zip -f
elif [ "$action" = "deploy" ]; then     # UPLOAD
  # delete data.zip
  rm data.zip -f
  # create data.zip
  "7z.exe" a data.zip ${dirs} -bso0 -x!.* -x!*.zip -x!index.html
  # upload data.zip
  if [ "$appname" = "www" ]; then 
    curl -X POST -H "Authorization: Token ${token}" -F "data=@data.zip" ${host}/api/core/dev/client-files --fail-with-body  --silent --show-error
  else
    curl -X POST -H "Authorization: Token ${token}" -F "data=@data.zip" ${host}/api/core/storage/upload/${appname} --fail-with-body  --silent --show-error
  fi
  # delete data.zip and list.txt
  rm data.zip -f

  # create index.html
  touch index.html
else
  printHelp
fi

2. Optional, setup .vscode/settings.json and .gitignore

Optional script to create .vscode/settings.json and .gitignore files.

Bash
curl -L -o .vscode/settings.json  https://jetquery.io/examples/scripts/settings.json.txt --create-dirs
curl -L -o .gitignore https://jetquery.io/examples/scripts/gitignore.txt

JSON
{
  "liveServer.settings.file": "index.html",
  "editor.tabSize": 2,
  "editor.detectIndentation": false,
  "html.format.wrapLineLength": 200,
  "formatSelectionAsHtml.printWidth": 200,
  "liveServer.settings.port": 5502,
  "markdown.validate.enabled": true,
  "diffEditor.ignoreTrimWhitespace": true,
  "markdown.copyFiles.destination": {
    "/docs/**/*": "img/${documentBaseName}/"
  },
  "liveServer.settings.ignoreFiles": [
    "srs/*",
    "data.zip",
    "list.txt"
  ],
  "terminal.integrated.defaultProfile.windows": "Git Bash",
  "rest-client.environmentVariables": {
    "client1": {
      "host": "https://xxxxx.com",
      "token": "xxxxxxxxxxxxxxxxxxxxxx",
      "appname": "app"
    },
    "client2": {
      "host": "https://xxxxx.com",
      "token": "xxxxxxxxxxxxxxxxxxxxxx",
      "appname": "erp"
    }
  }
}
JSON
1
2
3
4
5
6
index.html
data.zip
list.txt
.*/
/.*
!/.gitignore

3. Prepare token and applicationname

  • Application Name - {host}/get/apps
  • Token - Create an API key if you don't have one: {host}/get/admin
  • If the application is connected with a repository or there are problem with proper git setup, you should clone it using the command:
Bash
git clone https://username@github.com/paanda-io/repository-name

4. jq-cli reference

Arguments:

  • --action - action to perform
    • build or empty, generate index.html for live reload
    • deploy- deploy local copy to remote
    • get - get application from remote
  • --host - host name
    • ex. app.jetquery.io
    • you can save token in user environment variable - app_jetquery_io
  • --appname - application name
  • --token - token for api access