* chore: building out perf testing * chore: adding my printing code for the different formats of the marks * feat: adding invocation count table * fix: markOnce iunstead * fix: typescript additions * fix: adding more types * chore: adding telemetry panel as MVP, gonna remove the pane * chore: view telemetry from command bar in file route and home route * fix: deleting unused imports * fix: deleting some unused files * fix: auto cleanup * chore: adding other routes, these will need to be moved... * chore: moving some printing logic around and unit testing some of it * fix: moving command init * fix: removing debugging marks * fix: adding some comments * fix: fixed a bug with generating the go to page commands * chore: adding will pages load within the router config * chore: implementing marks for routes * fix: auto fixes and checkers * chore: implemented a route watcher at the root level... * fix: auto fixes, removing unused code * chore: timing for syntax highlighting and auto fixes * fix: didAuth issue and syntax highlighting in the packaged application. Constructor name gets renamed * fix: fixing typescript checks * chore: adding mag bar chart icon for telemetry * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest) * chore: swapped telemetry icon for stopwatch * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * chore: writing telemetry to disk * fix: auto fixers * chore: getting args parsed for cli flags and writing telemetry file * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * chore: swapped mark for markOnce since we infinitely write marks to a JS array... need to solve this run time marking in another way. We only need this for startup right now * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest) * chore: writing raw marks to disk as well * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest) * fix: cleaned up the testing names * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * Fix fmt and codespell * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * fix: moving this route loader data stuff * chore: adding comment * fix: fmt * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * empty :( * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * empty :( --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: 49fl <ircsurfer33@gmail.com>
132 lines
3.7 KiB
TypeScript
132 lines
3.7 KiB
TypeScript
import { onboardingPaths } from 'routes/Onboarding/paths'
|
|
import { BROWSER_FILE_NAME, BROWSER_PROJECT_NAME, FILE_EXT } from './constants'
|
|
import { isDesktop } from './isDesktop'
|
|
import { readAppSettingsFile } from './desktop'
|
|
import { readLocalStorageAppSettingsFile } from './settings/settingsUtils'
|
|
import { err } from 'lib/trap'
|
|
import { IS_PLAYWRIGHT_KEY } from '../../e2e/playwright/storageStates'
|
|
import { DeepPartial } from './types'
|
|
import { Configuration } from 'wasm-lib/kcl/bindings/Configuration'
|
|
import { PlatformPath } from 'path'
|
|
|
|
const prependRoutes =
|
|
(routesObject: Record<string, string>) => (prepend: string) => {
|
|
return Object.fromEntries(
|
|
Object.entries(routesObject).map(([constName, path]) => [
|
|
constName,
|
|
prepend + path,
|
|
])
|
|
)
|
|
}
|
|
|
|
type OnboardingPaths = {
|
|
[K in keyof typeof onboardingPaths]: `/onboarding${(typeof onboardingPaths)[K]}`
|
|
}
|
|
|
|
const SETTINGS = '/settings' as const
|
|
|
|
export type ProjectRoute = {
|
|
projectName: string | null
|
|
projectPath: string
|
|
currentFileName: string | null
|
|
currentFilePath: string | null
|
|
}
|
|
|
|
export const PATHS = {
|
|
INDEX: '/',
|
|
HOME: '/home',
|
|
FILE: '/file',
|
|
SETTINGS,
|
|
SETTINGS_USER: `${SETTINGS}?tab=user` as const,
|
|
SETTINGS_PROJECT: `${SETTINGS}?tab=project` as const,
|
|
SETTINGS_KEYBINDINGS: `${SETTINGS}?tab=keybindings` as const,
|
|
SIGN_IN: '/signin',
|
|
ONBOARDING: prependRoutes(onboardingPaths)('/onboarding') as OnboardingPaths,
|
|
TELEMETRY: '/telemetry',
|
|
} as const
|
|
export const BROWSER_PATH = `%2F${BROWSER_PROJECT_NAME}%2F${BROWSER_FILE_NAME}${FILE_EXT}`
|
|
|
|
export async function getProjectMetaByRouteId(
|
|
id?: string,
|
|
configuration?: DeepPartial<Configuration> | Error
|
|
): Promise<ProjectRoute | undefined> {
|
|
if (!id) return undefined
|
|
|
|
const onDesktop = isDesktop()
|
|
const isPlaywright = localStorage.getItem(IS_PLAYWRIGHT_KEY) === 'true'
|
|
|
|
if (configuration === undefined || isPlaywright) {
|
|
configuration = onDesktop
|
|
? await readAppSettingsFile()
|
|
: readLocalStorageAppSettingsFile()
|
|
}
|
|
|
|
if (err(configuration)) return Promise.reject(configuration)
|
|
|
|
// Should not be possible but I guess logically it could be
|
|
if (configuration === undefined) {
|
|
return Promise.reject(new Error('No configuration found'))
|
|
}
|
|
|
|
const route = parseProjectRoute(configuration, id, window?.electron?.path)
|
|
|
|
if (err(route)) return Promise.reject(route)
|
|
|
|
return route
|
|
}
|
|
|
|
export async function parseProjectRoute(
|
|
configuration: DeepPartial<Configuration>,
|
|
id: string,
|
|
pathlib: PlatformPath | undefined
|
|
): Promise<ProjectRoute> {
|
|
let projectName = null
|
|
let projectPath = ''
|
|
let currentFileName = null
|
|
let currentFilePath = null
|
|
if (
|
|
pathlib &&
|
|
configuration.settings?.project?.directory &&
|
|
id.startsWith(configuration.settings.project.directory)
|
|
) {
|
|
const relativeToRoot = pathlib.relative(
|
|
configuration.settings.project.directory,
|
|
id
|
|
)
|
|
projectName = relativeToRoot.split(pathlib.sep)[0]
|
|
projectPath = pathlib.join(
|
|
configuration.settings.project.directory,
|
|
projectName
|
|
)
|
|
projectName = projectName === '' ? null : projectName
|
|
} else {
|
|
projectPath = id
|
|
if (pathlib) {
|
|
if (pathlib.extname(id) === '.kcl') {
|
|
projectPath = pathlib.dirname(id)
|
|
}
|
|
projectName = pathlib.basename(projectPath)
|
|
} else {
|
|
if (id.endsWith('.kcl')) {
|
|
projectPath = '/browser'
|
|
projectName = 'browser'
|
|
}
|
|
}
|
|
}
|
|
if (pathlib) {
|
|
if (projectPath !== id) {
|
|
currentFileName = pathlib.basename(id)
|
|
currentFilePath = id
|
|
}
|
|
} else {
|
|
currentFileName = 'main.kcl'
|
|
currentFilePath = id
|
|
}
|
|
return {
|
|
projectName: projectName,
|
|
projectPath: projectPath,
|
|
currentFileName: currentFileName,
|
|
currentFilePath: currentFilePath,
|
|
}
|
|
}
|