topotopo 0.3.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 +40 -10
- package/README.md +475 -111
- package/dist/cli.js +328 -133
- package/dist/config.d.ts +48 -0
- package/dist/config.js +170 -0
- package/dist/core/analysis.d.ts +5 -1
- package/dist/core/analysis.js +8 -3
- package/dist/core/bake.d.ts +16 -8
- package/dist/core/bake.js +165 -29
- package/dist/core/bevel.d.ts +3 -1
- package/dist/core/bevel.js +238 -97
- 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 +204 -4
- package/dist/core/heightfield.d.ts +27 -4
- package/dist/core/heightfield.js +54 -16
- package/dist/core/imageops.d.ts +6 -0
- package/dist/core/imageops.js +51 -0
- 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 +11 -0
- package/dist/core/materials.js +56 -0
- package/dist/core/noise.d.ts +9 -0
- package/dist/core/noise.js +10 -1
- package/dist/core/packed.js +11 -0
- package/dist/core/particles.d.ts +1 -1
- package/dist/core/particles.js +1 -1
- package/dist/core/polymerge.d.ts +21 -0
- package/dist/core/polymerge.js +327 -0
- package/dist/core/rbd.js +13 -1
- 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/scatter.d.ts +1 -1
- package/dist/core/scatter.js +1 -1
- package/dist/core/scene.d.ts +20 -0
- package/dist/core/scene.js +72 -0
- 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 +15 -2
- package/dist/core/snippet-lib.js +40 -14
- package/dist/core/solidify.d.ts +38 -0
- package/dist/core/solidify.js +356 -0
- package/dist/core/tangents.d.ts +54 -0
- package/dist/core/tangents.js +218 -0
- package/dist/core/texcoord.d.ts +4 -0
- package/dist/core/texcoord.js +14 -0
- 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 +32 -0
- package/dist/core/topology.js +238 -7
- package/dist/core/traceimage.d.ts +7 -0
- package/dist/core/traceimage.js +221 -0
- package/dist/core/tritri.d.ts +5 -0
- package/dist/core/tritri.js +120 -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 +15 -16
- package/dist/core/uv.js +36 -189
- 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 +127 -0
- package/dist/core/uvreport.js +372 -0
- 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 +95 -61
- 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 +5 -3
- package/dist/index.js +3 -2
- package/dist/inspect.d.ts +84 -1
- package/dist/inspect.js +271 -24
- package/dist/io/common.d.ts +33 -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 +355 -51
- 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 +149 -14
- 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 +816 -119
- package/dist/mcp/inputs.d.ts +12 -5
- package/dist/mcp/inputs.js +50 -13
- package/dist/mcp/server.js +70 -24
- package/dist/mcp/tools.d.ts +14 -7
- package/dist/mcp/tools.js +207 -108
- 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 +207 -83
- package/dist/nodes/beam.d.ts +1 -0
- package/dist/nodes/beam.js +201 -0
- package/dist/nodes/bevel.js +54 -5
- package/dist/nodes/cloth.js +2 -0
- package/dist/nodes/code.js +22 -10
- package/dist/nodes/curves.js +440 -93
- package/dist/nodes/flow.js +53 -33
- package/dist/nodes/generate.js +13 -39
- package/dist/nodes/heightfield.js +248 -77
- package/dist/nodes/imageops.d.ts +1 -0
- package/dist/nodes/imageops.js +203 -0
- package/dist/nodes/index.d.ts +4 -0
- package/dist/nodes/index.js +4 -0
- package/dist/nodes/material.js +91 -23
- package/dist/nodes/measure.js +45 -18
- package/dist/nodes/particles.js +2 -0
- package/dist/nodes/pcg.js +6 -5
- package/dist/nodes/procedural.js +4 -3
- package/dist/nodes/rbd.js +1 -1
- package/dist/nodes/remesh.js +71 -15
- package/dist/nodes/scene.d.ts +1 -0
- package/dist/nodes/scene.js +55 -0
- package/dist/nodes/sdf.js +10 -5
- package/dist/nodes/solid.js +20 -5
- package/dist/nodes/solidify.d.ts +1 -0
- package/dist/nodes/solidify.js +52 -0
- 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 +11 -3
- package/dist/nodes/util.d.ts +1 -1
- package/dist/nodes/uv.js +192 -174
- package/dist/nodes/wasmcall.js +6 -2
- 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/pbr.d.ts +28 -0
- package/dist/render/pbr.js +378 -0
- package/dist/render/preview.d.ts +69 -0
- package/dist/render/preview.js +26 -0
- package/dist/render/raster.d.ts +78 -7
- package/dist/render/raster.js +600 -145
- package/dist/render/texview.d.ts +7 -1
- package/dist/render/texview.js +34 -2
- 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/camera.js +1 -1
- package/dist/viewer/app/cooking.js +78 -0
- package/dist/viewer/app/embed.js +100 -0
- package/dist/viewer/app/export-popover.js +118 -16
- package/dist/viewer/app/grid.js +6 -2
- package/dist/viewer/app/guides.js +123 -1
- package/dist/viewer/app/keymap.js +7 -4
- package/dist/viewer/app/layers.js +5 -5
- package/dist/viewer/app/main.js +186 -53
- package/dist/viewer/app/markers.js +61 -1
- 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 +177 -53
- package/dist/viewer/app/scene.js +35 -6
- package/dist/viewer/app/select.js +5 -4
- package/dist/viewer/app/selection.js +1 -1
- package/dist/viewer/app/status.js +12 -15
- package/dist/viewer/app/style.css +66 -8
- package/dist/viewer/app/units.js +1 -1
- package/dist/viewer/app/vars.js +48 -1
- 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 +24 -11
- 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 +24 -7
- package/dist/viewer/server.js +289 -31
- package/dist/web/app/web.css +419 -0
- package/dist/web/app/web.js +188 -0
- package/dist/web/bake.d.ts +34 -0
- package/dist/web/bake.js +153 -0
- 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 -105
- package/dist/workspace.js +359 -375
- 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 +23 -29
- package/kernels/pkg-simd/README.md +23 -29
- 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 +23 -8
- package/dist/graph/migrate.d.ts +0 -23
- package/dist/graph/migrate.js +0 -58
- package/shelf/index.json +0 -190
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
// The web app's commands (src/cli.ts dispatches here):
|
|
2
|
+
// topotopo web [--port 7340] [--library <folder>] [--no-bake] the web app on 127.0.0.1
|
|
3
|
+
// topotopo library add <name> <folder> register a folder as a library (~/.topotopo/config.json)
|
|
4
|
+
// topotopo library remove <name> unregister a library (its folder stays as it is)
|
|
5
|
+
// topotopo library list the registered libraries, their packages and problems
|
|
6
|
+
// topotopo library new <library or workspace> <folder/name> [--title t] [--tags a,b] [--description d]
|
|
7
|
+
// topotopo library bake <package folder> | --stale | --all bake previews in this process
|
|
8
|
+
// topotopo edit [folder] [--port 7341] [--json] the live viewer on a package (the web app's editor)
|
|
9
|
+
// and the packages a package uses (src/packages/registry.ts, src/packages/update.ts), as PACKAGE_COMMANDS says them:
|
|
10
|
+
// topotopo workspace [folder] the workspace around a folder
|
|
11
|
+
// topotopo workspace init [folder] [--name n] [--engine godot:<path>|unreal:<path>|none] [--library <name or folder>] [--follow | --no-follow]
|
|
12
|
+
// make a folder a workspace, or change one
|
|
13
|
+
// topotopo workspace library add|remove <name or folder> [--workspace <folder>]
|
|
14
|
+
// the shared libraries the workspace lists
|
|
15
|
+
// topotopo workspace add|list [folder] register a workspace for the web app's front page; list them
|
|
16
|
+
// topotopo init [folder] [--name owner/name] make a folder a package, or set the name it publishes under
|
|
17
|
+
// topotopo use owner/name [folder] [--version 1.1] add a package from the places the package looks in
|
|
18
|
+
// topotopo remove owner/name [folder] remove a package no graph of the package names
|
|
19
|
+
// topotopo packages [owner/name] [folder] what the package uses and can use; one package
|
|
20
|
+
// topotopo publish [folder] --note "..." [--big] [--dry-run] publish the next version of the package
|
|
21
|
+
// topotopo search [words] [folder] [--kind k] [--tag t] the outputs of every library, for the package
|
|
22
|
+
// topotopo outdated [folder] the newer versions of what it uses, with their notes
|
|
23
|
+
// topotopo check [folder] cook what the workspace relies on; what broke and why
|
|
24
|
+
// topotopo update owner/name [folder] [--to 1.4] [--render <folder>] the before/after of an update
|
|
25
|
+
// topotopo update owner/name [folder] --from 1.3 --to 1.4 --apply apply the update you looked at
|
|
26
|
+
// A folder named must exist (a package's folder, or one inside it); without one, the current folder's package. Each
|
|
27
|
+
// package command returns its exit code and says what it did through an Io (the console by default), so that tests
|
|
28
|
+
// run them in this process.
|
|
29
|
+
import fs from 'node:fs';
|
|
30
|
+
import path from 'node:path';
|
|
31
|
+
import { KINDS } from '../graph/outputs.js';
|
|
32
|
+
import { parsePackageName } from '../graph/scope.js';
|
|
33
|
+
import { addLibrary, loadConfig, removeLibrary } from '../config.js';
|
|
34
|
+
import { createPackage, isStale, placeNamed, readBakeState, scanAll, workspaceRef } from '../web/library.js';
|
|
35
|
+
import { initPackage, locate, oldManifestAbove, packageDirOf, slugify, workspaceFlag } from '../package.js';
|
|
36
|
+
import { forgetScans } from '../scan.js';
|
|
37
|
+
/**
|
|
38
|
+
* The package commands as every list of them says them: src/cli.ts (its header and --help), this file's header, the
|
|
39
|
+
* help topic "packages" and README.md, each of which holds every usage as it is here (test/docs.ts checks).
|
|
40
|
+
*/
|
|
41
|
+
export const PACKAGE_COMMANDS = [
|
|
42
|
+
{ usage: 'workspace [folder]', what: 'the workspace around a folder: its engine project, the shared libraries it lists, its packages (every folder in it with a .topo file)' },
|
|
43
|
+
{ usage: 'workspace init [folder] [--name n] [--engine godot:<path>|unreal:<path>|none] [--library <name or folder>] [--follow | --no-follow]', what: 'make a folder a workspace (topotopo-workspace.json; the engine project at or above it is found, else one below; --library lists shared libraries when it is made; its packages share one copy of each package, moved into topotopo-packages/; --follow shows its own packages live from their working folders, for looking), or change its name, engine or follow' },
|
|
44
|
+
{ usage: 'workspace library add|remove <name or folder> [--workspace <folder>]', what: 'list or unlist a shared library the workspace\'s packages use: a registered library\'s name, or a folder outside the workspace (written as its path from the workspace)' },
|
|
45
|
+
{ usage: 'workspace add|list [folder]', what: 'register a workspace by its name for the web app\'s front page, or list the registered ones' },
|
|
46
|
+
{ usage: 'init [folder] [--name owner/name]', what: 'make a folder a package (<id>.topo, graphs/main.json), or set the name an existing package publishes under' },
|
|
47
|
+
{ usage: 'use owner/name [folder] [--version 1.1]', what: 'add a package: its newest version (or --version) in the places the package looks in (its workspace and the libraries the workspace lists; outside a workspace every registered library; TopoTopo\'s built-in library), copied in' },
|
|
48
|
+
{ usage: 'remove owner/name [folder]', what: 'remove a package no graph of the package names: its copy goes, with the copies nothing else uses' },
|
|
49
|
+
{ usage: 'packages [owner/name] [folder]', what: 'what the package (or, at a workspace\'s root, the workspace) uses and can use, one line each; with a package, its versions and its outputs' },
|
|
50
|
+
{ usage: 'publish [folder] --note "..." [--big] [--dry-run]', what: 'publish the next version of the package into versions/; --dry-run checks everything and writes nothing' },
|
|
51
|
+
{ usage: 'search [words] [folder] [--kind k] [--tag t]', what: 'the outputs of every place the package looks in, and in a workspace the registered libraries it does not list' },
|
|
52
|
+
{ usage: 'outdated [folder]', what: 'the packages it uses that have newer versions, with their notes' },
|
|
53
|
+
{ usage: 'check [folder]', what: 'cook what the workspace relies on (the newest version of its packages that publish, every graph of the others, the newest versions in the libraries it lists; outside a workspace the package and its library); list what broke and why, changing nothing but missing .gdignore files inside a Godot project' },
|
|
54
|
+
{ usage: 'update owner/name [folder] [--to 1.4] [--render <folder>]', what: 'the before/after of an update: every place the package uses it, cooked with both versions; nothing is written' },
|
|
55
|
+
{ usage: 'update owner/name [folder] --from 1.3 --to 1.4 --apply', what: 'apply the update you looked at: copy it in, set "uses" and the lock, delete the copies nothing uses' },
|
|
56
|
+
];
|
|
57
|
+
export const consoleIo = { out: (s) => console.log(s), err: (s) => console.error(s) };
|
|
58
|
+
/** A command's failure, said on stderr: exit code 1. */
|
|
59
|
+
class Fail extends Error {
|
|
60
|
+
}
|
|
61
|
+
const fail = (msg) => { throw new Fail(msg); };
|
|
62
|
+
/** Run a command's body: a failure, or any error it throws, is said on stderr and exits 1. Scans start afresh. */
|
|
63
|
+
async function run(io, f) {
|
|
64
|
+
forgetScans();
|
|
65
|
+
try {
|
|
66
|
+
return await f();
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
io.err(String(e?.message ?? e));
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A command's arguments: its options (`valued` take the next argument as their value, `flags` none) and the rest in
|
|
75
|
+
* order. An unknown option, or a valued one without its value, fails with the usage.
|
|
76
|
+
*/
|
|
77
|
+
function args(argv, valued, flags, usage) {
|
|
78
|
+
const opts = new Map(), many = new Map(), rest = [];
|
|
79
|
+
for (let i = 0; i < argv.length; i++) {
|
|
80
|
+
const a = argv[i];
|
|
81
|
+
if (!a.startsWith('--')) {
|
|
82
|
+
rest.push(a);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (flags.includes(a)) {
|
|
86
|
+
opts.set(a, '');
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (!valued.includes(a))
|
|
90
|
+
fail(`unknown option ${a}\n${usage}`);
|
|
91
|
+
const v = argv[i + 1];
|
|
92
|
+
if (v === undefined || v.startsWith('--'))
|
|
93
|
+
fail(`${a} needs a value\n${usage}`);
|
|
94
|
+
opts.set(a, v);
|
|
95
|
+
many.set(a, [...(many.get(a) ?? []), v]);
|
|
96
|
+
i++;
|
|
97
|
+
}
|
|
98
|
+
// opt: the option's (last) value; all: every value of an option given more than once
|
|
99
|
+
return { opt: (f) => opts.get(f), all: (f) => many.get(f) ?? [], has: (f) => opts.has(f), rest };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The package a command acts on: the folder named (which must exist; a folder inside a package acts on that package),
|
|
103
|
+
* else the current folder's. Fails for a folder in no package, saying how to make one.
|
|
104
|
+
*/
|
|
105
|
+
function packageOf(folder, prog) {
|
|
106
|
+
const abs = path.resolve(folder ?? '.');
|
|
107
|
+
if (folder !== undefined && !isDir(abs))
|
|
108
|
+
fail(`no folder ${abs}`);
|
|
109
|
+
return packageDirOf(abs) ?? fail(`${abs} is in no package: ${prog} init${folder === undefined ? '' : ` ${quoted(folder)}`} makes the folder a package (<id>.topo)${oldManifestAbove(abs)}`);
|
|
110
|
+
}
|
|
111
|
+
const isDir = (abs) => !!fs.statSync(abs, { throwIfNoEntry: false })?.isDirectory();
|
|
112
|
+
/** "owner/name", a package (no output) */
|
|
113
|
+
const isPackage = (s) => { const n = parsePackageName(s); return typeof n !== 'string' && n.output === null; };
|
|
114
|
+
/** A folder argument that is a version ("1.1", "2") and no folder: what was meant, said. */
|
|
115
|
+
const versionGiven = (folder, meant) => {
|
|
116
|
+
if (folder !== undefined && /^\d+(\.\d+)?$/.test(folder) && !isDir(path.resolve(folder)))
|
|
117
|
+
fail(`"${folder}" is no folder here: ${meant}`);
|
|
118
|
+
};
|
|
119
|
+
/** The packages a package uses, in an engine of their own (its worker pool closed by `close`). */
|
|
120
|
+
async function usesOfPackage(folder) {
|
|
121
|
+
const { Engine } = await import('../graph/engine.js');
|
|
122
|
+
const { createNodeHost } = await import('../host/node.js');
|
|
123
|
+
const { openPackages } = await import('./registry.js');
|
|
124
|
+
const engine = new Engine(createNodeHost({ baseDir: folder }));
|
|
125
|
+
await engine.init();
|
|
126
|
+
return { engine, pk: openPackages(engine, folder), close: async () => { await engine.host.pool?.close(); } };
|
|
127
|
+
}
|
|
128
|
+
const quoted = (s) => (/[\s"]/.test(s) ? JSON.stringify(s) : s);
|
|
129
|
+
// ---------------------------------------------------------------------------------------------------- the web app
|
|
130
|
+
export async function webCommand(argv, prog, io = consoleIo) {
|
|
131
|
+
return run(io, async () => {
|
|
132
|
+
const a = args(argv, ['--port', '--library'], ['--no-bake'], `usage: ${prog} web [--port 7340] [--library <folder>] [--no-bake]`);
|
|
133
|
+
let cfg = loadConfig();
|
|
134
|
+
const extra = a.opt('--library');
|
|
135
|
+
if (extra) {
|
|
136
|
+
const name = slugify(path.basename(path.resolve(extra))) || 'library';
|
|
137
|
+
cfg = { ...cfg, libraries: [...cfg.libraries.filter((l) => l.name !== name), { name, path: path.resolve(extra) }] };
|
|
138
|
+
}
|
|
139
|
+
if (!cfg.libraries.length && !cfg.workspaces.length)
|
|
140
|
+
io.out(`no libraries or workspaces yet: register a folder with \`${prog} library add <name> <folder>\` or \`${prog} workspace add <folder>\` (or pass --library <folder>)`);
|
|
141
|
+
const port = a.opt('--port') !== undefined ? Number(a.opt('--port')) : cfg.web.port;
|
|
142
|
+
const { startWeb, runningWeb } = await import('../web/server.js');
|
|
143
|
+
try {
|
|
144
|
+
const g = await startWeb({ config: cfg, port, bake: !a.has('--no-bake'), log: (m) => io.out(m) });
|
|
145
|
+
const n = cfg.libraries.length, w = cfg.workspaces.length;
|
|
146
|
+
io.out(`web app: ${g.url} (${w ? `${w} workspace${w === 1 ? '' : 's'}: ${cfg.workspaces.map((x) => x.name).join(', ')}; ` : ''}${n} librar${n === 1 ? 'y' : 'ies'}: ${cfg.libraries.map((l) => `${l.name} → ${l.path}`).join(', ') || 'none'}; Ctrl+C to stop)`);
|
|
147
|
+
if (g.queue.size)
|
|
148
|
+
io.out(`baking ${g.queue.size} package(s) in the background`);
|
|
149
|
+
}
|
|
150
|
+
catch (e) {
|
|
151
|
+
if (e?.code !== 'EADDRINUSE')
|
|
152
|
+
throw e;
|
|
153
|
+
const url = await runningWeb(port);
|
|
154
|
+
if (url) {
|
|
155
|
+
io.out(`web app: ${url} (already running)`);
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
fail(`port ${port} is taken by another program: pass --port, or set "web": {"port": N} in ${cfg.file}`);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
export async function libraryCommand(argv, prog, io = consoleIo) {
|
|
163
|
+
return run(io, async () => {
|
|
164
|
+
const usage = `usage: ${prog} library add <name> <folder> | remove <name> | list | new <library or workspace> <folder/name> [--title t] [--tags a,b] [--description d] | bake <package folder> | bake --stale | bake --all`;
|
|
165
|
+
const a = args(argv, ['--title', '--tags', '--description'], ['--stale', '--all'], usage);
|
|
166
|
+
const [sub, x, y] = a.rest;
|
|
167
|
+
let cfg = loadConfig();
|
|
168
|
+
if (sub === 'add') {
|
|
169
|
+
if (!x || !y)
|
|
170
|
+
fail(usage);
|
|
171
|
+
cfg = addLibrary(x, y);
|
|
172
|
+
io.out(`library ${x} → ${path.resolve(y)} (in ${cfg.file})`);
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
175
|
+
if (sub === 'remove') {
|
|
176
|
+
if (!x || y)
|
|
177
|
+
fail(usage);
|
|
178
|
+
const was = cfg.libraries.find((l) => l.name === x);
|
|
179
|
+
cfg = removeLibrary(x);
|
|
180
|
+
io.out(`unregistered library ${x}${was ? ` (its folder ${was.path} stays as it is)` : ''} (in ${cfg.file}); a workspace that lists it by its name says so until it lists it no more`);
|
|
181
|
+
return 0;
|
|
182
|
+
}
|
|
183
|
+
if (sub === 'list') {
|
|
184
|
+
if (!cfg.libraries.length && !cfg.workspaces.length)
|
|
185
|
+
io.out(`no libraries or workspaces (config ${cfg.file}): ${prog} library add <name> <folder>, or ${prog} workspace add <folder>`);
|
|
186
|
+
for (const s of scanAll(cfg)) {
|
|
187
|
+
io.out(`${s.workspace ? 'workspace ' : ''}${s.name} ${s.root} (${s.packages.length} packages)`);
|
|
188
|
+
for (const p of s.packages) {
|
|
189
|
+
const st = readBakeState(p.dir);
|
|
190
|
+
const status = !st ? 'not baked' : !st.ok ? 'bake failed' : isStale(p) ? 'stale' : 'baked';
|
|
191
|
+
io.out(` ${p.id.padEnd(24)} ${p.rel.padEnd(32)} ${status}${p.manifest.tags.length ? ' [' + p.manifest.tags.join(', ') + ']' : ''}`);
|
|
192
|
+
}
|
|
193
|
+
for (const pr of s.problems)
|
|
194
|
+
io.out(` ! ${pr}`);
|
|
195
|
+
}
|
|
196
|
+
// a library inside a registered workspace: its packages are listed as the workspace's
|
|
197
|
+
for (const l of cfg.libraries) {
|
|
198
|
+
const at = placeNamed(cfg, l.name);
|
|
199
|
+
if (at?.place.workspace)
|
|
200
|
+
io.out(`${l.name} ${l.path} (shown as the workspace "${at.place.name}"'s, at ${at.prefix ? `${at.prefix}/` : 'its root'})`);
|
|
201
|
+
}
|
|
202
|
+
return 0;
|
|
203
|
+
}
|
|
204
|
+
if (sub === 'new') {
|
|
205
|
+
if (!x || !y)
|
|
206
|
+
fail(usage);
|
|
207
|
+
// a workspace by the name in its file; a library inside a registered workspace is the workspace's
|
|
208
|
+
const at = placeNamed(cfg, x)
|
|
209
|
+
?? fail(`no library or workspace "${x}" (${[...cfg.libraries, ...cfg.workspaces.map(workspaceRef)].map((l) => l.name).join(', ') || `none: ${prog} library add <name> <folder>, or ${prog} workspace add <folder>`})`);
|
|
210
|
+
const p = createPackage(at.place, at.prefix ? `${at.prefix}/${y}` : y, { title: a.opt('--title'), description: a.opt('--description'), tags: a.opt('--tags')?.split(',').map((t) => t.trim()).filter(Boolean) });
|
|
211
|
+
io.out(`package ${p.lib}/${p.id} → ${p.dir}${at.prefix ? ` (library "${x}" lies in the workspace "${at.place.name}": its packages are the workspace's)` : ''}`);
|
|
212
|
+
io.out(` page: http://127.0.0.1:${cfg.web.port}/p/${p.lib}/${p.id}`);
|
|
213
|
+
return 0;
|
|
214
|
+
}
|
|
215
|
+
if (sub === 'bake') {
|
|
216
|
+
const { bakePackage } = await import('../web/bake.js');
|
|
217
|
+
let dirs;
|
|
218
|
+
if (a.has('--all') || a.has('--stale'))
|
|
219
|
+
dirs = [...new Set(scanAll(cfg).flatMap((s) => s.packages).filter((p) => a.has('--all') || isStale(p)).map((p) => p.dir))];
|
|
220
|
+
else if (x)
|
|
221
|
+
dirs = [packageOf(x, prog)];
|
|
222
|
+
else
|
|
223
|
+
return fail(usage);
|
|
224
|
+
let failed = 0;
|
|
225
|
+
for (const d of dirs) {
|
|
226
|
+
const s = await bakePackage(d);
|
|
227
|
+
if (!s.ok)
|
|
228
|
+
failed++;
|
|
229
|
+
io.out(`${s.ok ? 'ok ' : 'FAIL'} ${d} ${s.ok ? `${s.ms} ms, ${s.points} points, ${s.prims} prims${s.glb ? '' : ', no preview.glb'}` : s.error}`);
|
|
230
|
+
}
|
|
231
|
+
if (!dirs.length)
|
|
232
|
+
io.out('nothing to bake');
|
|
233
|
+
return failed ? 1 : 0;
|
|
234
|
+
}
|
|
235
|
+
fail(usage);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/** `edit [folder]`: the live viewer on a package, following changes other processes make to it. */
|
|
239
|
+
export async function editCommand(argv, prog, io = consoleIo) {
|
|
240
|
+
return run(io, async () => {
|
|
241
|
+
const a = args(argv, ['--port'], ['--json'], `usage: ${prog} edit [folder] [--port 7341] [--json]`);
|
|
242
|
+
const dir = packageOf(a.rest[0], prog);
|
|
243
|
+
const { Engine } = await import('../graph/engine.js');
|
|
244
|
+
const { createNodeHost } = await import('../host/node.js');
|
|
245
|
+
const { openPackage } = await import('../open.js');
|
|
246
|
+
const { startViewer } = await import('../viewer/server.js');
|
|
247
|
+
const engine = new Engine(createNodeHost({ baseDir: dir }));
|
|
248
|
+
await engine.init();
|
|
249
|
+
const ws = openPackage(engine, dir, { watch: true }).session;
|
|
250
|
+
const v = await startViewer(ws, a.opt('--port') !== undefined ? Number(a.opt('--port')) : undefined);
|
|
251
|
+
if (a.has('--json')) {
|
|
252
|
+
// started by the web app: report the URL, and stop once no page has been open for a while
|
|
253
|
+
io.out(JSON.stringify({ url: v.url }));
|
|
254
|
+
let idleSince = Date.now();
|
|
255
|
+
setInterval(() => {
|
|
256
|
+
if (v.clients() > 0)
|
|
257
|
+
idleSince = Date.now();
|
|
258
|
+
else if (Date.now() - idleSince > 10 * 60_000) {
|
|
259
|
+
v.close();
|
|
260
|
+
process.exit(0);
|
|
261
|
+
}
|
|
262
|
+
}, 30_000);
|
|
263
|
+
}
|
|
264
|
+
else
|
|
265
|
+
io.out(`edit: ${v.url} (${dir}; Ctrl+C to stop)`);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
// ---------------------------------------------------------------------------------------------------- packages
|
|
269
|
+
/** `init [folder] [--name owner/name]`: make a folder a package, or set the name an existing package publishes under. */
|
|
270
|
+
export async function initCommand(argv, prog, io = consoleIo) {
|
|
271
|
+
return (await run(io, async () => {
|
|
272
|
+
const a = args(argv, ['--name'], [], `usage: ${prog} init [folder] [--name owner/name]`);
|
|
273
|
+
const r = initPackage(a.rest[0] ?? '.', { name: a.opt('--name') });
|
|
274
|
+
io.out(r.said);
|
|
275
|
+
const ws = locate(r.dir).workspace;
|
|
276
|
+
if (!/ publishes as \S+ (already|now)$/.test(r.said))
|
|
277
|
+
io.out(` graphs go in graphs/ (it shows "${r.manifest.graph}"); ${ws ? `it finds packages in its workspace and the libraries the workspace lists (${prog} workspace library add <name or folder>${workspaceFlag(ws)} lists one)` : 'outside a workspace it finds packages in every registered library'}; TopoTopo's own packages need none`);
|
|
278
|
+
return 0;
|
|
279
|
+
})) ?? 0;
|
|
280
|
+
}
|
|
281
|
+
/** `topotopo libraries …` is gone: it only says where its work went. */
|
|
282
|
+
export async function librariesCommand(_argv, prog, io = consoleIo) {
|
|
283
|
+
return (await run(io, async () => fail(`\`${prog} libraries\` is gone: \`${prog} workspace library add <entry>\` lists a library for the workspace; outside a workspace every registered library counts`))) ?? 1;
|
|
284
|
+
}
|
|
285
|
+
/** `use owner/name [folder] [--version 1.1]`: add a package to those the package uses, from the places it looks in. */
|
|
286
|
+
export async function useCommand(argv, prog, io = consoleIo) {
|
|
287
|
+
return (await run(io, async () => {
|
|
288
|
+
const usage = `usage: ${prog} use owner/name [folder] [--version 1.1]`;
|
|
289
|
+
const a = args(argv, ['--version'], [], usage);
|
|
290
|
+
const [pkg, folder] = a.rest;
|
|
291
|
+
if (!pkg)
|
|
292
|
+
fail(usage);
|
|
293
|
+
versionGiven(folder, `a version is named with --version, ${prog} use ${pkg} --version ${/^\d+$/.test(folder ?? '') ? `${folder}.0` : folder}`);
|
|
294
|
+
const { pk, close } = await usesOfPackage(packageOf(folder, prog));
|
|
295
|
+
try {
|
|
296
|
+
io.out(pk.use(pkg, { version: a.opt('--version') }).text);
|
|
297
|
+
for (const p of pk.check())
|
|
298
|
+
io.err(`warning: ${p}`);
|
|
299
|
+
return 0;
|
|
300
|
+
}
|
|
301
|
+
finally {
|
|
302
|
+
await close();
|
|
303
|
+
}
|
|
304
|
+
})) ?? 0;
|
|
305
|
+
}
|
|
306
|
+
/** `remove owner/name [folder]`: remove a package no graph of the package names any more. */
|
|
307
|
+
export async function removeCommand(argv, prog, io = consoleIo) {
|
|
308
|
+
return (await run(io, async () => {
|
|
309
|
+
const usage = `usage: ${prog} remove owner/name [folder]`;
|
|
310
|
+
const [pkg, folder] = args(argv, [], [], usage).rest;
|
|
311
|
+
if (!pkg)
|
|
312
|
+
fail(usage);
|
|
313
|
+
const { removePackage } = await import('./update.js');
|
|
314
|
+
const { pk, close } = await usesOfPackage(packageOf(folder, prog));
|
|
315
|
+
try {
|
|
316
|
+
io.out(removePackage(pk, pkg).text);
|
|
317
|
+
return 0;
|
|
318
|
+
}
|
|
319
|
+
finally {
|
|
320
|
+
await close();
|
|
321
|
+
}
|
|
322
|
+
})) ?? 0;
|
|
323
|
+
}
|
|
324
|
+
/** `packages [owner/name] [folder]`: what the package uses and can use, one line each; or one package with its outputs. */
|
|
325
|
+
export async function packagesCommand(argv, prog, io = consoleIo) {
|
|
326
|
+
return (await run(io, async () => {
|
|
327
|
+
const a = args(argv, [], [], `usage: ${prog} packages [owner/name] [folder]`);
|
|
328
|
+
// a package name first (one that is no folder here), then the folder
|
|
329
|
+
const first = a.rest[0], named = first !== undefined && isPackage(first) && !isDir(path.resolve(first));
|
|
330
|
+
const pkg = named ? first : undefined, folder = named ? a.rest[1] : a.rest[0];
|
|
331
|
+
const { packagesText, packageText } = await import('./registry.js');
|
|
332
|
+
// at a workspace's root (in no package): the workspace's
|
|
333
|
+
const at = path.resolve(folder ?? '.');
|
|
334
|
+
if (folder !== undefined && !isDir(at))
|
|
335
|
+
fail(`no folder ${at}`);
|
|
336
|
+
const { pk, close } = await usesOfPackage(!packageDirOf(at) && locate(at).workspace ? at : packageOf(folder, prog));
|
|
337
|
+
try {
|
|
338
|
+
io.out(pkg ? packageText(pk, pkg) : packagesText(pk));
|
|
339
|
+
return 0;
|
|
340
|
+
}
|
|
341
|
+
finally {
|
|
342
|
+
await close();
|
|
343
|
+
}
|
|
344
|
+
})) ?? 0;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* `publish [folder] --note "..." [--big] [--dry-run]`: publish the next version of the package; --dry-run
|
|
348
|
+
* says what publishing would do and writes nothing.
|
|
349
|
+
*/
|
|
350
|
+
export async function publishCommand(argv, prog, io = consoleIo) {
|
|
351
|
+
return (await run(io, async () => {
|
|
352
|
+
const a = args(argv, ['--note'], ['--big', '--dry-run'], `usage: ${prog} publish [folder] --note "what changed" [--big] [--dry-run]`);
|
|
353
|
+
const { publishPackage, publishText } = await import('./registry.js');
|
|
354
|
+
const { pk, close } = await usesOfPackage(packageOf(a.rest[0], prog));
|
|
355
|
+
try {
|
|
356
|
+
const r = await publishPackage(pk, { note: a.opt('--note'), big: a.has('--big'), dryRun: a.has('--dry-run') });
|
|
357
|
+
io.out(publishText(r));
|
|
358
|
+
return r.ok ? 0 : 1;
|
|
359
|
+
}
|
|
360
|
+
finally {
|
|
361
|
+
await close();
|
|
362
|
+
}
|
|
363
|
+
})) ?? 0;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* `search [words] [folder] [--kind k] [--tag t]`: the outputs of every library, and whether the package can use them.
|
|
367
|
+
* The folder is written as a path (".", "./forest", "../forest", an absolute path), so that a word is never one.
|
|
368
|
+
*/
|
|
369
|
+
export async function searchCommand(argv, prog, io = consoleIo) {
|
|
370
|
+
return (await run(io, async () => {
|
|
371
|
+
const a = args(argv, ['--kind', '--tag'], [], `usage: ${prog} search [words] [folder] [--kind ${KINDS.join('|')}] [--tag t]`);
|
|
372
|
+
const asPath = (s) => s === '.' || s === '..' || /^\.\.?[\\/]/.test(s) || path.isAbsolute(s) || /^[A-Za-z]:/.test(s);
|
|
373
|
+
const last = a.rest.at(-1), folder = last !== undefined && asPath(last) ? last : undefined;
|
|
374
|
+
const words = folder === undefined ? a.rest : a.rest.slice(0, -1);
|
|
375
|
+
if (folder !== undefined && !isDir(path.resolve(folder)))
|
|
376
|
+
fail(`no folder ${path.resolve(folder)}`);
|
|
377
|
+
const { searchPackages, searchText } = await import('./registry.js');
|
|
378
|
+
io.out(searchText(searchPackages(path.resolve(folder ?? '.'), { query: words.join(' '), kind: a.opt('--kind'), tag: a.opt('--tag') })));
|
|
379
|
+
return 0;
|
|
380
|
+
})) ?? 0;
|
|
381
|
+
}
|
|
382
|
+
/** `outdated [folder]`: the packages it uses that have newer versions, with their notes. */
|
|
383
|
+
export async function outdatedCommand(argv, prog, io = consoleIo) {
|
|
384
|
+
return (await run(io, async () => {
|
|
385
|
+
const folder = args(argv, [], [], `usage: ${prog} outdated [folder]`).rest[0];
|
|
386
|
+
const { outdatedText } = await import('./update.js');
|
|
387
|
+
const { pk, close } = await usesOfPackage(packageOf(folder, prog));
|
|
388
|
+
try {
|
|
389
|
+
io.out(outdatedText(pk, false, folder));
|
|
390
|
+
return 0;
|
|
391
|
+
}
|
|
392
|
+
finally {
|
|
393
|
+
await close();
|
|
394
|
+
}
|
|
395
|
+
})) ?? 0;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* `check [folder]`: cook the newest version of every package in the libraries of the workspace around the folder (or
|
|
399
|
+
* of its package), and every graph of its packages; say what broke and why. Writes nothing but the .gdignore files a
|
|
400
|
+
* package inside a Godot project lacks; exit code 1 when something broke (a build machine runs it after updating
|
|
401
|
+
* TopoTopo).
|
|
402
|
+
*/
|
|
403
|
+
export async function checkCommand(argv, prog, io = consoleIo) {
|
|
404
|
+
return (await run(io, async () => {
|
|
405
|
+
const folder = args(argv, [], [], `usage: ${prog} check [folder]`).rest[0];
|
|
406
|
+
const at = path.resolve(folder ?? '.');
|
|
407
|
+
if (folder !== undefined && !fs.existsSync(at))
|
|
408
|
+
fail(`${at} does not exist`);
|
|
409
|
+
const { checkAll, checkText } = await import('./check.js');
|
|
410
|
+
const r = await checkAll(at, { progress: (what) => io.err(`checking ${what}`) });
|
|
411
|
+
io.out(checkText(r));
|
|
412
|
+
return r.items.some((i) => i.failures.length) ? 1 : 0;
|
|
413
|
+
})) ?? 0;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* `update owner/name [folder] [--to <version>] [--render <folder>]`: the before/after of updating a package in
|
|
417
|
+
* use, which writes nothing (--render writes its overlay renders into a folder); `--from <version> --to <version>
|
|
418
|
+
* --apply` applies the update whose before/after the person saw. Ctrl+C stops a long before/after at the next node.
|
|
419
|
+
* Nothing to update is no failure.
|
|
420
|
+
*/
|
|
421
|
+
export async function updateCommand(argv, prog, io = consoleIo) {
|
|
422
|
+
return (await run(io, async () => {
|
|
423
|
+
const usage = `usage: ${prog} update owner/name [folder] [--to <version>] [--render <folder>] (the before/after)\n ${prog} update owner/name [folder] --from <version> --to <version> --apply (apply the update you looked at)`;
|
|
424
|
+
const a = args(argv, ['--to', '--from', '--render'], ['--apply'], usage);
|
|
425
|
+
const [pkg, folder] = a.rest;
|
|
426
|
+
if (!pkg)
|
|
427
|
+
fail(usage);
|
|
428
|
+
versionGiven(folder, `a version is named with --to, ${prog} update ${pkg} --to ${/^\d+$/.test(folder ?? '') ? `${folder}.0` : folder}`);
|
|
429
|
+
const { applyUpdate, beforeAfter, beforeAfterText, overlayRenders } = await import('./update.js');
|
|
430
|
+
const { NothingToUpdate, loadPackage } = await import('./registry.js');
|
|
431
|
+
const packageDir = packageOf(folder, prog);
|
|
432
|
+
const { engine, pk, close } = await usesOfPackage(packageDir);
|
|
433
|
+
try {
|
|
434
|
+
if (a.has('--apply')) {
|
|
435
|
+
const from = a.opt('--from'), to = a.opt('--to');
|
|
436
|
+
if (!from || !to)
|
|
437
|
+
fail(`--apply needs --from and --to: the version in use and the version of the before/after you looked at (the before/after ends with the command)\n${usage}`);
|
|
438
|
+
io.out(applyUpdate(pk, pkg, { from: from, to: to }).text);
|
|
439
|
+
return 0;
|
|
440
|
+
}
|
|
441
|
+
if (a.has('--from'))
|
|
442
|
+
fail(`--from goes with --apply\n${usage}`);
|
|
443
|
+
for (const p of loadPackage(engine, packageDir))
|
|
444
|
+
io.err(`warning: ${p}`);
|
|
445
|
+
const stop = { aborted: false };
|
|
446
|
+
const onStop = () => { stop.aborted = true; io.err('stopping at the next node (Ctrl+C again ends it at once); nothing is written'); };
|
|
447
|
+
process.once('SIGINT', onStop);
|
|
448
|
+
let r;
|
|
449
|
+
try {
|
|
450
|
+
r = await beforeAfter(pk, pkg, { to: a.opt('--to'), signal: stop, progress: (done, total, what) => io.err(`[${done + 1}/${total}] ${what}`) });
|
|
451
|
+
}
|
|
452
|
+
finally {
|
|
453
|
+
process.off('SIGINT', onStop);
|
|
454
|
+
}
|
|
455
|
+
const again = `${prog} ${['update', pkg, ...(folder ? [folder] : []), '--from', r.target.from, '--to', r.target.to, '--apply'].map(quoted).join(' ')}`;
|
|
456
|
+
io.out(beforeAfterText(r, `nothing was written. To apply it: ${again}`));
|
|
457
|
+
const renders = overlayRenders(r, Infinity), dir = a.opt('--render');
|
|
458
|
+
if (dir && renders.length) {
|
|
459
|
+
fs.mkdirSync(path.resolve(dir), { recursive: true });
|
|
460
|
+
const files = renders.map((x, i) => {
|
|
461
|
+
const file = path.join(path.resolve(dir), `${String(i + 1).padStart(2, '0')}-${x.title.replace(/[^A-Za-z0-9_.-]+/g, '_')}.png`);
|
|
462
|
+
fs.writeFileSync(file, x.png);
|
|
463
|
+
return file;
|
|
464
|
+
});
|
|
465
|
+
io.out([`overlay renders (grey: the same with both, blue: only with ${r.target.to}, orange: only with ${r.target.from}):`, ...files.map((f) => ` ${f}`)].join('\n'));
|
|
466
|
+
}
|
|
467
|
+
else if (renders.length)
|
|
468
|
+
io.out(`--render <folder> writes an overlay render of each place that changed`);
|
|
469
|
+
return r.stopped ? 1 : 0;
|
|
470
|
+
}
|
|
471
|
+
catch (e) {
|
|
472
|
+
if (e instanceof NothingToUpdate) {
|
|
473
|
+
io.out(e.message);
|
|
474
|
+
return 0;
|
|
475
|
+
}
|
|
476
|
+
throw e;
|
|
477
|
+
}
|
|
478
|
+
finally {
|
|
479
|
+
await close();
|
|
480
|
+
}
|
|
481
|
+
})) ?? 0;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* `workspace [folder]`, `workspace init …`, `workspace library add|remove …`, `workspace add|list`: the workspace a
|
|
485
|
+
* package sits in (src/workspace.ts).
|
|
486
|
+
*/
|
|
487
|
+
const workspaceCommand = (argv, prog, io = consoleIo) => run(io, async () => {
|
|
488
|
+
const { initWorkspace, workspaceLibrary, workspaceText, readWorkspace, assetsGone } = await import('../workspace.js');
|
|
489
|
+
const { addWorkspace } = await import('../config.js');
|
|
490
|
+
const sub = ['init', 'add', 'list', 'library'].includes(argv[0]) ? argv[0] : 'show';
|
|
491
|
+
const usage = `usage: ${prog} workspace [folder] | workspace init [folder] [--name n] [--engine godot:<path>|unreal:<path>|none] [--library <name or folder>] [--follow | --no-follow] | workspace library add|remove <name or folder> [--workspace <folder>] | workspace add|list [folder]`;
|
|
492
|
+
if (sub === 'library') {
|
|
493
|
+
const a = args(argv.slice(1), ['--workspace'], [], usage);
|
|
494
|
+
const [op, given, extra] = a.rest;
|
|
495
|
+
if ((op !== 'add' && op !== 'remove') || !given || extra !== undefined)
|
|
496
|
+
fail(`usage: ${prog} workspace library add|remove <name or folder> [--workspace <folder>]`);
|
|
497
|
+
const at = a.opt('--workspace');
|
|
498
|
+
if (at !== undefined && !fs.existsSync(path.resolve(at)))
|
|
499
|
+
fail(`${path.resolve(at)} does not exist`);
|
|
500
|
+
io.out(workspaceLibrary(op, given, { at: at === undefined ? undefined : path.resolve(at) }));
|
|
501
|
+
return 0;
|
|
502
|
+
}
|
|
503
|
+
const a = args(sub === 'show' ? argv : argv.slice(1), ['--name', '--engine', '--assets', '--library'], ['--follow', '--no-follow'], usage);
|
|
504
|
+
const folder = path.resolve(a.rest[0] ?? '.');
|
|
505
|
+
if (a.rest[0] !== undefined && !fs.existsSync(folder))
|
|
506
|
+
fail(`${folder} does not exist`);
|
|
507
|
+
if (sub === 'init') {
|
|
508
|
+
if (a.has('--assets'))
|
|
509
|
+
fail(assetsGone('--assets'));
|
|
510
|
+
if (a.has('--follow') && a.has('--no-follow'))
|
|
511
|
+
fail('--follow or --no-follow, not both');
|
|
512
|
+
const r = initWorkspace(folder, { name: a.opt('--name'), engine: a.opt('--engine'), libraries: a.all('--library'), follow: a.has('--follow') ? true : a.has('--no-follow') ? false : undefined });
|
|
513
|
+
io.out(r.text);
|
|
514
|
+
io.out(`next: ${prog} workspace add ${a.rest[0] ?? '.'} lists it on the web app's front page`);
|
|
515
|
+
return 0;
|
|
516
|
+
}
|
|
517
|
+
if (sub === 'add') {
|
|
518
|
+
const ws = locate(folder).workspace;
|
|
519
|
+
if (!ws)
|
|
520
|
+
fail(`${folder} is in no workspace: ${prog} workspace init <folder> makes one`);
|
|
521
|
+
const m = readWorkspace(ws);
|
|
522
|
+
const cfg = addWorkspace(m.name, ws);
|
|
523
|
+
io.out(`registered the workspace "${m.name}" (${ws}) in ${cfg.file}`);
|
|
524
|
+
return 0;
|
|
525
|
+
}
|
|
526
|
+
if (sub === 'list') {
|
|
527
|
+
const cfg = loadConfig();
|
|
528
|
+
io.out(cfg.workspaces.length ? cfg.workspaces.map((w) => `${w.name} ${w.path}`).join('\n') : `no workspaces registered (${cfg.file}): ${prog} workspace add <folder>`);
|
|
529
|
+
return 0;
|
|
530
|
+
}
|
|
531
|
+
io.out(workspaceText(folder));
|
|
532
|
+
return 0;
|
|
533
|
+
});
|
|
534
|
+
export const commands = {
|
|
535
|
+
web: webCommand, library: libraryCommand, edit: editCommand, workspace: workspaceCommand, init: initCommand, libraries: librariesCommand, use: useCommand,
|
|
536
|
+
remove: removeCommand, packages: packagesCommand, publish: publishCommand, search: searchCommand, outdated: outdatedCommand, check: checkCommand, update: updateCommand,
|
|
537
|
+
};
|