topotopo 0.4.0 → 0.5.0
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/NOTICE +10 -10
- package/README.md +460 -117
- package/dist/cli.js +323 -146
- package/dist/config.d.ts +48 -0
- package/dist/config.js +170 -0
- package/dist/core/bake.d.ts +14 -3
- package/dist/core/bake.js +153 -4
- package/dist/core/bevel.d.ts +3 -1
- package/dist/core/bevel.js +76 -3
- package/dist/core/decimate.d.ts +65 -0
- package/dist/core/decimate.js +409 -3
- package/dist/core/erosion.d.ts +37 -0
- package/dist/core/erosion.js +41 -1
- package/dist/core/geometry.d.ts +5 -1
- package/dist/core/geometry.js +203 -3
- package/dist/core/heightfield.d.ts +27 -4
- package/dist/core/heightfield.js +54 -16
- package/dist/core/intrinsics.d.ts +7 -0
- package/dist/core/intrinsics.js +94 -0
- package/dist/core/manifold.d.ts +12 -1
- package/dist/core/manifold.js +78 -6
- package/dist/core/materials.d.ts +7 -0
- package/dist/core/materials.js +45 -0
- package/dist/core/noise.d.ts +9 -0
- package/dist/core/noise.js +10 -1
- package/dist/core/polymerge.d.ts +21 -0
- package/dist/core/polymerge.js +327 -0
- package/dist/core/repair.d.ts +2 -0
- package/dist/core/repair.js +2 -0
- package/dist/core/report.d.ts +70 -0
- package/dist/core/report.js +275 -0
- package/dist/core/scene.js +2 -1
- package/dist/core/sha256.d.ts +4 -0
- package/dist/core/sha256.js +69 -0
- package/dist/core/shapes.d.ts +3 -0
- package/dist/core/shapes.js +34 -0
- package/dist/core/snippet-lib.d.ts +14 -1
- package/dist/core/snippet-lib.js +39 -13
- package/dist/core/tangents.d.ts +2 -0
- package/dist/core/tangents.js +5 -1
- package/dist/core/texnoise.d.ts +6 -1
- package/dist/core/texnoise.js +6 -2
- package/dist/core/texsdf.d.ts +131 -0
- package/dist/core/texsdf.js +637 -0
- package/dist/core/texture.d.ts +163 -9
- package/dist/core/texture.js +844 -20
- package/dist/core/topology.d.ts +10 -0
- package/dist/core/topology.js +168 -0
- package/dist/core/unwrap.d.ts +72 -0
- package/dist/core/unwrap.js +800 -0
- package/dist/core/usercode.d.ts +27 -0
- package/dist/core/usercode.js +87 -0
- package/dist/core/uv.d.ts +4 -18
- package/dist/core/uv.js +35 -188
- package/dist/core/uvislands.d.ts +62 -0
- package/dist/core/uvislands.js +574 -0
- package/dist/core/uvoverlap.d.ts +58 -0
- package/dist/core/uvoverlap.js +220 -0
- package/dist/core/uvpack.d.ts +64 -0
- package/dist/core/uvpack.js +628 -0
- package/dist/core/uvreport.d.ts +61 -0
- package/dist/core/uvreport.js +207 -143
- package/dist/core/wrangle.d.ts +6 -1
- package/dist/core/wrangle.js +27 -16
- package/dist/core/xatlas.d.ts +16 -1
- package/dist/core/xatlas.js +66 -62
- package/dist/engines.d.ts +63 -0
- package/dist/engines.js +180 -0
- package/dist/explain.d.ts +4 -3
- package/dist/explain.js +129 -12
- package/dist/graph/engine.d.ts +92 -29
- package/dist/graph/engine.js +298 -148
- package/dist/graph/expr.d.ts +6 -3
- package/dist/graph/expr.js +18 -8
- package/dist/graph/outputs.d.ts +23 -0
- package/dist/graph/outputs.js +41 -0
- package/dist/graph/packages.d.ts +72 -0
- package/dist/graph/packages.js +261 -0
- package/dist/graph/parallel.d.ts +3 -1
- package/dist/graph/parallel.js +4 -1
- package/dist/graph/params.d.ts +6 -0
- package/dist/graph/params.js +34 -7
- package/dist/graph/scope.d.ts +55 -0
- package/dist/graph/scope.js +14 -0
- package/dist/graph/types.d.ts +75 -12
- package/dist/graph/types.js +4 -2
- package/dist/graph/vars.d.ts +16 -0
- package/dist/graph/vars.js +80 -0
- package/dist/host/artifacts.d.ts +10 -1
- package/dist/host/artifacts.js +37 -6
- package/dist/host/cook.d.ts +241 -0
- package/dist/host/cook.js +844 -0
- package/dist/host/export-targets.d.ts +42 -5
- package/dist/host/export-targets.js +72 -13
- package/dist/host/godot-commands.d.ts +4 -0
- package/dist/host/godot-commands.js +21 -0
- package/dist/host/godot.d.ts +183 -0
- package/dist/host/godot.js +916 -0
- package/dist/host/node.d.ts +12 -7
- package/dist/host/node.js +27 -9
- package/dist/host/pool.js +51 -2
- package/dist/host/sidecars.d.ts +8 -0
- package/dist/host/sidecars.js +50 -0
- package/dist/host/types.d.ts +19 -6
- package/dist/host/version.d.ts +1 -0
- package/dist/host/version.js +3 -0
- package/dist/host/worker.js +5 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/inspect.d.ts +80 -2
- package/dist/inspect.js +265 -30
- package/dist/io/common.d.ts +25 -5
- package/dist/io/export.js +2 -1
- package/dist/io/files.d.ts +23 -4
- package/dist/io/files.js +60 -8
- package/dist/io/gltf.js +134 -47
- package/dist/io/heightmap.d.ts +3 -0
- package/dist/io/heightmap.js +1 -0
- package/dist/io/import.js +10 -0
- package/dist/io/inspect-scene.d.ts +55 -0
- package/dist/io/inspect-scene.js +155 -0
- package/dist/io/kinds.d.ts +81 -0
- package/dist/io/kinds.js +163 -0
- package/dist/io/points.d.ts +2 -1
- package/dist/io/points.js +3 -1
- package/dist/io/sidecars.d.ts +24 -0
- package/dist/io/sidecars.js +57 -0
- package/dist/io/source.d.ts +65 -0
- package/dist/io/source.js +112 -0
- package/dist/io/targets.d.ts +47 -3
- package/dist/io/targets.js +148 -13
- package/dist/io/textures.js +21 -1
- package/dist/io/unreal.js +5 -1
- package/dist/mcp/docs.d.ts +10 -1
- package/dist/mcp/docs.js +786 -143
- package/dist/mcp/inputs.d.ts +12 -5
- package/dist/mcp/inputs.js +50 -13
- package/dist/mcp/server.js +56 -27
- package/dist/mcp/tools.d.ts +14 -7
- package/dist/mcp/tools.js +196 -103
- package/dist/mcp/verify.d.ts +2 -2
- package/dist/mcp/verify.js +1 -1
- package/dist/mcp/workspace.d.ts +15 -0
- package/dist/mcp/workspace.js +349 -0
- package/dist/nodes/attributes.js +198 -1
- package/dist/nodes/bake.js +151 -47
- package/dist/nodes/beam.d.ts +1 -0
- package/dist/nodes/beam.js +201 -0
- package/dist/nodes/bevel.js +51 -3
- package/dist/nodes/cloth.js +2 -0
- package/dist/nodes/code.js +21 -9
- package/dist/nodes/curves.js +433 -93
- package/dist/nodes/flow.js +53 -33
- package/dist/nodes/generate.js +12 -38
- package/dist/nodes/heightfield.js +248 -77
- package/dist/nodes/imageops.js +16 -19
- package/dist/nodes/index.d.ts +1 -0
- package/dist/nodes/index.js +1 -0
- package/dist/nodes/material.js +89 -24
- package/dist/nodes/measure.js +43 -17
- package/dist/nodes/particles.js +2 -0
- package/dist/nodes/pcg.js +6 -5
- package/dist/nodes/procedural.js +4 -3
- package/dist/nodes/remesh.js +71 -15
- package/dist/nodes/scene.js +4 -2
- package/dist/nodes/sdf.js +10 -5
- package/dist/nodes/solid.js +20 -5
- package/dist/nodes/splines.d.ts +15 -1
- package/dist/nodes/splines.js +112 -105
- package/dist/nodes/texture.d.ts +21 -6
- package/dist/nodes/texture.js +1318 -185
- package/dist/nodes/topology.d.ts +7 -0
- package/dist/nodes/topology.js +133 -6
- package/dist/nodes/transform.js +6 -2
- package/dist/nodes/uv.js +192 -174
- package/dist/nodes/wasmcall.js +5 -1
- package/dist/open.d.ts +19 -0
- package/dist/open.js +12 -0
- package/dist/package.d.ts +288 -0
- package/dist/package.js +772 -0
- package/dist/packages/check.d.ts +32 -0
- package/dist/packages/check.js +169 -0
- package/dist/packages/commands.d.ts +57 -0
- package/dist/packages/commands.js +537 -0
- package/dist/packages/registry.d.ts +796 -0
- package/dist/packages/registry.js +2998 -0
- package/dist/packages/update.d.ts +124 -0
- package/dist/packages/update.js +476 -0
- package/dist/render/options.d.ts +2 -0
- package/dist/render/options.js +44 -5
- package/dist/render/preview.d.ts +15 -4
- package/dist/render/preview.js +6 -4
- package/dist/render/raster.d.ts +66 -5
- package/dist/render/raster.js +506 -138
- package/dist/render/texview.d.ts +6 -0
- package/dist/render/texview.js +27 -0
- package/dist/scan.d.ts +61 -0
- package/dist/scan.js +228 -0
- package/dist/session.d.ts +311 -0
- package/dist/session.js +849 -0
- package/dist/viewer/app/api.js +48 -6
- package/dist/viewer/app/cooking.js +78 -0
- package/dist/viewer/app/embed.js +27 -7
- package/dist/viewer/app/export-popover.js +118 -16
- package/dist/viewer/app/grid.js +5 -1
- package/dist/viewer/app/guides.js +122 -0
- package/dist/viewer/app/keymap.js +6 -3
- package/dist/viewer/app/layers.js +4 -4
- package/dist/viewer/app/main.js +185 -52
- package/dist/viewer/app/markers.js +60 -0
- package/dist/viewer/app/outliner.js +72 -27
- package/dist/viewer/app/output-info.js +45 -0
- package/dist/viewer/app/outputs.css +147 -8
- package/dist/viewer/app/outputs.js +168 -54
- package/dist/viewer/app/packages.js +614 -0
- package/dist/viewer/app/props.js +176 -52
- package/dist/viewer/app/scene.js +30 -5
- package/dist/viewer/app/select.js +4 -3
- package/dist/viewer/app/status.js +12 -15
- package/dist/viewer/app/style.css +65 -7
- package/dist/viewer/app/vars.js +47 -0
- package/dist/viewer/app/welcome.js +72 -0
- package/dist/viewer/graph-file.d.ts +62 -0
- package/dist/viewer/graph-file.js +175 -0
- package/dist/viewer/index.html +23 -10
- package/dist/viewer/json-edit.d.ts +13 -0
- package/dist/viewer/json-edit.js +274 -0
- package/dist/viewer/outputs.d.ts +49 -5
- package/dist/viewer/outputs.js +264 -56
- package/dist/viewer/packages.d.ts +121 -0
- package/dist/viewer/packages.js +584 -0
- package/dist/viewer/server.d.ts +14 -9
- package/dist/viewer/server.js +266 -28
- package/dist/web/app/web.css +419 -0
- package/dist/web/app/web.js +188 -0
- package/dist/{gallery → web}/bake.d.ts +4 -4
- package/dist/{gallery → web}/bake.js +24 -15
- package/dist/web/folder-page.d.ts +101 -0
- package/dist/web/folder-page.js +146 -0
- package/dist/web/folders.d.ts +280 -0
- package/dist/web/folders.js +970 -0
- package/dist/web/library.d.ts +91 -0
- package/dist/web/library.js +228 -0
- package/dist/web/markdown.d.ts +45 -0
- package/dist/web/markdown.js +677 -0
- package/dist/web/pages.d.ts +258 -0
- package/dist/web/pages.js +301 -0
- package/dist/web/server.d.ts +24 -0
- package/dist/web/server.js +1068 -0
- package/dist/workspace.d.ts +88 -118
- package/dist/workspace.js +358 -460
- package/integrations/godot/addons/topotopo/LICENSE +202 -0
- package/integrations/godot/addons/topotopo/README.md +57 -0
- package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
- package/integrations/godot/addons/topotopo/dock.gd +266 -0
- package/integrations/godot/addons/topotopo/dock.tscn +72 -0
- package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
- package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
- package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
- package/integrations/godot/addons/topotopo/inspector.gd +38 -0
- package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
- package/integrations/godot/addons/topotopo/package.gd +23 -0
- package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
- package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
- package/integrations/godot/addons/topotopo/plugin.gd +970 -0
- package/integrations/godot/addons/topotopo/record.gd +435 -0
- package/integrations/godot/addons/topotopo/runner.gd +458 -0
- package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
- package/integrations/godot/addons/topotopo/watcher.gd +199 -0
- package/kernels/pkg/README.md +2 -1
- package/kernels/pkg-simd/README.md +2 -1
- package/library/architecture/versions/1.0/architecture.topo +12 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
- package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
- package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
- package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
- package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
- package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
- package/library/architecture/versions/1.0/version.json +1119 -0
- package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
- package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
- package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
- package/library/nature/versions/1.0/graphs/lineup.json +24 -0
- package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
- package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
- package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
- package/library/nature/versions/1.0/nature.topo +12 -0
- package/library/nature/versions/1.0/version.json +534 -0
- package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
- package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
- package/library/props/versions/1.0/graphs/lineup.json +18 -0
- package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
- package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
- package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
- package/library/props/versions/1.0/props.topo +12 -0
- package/library/props/versions/1.0/version.json +336 -0
- package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
- package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
- package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
- package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
- package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
- package/library/street/versions/1.0/graphs/lineup.json +22 -0
- package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
- package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
- package/library/street/versions/1.0/street.topo +12 -0
- package/library/street/versions/1.0/version.json +421 -0
- package/package.json +17 -8
- package/dist/gallery/app/gallery.css +0 -100
- package/dist/gallery/app/gallery.js +0 -80
- package/dist/gallery/cli.d.ts +0 -4
- package/dist/gallery/cli.js +0 -157
- package/dist/gallery/library.d.ts +0 -124
- package/dist/gallery/library.js +0 -366
- package/dist/gallery/pages.d.ts +0 -94
- package/dist/gallery/pages.js +0 -148
- package/dist/gallery/server.d.ts +0 -21
- package/dist/gallery/server.js +0 -391
- package/dist/graph/migrate.d.ts +0 -23
- package/dist/graph/migrate.js +0 -58
- package/dist/mcp/library.d.ts +0 -12
- package/dist/mcp/library.js +0 -159
- package/shelf/index.json +0 -190
package/dist/workspace.js
CHANGED
|
@@ -1,483 +1,381 @@
|
|
|
1
|
-
// A workspace:
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
1
|
+
// A workspace: a folder tree (a game, an archviz job) whose folders holding a .topo file are its packages, found by
|
|
2
|
+
// scanning it (src/scan.ts). topotopo-workspace.json at its root names it, lists the shared libraries its packages use
|
|
3
|
+
// (registered names, or paths to folders outside the workspace), names the engine project the game is built with,
|
|
4
|
+
// whether its own packages are followed live for looking, and the one version of each package the whole workspace
|
|
5
|
+
// uses: its packages share one copy of it, in topotopo-packages/ beside the file (a package that publishes versions keeps
|
|
6
|
+
// its own copies: its uses are published with it).
|
|
7
|
+
// {"name": "my-game", "libraries": ["props", "../shared/materials"],
|
|
8
|
+
// "engine": {"type": "godot", "project": "../project.godot"}, "follow": false, "uses": {"topotopo/props": "1.1"}}
|
|
9
|
+
// Paths are written from the workspace's folder. Its preferred place is inside the engine's content folder (the Godot
|
|
10
|
+
// project folder or a folder in it, Unreal's Content/ or a folder in it), so Explorer, the engine and the web app show
|
|
11
|
+
// one tree and the engine imports each package's exports/ where they are. package.ts finds the workspace around a
|
|
12
|
+
// package (locate), the places it finds packages in (librariesFor) and where its copies are (copiesFor).
|
|
7
13
|
import fs from 'node:fs';
|
|
8
14
|
import path from 'node:path';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
15
|
+
import { ID_RE } from './graph/scope.js';
|
|
16
|
+
import { BUILTIN_LIBRARY, addWorkspace, loadConfig } from './config.js';
|
|
17
|
+
import { WORKSPACE_FILE, WORKSPACE_PACKAGES, workspaceFlag, copiesFor, libraryEntry, locate, manifestAt, parseUses, program, resolveListed, slugify, within, workspaceRepoFiles, writeAtomic } from './package.js';
|
|
18
|
+
import { gatherCopies } from './packages/registry.js';
|
|
19
|
+
import { folderKey, forgetScans, scanTree } from './scan.js';
|
|
20
|
+
import { detectEngine, engineTypeOf, godotIgnore, godotPresetReport, unrealSees } from './engines.js';
|
|
21
|
+
export { WORKSPACE_FILE };
|
|
22
|
+
/** What an "engine.assets" or --assets is told: the "engine:" export folder is gone. */
|
|
23
|
+
export const assetsGone = (what) => `${what} is gone: an export stays in its package's exports/ folder; put the workspace inside the engine project (Godot: the project folder or a folder in it; Unreal: Content/ or a folder in it) and the engine imports the exports from there`;
|
|
24
|
+
/** topotopo-workspace.json checked and normalised; throws naming the problem. */
|
|
25
|
+
export function parseWorkspace(raw, fallbackName) {
|
|
26
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
27
|
+
throw new Error(`${WORKSPACE_FILE} must be an object`);
|
|
28
|
+
const name = raw.name === undefined ? fallbackName : raw.name;
|
|
29
|
+
if (typeof name !== 'string' || !ID_RE.test(name))
|
|
30
|
+
throw new Error(`${WORKSPACE_FILE}: "name" must be lower-case letters, digits, - and _ ("my-game"), got ${JSON.stringify(name)}`);
|
|
31
|
+
const libraries = raw.libraries ?? [];
|
|
32
|
+
if (!Array.isArray(libraries) || libraries.some((l) => typeof l !== 'string'))
|
|
33
|
+
throw new Error(`${WORKSPACE_FILE}: "libraries" must be a list of registered library names and paths from the workspace to folders outside it ("../shared/props")`);
|
|
34
|
+
let engine = null;
|
|
35
|
+
if (raw.engine === 'none')
|
|
36
|
+
engine = 'none';
|
|
37
|
+
else if (raw.engine !== undefined && raw.engine !== null) {
|
|
38
|
+
const e = raw.engine;
|
|
39
|
+
if (e && typeof e === 'object' && e.assets !== undefined)
|
|
40
|
+
throw new Error(`${WORKSPACE_FILE}: ${assetsGone('"engine.assets"')}; remove "assets"`);
|
|
41
|
+
if (!e || typeof e !== 'object' || (e.type !== 'godot' && e.type !== 'unreal') || typeof e.project !== 'string' || !e.project)
|
|
42
|
+
throw new Error(`${WORKSPACE_FILE}: "engine" must be {"type": "godot" | "unreal", "project": "../project.godot"} or "none"`);
|
|
43
|
+
engine = { type: e.type, project: e.project };
|
|
33
44
|
}
|
|
45
|
+
if (raw.follow !== undefined && typeof raw.follow !== 'boolean')
|
|
46
|
+
throw new Error(`${WORKSPACE_FILE}: "follow" must be true or false`);
|
|
47
|
+
const uses = parseUses(raw.uses, WORKSPACE_FILE);
|
|
48
|
+
return { name, libraries: [...new Set(libraries.map((l) => l.trim().replace(/\\/g, '/')))], engine, follow: raw.follow === true, uses };
|
|
34
49
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
listeners = new Set();
|
|
42
|
-
/** the inputs folder given to the constructor (WorkspaceOptions.inputs), if any */
|
|
43
|
-
inputsAt;
|
|
44
|
-
exportsAt;
|
|
45
|
-
constructor(dir, engine, opts = {}) {
|
|
46
|
-
this.dir = path.resolve(dir);
|
|
47
|
-
this.engine = engine;
|
|
48
|
-
this.inputsAt = opts.inputs === undefined ? undefined : path.resolve(opts.inputs);
|
|
49
|
-
this.exportsAt = opts.exports === undefined ? undefined : path.resolve(opts.exports);
|
|
50
|
-
engine.graphResolver = (n) => this.graphs.get(n);
|
|
50
|
+
/** The workspace file of `dir` (the workspace's folder), checked. */
|
|
51
|
+
export function readWorkspace(dir) {
|
|
52
|
+
const file = path.join(dir, WORKSPACE_FILE);
|
|
53
|
+
let raw;
|
|
54
|
+
try {
|
|
55
|
+
raw = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
51
56
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
get exportDir() { return this.exportsAt ?? path.join(this.dir, 'exports'); }
|
|
55
|
-
/**
|
|
56
|
-
* files people drop in: meshes, guide curves and points, PNG masks and heightmaps (read as "inputs/<path>");
|
|
57
|
-
* <dir>/inputs unless the constructor was given another folder
|
|
58
|
-
*/
|
|
59
|
-
get inputDir() { return this.inputsAt ?? path.join(this.dir, 'inputs'); }
|
|
60
|
-
load() {
|
|
61
|
-
// the workspace's own inputs/ is made at once (people open it to drop files in); a folder given to the constructor
|
|
62
|
-
// is made by the first file written into it
|
|
63
|
-
for (const d of [this.dir, this.graphDir, this.assetDir, this.exportDir, ...(this.inputsAt ? [] : [this.inputDir])])
|
|
64
|
-
fs.mkdirSync(d, { recursive: true });
|
|
65
|
-
const assetErrors = [];
|
|
66
|
-
for (const f of fs.readdirSync(this.assetDir).filter((f) => f.endsWith('.json'))) {
|
|
67
|
-
try {
|
|
68
|
-
const spec = migrateGraph(JSON.parse(fs.readFileSync(path.join(this.assetDir, f), 'utf8')));
|
|
69
|
-
this.engine.registerAsset(path.basename(f, '.json'), spec);
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
assetErrors.push(`${f}: ${e.message}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
for (const f of fs.readdirSync(this.graphDir).filter((f) => f.endsWith('.json'))) {
|
|
76
|
-
// migrated in memory; the file is rewritten (with its version) on the next save
|
|
77
|
-
try {
|
|
78
|
-
this.graphs.set(path.basename(f, '.json'), migrateGraph(JSON.parse(fs.readFileSync(path.join(this.graphDir, f), 'utf8'))));
|
|
79
|
-
}
|
|
80
|
-
catch { /* skip unreadable */ }
|
|
81
|
-
}
|
|
82
|
-
// workspace assets were registered over shelf assets of the same name (engine.init loads the shelf first)
|
|
83
|
-
const defs = [...this.engine.assets.values()].map((a) => a.def);
|
|
84
|
-
return {
|
|
85
|
-
graphs: this.graphs.size, assets: defs.filter((d) => d.category !== 'shelf').length, shelf: defs.filter((d) => d.category === 'shelf').length,
|
|
86
|
-
assetErrors: [...assetErrors, ...this.engine.shelfErrors.map((e) => `shelf ${e}`)],
|
|
87
|
-
};
|
|
57
|
+
catch (e) {
|
|
58
|
+
throw new Error(`${file}: ${e.message}`);
|
|
88
59
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const file = path.join(this.graphDir, name + '.json');
|
|
92
|
-
if (!g) {
|
|
93
|
-
if (fs.existsSync(file))
|
|
94
|
-
fs.unlinkSync(file);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
fs.writeFileSync(file, JSON.stringify(g, null, 2));
|
|
60
|
+
try {
|
|
61
|
+
return parseWorkspace(raw, slugify(path.basename(path.resolve(dir))) || 'workspace');
|
|
98
62
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this.versions.set(name, v);
|
|
102
|
-
for (const l of this.listeners)
|
|
103
|
-
try {
|
|
104
|
-
l({ graph: name, version: v });
|
|
105
|
-
}
|
|
106
|
-
catch { /* ignore */ }
|
|
63
|
+
catch (e) {
|
|
64
|
+
throw new Error(`${file}: ${e.message.replace(`${WORKSPACE_FILE}: `, '')}`);
|
|
107
65
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
66
|
+
}
|
|
67
|
+
export function writeWorkspace(dir, m) {
|
|
68
|
+
const out = { name: m.name, libraries: m.libraries };
|
|
69
|
+
if (m.engine)
|
|
70
|
+
out.engine = m.engine === 'none' ? 'none' : { type: m.engine.type, project: m.engine.project };
|
|
71
|
+
if (m.follow)
|
|
72
|
+
out.follow = true;
|
|
73
|
+
if (Object.keys(m.uses).length)
|
|
74
|
+
out.uses = m.uses;
|
|
75
|
+
writeAtomic(path.join(dir, WORKSPACE_FILE), JSON.stringify(out, null, 2) + '\n');
|
|
76
|
+
forgetScans();
|
|
77
|
+
}
|
|
78
|
+
/** The engine project file a workspace names, absolute; null for none. */
|
|
79
|
+
export const engineFile = (ws, m) => (m.engine && m.engine !== 'none' ? path.resolve(ws, m.engine.project) : null);
|
|
80
|
+
/** The packages of a workspace (src/scan.ts), the folder of its own engine project scanned like any other. */
|
|
81
|
+
export function scanWorkspace(ws, m = readWorkspace(ws)) {
|
|
82
|
+
return scanTree(m.name, ws, { engine: engineFile(ws, m) });
|
|
83
|
+
}
|
|
84
|
+
const rel = (from, to) => path.relative(path.resolve(from), path.resolve(to)).split(path.sep).join('/') || '.';
|
|
85
|
+
/** "godot:game/project.godot" (or a bare path whose file name says the engine) as an engine link; the path may lead upward ("../project.godot"). */
|
|
86
|
+
export function parseEngineArg(arg, dir) {
|
|
87
|
+
const m = /^(godot|unreal):(.+)$/i.exec(arg.trim());
|
|
88
|
+
const file = (m ? m[2] : arg).trim().replace(/\\/g, '/');
|
|
89
|
+
const type = m ? m[1].toLowerCase() : engineTypeOf(file);
|
|
90
|
+
if (!type)
|
|
91
|
+
throw new Error(`--engine "${arg}": write godot:<path to project.godot>, unreal:<path to the .uproject> or none`);
|
|
92
|
+
const abs = path.resolve(dir, file);
|
|
93
|
+
if (!fs.statSync(abs, { throwIfNoEntry: false })?.isFile())
|
|
94
|
+
throw new Error(`--engine "${arg}": no file ${abs}`);
|
|
95
|
+
return { type, project: rel(dir, abs) };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The name an engine project gives itself, as a workspace name: project.godot's config/name, a .uproject's file name;
|
|
99
|
+
* null when it has none.
|
|
100
|
+
*/
|
|
101
|
+
export function engineProjectName(dir, e) {
|
|
102
|
+
const file = path.resolve(dir, e.project);
|
|
103
|
+
if (e.type === 'unreal')
|
|
104
|
+
return slugify(path.basename(file).replace(/\.uproject$/i, '')) || null;
|
|
105
|
+
try {
|
|
106
|
+
const m = /^config\/name\s*=\s*"([^"]*)"/m.exec(fs.readFileSync(file, 'utf8'));
|
|
107
|
+
return m ? slugify(m[1]) || null : null;
|
|
115
108
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
throw new Error(`graph name must match ${NAME_RE}`);
|
|
119
|
-
this.graphs.set(name, migrateGraph(spec));
|
|
120
|
-
this.persist(name);
|
|
109
|
+
catch {
|
|
110
|
+
return null;
|
|
121
111
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A name a workspace takes: refused when it is TopoTopo's built-in library's or a registered library's (workspaces and
|
|
115
|
+
* libraries share one set of names, so a web app address /p/<name>/<id> means one thing).
|
|
116
|
+
*/
|
|
117
|
+
export function checkWorkspaceName(name, how = '--name <another name>', dir) {
|
|
118
|
+
if (name === BUILTIN_LIBRARY.name)
|
|
119
|
+
throw new Error(`"${name}" is the name of TopoTopo's built-in library: give the workspace another name (${how})`);
|
|
120
|
+
let cfg;
|
|
121
|
+
try {
|
|
122
|
+
cfg = loadConfig();
|
|
126
123
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const out = [];
|
|
130
|
-
const walk = (dir, rel, depth) => {
|
|
131
|
-
let entries;
|
|
132
|
-
try {
|
|
133
|
-
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
134
|
-
}
|
|
135
|
-
catch {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
for (const e of entries) {
|
|
139
|
-
if (e.name.startsWith('.'))
|
|
140
|
-
continue;
|
|
141
|
-
const abs = path.join(dir, e.name), r = rel ? `${rel}/${e.name}` : e.name;
|
|
142
|
-
let st;
|
|
143
|
-
try {
|
|
144
|
-
st = fs.statSync(abs);
|
|
145
|
-
}
|
|
146
|
-
catch {
|
|
147
|
-
continue;
|
|
148
|
-
} // a broken link
|
|
149
|
-
if (st.isDirectory()) {
|
|
150
|
-
if (depth < 32)
|
|
151
|
-
walk(abs, r, depth + 1);
|
|
152
|
-
} // the depth cap stops link cycles
|
|
153
|
-
else if (st.isFile()) {
|
|
154
|
-
const ext = inputExt(e.name);
|
|
155
|
-
out.push({ path: r, kind: inputKind(ext), ext, size: st.size, mtime: Math.round(st.mtimeMs) });
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
walk(this.inputDir, '', 0);
|
|
160
|
-
return out.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
124
|
+
catch {
|
|
125
|
+
return;
|
|
161
126
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
127
|
+
const lib = cfg.libraries.find((l) => l.name === name);
|
|
128
|
+
if (lib)
|
|
129
|
+
throw new Error(`"${name}" is the name of a registered library (${lib.path}): workspaces and libraries share one set of names; give the workspace another name (${how})`);
|
|
130
|
+
const other = dir ? cfg.workspaces.find((w) => w.name === name && folderKey(w.path) !== folderKey(dir)) : undefined;
|
|
131
|
+
if (other)
|
|
132
|
+
throw new Error(`"${name}" is the name of another registered workspace (${other.path}): give the workspace another name (${how})`);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The entry a workspace's "libraries" gets for a library a person names (workspace library add, workspace init
|
|
136
|
+
* --library): a folder, as the person sees it (relative to `cwd`), written as its path from the workspace ("../shared");
|
|
137
|
+
* else a registered library's name. Refuses, worded for the workspace file: a folder inside the workspace or holding it
|
|
138
|
+
* (its packages are found by themselves), a package's folder, a folder on another drive, a name not registered.
|
|
139
|
+
*/
|
|
140
|
+
export function workspaceLibraryEntry(ws, given, cwd = process.cwd()) {
|
|
141
|
+
const file = path.join(ws, WORKSPACE_FILE);
|
|
142
|
+
const g = given.trim();
|
|
143
|
+
if (g === BUILTIN_LIBRARY.name)
|
|
144
|
+
throw new Error(`TopoTopo's built-in library is looked in by every package without being listed: ${file} "libraries" lists shared libraries only`);
|
|
145
|
+
const abs = path.resolve(cwd, g);
|
|
146
|
+
const isFolder = !!fs.statSync(abs, { throwIfNoEntry: false })?.isDirectory();
|
|
147
|
+
if (isFolder && (!ID_RE.test(g) || !registeredLibrary(g))) {
|
|
148
|
+
let at = null;
|
|
149
|
+
try {
|
|
150
|
+
at = manifestAt(abs);
|
|
151
|
+
}
|
|
152
|
+
catch { /* two manifests: a package's folder all the same */ }
|
|
153
|
+
if (at)
|
|
154
|
+
throw new Error(`${abs} is a package's folder (${path.basename(at.file)}), not a library: ${file} "libraries" lists the folders of shared libraries; give the library's folder, or its registered name`);
|
|
155
|
+
if (within(abs, ws))
|
|
156
|
+
throw new Error(`${abs} is inside the workspace (${ws}): its packages are found by themselves; ${file} "libraries" lists shared libraries outside it`);
|
|
157
|
+
if (within(ws, abs))
|
|
158
|
+
throw new Error(`${abs} holds the workspace (${ws}): ${file} "libraries" lists shared libraries outside it, and the workspace's own packages are found by themselves`);
|
|
159
|
+
const r = path.relative(ws, abs).split(path.sep).join('/');
|
|
160
|
+
if (path.isAbsolute(r) || /^[A-Za-z]:/.test(r))
|
|
161
|
+
throw new Error(`${abs} is on another drive than the workspace: register it (${program()} library add <name> ${abs}) and list it by its name`);
|
|
162
|
+
return r.startsWith('.') ? r : `./${r}`;
|
|
180
163
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
return n;
|
|
193
|
-
};
|
|
194
|
-
const refsTo = (target) => {
|
|
195
|
-
const out = [];
|
|
196
|
-
for (const [k, spec] of Object.entries(g.nodes)) {
|
|
197
|
-
if (Array.isArray(spec.in))
|
|
198
|
-
spec.in.forEach((r, i) => r === target && out.push({ node: k, idx: i }));
|
|
199
|
-
else if (typeof spec.in === 'string') {
|
|
200
|
-
if (spec.in === target)
|
|
201
|
-
out.push({ node: k, idx: 0 });
|
|
202
|
-
}
|
|
203
|
-
else if (spec.in && typeof spec.in === 'object')
|
|
204
|
-
for (const [ik, r] of Object.entries(spec.in))
|
|
205
|
-
if (r === target)
|
|
206
|
-
out.push({ node: k, idx: ik });
|
|
207
|
-
}
|
|
208
|
-
return out;
|
|
209
|
-
};
|
|
210
|
-
const setRef = (node, idx, value) => {
|
|
211
|
-
const spec = g.nodes[node];
|
|
212
|
-
if (typeof spec.in === 'string')
|
|
213
|
-
spec.in = [value];
|
|
214
|
-
else if (Array.isArray(spec.in))
|
|
215
|
-
spec.in[idx] = value;
|
|
216
|
-
else if (spec.in && typeof spec.in === 'object')
|
|
217
|
-
spec.in[idx] = value;
|
|
218
|
-
};
|
|
219
|
-
for (const [i, op] of ops.entries()) {
|
|
220
|
-
const where = `op ${i} (${op.op})`;
|
|
221
|
-
switch (op.op) {
|
|
222
|
-
case 'set': {
|
|
223
|
-
const n = need(op.node, where);
|
|
224
|
-
const spec = g.nodes[n];
|
|
225
|
-
spec.params = { ...(spec.params ?? {}) };
|
|
226
|
-
for (const [k, v] of Object.entries(op.params ?? {})) {
|
|
227
|
-
if (v === null)
|
|
228
|
-
delete spec.params[k];
|
|
229
|
-
else
|
|
230
|
-
spec.params[k] = v;
|
|
231
|
-
}
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
case 'add': {
|
|
235
|
-
if (!op.node || !NAME_RE.test(op.node))
|
|
236
|
-
throw new Error(`${where}: "node" must be a valid new node name`);
|
|
237
|
-
if (g.nodes[op.node])
|
|
238
|
-
throw new Error(`${where}: node "${op.node}" already exists (use set/replace)`);
|
|
239
|
-
g.nodes[op.node] = op.spec ?? { type: op.type, ...(op.in !== undefined ? { in: op.in } : {}), ...(op.params ? { params: op.params } : {}) };
|
|
240
|
-
if (!g.nodes[op.node].type)
|
|
241
|
-
throw new Error(`${where}: "type" is required`);
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
case 'replace': {
|
|
245
|
-
const n = need(op.node, where);
|
|
246
|
-
g.nodes[n] = op.spec ?? { ...g.nodes[n], ...(op.type ? { type: op.type } : {}), ...(op.params ? { params: op.params } : {}), ...(op.in !== undefined ? { in: op.in } : {}) };
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
case 'remove': {
|
|
250
|
-
const n = need(op.node, where);
|
|
251
|
-
const refs = refsTo(n);
|
|
252
|
-
// reconnect consumers to this node's first input when possible
|
|
253
|
-
const def = this.engine.resolveDef(g.nodes[n].type);
|
|
254
|
-
const up = def ? wiringOf(g.nodes[n], def).list[0] ?? null : null;
|
|
255
|
-
for (const r of refs)
|
|
256
|
-
setRef(r.node, r.idx, up);
|
|
257
|
-
if (refs.length)
|
|
258
|
-
notes.push(`removed "${n}"; rewired ${refs.map((r) => r.node).join(', ')} to ${up ?? '(nothing)'}`);
|
|
259
|
-
delete g.nodes[n];
|
|
260
|
-
if (g.output === n)
|
|
261
|
-
delete g.output;
|
|
262
|
-
for (const [id, out] of Object.entries(g.outputs ?? {}))
|
|
263
|
-
if (out.node === n)
|
|
264
|
-
delete g.outputs[id];
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
|
-
case 'connect': {
|
|
268
|
-
const n = need(op.node, where);
|
|
269
|
-
if (op.in !== undefined)
|
|
270
|
-
g.nodes[n].in = op.in;
|
|
271
|
-
else if (op.input !== undefined) {
|
|
272
|
-
const spec = g.nodes[n];
|
|
273
|
-
const def = this.engine.resolveDef(spec.type);
|
|
274
|
-
const list = def ? wiringOf(spec, def).list.slice() : [];
|
|
275
|
-
while (list.length <= op.input)
|
|
276
|
-
list.push(null);
|
|
277
|
-
list[op.input] = op.from ?? null;
|
|
278
|
-
spec.in = list;
|
|
279
|
-
}
|
|
280
|
-
else
|
|
281
|
-
throw new Error(`${where}: give "in" (full wiring) or "input" + "from"`);
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
case 'rename': {
|
|
285
|
-
const n = need(op.node, where);
|
|
286
|
-
if (!op.to || !NAME_RE.test(op.to) || g.nodes[op.to])
|
|
287
|
-
throw new Error(`${where}: "to" must be a new valid name`);
|
|
288
|
-
g.nodes[op.to] = g.nodes[n];
|
|
289
|
-
delete g.nodes[n];
|
|
290
|
-
for (const r of refsTo(n))
|
|
291
|
-
setRef(r.node, r.idx, op.to);
|
|
292
|
-
if (g.output === n)
|
|
293
|
-
g.output = op.to;
|
|
294
|
-
for (const out of Object.values(g.outputs ?? {}))
|
|
295
|
-
if (out.node === n)
|
|
296
|
-
out.node = op.to;
|
|
297
|
-
// expression references: npoints("old"), ch("old/param") …
|
|
298
|
-
const touched = [];
|
|
299
|
-
for (const [k, spec] of Object.entries(g.nodes)) {
|
|
300
|
-
if (!spec.params)
|
|
301
|
-
continue;
|
|
302
|
-
const before = JSON.stringify(spec.params);
|
|
303
|
-
spec.params = Object.fromEntries(Object.entries(spec.params).map(([pk, pv]) => [pk, renameExprRefs(pv, n, op.to)]));
|
|
304
|
-
if (JSON.stringify(spec.params) !== before)
|
|
305
|
-
touched.push(k);
|
|
306
|
-
}
|
|
307
|
-
if (touched.length)
|
|
308
|
-
notes.push(`updated expression references to "${n}" in ${touched.join(', ')}`);
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
case 'output':
|
|
312
|
-
g.output = need(op.node, where);
|
|
313
|
-
break;
|
|
314
|
-
case 'vars': {
|
|
315
|
-
g.vars = { ...(g.vars ?? {}) };
|
|
316
|
-
for (const [k, v] of Object.entries(op.vars ?? {})) {
|
|
317
|
-
if (v === null)
|
|
318
|
-
delete g.vars[k];
|
|
319
|
-
else
|
|
320
|
-
g.vars[k] = v;
|
|
321
|
-
}
|
|
322
|
-
break;
|
|
323
|
-
}
|
|
324
|
-
case 'bypass':
|
|
325
|
-
g.nodes[need(op.node, where)].bypass = op.value ?? true;
|
|
326
|
-
break;
|
|
327
|
-
case 'export': {
|
|
328
|
-
// the target of the default output, or of a named one; null removes it (validated with the graph)
|
|
329
|
-
if (op.export === undefined)
|
|
330
|
-
throw new Error(`${where}: give "export": a format ("glb"), {format, path?, ...options}, or null`);
|
|
331
|
-
if (op.output === undefined) {
|
|
332
|
-
if (op.export === null)
|
|
333
|
-
delete g.export;
|
|
334
|
-
else
|
|
335
|
-
g.export = op.export;
|
|
336
|
-
break;
|
|
337
|
-
}
|
|
338
|
-
const out = g.outputs?.[op.output];
|
|
339
|
-
if (!out) {
|
|
340
|
-
const s = didYouMean(op.output, Object.keys(g.outputs ?? {}));
|
|
341
|
-
throw new Error(`${where}: no output "${op.output}"${s.length ? ` — did you mean ${s.join(', ')}?` : ''} (publish it in "outputs" first)`);
|
|
342
|
-
}
|
|
343
|
-
if (op.export === null)
|
|
344
|
-
delete out.export;
|
|
345
|
-
else
|
|
346
|
-
out.export = op.export;
|
|
347
|
-
break;
|
|
348
|
-
}
|
|
349
|
-
case 'insert': {
|
|
350
|
-
const after = need(op.after, `${where} after`);
|
|
351
|
-
if (!op.node || !NAME_RE.test(op.node) || g.nodes[op.node])
|
|
352
|
-
throw new Error(`${where}: "node" must be a new valid name`);
|
|
353
|
-
if (!op.type && !op.spec)
|
|
354
|
-
throw new Error(`${where}: "type" is required`);
|
|
355
|
-
const consumers = refsTo(after);
|
|
356
|
-
g.nodes[op.node] = op.spec ?? { type: op.type, in: [after], ...(op.params ? { params: op.params } : {}) };
|
|
357
|
-
for (const r of consumers)
|
|
358
|
-
setRef(r.node, r.idx, op.node);
|
|
359
|
-
if (g.output === after)
|
|
360
|
-
g.output = op.node;
|
|
361
|
-
notes.push(`inserted "${op.node}" after "${after}"${consumers.length ? `; now feeds ${consumers.map((c) => c.node).join(', ')}` : ''}`);
|
|
362
|
-
break;
|
|
363
|
-
}
|
|
364
|
-
default: throw new Error(`${where}: unknown op. Use set, add, remove, connect, rename, output, vars, bypass, replace, insert, export`);
|
|
365
|
-
}
|
|
164
|
+
const k = libraryEntry(g);
|
|
165
|
+
if ('error' in k)
|
|
166
|
+
throw new Error(`${isFolder ? '' : `no folder ${abs}, and `}${k.error}`);
|
|
167
|
+
if ('path' in k)
|
|
168
|
+
throw new Error(`no folder ${abs}: give the library's folder, or its registered name`);
|
|
169
|
+
const lib = registeredLibrary(g);
|
|
170
|
+
if (!lib) {
|
|
171
|
+
let names = 'none are registered';
|
|
172
|
+
try {
|
|
173
|
+
names = loadConfig().libraries.map((l) => l.name).join(', ') || names;
|
|
366
174
|
}
|
|
367
|
-
|
|
175
|
+
catch { /* said as none */ }
|
|
176
|
+
throw new Error(`"${g}" is no folder here and no registered library (${names}): ${file} "libraries" lists a registered library by its name; register it first (${program()} library add ${g} <folder>), or give the library's folder`);
|
|
368
177
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
178
|
+
if (within(lib.path, ws))
|
|
179
|
+
throw new Error(`library "${g}" (${lib.path}) is inside the workspace: its packages are found by themselves; ${file} "libraries" lists shared libraries outside it`);
|
|
180
|
+
if (within(ws, lib.path))
|
|
181
|
+
throw new Error(`library "${g}" (${lib.path}) holds the workspace: ${file} "libraries" lists shared libraries outside it`);
|
|
182
|
+
return g;
|
|
183
|
+
}
|
|
184
|
+
const registeredLibrary = (name) => { try {
|
|
185
|
+
return loadConfig().libraries.find((l) => l.name === name) ?? null;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return null;
|
|
189
|
+
} };
|
|
190
|
+
/** The workspace around a folder, or an error saying there is none and how one is made. */
|
|
191
|
+
function workspaceOf(start) {
|
|
192
|
+
const at = locate(start);
|
|
193
|
+
if (at.outside)
|
|
194
|
+
throw new Error(`${path.resolve(start)} is in no workspace: the workspace ${at.outside.workspace} does not look in it (${at.outside.why}); outside a workspace every registered library counts`);
|
|
195
|
+
if (!at.workspace)
|
|
196
|
+
throw new Error(`${path.resolve(start)} is in no workspace: ${program()} workspace init <folder> makes one; outside a workspace every registered library counts`);
|
|
197
|
+
return at.workspace;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Add a shared library to the workspace's "libraries", or remove one (`topotopo workspace library add|remove`, MCP
|
|
201
|
+
* workspace {action:"libraries"}): the workspace around `at` (default: the current folder). A library is given as a
|
|
202
|
+
* folder, as the person sees it from `cwd`, or by its registered name. Changes the list only. Says what it lists now.
|
|
203
|
+
*/
|
|
204
|
+
export function workspaceLibrary(op, given, o = {}) {
|
|
205
|
+
const cwd = o.cwd ?? process.cwd();
|
|
206
|
+
const ws = workspaceOf(o.at ?? cwd);
|
|
207
|
+
const m = readWorkspace(ws), file = path.join(ws, WORKSPACE_FILE);
|
|
208
|
+
// entries are one library when they name one folder: a registered name and a path to its folder alike
|
|
209
|
+
const folderOf = (e) => {
|
|
210
|
+
const k = libraryEntry(e);
|
|
211
|
+
return 'path' in k ? folderKey(path.resolve(ws, k.path)) : 'name' in k && registeredLibrary(e) ? folderKey(registeredLibrary(e).path) : null;
|
|
212
|
+
};
|
|
213
|
+
if (op === 'add') {
|
|
214
|
+
const entry = workspaceLibraryEntry(ws, given, cwd), at = folderOf(entry);
|
|
215
|
+
const have = m.libraries.find((e) => e === entry || (at !== null && folderOf(e) === at));
|
|
216
|
+
if (have)
|
|
217
|
+
return `${file} lists "${entry}" already${have !== entry ? ` (as "${have}", the same folder)` : ''}\n${librariesLine(ws, m)}`;
|
|
218
|
+
m.libraries.push(entry);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
const g = given.trim(), reg = ID_RE.test(g) ? registeredLibrary(g) : null;
|
|
222
|
+
const at = folderKey(reg ? reg.path : path.resolve(cwd, g));
|
|
223
|
+
const gone = m.libraries.filter((e) => e === g || e === g.replace(/\\/g, '/') || folderOf(e) === at);
|
|
224
|
+
if (!gone.length)
|
|
225
|
+
throw new Error(`${file} does not list "${given}": it lists ${m.libraries.map((e) => `"${e}"`).join(', ') || 'no libraries'}`);
|
|
226
|
+
m.libraries = m.libraries.filter((e) => !gone.includes(e));
|
|
227
|
+
}
|
|
228
|
+
writeWorkspace(ws, m);
|
|
229
|
+
return `the workspace "${m.name}" lists ${m.libraries.length ? m.libraries.map((e) => `"${e}"`).join(', ') : 'no libraries'} in ${file} "libraries" now\n${librariesLine(ws, m)}`;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The shared libraries the workspace around a folder lists and where its packages find packages (MCP workspace
|
|
233
|
+
* {action:"libraries"}); outside a workspace, that every registered library counts.
|
|
234
|
+
*/
|
|
235
|
+
export function workspaceLibrariesText(start) {
|
|
236
|
+
const ws = locate(start).workspace;
|
|
237
|
+
if (!ws) {
|
|
238
|
+
let names = 'none is registered';
|
|
382
239
|
try {
|
|
383
|
-
|
|
240
|
+
names = loadConfig().libraries.map((l) => `"${l.name}"`).join(', ') || names;
|
|
384
241
|
}
|
|
385
|
-
|
|
386
|
-
|
|
242
|
+
catch { /* said as none */ }
|
|
243
|
+
return `${path.resolve(start)} is in no workspace: its package finds packages in every registered library (${names}), then in TopoTopo's built-in library; ${program()} workspace init <folder> makes a workspace, whose ${WORKSPACE_FILE} lists the shared libraries its packages use`;
|
|
244
|
+
}
|
|
245
|
+
const m = readWorkspace(ws);
|
|
246
|
+
return `the workspace "${m.name}" lists ${m.libraries.length ? m.libraries.map((e) => `"${e}"`).join(', ') : 'no libraries'} in ${path.join(ws, WORKSPACE_FILE)} "libraries"
|
|
247
|
+
${librariesLine(ws, m)}`;
|
|
248
|
+
}
|
|
249
|
+
/** Where a workspace's packages find packages, in a line, and what is wrong with its list. */
|
|
250
|
+
function librariesLine(ws, m) {
|
|
251
|
+
const libs = resolveListed(ws, m.libraries);
|
|
252
|
+
return [
|
|
253
|
+
`its packages find packages in the workspace itself, then in ${libs.libs.length ? libs.libs.map((l) => `library "${l.name}" (${l.root})`).join(', ') : 'no shared library'}, then in TopoTopo's built-in library`,
|
|
254
|
+
...libs.problems.map((p) => `problem: ${p}`),
|
|
255
|
+
].join('\n');
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Make `dir` a workspace: topotopo-workspace.json with its name (the engine project's, else the folder's), the shared
|
|
259
|
+
* libraries given and the engine project (given, or found: the nearest at or above the folder, else below it; "none"
|
|
260
|
+
* for none, kept). A folder that is a workspace already is changed only where an option says so (its name, engine and
|
|
261
|
+
* follow; --library is for making one). It then says what Unreal will not see, the packages outside the engine
|
|
262
|
+
* project's folder, the Godot export presets that would ship TopoTopo's files; keeps Godot's importer out of the
|
|
263
|
+
* packages' working folders (.gdignore); and moves the copies of the packages inside into the workspace's one copy.
|
|
264
|
+
*/
|
|
265
|
+
export function initWorkspace(dir, o = {}) {
|
|
266
|
+
const abs = path.resolve(dir);
|
|
267
|
+
if (o.assets !== undefined)
|
|
268
|
+
throw new Error(assetsGone('--assets'));
|
|
269
|
+
if (!fs.statSync(abs, { throwIfNoEntry: false })?.isDirectory())
|
|
270
|
+
throw new Error(`${abs} is no folder`);
|
|
271
|
+
const had = fs.existsSync(path.join(abs, WORKSPACE_FILE));
|
|
272
|
+
const m = had ? readWorkspace(abs) : { name: slugify(path.basename(abs)) || 'workspace', libraries: [], engine: null, follow: false, uses: {} };
|
|
273
|
+
if (had && o.libraries?.length)
|
|
274
|
+
throw new Error(`--library is for making a workspace, and ${abs} is the workspace "${m.name}" already: ${program()} workspace library add <name or folder>${workspaceFlag(abs, o.cwd)} lists a library for it`);
|
|
275
|
+
if (o.name !== undefined) {
|
|
276
|
+
if (!ID_RE.test(o.name))
|
|
277
|
+
throw new Error(`--name "${o.name}": lower-case letters, digits, - and _ ("my-game")`);
|
|
278
|
+
m.name = o.name;
|
|
279
|
+
}
|
|
280
|
+
let found = '';
|
|
281
|
+
if (o.engine === 'none')
|
|
282
|
+
m.engine = 'none';
|
|
283
|
+
else if (o.engine)
|
|
284
|
+
m.engine = parseEngineArg(o.engine, abs);
|
|
285
|
+
else if (!had || m.engine === null) {
|
|
286
|
+
const d = detectEngine(abs);
|
|
287
|
+
if (d) {
|
|
288
|
+
m.engine = d.link;
|
|
289
|
+
found = d.below.length ? (d.below.length > 1 ? ` (found below the workspace, ${d.below.length}: ${d.below.map((e) => e.project).join(', ')}; --engine picks another)` : ' (found below the workspace)') : ' (found at or above the workspace)';
|
|
387
290
|
}
|
|
388
|
-
return { graph: this.getGraph(name), notes, report };
|
|
389
291
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
292
|
+
// a new workspace is named after its engine project when that has a name (a checkout's folder may be named otherwise)
|
|
293
|
+
if (!had && o.name === undefined && m.engine && m.engine !== 'none')
|
|
294
|
+
m.name = engineProjectName(abs, m.engine) ?? m.name;
|
|
295
|
+
if (!had || o.name !== undefined)
|
|
296
|
+
checkWorkspaceName(m.name, o.name === undefined ? `--name <another name>: it took "${m.name}" from ${m.engine && m.engine !== 'none' ? 'its engine project' : 'its folder'}` : '--name <another name>', abs);
|
|
297
|
+
for (const l of o.libraries ?? []) {
|
|
298
|
+
const entry = workspaceLibraryEntry(abs, l, o.cwd);
|
|
299
|
+
if (!m.libraries.includes(entry))
|
|
300
|
+
m.libraries.push(entry);
|
|
396
301
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
const on = (dir, apply) => {
|
|
410
|
-
try {
|
|
411
|
-
const w = fs.watch(dir, (_ev, f) => {
|
|
412
|
-
const rel = f ? String(f) : '';
|
|
413
|
-
// Windows names a removed folder by its absolute path: stop rather than follow a folder that is gone
|
|
414
|
-
if (path.isAbsolute(rel)) {
|
|
415
|
-
w.close();
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
if (!rel.endsWith('.json') || rel.includes(path.sep) || rel.startsWith('.'))
|
|
419
|
-
return;
|
|
420
|
-
const name = rel.slice(0, -'.json'.length), key = dir + '|' + name;
|
|
421
|
-
clearTimeout(this.watchTimers.get(key));
|
|
422
|
-
// persist() is not atomic: let the writer finish, and read again if the JSON is still half written
|
|
423
|
-
let tries = 0;
|
|
424
|
-
const run = () => {
|
|
425
|
-
this.watchTimers.delete(key);
|
|
426
|
-
try {
|
|
427
|
-
apply(name, path.join(dir, rel));
|
|
428
|
-
}
|
|
429
|
-
catch (e) {
|
|
430
|
-
if (e instanceof SyntaxError && ++tries < 5)
|
|
431
|
-
this.watchTimers.set(key, setTimeout(run, 100).unref());
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
this.watchTimers.set(key, setTimeout(run, 150).unref());
|
|
435
|
-
});
|
|
436
|
-
w.on('error', () => w.close());
|
|
437
|
-
w.unref();
|
|
438
|
-
this.watchers.push(w);
|
|
439
|
-
}
|
|
440
|
-
catch { /* no folder: nothing to follow */ }
|
|
441
|
-
};
|
|
442
|
-
on(this.graphDir, (name, file) => {
|
|
443
|
-
if (!NAME_RE.test(name))
|
|
444
|
-
return;
|
|
445
|
-
if (!fs.existsSync(file)) {
|
|
446
|
-
if (this.graphs.delete(name)) {
|
|
447
|
-
this.lastReport.delete(name);
|
|
448
|
-
this.bump(name);
|
|
449
|
-
}
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
const spec = migrateGraph(JSON.parse(fs.readFileSync(file, 'utf8')));
|
|
453
|
-
const cur = this.graphs.get(name);
|
|
454
|
-
if (cur && JSON.stringify(cur) === JSON.stringify(spec))
|
|
455
|
-
return;
|
|
456
|
-
this.graphs.set(name, spec);
|
|
457
|
-
this.lastReport.delete(name);
|
|
458
|
-
this.bump(name);
|
|
459
|
-
});
|
|
460
|
-
on(this.assetDir, (name, file) => {
|
|
461
|
-
if (!fs.existsSync(file))
|
|
462
|
-
return;
|
|
463
|
-
const spec = migrateGraph(JSON.parse(fs.readFileSync(file, 'utf8')));
|
|
464
|
-
const before = this.engine.assets.get(name)?.hash;
|
|
465
|
-
this.engine.registerAsset(name, spec);
|
|
466
|
-
if (this.engine.assets.get(name)?.hash === before)
|
|
467
|
-
return;
|
|
468
|
-
for (const g of this.graphs.keys()) {
|
|
469
|
-
this.lastReport.delete(g);
|
|
470
|
-
this.bump(g);
|
|
471
|
-
}
|
|
472
|
-
});
|
|
302
|
+
if (o.follow !== undefined)
|
|
303
|
+
m.follow = o.follow;
|
|
304
|
+
writeWorkspace(abs, m);
|
|
305
|
+
workspaceRepoFiles(abs);
|
|
306
|
+
// a registered workspace renamed is registered again under its new name (the old one would name nothing)
|
|
307
|
+
let registered = '';
|
|
308
|
+
try {
|
|
309
|
+
const was = loadConfig().workspaces.find((w) => folderKey(w.path) === folderKey(abs));
|
|
310
|
+
if (was && was.name !== m.name) {
|
|
311
|
+
addWorkspace(m.name, abs);
|
|
312
|
+
registered = `registered again under its new name "${m.name}" (it was "${was.name}")`;
|
|
313
|
+
}
|
|
473
314
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
for (const w of this.watchers)
|
|
477
|
-
w.close();
|
|
478
|
-
for (const t of this.watchTimers.values())
|
|
479
|
-
clearTimeout(t);
|
|
480
|
-
this.watchers = [];
|
|
481
|
-
this.watchTimers.clear();
|
|
315
|
+
catch (e) {
|
|
316
|
+
registered = `still registered under its old name: ${e.message}`;
|
|
482
317
|
}
|
|
318
|
+
const scan = scanWorkspace(abs, m);
|
|
319
|
+
const engineLines = [];
|
|
320
|
+
const project = engineFile(abs, m);
|
|
321
|
+
if (m.engine && m.engine !== 'none' && project) {
|
|
322
|
+
if (m.engine.type === 'unreal' && !unrealSees(abs, project))
|
|
323
|
+
engineLines.push(` Unreal will not see this workspace: it imports only what lies under the project's Content/ folder (or a plugin's Content/); move the workspace there, so the engine imports each package's exports/`);
|
|
324
|
+
const home = path.dirname(project);
|
|
325
|
+
if (within(home, abs) && path.resolve(home) !== abs) {
|
|
326
|
+
const outside = scan.packages.filter((p) => !within(p.dir, home)).map((p) => p.rel);
|
|
327
|
+
if (outside.length)
|
|
328
|
+
engineLines.push(` packages outside the engine project's folder (${rel(abs, home)}/), whose exports the engine does not import: ${outside.slice(0, 20).join(', ')}${outside.length > 20 ? ` and ${outside.length - 20} more` : ''}`);
|
|
329
|
+
}
|
|
330
|
+
if (m.engine.type === 'godot')
|
|
331
|
+
engineLines.push(...godotPresetReport(home).map((l) => ` ${l}`));
|
|
332
|
+
}
|
|
333
|
+
// Godot imports none of TopoTopo's working folders (versions/, packages/, inputs/)
|
|
334
|
+
const ignored = scan.packages.flatMap((p) => godotIgnore(p.dir));
|
|
335
|
+
// the packages inside that kept their own copies share the workspace's now
|
|
336
|
+
const gathered = gatherCopies(abs);
|
|
337
|
+
const libs = resolveListed(abs, m.libraries);
|
|
338
|
+
const text = [
|
|
339
|
+
`${had ? 'updated' : 'made'} the workspace "${m.name}" (${path.join(abs, WORKSPACE_FILE)})${registered ? `; ${registered}` : ''}`,
|
|
340
|
+
`engine: ${m.engine === 'none' ? 'none (kept: --engine godot:<path> or unreal:<path> names one)' : m.engine ? `${m.engine.type} ${m.engine.project}${found}` : `none found (--engine godot:<path>|unreal:<path>|none)`}`,
|
|
341
|
+
...engineLines,
|
|
342
|
+
`shared libraries: ${libs.libs.length ? libs.libs.map((l) => l.entry).join(', ') : `none yet (${program()} workspace library add <name or folder>${workspaceFlag(abs, o.cwd)} lists one)`}; its packages find each other by themselves, then look in these, then in TopoTopo's built-in library`,
|
|
343
|
+
...libs.problems.map((p) => ` problem: ${p}`),
|
|
344
|
+
`packages: ${scan.packages.length}${scan.workspaces.length ? `; other workspaces inside, not scanned: ${scan.workspaces.map((w) => rel(abs, w)).join(', ')}` : ''}`,
|
|
345
|
+
`follow its own packages live: ${m.follow ? 'on (their working folders inside the workspace show in the viewer and renders, for looking; exports use the published versions)' : 'off'}`,
|
|
346
|
+
...(ignored.length ? [`kept Godot's importer out of the packages' working folders: added ${ignored.length} .gdignore file${ignored.length === 1 ? '' : 's'} (versions/, packages/, inputs/)`] : []),
|
|
347
|
+
...gathered,
|
|
348
|
+
].join('\n');
|
|
349
|
+
return { dir: abs, manifest: m, text };
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* The workspace around a folder in a few lines: its name and file, its engine project, the shared libraries it lists
|
|
353
|
+
* (and what is wrong with an entry), whether it follows its own packages, and the packages inside it (scanned) with
|
|
354
|
+
* what they publish and use. Throws when the folder is in no workspace, saying how one is made.
|
|
355
|
+
*/
|
|
356
|
+
export function workspaceText(start) {
|
|
357
|
+
const ws = workspaceOf(start);
|
|
358
|
+
const m = readWorkspace(ws);
|
|
359
|
+
const libs = resolveListed(ws, m.libraries);
|
|
360
|
+
const scan = scanWorkspace(ws, m);
|
|
361
|
+
const lines = [
|
|
362
|
+
`workspace "${m.name}" (${path.join(ws, WORKSPACE_FILE)})`,
|
|
363
|
+
`engine: ${m.engine === 'none' ? 'none' : m.engine ? `${m.engine.type} ${m.engine.project}` : 'none found'}`,
|
|
364
|
+
`shared libraries: ${libs.libs.length ? libs.libs.map((l) => `${l.entry} (${l.root}${l.name !== l.entry ? `, named "${l.name}"` : ''})`).join(', ') : 'none'}; its packages find each other by themselves, then look in these, then in TopoTopo's built-in library`,
|
|
365
|
+
`follow its own packages live: ${m.follow ? 'on (the working folders of its own packages, for looking; exports use the published versions)' : 'off'}`,
|
|
366
|
+
`uses: ${Object.keys(m.uses).length ? Object.entries(m.uses).map(([k, v]) => `${k} ${v}`).join(', ') : 'nothing yet'}; one copy for every package inside (${WORKSPACE_PACKAGES}/), the packages that publish keep their own`,
|
|
367
|
+
`packages: ${scan.packages.length}`,
|
|
368
|
+
...scan.packages.slice(0, 40).map((p) => {
|
|
369
|
+
const own = copiesFor(p.dir).workspace === null;
|
|
370
|
+
const uses = Object.entries(p.manifest.uses);
|
|
371
|
+
const listed = uses.map(([k, v]) => `${k} ${v}`).join(', ');
|
|
372
|
+
return ` ${p.rel}${p.manifest.name ? ` package ${p.manifest.name}` : ''}${!uses.length ? '' : own ? ` uses ${listed} (its own copies)` : ` its manifest still uses ${listed}: ${program()} workspace init ${ws} moves them into the workspace's`}`;
|
|
373
|
+
}),
|
|
374
|
+
...(scan.packages.length > 40 ? [` … ${scan.packages.length - 40} more`] : []),
|
|
375
|
+
...(scan.workspaces.length ? [`other workspaces inside, not scanned: ${scan.workspaces.map((w) => rel(ws, w)).join(', ')}`] : []),
|
|
376
|
+
];
|
|
377
|
+
const problems = [...libs.problems, ...scan.problems];
|
|
378
|
+
if (problems.length)
|
|
379
|
+
lines.push(`problems: ${problems.length}`, ...problems.map((x) => ` ${x}`));
|
|
380
|
+
return lines.join('\n');
|
|
483
381
|
}
|