Fix file creation

This commit is contained in:
Pierre Jacquier
2024-02-07 08:35:46 -05:00
parent 6deac3f388
commit 96f8b67dc2
7 changed files with 29 additions and 40 deletions

View File

@ -47,7 +47,6 @@
"react-router-dom": "^6.14.2",
"sketch-helpers": "^0.0.4",
"swr": "^2.2.2",
"tauri-plugin-fs-extra-api": "https://github.com/tauri-apps/tauri-plugin-fs-extra#v1",
"toml": "^3.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",

View File

@ -24,6 +24,7 @@
"fs:allow-remove",
"fs:allow-rename",
"fs:allow-exists",
"fs:allow-stat",
{
"identifier": "fs:scope",
"allow": [

View File

@ -1 +1 @@
{"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","context":"local","windows":["main"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","tray:default","fs:allow-read-file","fs:allow-read-text-file","fs:allow-write-file","fs:allow-write-text-file","fs:allow-read-dir","fs:allow-copy-file","fs:allow-mkdir","fs:allow-remove","fs:allow-remove","fs:allow-rename","fs:allow-exists",{"identifier":"fs:scope","allow":[{"path":"$HOME/**/*"},{"path":"$APPDATA/**/*"}]},"shell:allow-open","dialog:allow-open","dialog:allow-save","dialog:allow-message","dialog:allow-ask","dialog:allow-confirm",{"identifier":"http:default","allow":["https://dev.kittycad.io/*","https://kittycad.io/*","https://api.dev.kittycad.io/*"]},"os:allow-platform","os:allow-version","os:allow-os-type","os:allow-family","os:allow-arch","os:allow-exe-extension","os:allow-locale","os:allow-hostname"],"platforms":["linux","macOS","windows","android","iOS"]}}
{"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","context":"local","windows":["main"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","tray:default","fs:allow-read-file","fs:allow-read-text-file","fs:allow-write-file","fs:allow-write-text-file","fs:allow-read-dir","fs:allow-copy-file","fs:allow-mkdir","fs:allow-remove","fs:allow-remove","fs:allow-rename","fs:allow-exists","fs:allow-stat",{"identifier":"fs:scope","allow":[{"path":"$HOME/**/*"},{"path":"$APPDATA/**/*"}]},"shell:allow-open","dialog:allow-open","dialog:allow-save","dialog:allow-message","dialog:allow-ask","dialog:allow-confirm",{"identifier":"http:default","allow":["https://dev.kittycad.io/*","https://kittycad.io/*","https://api.dev.kittycad.io/*"]},"os:allow-platform","os:allow-version","os:allow-os-type","os:allow-family","os:allow-arch","os:allow-exe-extension","os:allow-locale","os:allow-hostname"],"platforms":["linux","macOS","windows","android","iOS"]}}

View File

@ -22,14 +22,20 @@ import SignIn from './routes/SignIn'
import { Auth } from './Auth'
import { isTauri } from './lib/isTauri'
import Home from './routes/Home'
import { FileEntry, readDir, readTextFile } from '@tauri-apps/plugin-fs'
import {
readDir,
readTextFile,
stat,
FileInfo,
FileHandle,
DirEntry,
} from '@tauri-apps/plugin-fs'
import makeUrlPathRelative from './lib/makeUrlPathRelative'
import {
initializeProjectDirectory,
isProjectDirectory,
PROJECT_ENTRYPOINT,
} from './lib/tauriFS'
import { metadata, type Metadata } from 'tauri-plugin-fs-extra-api'
import DownloadAppBanner from './components/DownloadAppBanner'
import { WasmErrBanner } from './components/WasmErrBanner'
import { GlobalStateProvider } from './components/GlobalStateProvider'
@ -104,11 +110,11 @@ export const BROWSER_FILE_NAME = 'new'
export type IndexLoaderData = {
code: string | null
project?: ProjectWithEntryPointMetadata
file?: FileEntry
file?: FileHandle
}
export type ProjectWithEntryPointMetadata = FileEntry & {
entrypointMetadata: Metadata
export type ProjectWithEntryPointMetadata = FileHandle & {
entrypointMetadata: FileInfo
}
export type HomeLoaderData = {
projects: ProjectWithEntryPointMetadata[]
@ -189,8 +195,8 @@ const router = createBrowserRouter(
if (params.id && params.id !== BROWSER_FILE_NAME) {
const decodedId = decodeURIComponent(params.id)
const projectAndFile = decodedId.replace(defaultDir + sep, '')
const firstSlashIndex = projectAndFile.indexOf(sep)
const projectAndFile = decodedId.replace(defaultDir + sep(), '')
const firstSlashIndex = projectAndFile.indexOf(sep())
const projectName = projectAndFile.slice(0, firstSlashIndex)
const projectPath = defaultDir + sep() + projectName
const currentFileName = projectAndFile.slice(firstSlashIndex + 1)
@ -204,10 +210,11 @@ const router = createBrowserRouter(
// Note that PROJECT_ENTRYPOINT is hardcoded until we support multiple files
const code = await readTextFile(decodedId)
const entrypointMetadata = await metadata(
const entrypointMetadata = await stat(
projectPath + sep() + PROJECT_ENTRYPOINT
)
const children = await readDir(projectPath, { recursive: true })
// TODO: add back recursive?
const children = await readDir(projectPath)
kclManager.setCodeAndExecute(code, false)
return {
@ -275,10 +282,8 @@ const router = createBrowserRouter(
isProjectDirectory
)
const projects = await Promise.all(
projectsNoMeta.map(async (p: FileEntry) => ({
entrypointMetadata: await metadata(
p.path + sep() + PROJECT_ENTRYPOINT
),
projectsNoMeta.map(async (p: DirEntry) => ({
entrypointMetadata: await stat(p.name + sep() + PROJECT_ENTRYPOINT),
...p,
}))
)

View File

@ -13,12 +13,7 @@ import {
} from 'xstate'
import { useCommandsContext } from 'hooks/useCommandsContext'
import { DEFAULT_FILE_NAME, fileMachine } from 'machines/fileMachine'
import {
mkdir,
remove,
rename,
create,
} from '@tauri-apps/plugin-fs'
import { mkdir, remove, rename, create } from '@tauri-apps/plugin-fs'
import { FILE_EXT, readProject } from 'lib/tauriFS'
import { isTauri } from 'lib/isTauri'
import { sep } from '@tauri-apps/api/path'
@ -88,7 +83,7 @@ export const FileMachineProvider = ({
context.selectedDirectory.path +
sep() +
name +
(name.endsWith(FILE_EXT) ? '' : FILE_EXT),
(name.endsWith(FILE_EXT) ? '' : FILE_EXT)
)
}
@ -106,8 +101,9 @@ export const FileMachineProvider = ({
context.selectedDirectory.path +
sep() +
name +
(name.endsWith(FILE_EXT) || isDir ? '' : FILE_EXT)
, {})
(name.endsWith(FILE_EXT) || isDir ? '' : FILE_EXT),
{}
)
return (
oldName !== name && `Successfully renamed "${oldName}" to "${name}"`
)

View File

@ -3,11 +3,11 @@ import {
exists,
readDir,
writeTextFile,
stat,
} from '@tauri-apps/plugin-fs'
import { documentDir, homeDir, sep } from '@tauri-apps/api/path'
import { isTauri } from './isTauri'
import { ProjectWithEntryPointMetadata } from '../Router'
import { metadata } from 'tauri-plugin-fs-extra-api'
const PROJECT_FOLDER = 'zoo-modeling-app-projects'
export const FILE_EXT = '.kcl'
@ -69,7 +69,7 @@ export async function getProjectsInDir(projectDir: string) {
const projectsWithMetadata = await Promise.all(
readProjects.map(async (p) => ({
entrypointMetadata: await metadata(p.path + sep() + PROJECT_ENTRYPOINT),
entrypointMetadata: await stat(p.name + sep() + PROJECT_ENTRYPOINT),
...p,
}))
)
@ -77,8 +77,7 @@ export async function getProjectsInDir(projectDir: string) {
return projectsWithMetadata
}
export const isHidden = (fileOrDir: any) =>
!!fileOrDir.name?.startsWith('.')
export const isHidden = (fileOrDir: any) => !!fileOrDir.name?.startsWith('.')
export const isDir = (fileOrDir: any) =>
'children' in fileOrDir && fileOrDir.children !== undefined
@ -231,7 +230,7 @@ export async function createNewProject(
}
)
const m = await metadata(path)
const m = await stat(path)
return {
name: path.slice(path.lastIndexOf(sep()) + 1),

View File

@ -1946,11 +1946,6 @@
dependencies:
defer-to-connect "^2.0.1"
"@tauri-apps/api@1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/api/-/api-1.4.0.tgz#b4013ca3d17b853f7df29fe14079ebb4d52dbffa"
integrity sha512-Jd6HPoTM1PZSFIzq7FB8VmMu3qSSyo/3lSwLpoapW+lQ41CL5Dow2KryLg+gyazA/58DRWI9vu/XpEeHK4uMdw==
"@tauri-apps/api@2.0.0-beta.0", "@tauri-apps/api@^2.0.0-beta.0":
version "2.0.0-beta.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/api/-/api-2.0.0-beta.0.tgz#36b10e6f459fd125530ac083262a355b84ce9b95"
@ -7767,12 +7762,6 @@ tar@^6.1.11:
mkdirp "^1.0.3"
yallist "^4.0.0"
"tauri-plugin-fs-extra-api@https://github.com/tauri-apps/tauri-plugin-fs-extra#v1":
version "0.0.0"
resolved "https://github.com/tauri-apps/tauri-plugin-fs-extra#1344db48a39b44fe46e9943bf7cddca2fa00caaf"
dependencies:
"@tauri-apps/api" "1.4.0"
test-exclude@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-6.0.0.tgz#04a8698661d805ea6fa293b6cb9e63ac044ef15e"