diff --git a/socket.ini b/socket.ini index e25e41f..eac4ced 100644 --- a/socket.ini +++ b/socket.ini @@ -83,6 +83,8 @@ src/css = css node_modules/@socketsupply/components = node_modules/@socketsupply/components node_modules/@socketsupply/indexed = node_modules/@socketsupply/indexed node_modules/@socketsupply/tonic = node_modules/@socketsupply/tonic +node_modules/@socketsupply/socket = node_modules/@socketsupply/socket +node_modules/@socketsupply/socket-darwin-arm64 = node_modules/@socketsupply/socket-darwin-arm64 [build.script] @@ -97,7 +99,7 @@ forward_arguments = false sources[] = "src" [webview] -importmap = "/importmap.json" +importmap = "importmap.json" ; Make root open index.html ; default value: "/" diff --git a/src/index.html b/src/index.html index ffb5b26..51a524c 100644 --- a/src/index.html +++ b/src/index.html @@ -6,7 +6,7 @@ http-equiv="Content-Security-Policy" content=" connect-src socket: npm: https: http: blob: ipc: wss: ws: ws://localhost:*; - script-src socket: npm: https: http: blob: http://localhost:* 'unsafe-eval' 'unsafe-inline'; + script-src socket: npm: node: https: http: blob: http://localhost:* 'unsafe-eval' 'unsafe-inline'; worker-src socket: https: http: blob: 'unsafe-eval' 'unsafe-inline'; frame-src socket: https: http: blob: http://localhost:*; img-src socket: https: http: blob: data: http://localhost:*; diff --git a/src/index.js b/src/index.js index ee4063b..77aa472 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ import { network, Encryption } from 'socket:network' import vm from 'socket:vm' import { inspect, format } from 'socket:util' import { spawn, exec } from 'socket:child_process' +import os from 'socket:os' import Tonic from '@socketsupply/tonic' import components from '@socketsupply/components' @@ -339,9 +340,18 @@ class AppView extends Tonic { await this.db.projects.put(bundleId, project) await fs.promises.mkdir(project.path, { recursive: true }) + const runtime = await import(`npm:@socketsupply/socket-${os.platform()}-${os.arch()}`) + const ssc = path.join(process.cwd(), runtime.bin.ssc.replace(globalThis.location.origin, '')) + console.log({ ssc }) + try { + await fs.promises.access('/Applications/Xcode.app/Contents/Developer/usr/bin/git', fs.constants.X_OK) + } catch (err) { + console.error(err) + } try { - await exec('ssc init', { cwd: project.path }) - await exec('git init', { cwd: project.path }) + await exec(`${ssc} init`, { cwd: project.path }) + + console.log(await exec('/Applications/Xcode.app/Contents/Developer/usr/bin/git init', { cwd: project.path })) } catch (err) { console.error(err) } diff --git a/src/lib/fs.js b/src/lib/fs.js index ed95006..d1e221e 100644 --- a/src/lib/fs.js +++ b/src/lib/fs.js @@ -2,19 +2,21 @@ import fs from 'socket:fs' import path from 'socket:path' export async function rm (directory) { - const files = await fs.promises.readdir(directory, { withFileTypes: true }) + try { + const files = await fs.promises.readdir(directory, { withFileTypes: true }) - for (const file of files) { - const filePath = path.join(directory, file.name) + for (const file of files) { + const filePath = path.join(directory, file.name) - if (file.isDirectory()) { - await rm(filePath) - } else { - await fs.promises.unlink(filePath) + if (file.isDirectory()) { + await rm(filePath) + } else { + await fs.promises.unlink(filePath) + } } - } - await fs.promises.rmdir(directory) + await fs.promises.rmdir(directory) + } catch {} } export async function cp (srcDir, destDir) { diff --git a/src/worker.js b/src/worker.js index 72abbd0..861c724 100644 --- a/src/worker.js +++ b/src/worker.js @@ -1,9 +1,7 @@ import path from 'socket:path' import { lookup } from 'socket:mime' import application from 'socket:application' - -const mount = '/user/home' -const navigatorPath = path.DATA.replace(path.HOME, mount) +import fs from 'socket:fs/promises' export default async function (req, env, ctx) { const url = new URL(req.url) @@ -12,7 +10,7 @@ export default async function (req, env, ctx) { if (!route) return - const p = path.join(navigatorPath, route.pathname.groups[0]) + const p = path.join(path.DATA, route.pathname.groups[0]) const params = url.searchParams const types = await lookup(path.extname(url.pathname).slice(1)) @@ -27,11 +25,9 @@ export default async function (req, env, ctx) { let data = '' try { - const res = await fetch(p) - - if (res.ok && res.status === 200) { - data = await res.text() - } else if (!res.ok || res.status === 404) { + if (await fs.access(p, fs.constants.R_OK)) { + data = await fs.readFile(p, 'utf8') + } else { data = '

Not Found

' headers['Runtime-Preload-Injection'] = 'disabled' }