Skip to content

Commit

Permalink
V2.0.0 beta.43 - icon field type, enable gitlab as depoloyment option
Browse files Browse the repository at this point in the history
  • Loading branch information
mateomorris committed Jan 29, 2024
1 parent 1d37327 commit cd9ae80
Show file tree
Hide file tree
Showing 8 changed files with 458 additions and 284 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dependencies": {
"@fontsource/fira-code": "^5.0.5",
"@iconify/svelte": "^2.2.1",
"@primocms/builder": "^0.1.58",
"@primocms/builder": "^0.1.59",
"@rollup/browser": "^3.28.0",
"@supabase/auth-helpers-sveltekit": "^0.10.2",
"@supabase/supabase-js": "^2.31.0",
Expand Down
69 changes: 44 additions & 25 deletions src/lib/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,79 @@ import { invalidate } from '$app/navigation'

export const sites = {
create: async (data, preview = null) => {

await supabase.from('sites').insert(data.site)

// create symbols and root pages
// create symbols and root pages
const { pages, symbols, sections } = data
const home_page = pages.find(page => page.url === 'index')
const root_pages = pages.filter(page => page.parent === null && page.id !== home_page.id)
const child_pages = pages.filter(page => page.parent !== null)
const home_page = pages.find((page) => page.url === 'index')
const root_pages = pages.filter(
(page) => page.parent === null && page.id !== home_page.id
)
const child_pages = pages.filter((page) => page.parent !== null)

// create home page first (to ensure it appears first)
await supabase.from('pages').insert(home_page)

await Promise.all([
supabase.from('symbols').insert(symbols),
supabase.from('pages').insert(root_pages)
supabase.from('pages').insert(root_pages),
])

// upload preview to supabase storage
if (preview) {
await supabase.storage.from('sites').upload(`${data.site.id}/preview.html`, preview)
await supabase.storage
.from('sites')
.upload(`${data.site.id}/preview.html`, preview)
}

// create child pages (dependant on parent page IDs)
await supabase.from('pages').insert(child_pages)

// create sections (dependant on page IDs)
await supabase.from('sections').insert(sections)

},
update: async (id, props) => {
await supabase.from('sites').update(props).eq('id', id)
},
delete: async (site, { delete_repo, delete_files }) => {

const [{data:pages}, {data:sections}, {data:symbols}] = await Promise.all([
supabase.from('pages').select('id, url, name, code, fields, content, site, parent').filter('site', 'eq', site.id),
supabase.from('sections').select('id, content, page!inner(id, site), symbol, index').filter('page.site', 'eq', site.id),
supabase.from('symbols').select('id, name, code, fields, content, site').filter('site', 'eq', site.id),
])
const [{ data: pages }, { data: sections }, { data: symbols }] =
await Promise.all([
supabase
.from('pages')
.select('id, url, name, code, fields, content, site, parent')
.filter('site', 'eq', site.id),
supabase
.from('sections')
.select('id, content, page!inner(id, site), symbol, index')
.filter('page.site', 'eq', site.id),
supabase
.from('symbols')
.select('id, name, code, fields, content, site')
.filter('site', 'eq', site.id),
])

// Backup site
const backup_json = JSON.stringify({
site,
pages,
sections: sections.map(section => ({
sections: sections.map((section) => ({
...section,
page: section.page.id
page: section.page.id,
})),
symbols,
version: 2
version: 2,
})

await supabase.storage.from('sites').upload(`backups/${site.url}-${site.id}.json`, backup_json)
console.log({ site, pages, sections, symbols, backup_json })
await supabase.storage
.from('sites')
.upload(`backups/${site.url}-${site.id}.json`, backup_json)

if (sections) {
await Promise.all(sections.map(section => supabase.from('sections').delete().eq('id', section.id)))
await Promise.all(
sections.map((section) =>
supabase.from('sections').delete().eq('id', section.id)
)
)
}

await Promise.all([
Expand All @@ -73,19 +89,22 @@ export const sites = {

if (delete_files) {
let siteFiles = await getFiles('sites', site.id)
if (siteFiles.length) await supabase.storage.from('sites').remove(siteFiles)
if (siteFiles.length)
await supabase.storage.from('sites').remove(siteFiles)

let imageFiles = await getFiles('images', site.id)
if (imageFiles.length) await supabase.storage.from('images').remove(imageFiles)

if (imageFiles.length)
await supabase.storage.from('images').remove(imageFiles)
}
if (delete_repo) {
const repo_deleted = await axios.post('/api/deploy/delete', { site })
if (!repo_deleted) {
alert(`Could not delete repo. Ensure Personal Access Token has the 'delete_repo' permission`)
alert(
`Could not delete repo. Ensure Personal Access Token has the 'delete_repo' permission`
)
}
}
await supabase.from('sites').delete().eq('id', site.id)
invalidate('app:data')
},
}
}
Loading

0 comments on commit cd9ae80

Please sign in to comment.