npm.io
2.0.0 • Published 5 years ago

smartuxdeploy

Licence
ISC
Version
2.0.0
Deps
5
Size
37 kB
Vulns
2
Weekly
0

SmartUX Studio application deployment to SmartUX runtime

Overview

The npm package contains all the method for SmartUX application deploy process from SmartUX Studio. These methods makes API calls to the SmartUX runtime environment and publishe the application files downloaded from SmartUX Studio environment.

Requirements

NodeJS

npm modules preinstalled in the package

http
https
fs
form-data
zip-local
path
Installation
 $ npm install smartuxdeploy

Usage

input parameters:
Parameter Description Example value Data type
protocol protocol of the smartUX studio environment 'http' or 'https' String
hostURL URL of the SmartUX Studio (do not include http:// or https://) studio.smartux.com String
username username to log in to SmartUX Studio admin String
encryptedPassword encrypted password Click here for details String
import the required npm modules in your file
  const smartuxdeploy = require('smartuxdeploy');
  const fs = require('fs');
  const zipper = require('zip-local');
  const path = require('path');
  const FormData = require('form-data');
example usage:
// Set the enviroment variables
    const protocol = "<http or https>";
    const hostURL = "<YOUR STUDIO URL>";
    const username = "<STUDIO USERNAME>";
    const encryptedPassword = "<ENCRYPTED PASSWORD>";
// deployAll method calls the getZipFilesToDeploy which results the list of published apps from the smartUx build process.
// next it chceks if there are already files from previously unzipped applications and makes sure that the unzip directory is empty.
// next it unzips the first application from list of published apps and calls the publishZipFile method. 
// All the above steps are repeated for all the applications from published app list from the smartUX build process.
async function deployAll() {
    var appZipDir = './smartUXPublishedApps/';
    var unzipDir = './tempunzipdir';
    var zipFilesToDeploy;
    try {
        zipFilesToDeploy = await smartuxdeploy.getZipFilesToDeploy(appZipDir);
        console.log(zipFilesToDeploy);
    } catch (error) {
        console.error(error);
    }

    for (file of zipFilesToDeploy) {
        // Emptying the unzip directory or create unzipDir if does not exists
        if (fs.existsSync(unzipDir)) {
            for (const file of fs.readdirSync(unzipDir)) {
                fs.unlinkSync(path.join(unzipDir, file));
            }
        } else {
            fs.mkdirSync(unzipDir);
        }
        console.log(file);
        // unzip the zipfile to get smartuxapp.json
        zipper.sync.unzip(appZipDir + file).save(unzipDir);
        var smartuxAppJson = await smartuxdeploy.readSmartUXAppJs(unzipDir, file);
        let appZipFile = appZipDir + file;
        var appNameFromZipFile = smartuxAppJson.name;
        console.log("Calling runtime publish for app : " + appNameFromZipFile);
        try {
            await smartuxdeploy.publishZipFile(protocol, hostURL, username, encryptedPassword, appZipFile, smartuxAppJson, file);
        } catch (error) {
            console.error(error);
        }

        console.log("Runtime publish completed for app : " + appNameFromZipFile);
    }
}
try {
    deployAll();
} catch (error) {
    console.error(error);
}

publishZipFile

This method calls all the methods requires to make the API calls for the deploy process for example login method.

input parameters:
Parameter Description Example value Data type
protocol protocol of the smartUX studio environment 'http' or 'https' String
hostURL URL of the SmartUX dashboard (do not include http:// or https://) smartuxdashboard.com String
username username to log in to SmartUX dashboard user String
encryptedPassword encrypted password Click here for details String