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