0.0.4 • Published 1 month ago

@cartona/deploy-capacitor v0.0.4

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
1 month ago

@cartona/capacitor-deploy

Live updates for Ionic apps. Inspired by ideas from Microsoft's CodePush and Cap-go/capacitor-updater.

Currently supported in both Android and iOS.

Not yet tested for use in Production environments.

Install

npm install @cartona/capacitor-deploy
npx cap sync

Example

The DeployClient class allows control of every step of the update process.

You can check, download, and install updates in one step (e.g. at startup) or split it over phases (e.g. on application state change).

import { DeployClient, AppBuild, DeployConfig } from '@cartona/capacitor-deploy';
...

async checkUpdates() {

    // Prepare global configuration

    let config: DeployConfig = {
        server_url: 'https://deploy-api.cartona.space',
        appcode: '<application identifier used to upload and rollout>'
    }

    // MUST call startup() with application start

    await DeployClient.startup(config);

    // Check if any updates are available for this app on this device
    // You may show your Splash screen if this method returns a pending build
    // Then remove the Splash screen once the install is successful

    const found = await DeployClient.checkLatest();

    if (found) {
        // If a build needs to be installed, download it
        // If this is not the first update, a delta build will be fetched
        // You should call this on startup or only if the app status is active

        const local = await DeployClient.download(found);

        if (local) {
            // If the download is successful, install the bundle
            // This automatically restarts the web view
            // You may call this on startup or when the app status becomes inactive

            const ok = await DeployClient.install(local);

            if (ok) {
                console.log('Installed update!! ');
            } else {
                console.log('Failed to install update ');
            }
        }
    }
}

API

startup(...)

startup(config: DeployConfig) => Promise<void>

Initialize the client and load the latest installed build.

This MUST be called IMMEDIATELY on application startup.

ParamTypeDescription
configDeployConfigthe global configuration to use

getDeployConfig()

getDeployConfig() => Promise<DeployConfig>

Fetch the current configuration of DeployClient

including the read-only device_id and current_build values

Returns: Promise<DeployConfig>


checkLatest()

checkLatest() => Promise<AppBuild | null>

Request the latest build available for download, if any.

Returns: Promise<AppBuild | null>


download(...)

download(latest: AppBuild) => Promise<AppBuild>

Download a build from the deploy-api server.

ParamTypeDescription
latestAppBuildthe build to download

Returns: Promise<AppBuild>


install(...)

install(latest: AppBuild) => Promise<DeployResult>

Install a downloaded build and apply immediately.

This forces an immediate reload of the web view.

ParamTypeDescription
latestAppBuildthe build to install

Returns: Promise<DeployResult>


reload()

reload() => Promise<DeployResult>

Reload the web view using the latest installed bundle.

You normally don't call this function. This is automatically called after an install.

Returns: Promise<DeployResult>


confirmInstall(...)

confirmInstall(latest: AppBuild) => Promise<DeployResult>

Register the current build on the deploy-api server.

You normally don't call this function. This is automatically called after a successful reload.

ParamTypeDescription
latestAppBuildthe build to confirm

Returns: Promise<DeployResult>


rollback(...)

rollback(latest: AppBuild) => Promise<DeployResult>

Return to the prior build (i.e. UNDO an install).

You normally don't call this function. This is automatically called after a failed reload.

ParamTypeDescription
latestAppBuildthe build to undo

Returns: Promise<DeployResult>


Interfaces

DeployConfig

Global configuration for all methods.

This MUST be provided at the first method call.

PropTypeDescription
server_urlstringBase url for Cartona deploy-api server <protocol>://<domain>
appcodestringApplication identifier (used to upload and rollout builds)
usernamestringOptional user name
device_idstringDevice identifier (set automatically)
current_buildnumberInstalled build number (set automatically)

AppBuild

Application version (Build) metadata.

This is fetched whenever a new build is available for download.

PropTypeDescription
idstringUnique build identifier
appcodestringApplication identifier (used to upload and rollout builds)
buildnumberBuild number
download_urlstringUrl used to download the build bundle
local_pathstringLocal path used to save the build bundle

DeployResult

Result of plugin calls

PropTypeDescription
okbooleanHolds true if the operation was successful, otherwise false
errorstringOptional error message if the operation was not successful
0.0.3

1 month ago

0.0.4

1 month ago

0.0.1

9 months ago