2.0.0 • Published 3 years ago

smartuxbuild v2.0.0

Weekly downloads
57
License
ISC
Repository
-
Last release
3 years ago

Overview

Requirements

NodeJS

Installation

 $ npm install smartuxbuild

Usage

input parameters:

ParameterDescriptionExample valueData type
protocolprotocol of the smartUX studio environment'http' or 'https'String
hostURLURL of the SmartUX Studio (do not include http:// or https://)studio.smartux.comString
usernameusername to log in to SmartUX StudioadminString
encryptedPasswordencrypted passwordClick here for detailsString
appsForBuild optionalList of specific apps for build separated by ':'app1:app2:app3String
port optionalport at which the SmartUX studio is running3000 or default port is 80String

import the required npm modules in your file

  const smartuxbuild = require(‘smartuxbuild’);
  const fs = require('fs');
  const path = require('path');

example usage:

    // Set the enviroment variables
    const protocol = "<http or https>";
    const hostURL = "<YOUR STUDIO URL>";
    const username = "<STUDIO USERNAME>";
    const encryptedPassword = "<ENCRYPTED PASSWORD>";
    const port = "<port number at which the SmartUX studio is running>";
    // Calling the buildAllAps - this method calls all the methods to make API calls to SmartUX Studio eg. login method to call login API etc.
    martuxbuild.buildAllApps(protocol,hostURL,username,encryptedPassword,appsForBuild).catch((e) => {
        console.log(e);
        process.exit(1);
        });

For advanced users buildAllApps in detail

async function buildAllApps(protocol,hostURL,username,encryptedPassword,appsForBuild) {
    var result = {};
    var lastVersion;
    var appsInStudio = [];
    var appsForBuildArray= [];
    var smartUXPublishedApps = "<Your directory to save the application zip file>";
    if (fs.existsSync(smartUXPublishedApps)) {
        for (const file of fs.readdirSync(smartUXPublishedApps)) {
          fs.unlinkSync(path.join(smartUXPublishedApps, file));
        }
      } else {
        fs.mkdirSync(smartUXPublishedApps);
      }
    if(appsForBuild){
        appsForBuildArray = appsForBuild.split(':');
    }
    else {
        console.log("List of applications for build is not defined. All apps will be published.")
    }
    console.log("Trying to login to the SmartUX studio environment!");
    authObject = await smartuxbuild.login(protocol,hostURL,username,encryptedPassword);
    console.log("Login Successful!" + JSON.stringify(authObject));
    console.log("Getting the list of applications from SmartUX studio!");
    result = await smartuxbuild.getApps(authObject);
    if (result && result.error) {
        throw "Get apps failed with error: " + result.error.message;
    }
    console.log("List of application from SmartUX studio : " + JSON.stringify(result, null, 2));
    appsInStudio = JSON.stringify(result, null, 2);
    appsInStudio = JSON.parse(appsInStudio);
    var buildAllApps = !appsForBuildArray || appsForBuildArray.length===0;
    for (var i = 0; i < appsInStudio.result.length; i++) {
        var appId = appsInStudio.result[i].id;
        var fileName = appId + "_" + smartuxbuild.fullDate + ".zip";
        var appInBuildList = appsForBuildArray.length!==0 && appsForBuildArray.indexOf(appId) > -1;
        if (buildAllApps || appInBuildList) {
            console.log(appId + " Found in the list of applications required to be build");
            console.log("Opening application with app id : " + appId);
            result = await smartuxbuild.open(authObject, appId);
            if (result && result.error) {
                throw "Open apps failed with error: " + result.error.message;
            }
            console.log(appId + " opened in SmartUX Studio successfully!")
            result = await smartuxbuild.getPublishInfo(authObject, appId);
            if (result && result.error) {
                console.log("Publish Info failed for " + appId);
                throw "Error: "+result.error.message;
            }
            lastVersion = result.result.version;
            if(!lastVersion || lastVersion===""){
                lastVersion ="1.0.0";
            }


            console.log("Initiating Git pull for application Id: " + appId+", version: "+lastVersion);
            result = await smartuxbuild.pull(authObject, appId);
            if (result && result.error) {
                throw "Git pull for " + appId + " failed with error: " + result.error.message;
            }
            console.log("Completed Git pull for application Id: " +  appId+", version: "+lastVersion);
            console.log("Initiating publish for application Id: " +  appId+", version: "+lastVersion);
            result = await smartuxbuild.publish(authObject, appId, fileName,lastVersion);
            if (result && result.error) {
                console.log("Publish failed for " + appId);
                throw "Error: "+result.error.message;
            }
            console.log("Completed publish for application Id: " + appId+", version: "+lastVersion);
            console.log("Starting download for application Id: " + appId+", version: "+lastVersion);
            result = await smartuxbuild.download(authObject, appId, fileName, smartUXPublishedApps);
            if (result && result.error) {
                throw "Download failed for " + appId + " with error: " + result.error.message;;
            }
            console.log("Completed download  for application Id: " + appId);
            console.log("Application: " + appId + " successfully saved as " + fileName);
        }
        else {
            console.log(appId + " Application id not found in the list apps for build. This app will not be built!");
            console.log("Exiting!")
        }
    }
}

smartuxbuild npm module contains following methods

Login:

input parameters:

ParameterDescriptionExample valueData type
protocolprotocol of the smartUX studio environment'http' or 'https'String
hostURLURL of the SmartUX Studio (do not include http:// or https://)studio.smartux.comString
usernameusername to log in to SmartUX StudioadminString
encryptedPasswordencrypted passwordClick here for detailsString
appsForBuild optionalList of specific apps for build separated by ':'app1:app2:app3String
port optionalport at which the SmartUX studio is running3000 or default port is 80String

example usage:

  authObject = smartuxbuild.login(protocol, hostURL, username, password);

sample output:

{
"protocol":"http",
"hostURL":"ec2-18-236-68-81.us-west-2.compute.amazonaws.com",
"accessToken":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImFkbWluIiwiaWF0IjoxNTk1ODg3NTQ1LCJleHAiOjE1OTY0OTIzNDV9.azqn9Z1SNxoIyLL1EkefaJOcj7oePV_Lv8cZp8ueA3w"
}

getApps:

input parameters:

ParameterDescriptionExample valueData type
authObjectresult object from login methodcheck sample authObject belowJSON object

sample authObject:

authObject = {
    "protocol": protocol,
    "hostURL": hostURL,
    "accessToken": accessToken
              };

example usage:

smartuxbuild.getApps(authObject);

sample output:

{"jsonrpc": "2.0",
"result": [
 {"name": "testApp",
"defaultLayout": "PhonePortrait",
"previewToken": "6637a22e",
"theme": "Anchor",
"clientVersion": "6.1.0",
"hidden": false,
"isBuiltInTemplate": false,
"disableSideMenu": false,
"description": "",
"creatorId": "testuser",
"created": 1588151947117,
"screensCount": 11,
"viewOnly": false,
"branch": "master",
"isRemote": true,
"creatorName": "testuser ",
"explorations": [],
"useMockData": false,
"iconUrl": "/previews/home.png",
"id": "backtowork",
"updated": 1595881366524}
]}

open

input parameters:

ParameterDescriptionExample valueData type
authObjectresult object from login methodsample authObject aboveJSON object
appIdid from the app list from getApps methodApp1string

example usage:

smartuxbuild.open(authObject, appId);

getPublishInfo:

input parameters:

ParameterDescriptionExample valueData type
authObjectresult object from login methodsample authObject aboveJSON object
appIdid from the app list from getApps methodApp1string

example usage:

smartuxbuild.getPublishInfo(authObject, appId);

sample output:

{
"jsonrpc": "2.0",
"result": {
"smartuxApp": "1.0",
"version": "1.0.1",
"date": 1595887546977,
"creator": "Admin",
"clientVersion": "6.1.0",
"id": " App1",
"name": "App1",
"serverVersion": "6.1.0",
"serverModulesIncluded": true,
"buildType": "AOT",
"cbUrl": "/cb",
"packageName": "App1_2020-07-27-17:5:12.zip" },
"id": ""
}

pull:

input parameters:

ParameterDescriptionExample valueData type
authObjectresult object from login methodsample authObject aboveJSON object
appIdid from the app list from getApps methodApp1string

example usage:

smartuxbuild.pull(authObject, appId);

sample output:

{
"jsonrpc": "2.0",
"result": {
  "success": true},
"id": ""
}

publish:

input parameters:

ParameterDescriptionExample valueData type
authObjectresult object from login methodsample authObject aboveJSON object
appIdid from the app list from getApps methodApp1string
fileNamePackage name from output of getPublishhInfo methodApp1_2020-07-27-17:5:12.zipstring
lasrVersionApp version from output of getPublishhInfo method1.0.1string

example usage:

smartuxbuild.publish(authObject, appId, fileName, lastVersion);

sample output:

{
"jsonrpc": "2.0",
"result": {
"packageName": "jenkinstestapp_2020-07-28-8:33:55.zip" },
"id": ""
}

download:

input parameters:

ParameterDescriptionExample valueData type
authObjectresult object from login methodsample authObject aboveJSON object
appIdid from the app list from getApps methodApp1string
fileNamePackage name from output of getPublishhInfo methodApp1_2020-07-27-17:5:12.zipstring
smartUXPublishedAppsDirectory path where app zip will be downloaded‘./smartUXPublishedApps’string

example usage:

smartuxbuild.download(authObject, appId, fileName, smartUXPublishedApps);
2.0.0

3 years ago

1.0.74

4 years ago

1.0.73

4 years ago

1.0.72

4 years ago

1.0.71

4 years ago

1.0.66

4 years ago

1.0.65

4 years ago

1.0.64

4 years ago

1.0.63

4 years ago

1.0.69

4 years ago

1.0.68

4 years ago

1.0.67

4 years ago

1.0.70

4 years ago

1.0.62

4 years ago

1.0.61

4 years ago

1.0.60

4 years ago

1.0.58

4 years ago

1.0.57

4 years ago

1.0.56

4 years ago

1.0.55

4 years ago

1.0.54

4 years ago

1.0.52

4 years ago

1.0.48

4 years ago

1.0.49

4 years ago

1.0.51

4 years ago

1.0.50

4 years ago

1.0.47

4 years ago

1.0.46

4 years ago

1.0.44

4 years ago

1.0.43

4 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.45

4 years ago

1.0.40

4 years ago

1.0.39

4 years ago

1.0.38

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.37

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.19

4 years ago

1.0.20

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago