Repetitive structs removed for import file extensions (#6211)
* get rid of repetitive structs Signed-off-by: Jess Frazelle <github@jessfraz.com> fmt Signed-off-by: Jess Frazelle <github@jessfraz.com> get rid of more Signed-off-by: Jess Frazelle <github@jessfraz.com> add more Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> fix Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> await the shit Signed-off-by: Jess Frazelle <github@jessfraz.com> updates Signed-off-by: Jess Frazelle <github@jessfraz.com> put it at the root Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix;es Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix Signed-off-by: Jess Frazelle <github@jessfraz.com> * kcl-language-server flake Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import type { Models } from '@kittycad/lib/dist/types/src'
|
||||
import type { FileImportFormat_type } from '@kittycad/lib/dist/types/src/models'
|
||||
|
||||
import type { UnitAngle, UnitLength } from '@rust/kcl-lib/bindings/ModelingCmd'
|
||||
|
||||
@ -36,29 +35,6 @@ export const PROJECT_IMAGE_NAME = `thumbnail.png`
|
||||
export const FILE_PERSIST_KEY = `${PROJECT_FOLDER}-last-opened` as const
|
||||
/** The default name given to new kcl files in a project */
|
||||
export const DEFAULT_FILE_NAME = 'Untitled'
|
||||
/** The file endings that will appear in
|
||||
* the file explorer if found in a project directory */
|
||||
// TODO: make stp part of this enum as an alias to step
|
||||
// TODO: make glb part of this enum as it is in fact supported
|
||||
export type NativeFileType = 'kcl'
|
||||
export type RelevantFileType =
|
||||
| FileImportFormat_type
|
||||
| NativeFileType
|
||||
| 'stp'
|
||||
| 'glb'
|
||||
export const NATIVE_FILE_TYPE: NativeFileType = 'kcl'
|
||||
export const RELEVANT_FILE_TYPES: RelevantFileType[] = [
|
||||
'kcl',
|
||||
'fbx',
|
||||
'gltf',
|
||||
'glb',
|
||||
'obj',
|
||||
'ply',
|
||||
'sldprt',
|
||||
'stp',
|
||||
'step',
|
||||
'stl',
|
||||
] as const
|
||||
/** The default name for a tutorial project */
|
||||
export const ONBOARDING_PROJECT_NAME = 'Tutorial Project $nn'
|
||||
/**
|
||||
|
||||
@ -2,9 +2,14 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { Configuration } from '@rust/kcl-lib/bindings/Configuration'
|
||||
|
||||
import { isRelevantFile, listProjects } from '@src/lib/desktop'
|
||||
import { initPromise } from '@src/lang/wasm'
|
||||
import { listProjects } from '@src/lib/desktop'
|
||||
import type { DeepPartial } from '@src/lib/types'
|
||||
|
||||
beforeAll(async () => {
|
||||
await initPromise
|
||||
})
|
||||
|
||||
// Mock the electron window global
|
||||
const mockElectron = {
|
||||
readdir: vi.fn(),
|
||||
@ -112,41 +117,6 @@ describe('desktop utilities', () => {
|
||||
mockElectron.kittycad.mockResolvedValue({})
|
||||
})
|
||||
|
||||
describe('isRelevantFile', () => {
|
||||
it('finds supported extension files relevant', () => {
|
||||
expect(isRelevantFile('part.kcl')).toEqual(true)
|
||||
expect(isRelevantFile('part.fbx')).toEqual(true)
|
||||
expect(isRelevantFile('part.gltf')).toEqual(true)
|
||||
expect(isRelevantFile('part.glb')).toEqual(true)
|
||||
expect(isRelevantFile('part.obj')).toEqual(true)
|
||||
expect(isRelevantFile('part.ply')).toEqual(true)
|
||||
expect(isRelevantFile('part.sldprt')).toEqual(true)
|
||||
expect(isRelevantFile('part.stp')).toEqual(true)
|
||||
expect(isRelevantFile('part.step')).toEqual(true)
|
||||
expect(isRelevantFile('part.stl')).toEqual(true)
|
||||
})
|
||||
|
||||
// TODO: we should be lowercasing the extension here to check. .sldprt or .SLDPRT should be supported
|
||||
// But the api doesn't allow it today, so revisit this and the tests once this is done
|
||||
it('finds (now) supported uppercase extension files *not* relevant', () => {
|
||||
expect(isRelevantFile('part.KCL')).toEqual(false)
|
||||
expect(isRelevantFile('part.FBX')).toEqual(false)
|
||||
expect(isRelevantFile('part.GLTF')).toEqual(false)
|
||||
expect(isRelevantFile('part.GLB')).toEqual(false)
|
||||
expect(isRelevantFile('part.OBJ')).toEqual(false)
|
||||
expect(isRelevantFile('part.PLY')).toEqual(false)
|
||||
expect(isRelevantFile('part.SLDPRT')).toEqual(false)
|
||||
expect(isRelevantFile('part.STP')).toEqual(false)
|
||||
expect(isRelevantFile('part.STEP')).toEqual(false)
|
||||
expect(isRelevantFile('part.STL')).toEqual(false)
|
||||
})
|
||||
|
||||
it("doesn't find .docx or .SLDASM relevant", () => {
|
||||
expect(isRelevantFile('paper.docx')).toEqual(false)
|
||||
expect(isRelevantFile('assembly.SLDASM')).toEqual(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('listProjects', () => {
|
||||
it('does not list .git directories', async () => {
|
||||
const projects = await listProjects(mockConfig)
|
||||
|
||||
@ -10,13 +10,13 @@ import {
|
||||
parseAppSettings,
|
||||
parseProjectSettings,
|
||||
} from '@src/lang/wasm'
|
||||
import { relevantFileExtensions } from '@src/lang/wasmUtils'
|
||||
import {
|
||||
DEFAULT_DEFAULT_LENGTH_UNIT,
|
||||
PROJECT_ENTRYPOINT,
|
||||
PROJECT_FOLDER,
|
||||
PROJECT_IMAGE_NAME,
|
||||
PROJECT_SETTINGS_FILE_NAME,
|
||||
RELEVANT_FILE_TYPES,
|
||||
SETTINGS_FILE_NAME,
|
||||
TELEMETRY_FILE_NAME,
|
||||
TELEMETRY_RAW_FILE_NAME,
|
||||
@ -201,15 +201,13 @@ export async function listProjects(
|
||||
return projects
|
||||
}
|
||||
|
||||
// TODO: we should be lowercasing the extension here to check. .sldprt or .SLDPRT should be supported
|
||||
// But the api doesn't allow it today, so revisit this and the tests once this is done
|
||||
export const isRelevantFile = (filename: string): boolean =>
|
||||
RELEVANT_FILE_TYPES.some((ext) => filename.endsWith('.' + ext))
|
||||
|
||||
const collectAllFilesRecursiveFrom = async (
|
||||
path: string,
|
||||
canReadWritePath: boolean
|
||||
) => {
|
||||
const RELEVANT_FILE_EXTENSIONS = relevantFileExtensions()
|
||||
const isRelevantFile = (filename: string): boolean =>
|
||||
RELEVANT_FILE_EXTENSIONS.some((ext) => filename.endsWith('.' + ext))
|
||||
// Make sure the filesystem object exists.
|
||||
try {
|
||||
await window.electron.stat(path)
|
||||
|
||||
@ -3,8 +3,13 @@ import os from 'os'
|
||||
import path from 'path'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
import { initPromise } from '@src/lang/wasm'
|
||||
import getCurrentProjectFile from '@src/lib/getCurrentProjectFile'
|
||||
|
||||
beforeAll(async () => {
|
||||
await initPromise
|
||||
})
|
||||
|
||||
describe('getCurrentProjectFile', () => {
|
||||
test('with explicit open file with space (URL encoded)', async () => {
|
||||
const name = `kittycad-modeling-projects-${uuidv4()}`
|
||||
|
||||
@ -1,17 +1,12 @@
|
||||
import {
|
||||
importFileExtensions,
|
||||
relevantFileExtensions,
|
||||
} from '@src/lang/wasmUtils'
|
||||
import type { Stats } from 'fs'
|
||||
import * as fs from 'fs/promises'
|
||||
import * as path from 'path'
|
||||
|
||||
import {
|
||||
NATIVE_FILE_TYPE,
|
||||
PROJECT_ENTRYPOINT,
|
||||
RELEVANT_FILE_TYPES,
|
||||
type RelevantFileType,
|
||||
} from '@src/lib/constants'
|
||||
|
||||
const shouldWrapExtension = (extension: string) =>
|
||||
RELEVANT_FILE_TYPES.includes(extension as RelevantFileType) &&
|
||||
extension !== NATIVE_FILE_TYPE
|
||||
import { PROJECT_ENTRYPOINT } from '@src/lib/constants'
|
||||
|
||||
/// Get the current project file from the path.
|
||||
/// This is used for double-clicking on a file in the file explorer,
|
||||
@ -19,6 +14,12 @@ const shouldWrapExtension = (extension: string) =>
|
||||
export default async function getCurrentProjectFile(
|
||||
pathString: string
|
||||
): Promise<string | Error> {
|
||||
// Extract the values into an array
|
||||
const allFileImportFormats: string[] = importFileExtensions()
|
||||
const relevantExtensions: string[] = relevantFileExtensions()
|
||||
const shouldWrapExtension = (extension: string) =>
|
||||
allFileImportFormats.includes(extension)
|
||||
|
||||
// Fix for "." path, which is the current directory.
|
||||
let sourcePath = pathString === '.' ? process.cwd() : pathString
|
||||
|
||||
@ -71,12 +72,9 @@ export default async function getCurrentProjectFile(
|
||||
// Check if the extension on what we are trying to open is a relevant file type.
|
||||
const extension = path.extname(sourcePath).slice(1).toLowerCase()
|
||||
|
||||
if (
|
||||
!RELEVANT_FILE_TYPES.includes(extension as RelevantFileType) &&
|
||||
extension !== 'toml'
|
||||
) {
|
||||
if (!relevantExtensions.includes(extension) && extension !== 'toml') {
|
||||
return new Error(
|
||||
`File type (${extension}) cannot be opened with this app: '${sourcePath}', try opening one of the following file types: ${RELEVANT_FILE_TYPES.join(
|
||||
`File type (${extension}) cannot be opened with this app: '${sourcePath}', try opening one of the following file types: ${relevantExtensions.join(
|
||||
', '
|
||||
)}`
|
||||
)
|
||||
|
||||
@ -15,6 +15,7 @@ import type {
|
||||
format_number as FormatNumber,
|
||||
get_kcl_version as GetKclVersion,
|
||||
get_tangential_arc_to_info as GetTangentialArcToInfo,
|
||||
import_file_extensions as ImportFileExtensions,
|
||||
is_kcl_empty_or_only_settings as IsKclEmptyOrOnlySettings,
|
||||
is_points_ccw as IsPointsCcw,
|
||||
kcl_lint as KclLint,
|
||||
@ -23,6 +24,7 @@ import type {
|
||||
parse_project_settings as ParseProjectSettings,
|
||||
parse_wasm as ParseWasm,
|
||||
recast_wasm as RecastWasm,
|
||||
relevant_file_extensions as RelevantFileExtensions,
|
||||
serialize_configuration as SerializeConfiguration,
|
||||
serialize_project_configuration as SerializeProjectConfiguration,
|
||||
} from '@rust/kcl-wasm-lib/pkg/kcl_wasm_lib'
|
||||
@ -111,3 +113,9 @@ export const serialize_project_configuration: typeof SerializeProjectConfigurati
|
||||
(...args) => {
|
||||
return getModule().serialize_project_configuration(...args)
|
||||
}
|
||||
export const import_file_extensions: typeof ImportFileExtensions = () => {
|
||||
return getModule().import_file_extensions()
|
||||
}
|
||||
export const relevant_file_extensions: typeof RelevantFileExtensions = () => {
|
||||
return getModule().relevant_file_extensions()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user