More fixes, incl. conf files
This commit is contained in:
@ -86,7 +86,7 @@
|
||||
"remove-importmeta": "sed -i 's/import.meta.url/window.location.origin/g' \"./src/wasm-lib/pkg/wasm_lib.js\"; sed -i '' 's/import.meta.url/window.location.origin/g' \"./src/wasm-lib/pkg/wasm_lib.js\" || echo \"sed for both mac and linux\"",
|
||||
"wasm-prep": "rm -rf src/wasm-lib/pkg && mkdir src/wasm-lib/pkg && rm -rf src/wasm-lib/kcl/bindings",
|
||||
"lint": "eslint --fix src",
|
||||
"bump-jsons": "echo \"$(jq --arg v \"$VERSION\" '.version=$v' package.json --indent 2)\" > package.json && echo \"$(jq --arg v \"$VERSION\" '.package.version=$v' src-tauri/tauri.conf.json --indent 2)\" > src-tauri/tauri.conf.json",
|
||||
"bump-jsons": "echo \"$(jq --arg v \"$VERSION\" '.version=$v' package.json --indent 2)\" > package.json && echo \"$(jq --arg v \"$VERSION\" '.version=$v' src-tauri/tauri.conf.json --indent 2)\" > src-tauri/tauri.conf.json",
|
||||
"postinstall": "patch-package && yarn xstate:typegen",
|
||||
"xstate:typegen": "yarn xstate typegen \"src/**/*.ts?(x)\""
|
||||
},
|
||||
|
||||
@ -29,6 +29,7 @@ fn read_toml(path: &str) -> Result<String, InvokeError> {
|
||||
}
|
||||
|
||||
/// From https://github.com/tauri-apps/tauri/blob/1.x/core/tauri/src/api/dir.rs#L51
|
||||
/// Removed from tauri v2
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct DiskEntry {
|
||||
/// The path to the entry.
|
||||
@ -40,10 +41,14 @@ pub struct DiskEntry {
|
||||
pub children: Option<Vec<DiskEntry>>,
|
||||
}
|
||||
|
||||
/// From https://github.com/tauri-apps/tauri/blob/1.x/core/tauri/src/api/dir.rs#L51
|
||||
/// Removed from tauri v2
|
||||
fn is_dir<P: AsRef<Path>>(path: P) -> Result<bool> {
|
||||
std::fs::metadata(path).map(|md| md.is_dir()).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// From https://github.com/tauri-apps/tauri/blob/1.x/core/tauri/src/api/dir.rs#L51
|
||||
/// Removed from tauri v2
|
||||
#[tauri::command]
|
||||
fn read_dir_recursive(path: &str) -> Result<Vec<DiskEntry>, InvokeError> {
|
||||
let mut files_and_dirs: Vec<DiskEntry> = vec![];
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
{
|
||||
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
|
||||
"package": {
|
||||
"productName": "Zoo Modeling App"
|
||||
}
|
||||
"productName": "Zoo Modeling App"
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
|
||||
"tauri": {
|
||||
"plugins": {
|
||||
"updater": {
|
||||
"active": true,
|
||||
"endpoints": [
|
||||
@ -1,6 +1,4 @@
|
||||
{
|
||||
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
|
||||
"package": {
|
||||
"productName": "Zoo Modeling App"
|
||||
}
|
||||
"productName": "Zoo Modeling App"
|
||||
}
|
||||
@ -19,14 +19,7 @@ import SignIn from './routes/SignIn'
|
||||
import { Auth } from './Auth'
|
||||
import { isTauri } from './lib/isTauri'
|
||||
import Home from './routes/Home'
|
||||
import {
|
||||
readDir,
|
||||
readTextFile,
|
||||
stat,
|
||||
FileInfo,
|
||||
FileHandle,
|
||||
DirEntry,
|
||||
} from '@tauri-apps/plugin-fs'
|
||||
import { readTextFile, stat } from '@tauri-apps/plugin-fs'
|
||||
import makeUrlPathRelative from './lib/makeUrlPathRelative'
|
||||
import {
|
||||
getProjectsInDir,
|
||||
@ -49,8 +42,9 @@ import { KclContextProvider, kclManager } from 'lang/KclSingleton'
|
||||
import FileMachineProvider from 'components/FileMachineProvider'
|
||||
import { sep } from '@tauri-apps/api/path'
|
||||
import { paths } from 'lib/paths'
|
||||
import { IndexLoaderData, HomeLoaderData } from 'lib/types'
|
||||
import { IndexLoaderData, HomeLoaderData, FileEntry } from 'lib/types'
|
||||
import { fileSystemManager } from 'lang/std/fileSystemManager'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
|
||||
if (VITE_KC_SENTRY_DSN && !TEST) {
|
||||
Sentry.init({
|
||||
@ -178,8 +172,9 @@ const router = createBrowserRouter(
|
||||
const entrypointMetadata = await stat(
|
||||
projectPath + sep() + PROJECT_ENTRYPOINT
|
||||
)
|
||||
// TODO: add back recursive?
|
||||
const children = await readDir(projectPath)
|
||||
const children = await invoke<FileEntry[]>('read_dir_recursive', {
|
||||
path: projectPath,
|
||||
})
|
||||
kclManager.setCodeAndExecute(code, false)
|
||||
|
||||
// Set the file system manager to the project path
|
||||
@ -247,6 +242,7 @@ const router = createBrowserRouter(
|
||||
)
|
||||
newDefaultDirectory = projectDir
|
||||
}
|
||||
// TODO: here we're doing recursive instead of non-recursive?
|
||||
const projects = await getProjectsInDir(projectDir)
|
||||
|
||||
return {
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import { type IndexLoaderData } from 'lib/types'
|
||||
import { FileEntry, type IndexLoaderData } from 'lib/types'
|
||||
import { paths } from 'lib/paths'
|
||||
import { ActionButton } from './ActionButton'
|
||||
import Tooltip from './Tooltip'
|
||||
import { FileEntry } from '@tauri-apps/plugin-fs'
|
||||
import { Dispatch, useRef, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Dialog, Disclosure } from '@headlessui/react'
|
||||
|
||||
@ -14,9 +14,9 @@ export default function usePlatform() {
|
||||
void getPlatform()
|
||||
} else {
|
||||
if (navigator.userAgent.indexOf('Mac') !== -1) {
|
||||
setPlatformName('darwin')
|
||||
setPlatformName('macos')
|
||||
} else if (navigator.userAgent.indexOf('Win') !== -1) {
|
||||
setPlatformName('win32')
|
||||
setPlatformName('windows')
|
||||
} else if (navigator.userAgent.indexOf('Linux') !== -1) {
|
||||
setPlatformName('linux')
|
||||
}
|
||||
|
||||
@ -69,18 +69,17 @@ export async function getProjectsInDir(projectDir: string) {
|
||||
|
||||
const projectsWithMetadata = await Promise.all(
|
||||
readProjects.map(async (p) => ({
|
||||
entrypointMetadata: await stat(
|
||||
await join(p.path, PROJECT_ENTRYPOINT)
|
||||
),
|
||||
...p,
|
||||
}))
|
||||
entrypointMetadata: await stat(await join(p.path, PROJECT_ENTRYPOINT)),
|
||||
...p,
|
||||
}))
|
||||
)
|
||||
console.log('projectsWithMetadata', projectsWithMetadata)
|
||||
|
||||
return projectsWithMetadata
|
||||
}
|
||||
|
||||
export const isHidden = (fileOrDir: FileEntry) => !!fileOrDir.name?.startsWith('.')
|
||||
export const isHidden = (fileOrDir: FileEntry) =>
|
||||
!!fileOrDir.name?.startsWith('.')
|
||||
|
||||
export const isDir = (fileOrDir: FileEntry) =>
|
||||
'children' in fileOrDir && fileOrDir.children !== undefined
|
||||
@ -131,7 +130,9 @@ export function deepFileFilterFlat(
|
||||
// Read the contents of a project directory
|
||||
// and return all relevant files and sub-directories recursively
|
||||
export async function readProject(projectDir: string) {
|
||||
const readFiles = await invoke<FileEntry[]>('read_dir_recursive', { path: projectDir })
|
||||
const readFiles = await invoke<FileEntry[]>('read_dir_recursive', {
|
||||
path: projectDir,
|
||||
})
|
||||
console.log('read_dir_recursive', readFiles)
|
||||
|
||||
return deepFileFilter(readFiles, isRelevantFileOrDir)
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { type FileHandle, type FileInfo } from '@tauri-apps/plugin-fs'
|
||||
import { type FileInfo } from '@tauri-apps/plugin-fs'
|
||||
|
||||
export type IndexLoaderData = {
|
||||
code: string | null
|
||||
project?: ProjectWithEntryPointMetadata
|
||||
file?: FileHandle
|
||||
file?: FileEntry
|
||||
}
|
||||
|
||||
export type ProjectWithEntryPointMetadata = FileHandle & {
|
||||
export type ProjectWithEntryPointMetadata = FileEntry & {
|
||||
entrypointMetadata: FileInfo
|
||||
}
|
||||
export type HomeLoaderData = {
|
||||
@ -15,6 +15,7 @@ export type HomeLoaderData = {
|
||||
}
|
||||
|
||||
// From https://github.com/tauri-apps/tauri/blob/1.x/tooling/api/src/fs.ts#L159
|
||||
// Removed from tauri v2
|
||||
export interface FileEntry {
|
||||
path: string
|
||||
/**
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import { assign, createMachine } from 'xstate'
|
||||
import { type ProjectWithEntryPointMetadata } from 'lib/types'
|
||||
import { FileEntry } from '@tauri-apps/plugin-fs'
|
||||
import { FileEntry, type ProjectWithEntryPointMetadata } from 'lib/types'
|
||||
|
||||
export const FILE_PERSIST_KEY = 'Last opened KCL files'
|
||||
export const DEFAULT_FILE_NAME = 'Untitled'
|
||||
|
||||
Reference in New Issue
Block a user