WPMv2

WPMv2

WebstratePackageManager version 2 It is used to install WPM packages into webstrates.
WPMv2.require([
     {package: "somePackageName", repository: "/somewebstraterepo"},
     {package: "someOtherPackageName", repository: "/somewebstraterepo"}
]).then(()=>{
    //Packages are now installed
});

Classes

WPMInterface
WPMPackage

Methods

(static) clearRegisteredRepositories(useLocalStorage)

Description:
  • Clears all registered aliases from storage
Source:
Parameters:
Name Type Default Description
useLocalStorage false If true, clears from localStorage, if not, from sessionStorage

(async, static) findCompletePackageTreeSorted(packages) → {Promise.<void>}

Source:
Parameters:
Name Type Description
packages Array.<WPMv2.WPMPackage>
Returns:
Type
Promise.<void>

(static) getCurrentlyInstalledPackages() → {Array.<WPMv2.WPMPackage>}

Description:
  • Get an array of all packages that is currently installed in the dom
Source:
Example
let installedPackages = WPMv2.getCurrentlyInstalledPackages();
Returns:
Type
Array.<WPMv2.WPMPackage>

(async, static) getLatestPackageFromPackage(p) → {Promise.<WPMv2.WPMPackage>}

Description:
  • Retrieve the latest package data from the original repository this package is from
Source:
Example
WPMv2.getCurrentlyInstalledPackages().forEach((pkg)=>{
    let package = WPMv2.getLatestPackageFromPackage(pkg);
    //package now holds the latest data retrieved from the original repo it was installed from: like version, dependencies, changelog etc.
});
Parameters:
Name Type Description
p WPMv2.WPMPackage The package to update package data for
Returns:
Type
Promise.<WPMv2.WPMPackage>

(async, static) getPackagesFromRepository(repositoryUrl) → {Array.<WPMv2.WPMPackage>}

Description:
  • Find all packages at a repository
Source:
Example
WPMv2.getPackagesFromRepository("some.site.com/myRepo").then((packages)=>{
    console.log("Packages at repo:");
    packages.forEach((pkg)=>{
        console.log(pkg);
    }):
});
Parameters:
Name Type Description
repositoryUrl String the repository to search
Returns:
the packages found
Type
Array.<WPMv2.WPMPackage>

(async, static) installWPMInto(iframeOrUrl) → {Promise.<void>}

Description:
  • Installs WPMv2 into the given webstrate. Can be given as an iframe that already points to a transcluded webstrate, or the url to a webstrate.
Source:
Example
await WPMv2.installWPMInto("https://some.site.com/myWebstrate");
//WPMv2 is now installed
Parameters:
Name Type Description
iframeOrUrl HTMLIFrameElement | string The iframe or url that WPMv2 should be installed into
Returns:
- Resolves when WPMv2 is done installing.
Type
Promise.<void>

(static) registerRepository(alias, repository, useLocalStorage)

Description:
  • Registers a repository alias
Source:
Parameters:
Name Type Default Description
alias The alias to register
repository The repository to register the alias to
useLocalStorage false If true, the registered alias is registered in localStorage, if not, in sessionStorage

(async, static) require(packages, overrideOptions) → {Promise.<void>}

Description:
  • Installs the given packages into the current document Override options set in overrideOptions, override the options given in packages.
Source:
Example
WPMv2.require([{package: "myPackage", repository: "myRepositoryUrl"}]);
Parameters:
Name Type Description
packages Array.<WPMv2.WPMPackage> | WPMv2.WPMPackage | Array.<WPMv2~PackageJson> | WPMv2~PackageJson the packages to install
overrideOptions WPMv2~PackageOptions options to use for overriding packages options, also applies for dependencies
Returns:
- Resolves when the packages are done installing
Type
Promise.<void>

(async, static) requireAll(repository, options) → {Promise.<void>}

Description:
  • Installs all packages at the given repository into the current page
Source:
Example
WPMv2.requireAll("https://some.site.com/myRepo");
Parameters:
Name Type Description
repository string The repository to lookup packages from
options WPMv2~PackageOptions options to use for overriding packages options, also applies for dependencies
Returns:
- Resolved when packages are installed
Type
Promise.<void>

(static) stripProtection(html)

Description:
  • Strips all Webstrate protection from the given dom element and its children.
Source:
Example
WPMv2.stripProtection(document.querySelector("#myElement"));
Parameters:
Name Type Description
html HTMLElement The element to strip protection from

(static) unregisterRepository(alias, useLocalStorage)

Description:
  • Unregisters a repository alias
Source:
Parameters:
Name Type Default Description
alias The alias to unregister
useLocalStorage false If true, the alias is removed from localStorage, if not, from sessionStorage

(async, static) updateWPM(url) → {Promise.<void>}

Description:
  • Updates the version of WPMv2 in the current page, with the version in the given url
Source:
Example
await WPMv2.updateWPM("https://some.site.com/containsLatestWPMv2");
//WPMv2 is now updated
Parameters:
Name Type Description
url string URL to the webstrate to update WPMv2 from
Returns:
- Resolves when WPMv2 is updated
Type
Promise.<void>

Type Definitions

PackageJson

Source:
Properties:
Name Type Attributes Description
package string The name of the package
repository string <optional>
The repository to lookup the package inside. If left unset, the current page is used.
appendTarget HTMLElement | string <optional>
The dom node to append to. If a string, will be looked up by document.querySelector(appendTarget). Defaults to a transient div inside document.head
appendMethod 'append' | 'before' | 'after' | 'prepend' <optional>
How to append to the appendTarget. Defaults to 'append'.
Type:
  • Object

PackageOptions

Source:
Properties:
Name Type Attributes Description
repository string <optional>
The repository to lookup the package inside. If left unset, the current page is used.
appendTarget HTMLElement | string <optional>
The dom node to append to. If a string, will be looked up by document.querySelector(appendTarget). Defaults to a transient div inside document.head
appendMethod 'append' | 'before' | 'after' | 'prepend' <optional>
How to append to the appendTarget. Defaults to 'append'.
Type:
  • Object