@series-inc/stowkit-cli 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/encoders/fbx-loader.js +14 -1
- package/dist/node-fs.d.ts +1 -0
- package/dist/node-fs.js +11 -0
- package/dist/server.js +51 -2
- package/package.json +5 -1
|
@@ -11,7 +11,20 @@ function ensureDomShim() {
|
|
|
11
11
|
g.document = {
|
|
12
12
|
createElementNS(_ns, tag) {
|
|
13
13
|
if (tag === 'img') {
|
|
14
|
-
|
|
14
|
+
const listeners = {};
|
|
15
|
+
return {
|
|
16
|
+
set src(_) { },
|
|
17
|
+
set onload(fn) { listeners['load'] = [fn]; },
|
|
18
|
+
set onerror(fn) { listeners['error'] = [fn]; },
|
|
19
|
+
addEventListener(event, fn) {
|
|
20
|
+
(listeners[event] ??= []).push(fn);
|
|
21
|
+
},
|
|
22
|
+
removeEventListener(event, fn) {
|
|
23
|
+
const arr = listeners[event];
|
|
24
|
+
if (arr)
|
|
25
|
+
listeners[event] = arr.filter(f => f !== fn);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
15
28
|
}
|
|
16
29
|
return {};
|
|
17
30
|
},
|
package/dist/node-fs.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { FelicityProject, FileSnapshot } from './app/disk-project.js';
|
|
|
2
2
|
export declare function readFile(basePath: string, relativePath: string): Promise<Uint8Array | null>;
|
|
3
3
|
export declare function readTextFile(basePath: string, relativePath: string): Promise<string | null>;
|
|
4
4
|
export declare function writeFile(basePath: string, relativePath: string, data: string | Uint8Array): Promise<void>;
|
|
5
|
+
export declare function renameFile(basePath: string, oldRelative: string, newRelative: string): Promise<void>;
|
|
5
6
|
export declare function deleteFile(basePath: string, relativePath: string): Promise<void>;
|
|
6
7
|
export declare function fileExists(basePath: string, relativePath: string): Promise<boolean>;
|
|
7
8
|
export declare function getFileSnapshot(basePath: string, relativePath: string): Promise<FileSnapshot | null>;
|
package/dist/node-fs.js
CHANGED
|
@@ -25,6 +25,17 @@ export async function writeFile(basePath, relativePath, data) {
|
|
|
25
25
|
await fs.mkdir(path.dirname(fullPath), { recursive: true });
|
|
26
26
|
await fs.writeFile(fullPath, data);
|
|
27
27
|
}
|
|
28
|
+
export async function renameFile(basePath, oldRelative, newRelative) {
|
|
29
|
+
try {
|
|
30
|
+
const oldPath = path.join(basePath, oldRelative);
|
|
31
|
+
const newPath = path.join(basePath, newRelative);
|
|
32
|
+
await fs.mkdir(path.dirname(newPath), { recursive: true });
|
|
33
|
+
await fs.rename(oldPath, newPath);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Ignore — file may not exist
|
|
37
|
+
}
|
|
38
|
+
}
|
|
28
39
|
export async function deleteFile(basePath, relativePath) {
|
|
29
40
|
try {
|
|
30
41
|
const fullPath = path.join(basePath, relativePath);
|
package/dist/server.js
CHANGED
|
@@ -5,7 +5,7 @@ import { WebSocketServer, WebSocket } from 'ws';
|
|
|
5
5
|
import { AssetType } from './core/types.js';
|
|
6
6
|
import { defaultAssetSettings } from './app/state.js';
|
|
7
7
|
import { BlobStore } from './app/blob-store.js';
|
|
8
|
-
import { readProjectConfig, scanDirectory, readFile, writeFile, deleteFile, getFileSnapshot, } from './node-fs.js';
|
|
8
|
+
import { readProjectConfig, scanDirectory, readFile, writeFile, renameFile, deleteFile, getFileSnapshot, } from './node-fs.js';
|
|
9
9
|
import { detectAssetType, readStowmeta, writeStowmeta, stowmetaToAssetSettings, assetSettingsToStowmeta, generateDefaultStowmeta, } from './app/stowmeta-io.js';
|
|
10
10
|
import { readStowmat, writeStowmat, stowmatToMaterialConfig, materialConfigToStowmat } from './app/stowmat-io.js';
|
|
11
11
|
import { readCacheBlobs, writeCacheBlobs, buildCacheStamp, isCacheValid, } from './app/process-cache.js';
|
|
@@ -42,6 +42,7 @@ let assets = [];
|
|
|
42
42
|
let folders = [];
|
|
43
43
|
let processingCtx = null;
|
|
44
44
|
let encodersReady = false;
|
|
45
|
+
let lastScanTime = 0;
|
|
45
46
|
// Track in-flight processing
|
|
46
47
|
const processing = new Set();
|
|
47
48
|
// staticApps is passed per-server via closure, not module-level
|
|
@@ -119,6 +120,7 @@ async function initEncoders(wasmDir) {
|
|
|
119
120
|
// ─── Open project ──────────────────────────────────────────────────────────
|
|
120
121
|
async function openProject(projectDir) {
|
|
121
122
|
projectConfig = await readProjectConfig(projectDir);
|
|
123
|
+
lastScanTime = Date.now();
|
|
122
124
|
BlobStore.clear();
|
|
123
125
|
assets = [];
|
|
124
126
|
folders = [];
|
|
@@ -296,8 +298,23 @@ async function handleRequest(req, res, staticApps) {
|
|
|
296
298
|
}
|
|
297
299
|
const url = new URL(req.url ?? '/', `http://localhost`);
|
|
298
300
|
const pathname = url.pathname;
|
|
299
|
-
// GET /api/project — project state
|
|
301
|
+
// GET /api/project — project state (auto-rescans every 5s for external changes)
|
|
300
302
|
if (pathname === '/api/project' && req.method === 'GET') {
|
|
303
|
+
if (projectConfig && Date.now() - lastScanTime > 5000) {
|
|
304
|
+
lastScanTime = Date.now();
|
|
305
|
+
const scan = await scanDirectory(projectConfig.srcArtDir);
|
|
306
|
+
const currentIds = new Set(assets.map(a => a.id));
|
|
307
|
+
const diskIds = new Set([
|
|
308
|
+
...scan.sourceFiles.map(f => f.relativePath),
|
|
309
|
+
...scan.matFiles.map(f => f.relativePath),
|
|
310
|
+
]);
|
|
311
|
+
const changed = currentIds.size !== diskIds.size ||
|
|
312
|
+
[...currentIds].some(id => !diskIds.has(id)) ||
|
|
313
|
+
[...diskIds].some(id => !currentIds.has(id));
|
|
314
|
+
if (changed) {
|
|
315
|
+
await openProject(projectConfig.projectDir);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
301
318
|
json(res, {
|
|
302
319
|
project: projectConfig ? {
|
|
303
320
|
projectName: projectConfig.projectName,
|
|
@@ -440,6 +457,38 @@ async function handleRequest(req, res, staticApps) {
|
|
|
440
457
|
json(res, { ok: true });
|
|
441
458
|
return;
|
|
442
459
|
}
|
|
460
|
+
// PUT /api/asset/:id/rename — rename asset file on disk
|
|
461
|
+
if (pathname.startsWith('/api/asset/') && pathname.endsWith('/rename') && req.method === 'PUT') {
|
|
462
|
+
const id = decodeURIComponent(pathname.slice('/api/asset/'.length, -'/rename'.length));
|
|
463
|
+
if (!projectConfig) {
|
|
464
|
+
json(res, { error: 'No project open' }, 400);
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const body = JSON.parse(await readBody(req));
|
|
468
|
+
const newFileName = body.fileName;
|
|
469
|
+
if (!newFileName) {
|
|
470
|
+
json(res, { error: 'Missing fileName' }, 400);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const asset = assets.find(a => a.id === id);
|
|
474
|
+
if (!asset) {
|
|
475
|
+
json(res, { error: 'Asset not found' }, 404);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
// Build new ID: same folder, new filename
|
|
479
|
+
const folder = id.includes('/') ? id.slice(0, id.lastIndexOf('/') + 1) : '';
|
|
480
|
+
const newId = folder + newFileName;
|
|
481
|
+
// Rename source file, .stowmeta, and .stowcache on disk
|
|
482
|
+
await renameFile(projectConfig.srcArtDir, id, newId);
|
|
483
|
+
await renameFile(projectConfig.srcArtDir, `${id}.stowmeta`, `${newId}.stowmeta`);
|
|
484
|
+
await renameFile(projectConfig.srcArtDir, `${id}.stowcache`, `${newId}.stowcache`);
|
|
485
|
+
// Update in-memory state
|
|
486
|
+
asset.id = newId;
|
|
487
|
+
asset.fileName = newFileName;
|
|
488
|
+
BlobStore.renameAll(id, newId);
|
|
489
|
+
json(res, { ok: true, newId });
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
443
492
|
// DELETE /api/asset/:id — delete asset
|
|
444
493
|
if (pathname.startsWith('/api/asset/') && req.method === 'DELETE') {
|
|
445
494
|
const id = decodeURIComponent(pathname.slice('/api/asset/'.length));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@series-inc/stowkit-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"stowkit": "./dist/cli.js"
|
|
@@ -32,6 +32,10 @@
|
|
|
32
32
|
"@types/ws": "^8.5.13",
|
|
33
33
|
"typescript": "~5.9.3"
|
|
34
34
|
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/series-ai/rundot-stowkit.git"
|
|
38
|
+
},
|
|
35
39
|
"publishConfig": {
|
|
36
40
|
"access": "public"
|
|
37
41
|
}
|