This commit is contained in:
ochafik 2023-03-26 21:36:47 +01:00
commit 8e33e4ed7e
4 changed files with 11 additions and 5 deletions

View file

@ -8,7 +8,9 @@ import { ModelContext, FSContext } from './contexts';
export const isFileWritable = (path: string) => getParentDir(path) === '/home' export const isFileWritable = (path: string) => getParentDir(path) === '/home'
function listFilesAsNodes(fs: FS, path: string): TreeNode[] { // export const isFileWritable = (path: string) => !path.startsWith(librariesFolder + '/');
function listFilesAsNodes(fs: FS, path: string, accept?: (path: string) => boolean): TreeNode[] {
const files: [string, string][] = [] const files: [string, string][] = []
const dirs: [string, string][] = [] const dirs: [string, string][] = []
for (const name of fs.readdirSync(path)) { for (const name of fs.readdirSync(path)) {
@ -16,6 +18,9 @@ function listFilesAsNodes(fs: FS, path: string): TreeNode[] {
continue; continue;
} }
const childPath = `${path}/${name}`; const childPath = `${path}/${name}`;
if (accept && !accept(childPath)) {
continue;
}
const stat = fs.lstatSync(childPath); const stat = fs.lstatSync(childPath);
const isDirectory = stat.isDirectory(); const isDirectory = stat.isDirectory();
if (!isDirectory && !name.endsWith('.scad')) { if (!isDirectory && !name.endsWith('.scad')) {
@ -58,7 +63,8 @@ export default function FilePicker({className, style}: {className?: string, styl
icon: 'pi pi-home', icon: 'pi pi-home',
label: 'User files', label: 'User files',
key: '/home', key: '/home',
children: listFilesAsNodes(fs, '/home'), children: listFilesAsNodes(fs, '/home'),//
// children: listFilesAsNodes(fs, '/', f => f != librariesFolder && !f.startsWith(`${librariesFolder}/`)),
selectable: false selectable: false
}, },
{ {

View file

@ -2,6 +2,8 @@
import { zipArchives } from "./zip-archives"; import { zipArchives } from "./zip-archives";
export const librariesFolder = '/libraries'
declare var BrowserFS: BrowserFSInterface declare var BrowserFS: BrowserFSInterface
export type FSMounts = { export type FSMounts = {

View file

@ -16,7 +16,6 @@ export const checkSyntax =
source = '$preview=true;\n' + source; source = '$preview=true;\n' + source;
const job = spawnOpenSCAD({ const job = spawnOpenSCAD({
workingDir: getParentDir(sourcePath),
inputs: [[sourcePath, source + '\n']], inputs: [[sourcePath, source + '\n']],
args: [sourcePath, "-o", "out.ast"], args: [sourcePath, "-o", "out.ast"],
}); });
@ -67,7 +66,6 @@ export const render =
const job = spawnOpenSCAD({ const job = spawnOpenSCAD({
// wasmMemory, // wasmMemory,
workingDir: getParentDir(params.sourcePath),
inputs: [[params.sourcePath, source]], inputs: [[params.sourcePath, source]],
args, args,
outputPaths: ['/home/out.stl'] outputPaths: ['/home/out.stl']

View file

@ -18,7 +18,7 @@ export function createWasmMemory({maximumMegabytes, maximumBytes}: {maximumMegab
// Output is {outputs: [name, content][], mergedOutputs: [{(stderr|stdout|error)?: string}], exitCode: number} // Output is {outputs: [name, content][], mergedOutputs: [{(stderr|stdout|error)?: string}], exitCode: number}
export type OpenSCADInvocation = { export type OpenSCADInvocation = {
wasmMemory?: WebAssembly.Memory, wasmMemory?: WebAssembly.Memory,
workingDir: string, // workingDir: string,
inputs?: [string, string][], inputs?: [string, string][],
args: string[], args: string[],
outputPaths?: string[], outputPaths?: string[],