3.1.2 • Published 3 years ago

@k15t/viewport-uploader v3.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

Viewport Uploader

Latest Version

Introduction

The viewport-uploader package is a node module to upload local resources to Scroll Viewport App inside Atlassian Confluence. For example, it can be used as part of a webpack build process to automate building and uploading a theme.

Note: viewport-uploader was formerly known as gulp-viewport. Read more about the name change in the CHANGELOG.

Getting started with Scroll Viewport theme development

See the basic example on how to use viewpoort-uploader with webpack as a starting point for Scroll Viewport theme development.

Create Environment Config

Viewport Uploader uses Confluence environments specified in ~/.vpconfig.json. Use this file to provide credentials and Confluence base url that will be used for uploading.

Create the file .vpconfig.json in your home directory and add your Confluence environments similar to the example below.

// ~/.vpconfig.json

{
  "DEV": {
    "envName": "DEV",
    "confluenceBaseUrl": "http://localhost:8090/confluence",
    "username": "admin",
    "password": "admin",
    "spaceKey": ""
  },
  "PROD": {
    "envName": "PROD",
    "confluenceBaseUrl": "https://example.com/confluence",
    "username": "admin",
    "password": "admin",
    "spaceKey": "prodspace"
  }
}
PropertiesTypesDescription
envNameStringName of target environment. This should also be the name of the identifier.
confluenceBaseUrlStringURL of Confluence Server. It may not contain a trailing slash.
usernameStringUsername for Confluence Server
passwordStringPassword for Confluence Server
spaceKeyStringSpace key (empty for global). It may contain up to 225 alphanumeric characters. :warning:   Scroll Viewport treats space keys case-sensitive even though for Confluence they are case-insensitive. If you provide the wrong case, the upload will fail without a helpful error message.

API Documentation

The ViewportTheme class provides methods for uploading resources to Scroll Viewport.

Getting started

This is a full example of how viewport uploader works. See the sections below for further details.

const ViewportTheme = require('@k15t/viewport-uploader');

// Initialize the theme instance
const themeOptions = {
    // identifies the theme in the Scroll Viewport app
    themeName: 'my-viewport-theme', 

    // identifies the environment inside the `~/.vpconfig.json`
    envName: 'DEV' 
}

const theme = new ViewportTheme(themeOptions);

// Upload theme code
const uploadOptions = {
    glob: 'build/',
    sourcePath: 'build/',
    targetPath: ''
}

theme.upload(uploadOptions, true);

Initialize a ViewportTheme instance

const ViewportTheme = require('@k15t/viewport-uploader');

const theme = new ViewportTheme({
    themeName: 'my-viewport-theme',
    envName: 'DEV'
});
PropertyTypeDescriptionRequired
themeNameStringName of the theme in Scroll Viewporttrue
envNameStringName of the target environment that is used from ~/.vpconfig.jsontrue

Initialize a ViewportTheme instance – Using environmental variables

Alternatively environmental variables can be set. This is especially useful for CI/CD pipelines. If all of the following environmental variables are set, they will be preferred. Argument options from eg ~/.vpconfig.json will be ignored.

Environmental VariablesDescription
VPRT_THEMENAMEName of the theme in Scroll Viewport
VPRT_ENVName of the target environment that is used from ~/.vpconfig.json
VPRT_CONFLUENCEBASEURLsee Create Environment Config for more Information
VPRT_USERNAMEsee Create Environment Config for more Information
VPRT_PASSWORDsee Create Environment Config for more Information
VPRT_SPACEKEYsee Create Environment Config for more Information

Methods

All methods are async methods that return a promise.

Create a theme

// Creates a theme with the `themeName` in Scroll Viewport

await theme.create();

Must be run before any other method as it initialises internal variables required by reset() and upload().


Check if a theme exist

// Checks if a theme with the `themeName` exists in Scroll Viewport

await theme.exists();

Is executed at the beginning of every method, i.e. no need to run it on it's own, every method has existence check built in.


Reset a theme

// Resets a theme with the `themeName` in Scroll Viewport, deletes all resources but doesn't delete the theme itself

await theme.reset();

Upload a theme

await theme.upload({
    glob: 'build/',
    sourcePath: 'build/',
    targetPath: ''
}, true);
propertiesTypeDescriptionRequired
globStringFile path pattern of resources that should be uploaded, path is taken relative to the CWD, e.g. build/images/*.jpg.true
targetPathStringDirectory path where the resources should be deployed to, path is taken relative to the theme base URL e.g. x/y/ results in files being uploaded to <themeBaseUrl>/x/y/build/images/*.jpgtrue
sourcePathStringDirectory path which should be "subtracted" from glob path when uploading, path is taken relative to the CWD, e.g. build/images/ results in files being uploaded to <themeBaseUrl>/x/y/*.jpgtrue
verboseBooleanOptional, if set to true enables detailed logging of the files that are uploadedfalse

:warning:   Paths should follow this pattern:

# Correct: path with a trailing slash and without a leading slash
your/custom/path/

# Incorrect:
/your/custom/path/
/your/custom/path
your/custom/path