Merge branch 'master' into feat/update-automation-tests

This commit is contained in:
Peter Clement 2024-11-27 09:16:41 +00:00 committed by GitHub
commit 5ccef12d97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 47 additions and 29 deletions

View File

@ -6,3 +6,4 @@ release/
dist/ dist/
routify routify
.routify/ .routify/
.rollup.cache

View File

@ -4,14 +4,14 @@
"license": "GPL-3.0", "license": "GPL-3.0",
"private": true, "private": true,
"scripts": { "scripts": {
"svelte-check": "svelte-check --no-tsconfig", "build": "routify -b && NODE_OPTIONS=\"--max_old_space_size=4096\" vite build --emptyOutDir",
"build": "yarn svelte-check && routify -b && vite build --emptyOutDir",
"start": "routify -c rollup", "start": "routify -c rollup",
"dev": "routify -c dev:vite", "dev": "routify -c dev:vite",
"dev:vite": "vite --host 0.0.0.0", "dev:vite": "vite --host 0.0.0.0",
"rollup": "rollup -c -w", "rollup": "rollup -c -w",
"test": "vitest run", "test": "vitest run",
"test:watch": "vitest" "test:watch": "vitest",
"check:types": "yarn svelte-check"
}, },
"jest": { "jest": {
"globals": { "globals": {
@ -89,6 +89,7 @@
"@babel/plugin-transform-runtime": "^7.13.10", "@babel/plugin-transform-runtime": "^7.13.10",
"@babel/preset-env": "^7.13.12", "@babel/preset-env": "^7.13.12",
"@rollup/plugin-replace": "^5.0.3", "@rollup/plugin-replace": "^5.0.3",
"@rollup/plugin-typescript": "8.3.0",
"@roxi/routify": "2.18.12", "@roxi/routify": "2.18.12",
"@sveltejs/vite-plugin-svelte": "1.4.0", "@sveltejs/vite-plugin-svelte": "1.4.0",
"@testing-library/jest-dom": "6.4.2", "@testing-library/jest-dom": "6.4.2",

View File

@ -8,7 +8,7 @@ import { get } from "svelte/store"
import { auth, navigation } from "./stores/portal" import { auth, navigation } from "./stores/portal"
export const API = createAPIClient({ export const API = createAPIClient({
attachHeaders: headers => { attachHeaders: (headers: Record<string, string>) => {
// Attach app ID header from store // Attach app ID header from store
let appId = get(appStore).appId let appId = get(appStore).appId
if (appId) { if (appId) {
@ -16,13 +16,13 @@ export const API = createAPIClient({
} }
// Add csrf token if authenticated // Add csrf token if authenticated
const user = get(auth).user const user: any = get(auth).user
if (user?.csrfToken) { if (user?.csrfToken) {
headers["x-csrf-token"] = user.csrfToken headers["x-csrf-token"] = user.csrfToken
} }
}, },
onError: error => { onError: (error: any) => {
const { url, message, status, method, handled } = error || {} const { url, message, status, method, handled } = error || {}
// Log any errors that we haven't manually handled // Log any errors that we haven't manually handled
@ -45,14 +45,14 @@ export const API = createAPIClient({
} }
} }
}, },
onMigrationDetected: appId => { onMigrationDetected: (appId: string) => {
const updatingUrl = `/builder/app/updating/${appId}` const updatingUrl = `/builder/app/updating/${appId}`
if (window.location.pathname === updatingUrl) { if (window.location.pathname === updatingUrl) {
return return
} }
get(navigation).goto( get(navigation)?.goto(
`${updatingUrl}?returnUrl=${encodeURIComponent(window.location.pathname)}` `${updatingUrl}?returnUrl=${encodeURIComponent(window.location.pathname)}`
) )
}, },

8
packages/builder/src/index.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
declare module "api" {
const API: {
getPlugins: () => Promise<any>
createPlugin: (plugin: object) => Promise<any>
uploadPlugin: (plugin: FormData) => Promise<any>
deletePlugin: (id: string) => Promise<void>
}
}

View File

@ -1,13 +1,20 @@
import { writable } from "svelte/store" import { writable } from "svelte/store"
type GotoFuncType = (path: string) => void
interface Store {
initialisated: boolean
goto: GotoFuncType
}
export function createNavigationStore() { export function createNavigationStore() {
const store = writable({ const store = writable<Store>({
initialisated: false, initialisated: false,
goto: undefined, goto: undefined as any,
}) })
const { set, subscribe } = store const { set, subscribe } = store
const init = gotoFunc => { const init = (gotoFunc: GotoFuncType) => {
if (typeof gotoFunc !== "function") { if (typeof gotoFunc !== "function") {
throw new Error( throw new Error(
`gotoFunc must be a function, found a "${typeof gotoFunc}" instead` `gotoFunc must be a function, found a "${typeof gotoFunc}" instead`

View File

@ -1,16 +1,21 @@
import { writable } from "svelte/store" import { writable } from "svelte/store"
import { PluginSource } from "constants/index"
import { API } from "api" import { API } from "api"
import { PluginSource } from "constants"
interface Plugin {
_id: string
}
export function createPluginsStore() { export function createPluginsStore() {
const { subscribe, set, update } = writable([]) const { subscribe, set, update } = writable<Plugin[]>([])
async function load() { async function load() {
const plugins = await API.getPlugins() const plugins = await API.getPlugins()
set(plugins) set(plugins)
} }
async function deletePlugin(pluginId) { async function deletePlugin(pluginId: string) {
await API.deletePlugin(pluginId) await API.deletePlugin(pluginId)
update(state => { update(state => {
state = state.filter(existing => existing._id !== pluginId) state = state.filter(existing => existing._id !== pluginId)
@ -18,8 +23,8 @@ export function createPluginsStore() {
}) })
} }
async function createPlugin(source, url, auth = null) { async function createPlugin(source: string, url: string, auth = null) {
let pluginData = { let pluginData: any = {
source, source,
url, url,
} }
@ -46,7 +51,7 @@ export function createPluginsStore() {
}) })
} }
async function uploadPlugin(file) { async function uploadPlugin(file: File) {
if (!file) { if (!file) {
return return
} }

View File

@ -9,15 +9,9 @@
"noImplicitAny": true, "noImplicitAny": true,
"esModuleInterop": true, "esModuleInterop": true,
"resolveJsonModule": true, "resolveJsonModule": true,
"incremental": true "incremental": true,
"skipLibCheck": true
}, },
"include": [ "include": ["./src/**/*"],
"./src/**/*" "exclude": ["node_modules", "**/*.json", "**/*.spec.ts", "**/*.spec.js"]
],
"exclude": [
"node_modules",
"**/*.json",
"**/*.spec.ts",
"**/*.spec.js"
]
} }

View File

@ -3,6 +3,7 @@ import replace from "@rollup/plugin-replace"
import { defineConfig, loadEnv } from "vite" import { defineConfig, loadEnv } from "vite"
import { viteStaticCopy } from "vite-plugin-static-copy" import { viteStaticCopy } from "vite-plugin-static-copy"
import path from "path" import path from "path"
import typescript from "@rollup/plugin-typescript"
const ignoredWarnings = [ const ignoredWarnings = [
"unused-export-let", "unused-export-let",
@ -35,7 +36,7 @@ export default defineConfig(({ mode }) => {
// Copy fonts to an additional path so that svelte's automatic // Copy fonts to an additional path so that svelte's automatic
// prefixing of the base URL path can still resolve assets // prefixing of the base URL path can still resolve assets
copyFonts("builder/fonts"), copyFonts("builder/fonts"),
] ]
return { return {
test: { test: {
@ -61,6 +62,7 @@ export default defineConfig(({ mode }) => {
sourcemap: !isProduction, sourcemap: !isProduction,
}, },
plugins: [ plugins: [
typescript({ outDir: "../server/builder/dist" }),
svelte({ svelte({
hot: !isProduction, hot: !isProduction,
emitCss: true, emitCss: true,