Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Cap-go/CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Jan 15, 2025
2 parents 80d4417 + bd5dd15 commit a53d3cf
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [4.31.0](https://github.com/Cap-go/CLI/compare/v4.30.10...v4.31.0) (2025-01-15)


### Features

* delete-linked-bundle-on-upload ([18cc22e](https://github.com/Cap-go/CLI/commit/18cc22e8bf9b4e4cd5cd5edc51527ec448d24ae7))

### [4.30.10](https://github.com/Cap-go/CLI/compare/v4.30.9...v4.30.10) (2025-01-15)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@capgo/cli",
"version": "4.30.10",
"version": "4.31.0",
"description": "A CLI to upload to capgo servers",
"author": "github.com/riderx",
"license": "Apache 2.0",
Expand Down
50 changes: 50 additions & 0 deletions src/bundle/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface Options extends OptionsBase {
dryUpload?: boolean
nodeModules?: string
encryptPartial?: boolean
deleteLinkedBundleOnUpload?: boolean
tusChunkSize?: number
}

Expand Down Expand Up @@ -446,6 +447,43 @@ async function uploadBundleToCapgoCloud(apikey: string, supabase: SupabaseType,
})
}

// It is really important that his function never terminates the program, it should always return, even if it fails
async function deleteLinkedBundleOnUpload(supabase: SupabaseType, appid: string, channel: string) {
const { data, error } = await supabase
.from('channels')
.select('version ( id, name, deleted )')
.eq('app_id', appid)
.eq('name', channel)

if (error) {
log.error(`Cannot delete linked bundle on upload ${formatError(error)}`)
return
}

if (data.length === 0) {
log.warn('No linked bundle found in the channel you are trying to upload to')
return
}

const version = data[0].version
if (version.deleted) {
log.warn('The linked bundle is already deleted')
return
}

const { error: deleteError } = await supabase
.from('app_versions')
.update({ deleted: true })
.eq('id', version.id)

if (deleteError) {
log.error(`Cannot delete linked bundle on upload ${formatError(deleteError)}`)
return
}

log.info('Linked bundle deleted')
}

async function setVersionInChannel(
supabase: SupabaseType,
apikey: string,
Expand Down Expand Up @@ -547,6 +585,11 @@ export async function uploadBundle(preAppid: string, options: Options, shouldExi
program.error('')
}

if (options.deleteLinkedBundleOnUpload) {
log.warn('Deleting linked bundle on upload is destructive, it will delete the currently linked bundle in the channel you are trying to upload to.')
log.warn('Please make sure you want to do this, if you are not sure, please do not use this option.')
}

const versionData = {
name: bundle,
app_id: appid,
Expand Down Expand Up @@ -692,6 +735,13 @@ export async function uploadBundle(preAppid: string, options: Options, shouldExi
// Check we have app access to this appId
const permissions = await checkAppExistsAndHasPermissionOrgErr(supabase, apikey, appid, OrganizationPerm.upload)

if (options.deleteLinkedBundleOnUpload && hasOrganizationPerm(permissions, OrganizationPerm.write)) {
await deleteLinkedBundleOnUpload(supabase, appid, channel)
}
else if (options.deleteLinkedBundleOnUpload) {
log.warn('Cannot delete linked bundle on upload as a upload organization member')
}

if (hasOrganizationPerm(permissions, OrganizationPerm.write)) {
await setVersionInChannel(supabase, apikey, !!options.bundleUrl, bundle, channel, userId, orgId, appid, localConfig)
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ bundle
.option('--package-json <packageJson>', 'A list of path to package.json. Usefull for monorepos (comma separated ex: ../../package.json,./package.json)')
.option('--node-modules <nodeModules>', 'A list of path to node_modules. Usefull for monorepos (comma separated ex: ../../node_modules,./node_modules)')
.option('--encrypt-partial', 'Encrypt the partial update files')
.option('--delete-linked-bundle-on-upload', 'Locates the currently linked bundle in the channel you are trying to upload to, and deletes it')

bundle
.command('compatibility [appId]')
Expand Down

0 comments on commit a53d3cf

Please sign in to comment.