@tokenoftrust/cli 2.0.0 → 2.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/cli",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Token of Trust developer CLI — clone a tenant store, run it locally with save→reload, and submit it for preview. Installs the `tot` command.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Token of Trust",
@@ -17,6 +17,7 @@ import { existsSync } from "node:fs";
17
17
  import { join, resolve } from "node:path";
18
18
  import { validateTenant, ERROR, WARN } from "../validate.mjs";
19
19
  import { fail } from "../errors.mjs";
20
+ import { tenantDirSegments } from "../tenant-dirs.mjs";
20
21
 
21
22
  function parseArgs(argv) {
22
23
  const a = { tenant: null, workspace: null, json: false, help: false };
@@ -47,7 +48,7 @@ function resolveTarget(args, ctx) {
47
48
  }
48
49
  if (args.tenant) {
49
50
  if (ctx.mode === "monorepo") {
50
- return { dir: join(ctx.repoRoot, "tenants", args.tenant), tenantId: args.tenant };
51
+ return { dir: join(ctx.repoRoot, ...tenantDirSegments(args.tenant)), tenantId: args.tenant };
51
52
  }
52
53
  // A bare tenant name outside the monorepo has no directory to resolve.
53
54
  return { error: `"${args.tenant}" is a tenant name, but you're not in a storefront monorepo. Run from a checkout, or use --workspace <dir>.` };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Where a tenant's colocated directory lives — the CLI's mirror.
3
+ *
4
+ * A tenant IS a directory. Real tenants sit directly under `tenants/<id>/`;
5
+ * PLATFORM TEST tenants (every id ending `.e2e.test`) sit one level deeper,
6
+ * under `tenants/e2e/<id>/`.
7
+ *
8
+ * `@tokenoftrust/cli` is a SEPARATE published package kept dependency-free (same
9
+ * stance as `src/validate.mjs` mirroring `scripts/tenant/validate.mjs` and
10
+ * `src/open.mjs` mirroring `scripts/dev/port-check.mjs`), so it carries its own
11
+ * copy rather than importing the monorepo's. All three copies — this,
12
+ * `scripts/lib/tenant-dirs.mjs`, and `packages/public-runtime/src/tenant.ts` —
13
+ * are held in lockstep by `packages/public-runtime/tests/tenant-dirs-parity.test.ts`.
14
+ */
15
+
16
+ /** The directory segment platform test tenants are nested under. */
17
+ export const E2E_TENANT_DIR = "e2e";
18
+
19
+ /** True for a PLATFORM TEST tenant id — the `<scenario>.e2e.test` class. */
20
+ export function isE2ETenantId(tenantId) {
21
+ return /\.e2e\.test$/.test(tenantId);
22
+ }
23
+
24
+ /** Repo-relative, POSIX-separated directory for a tenant id. */
25
+ export function tenantDirRelative(tenantId) {
26
+ return isE2ETenantId(tenantId)
27
+ ? `tenants/${E2E_TENANT_DIR}/${tenantId}`
28
+ : `tenants/${tenantId}`;
29
+ }
30
+
31
+ /** The `/tenants/…/<id>/` substring identifying one tenant inside a path. */
32
+ export function tenantDirSegment(tenantId) {
33
+ return `/${tenantDirRelative(tenantId)}/`;
34
+ }
35
+
36
+ /** The tenant id a `…/tenants/[e2e/]<id>/…` path encodes, or null. */
37
+ export function tenantIdFromPath(path) {
38
+ return /\/tenants\/(?:e2e\/)?([^/]+)\//.exec(path)?.[1] ?? null;
39
+ }
40
+
41
+ /**
42
+ * Narrow a set of tenant ids to what a generalized listing should show —
43
+ * platform test tenants are dropped unless explicitly requested.
44
+ */
45
+ export function listedTenantIds(ids, opts = {}) {
46
+ return opts.includeTestTenants ? [...ids] : ids.filter((id) => !isE2ETenantId(id));
47
+ }
48
+
49
+ /** Path segments for `join(repoRoot, ...tenantDirSegments(id))`. */
50
+ export function tenantDirSegments(tenantId) {
51
+ return tenantDirRelative(tenantId).split("/");
52
+ }