mirror of https://github.com/Budibase/budibase.git
7 changed files with 157 additions and 51 deletions
@ -0,0 +1,83 @@ |
|||||
|
<script> |
||||
|
import { |
||||
|
Icon, |
||||
|
Modal, |
||||
|
notifications, |
||||
|
ModalContent, |
||||
|
Body, |
||||
|
} from "@budibase/bbui" |
||||
|
import { store } from "builderStore" |
||||
|
import api from "builderStore/api" |
||||
|
import clientPackage from "@budibase/client/package.json" |
||||
|
|
||||
|
let updateModal |
||||
|
|
||||
|
$: appId = $store.appId |
||||
|
$: updateAvailable = clientPackage.version !== $store.version |
||||
|
|
||||
|
const update = async () => { |
||||
|
try { |
||||
|
const response = await api.post( |
||||
|
`/api/applications/${appId}/client/update` |
||||
|
) |
||||
|
const json = await response.json() |
||||
|
if (response.status !== 200) { |
||||
|
throw json.message |
||||
|
} |
||||
|
|
||||
|
// Reset frontend state after revert |
||||
|
const applicationPkg = await api.get( |
||||
|
`/api/applications/${appId}/appPackage` |
||||
|
) |
||||
|
const pkg = await applicationPkg.json() |
||||
|
if (applicationPkg.ok) { |
||||
|
await store.actions.initialise(pkg) |
||||
|
} else { |
||||
|
throw new Error(pkg) |
||||
|
} |
||||
|
|
||||
|
notifications.success( |
||||
|
`App updated successfully to version ${clientPackage.version}` |
||||
|
) |
||||
|
} catch (err) { |
||||
|
notifications.error(`Error updating app: ${err}`) |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<div class="icon-wrapper" class:highlight={updateAvailable}> |
||||
|
<Icon name="Refresh" hoverable on:click={updateModal.show} /> |
||||
|
</div> |
||||
|
<Modal bind:this={updateModal}> |
||||
|
<ModalContent |
||||
|
title="App version" |
||||
|
confirmText="Update" |
||||
|
cancelText={updateAvailable ? "Cancel" : "Close"} |
||||
|
onConfirm={update} |
||||
|
showConfirmButton={updateAvailable} |
||||
|
> |
||||
|
{#if updateAvailable} |
||||
|
<Body size="S"> |
||||
|
This app is currently using version <b>{$store.version}</b>, but version |
||||
|
<b>{clientPackage.version}</b> is available. Updates can contain new |
||||
|
features, performance improvements and bug fixes. |
||||
|
<br /><br /> |
||||
|
Would you like to update this app? |
||||
|
</Body> |
||||
|
{:else} |
||||
|
<Body size="S"> |
||||
|
This app is currently using version <b>{$store.version}</b> which is the |
||||
|
latest version available. |
||||
|
</Body> |
||||
|
{/if} |
||||
|
</ModalContent> |
||||
|
</Modal> |
||||
|
|
||||
|
<style> |
||||
|
.icon-wrapper { |
||||
|
display: contents; |
||||
|
} |
||||
|
.icon-wrapper.highlight :global(svg) { |
||||
|
color: var(--spectrum-global-color-blue-600); |
||||
|
} |
||||
|
</style> |
||||
@ -1,36 +1,27 @@ |
|||||
const packageJson = require("../../../package.json") |
|
||||
const { join } = require("path") |
const { join } = require("path") |
||||
const { ObjectStoreBuckets } = require("../../constants") |
const { ObjectStoreBuckets } = require("../../constants") |
||||
const { streamUpload, downloadTarball } = require("./utilities") |
const { streamUpload } = require("./utilities") |
||||
const fs = require("fs") |
const fs = require("fs") |
||||
|
|
||||
const BUCKET_NAME = ObjectStoreBuckets.APPS |
const BUCKET_NAME = ObjectStoreBuckets.APPS |
||||
|
|
||||
// can't really test this due to the downloading nature of it, wouldn't be a great test case
|
|
||||
/* istanbul ignore next */ |
|
||||
exports.downloadLibraries = async appId => { |
|
||||
const LIBRARIES = ["standard-components"] |
|
||||
|
|
||||
const paths = {} |
|
||||
// Need to download tarballs directly from NPM as our users may not have node on their machine
|
|
||||
for (let lib of LIBRARIES) { |
|
||||
// download tarball
|
|
||||
const registryUrl = `https://registry.npmjs.org/@budibase/${lib}/-/${lib}-${packageJson.version}.tgz` |
|
||||
const path = join(appId, "node_modules", "@budibase", lib) |
|
||||
paths[`@budibase/${lib}`] = await downloadTarball( |
|
||||
registryUrl, |
|
||||
BUCKET_NAME, |
|
||||
path |
|
||||
) |
|
||||
} |
|
||||
return paths |
|
||||
} |
|
||||
|
|
||||
exports.uploadClientLibrary = async appId => { |
exports.uploadClientLibrary = async appId => { |
||||
const sourcepath = require.resolve("@budibase/client") |
await streamUpload( |
||||
const destPath = join(appId, "budibase-client.js") |
BUCKET_NAME, |
||||
|
join(appId, "budibase-client.js"), |
||||
await streamUpload(BUCKET_NAME, destPath, fs.createReadStream(sourcepath), { |
fs.createReadStream(require.resolve("@budibase/client")), |
||||
ContentType: "application/javascript", |
{ |
||||
}) |
ContentType: "application/javascript", |
||||
|
} |
||||
|
) |
||||
|
await streamUpload( |
||||
|
BUCKET_NAME, |
||||
|
join(appId, "manifest.json"), |
||||
|
fs.createReadStream( |
||||
|
require.resolve("@budibase/standard-components/manifest.json") |
||||
|
), |
||||
|
{ |
||||
|
ContentType: "application/javascript", |
||||
|
} |
||||
|
) |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue