@phreshos/cli 0.1.61 → 0.1.63

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.
@@ -1,11 +1,11 @@
1
1
  import { inspect } from "node:util";
2
2
  import { assertValue } from "../contract/schema.js";
3
- import { readPath, renderFields, renderTable } from "./table.js";
3
+ import { readPath, renderFields, renderList } from "./format.js";
4
4
  /** Validate command data once, then select its machine or human representation. */
5
5
  export function writeData(result, contract, machine) {
6
6
  const normalized = result ?? null;
7
7
  assertValue(normalized, contract.value);
8
- if (machine) {
8
+ if (machine || contract.presentation.format === "json") {
9
9
  console.log(JSON.stringify(normalized));
10
10
  return;
11
11
  }
@@ -14,10 +14,11 @@ export function writeData(result, contract, machine) {
14
14
  }
15
15
  function render(value, presentation) {
16
16
  switch (presentation.format) {
17
- case "table": return renderCollection(value, presentation);
17
+ case "list": return renderCollection(value, presentation);
18
18
  case "fields": return renderFields(presentation.fields, value);
19
19
  case "document": return String(readPath(value, presentation.content) ?? "");
20
20
  case "value": return inspect(value, { colors: false, depth: null, compact: false });
21
+ case "json": return JSON.stringify(value);
21
22
  }
22
23
  }
23
24
  function renderCollection(value, presentation) {
@@ -25,7 +26,7 @@ function renderCollection(value, presentation) {
25
26
  const rows = Array.isArray(selected) ? selected : [];
26
27
  if (rows.length === 0)
27
28
  return presentation.empty;
28
- const table = renderTable(presentation.columns, rows);
29
+ const list = renderList(presentation.fields, rows);
29
30
  const totalValue = presentation.total ? readPath(value, presentation.total) : rows.length;
30
31
  const total = typeof totalValue === "number" ? totalValue : rows.length;
31
32
  const noun = total === 1 ? presentation.item : presentation.items;
@@ -35,5 +36,5 @@ function renderCollection(value, presentation) {
35
36
  const truncated = presentation.truncated && readPath(value, presentation.truncated) === true
36
37
  ? " · more available"
37
38
  : "";
38
- return `${table}\n${summary}${truncated}`;
39
+ return `${list}\n\n${summary}${truncated}`;
39
40
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "phresh",
3
3
  "private": true,
4
- "version": "0.1.37",
4
+ "version": "0.1.39",
5
5
  "description": "The official PhreshOS starter Program.",
6
6
  "type": "module",
7
7
  "scripts": {
@@ -14,15 +14,15 @@
14
14
  "starter"
15
15
  ],
16
16
  "dependencies": {
17
- "@phreshos/client": "^0.1.43",
18
- "@phreshos/core": "^0.1.49",
19
- "@phreshos/react": "^0.1.25",
20
- "@phreshos/server": "^0.1.47",
17
+ "@phreshos/client": "^0.1.46",
18
+ "@phreshos/core": "^0.1.53",
19
+ "@phreshos/react": "^0.1.28",
20
+ "@phreshos/server": "^0.1.50",
21
21
  "react": "^19.2.8",
22
22
  "react-dom": "^19.2.8"
23
23
  },
24
24
  "devDependencies": {
25
- "@phreshos/cli": "^0.1.61",
25
+ "@phreshos/cli": "^0.1.63",
26
26
  "@types/node": "^26.4.0",
27
27
  "@types/react": "^19.2.18",
28
28
  "@types/react-dom": "^19.2.5",
@@ -4,7 +4,7 @@ export default defineConfig({
4
4
  identity: "phresh",
5
5
  name: "Phresh Program",
6
6
  description: "A minimal counter with direct Client and Server endpoints.",
7
- version: "0.1.37",
7
+ version: "0.1.39",
8
8
  icon: "icon.png",
9
9
  categories: ["Development"],
10
10
  keywords: ["example", "counter", "client", "server"],
@@ -12,9 +12,9 @@ export default defineConfig({
12
12
  buildCommand: "vite-node scripts/build.ts",
13
13
  server: {
14
14
  location: "dist/server",
15
- entryFile: "main.js",
15
+ worker: "main.js",
16
16
  development: {
17
- startCommand: "vite-node server/main.ts"
17
+ command: "vite-node server/main.ts"
18
18
  }
19
19
  },
20
20
  client: {
@@ -9,8 +9,8 @@ test("build contract", async () => {
9
9
  assert.equal(config.name, "Phresh Program")
10
10
  assert.equal(config.version, manifest.version)
11
11
  assert.equal(config.server?.location, "dist/server")
12
- assert.equal(config.server?.entryFile, "main.js")
13
- assert.equal(config.server?.development?.startCommand, "vite-node server/main.ts")
12
+ assert.equal(config.server?.worker, "main.js")
13
+ assert.equal(config.server?.development?.command, "vite-node server/main.ts")
14
14
  assert.equal(config.client?.location, "dist/client")
15
15
  assert.deepEqual(config.client?.size, { width: 600, height: 500 })
16
16
 
@@ -7,8 +7,7 @@ export default defineConfig({
7
7
  plugins: [react()],
8
8
  base: process.env.PHRESHOS_CLIENT_BASE ?? "./",
9
9
  resolve: {
10
- tsconfigPaths: true,
11
- dedupe: ["react"]
10
+ tsconfigPaths: true
12
11
  },
13
12
  server: {
14
13
  port: Number(process.env.PHRESHOS_CLIENT_PORT ?? "5200"),
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "repository": "PhreshOS/phresh-program",
3
- "version": "0.1.37",
4
- "sha256": "2cf505d4ee6be9a7659b5969d59f7ed68fe9a2e44e79bd7fe827e9e42423b003",
3
+ "version": "0.1.39",
4
+ "sha256": "faf95c8b089928f9dca8ef0a0ff8063a54d0f90b602b4f237d009860ea884c23",
5
5
  "development": true
6
6
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@phreshos/cli",
3
3
  "type": "module",
4
- "version": "0.1.61",
4
+ "version": "0.1.63",
5
5
  "description": "The Phresh command-line interface for Program projects and system management.",
6
6
  "engines": {
7
7
  "node": ">=20.10"
@@ -47,13 +47,11 @@
47
47
  "packageManager": "bun@1.3.14",
48
48
  "dependencies": {
49
49
  "@clack/prompts": "^1.7.0",
50
- "@phreshos/core": "^0.1.52",
51
- "@phreshos/node": "^0.1.24",
50
+ "@phreshos/core": "^0.1.53",
51
+ "@phreshos/node": "^0.1.26",
52
52
  "adm-zip": "^0.6.0",
53
- "cli-table3": "^0.6.5",
54
53
  "commander": "^15.0.0",
55
- "picocolors": "^1.1.1",
56
- "string-width": "^4.2.3"
54
+ "picocolors": "^1.1.1"
57
55
  },
58
56
  "devDependencies": {
59
57
  "@types/adm-zip": "^0.5.8",
@@ -1,4 +0,0 @@
1
- /** Wait for one named event while preserving the target's own subscription contract. */
2
- export async function wait(target, event, timeout) {
3
- return target.wait(event, timeout);
4
- }
@@ -1,88 +0,0 @@
1
- import Table from "cli-table3";
2
- import stringWidth from "string-width";
3
- const style = Object.freeze({ head: [], border: [] });
4
- /** Render a table at its natural width, constraining and wrapping it only when necessary. */
5
- export function renderTable(fields, rows) {
6
- const width = terminalWidth();
7
- if (width < minimumTableWidth(fields)) {
8
- return rows.map(row => renderFields(fields, row)).join("\n");
9
- }
10
- const natural = createTable(fields, rows);
11
- const rendered = natural.toString();
12
- if (rendered.split("\n").every(line => stringWidth(line) <= width))
13
- return rendered;
14
- return createTable(fields, rows, allocateWidths(width, fields)).toString();
15
- }
16
- /** Render one value vertically so field names remain readable on narrow terminals. */
17
- export function renderFields(fields, source) {
18
- const rows = fields.map(field => [field.label, display(readPath(source, field.path), true)]);
19
- const width = terminalWidth();
20
- const desiredLabelWidth = Math.max(6, ...fields.map(field => stringWidth(field.label) + 2));
21
- const labelWidth = Math.min(24, Math.max(6, width - 11), desiredLabelWidth);
22
- const valueWidth = Math.max(8, width - labelWidth - 3);
23
- const table = new Table({
24
- colWidths: [labelWidth, valueWidth],
25
- wordWrap: true,
26
- wrapOnWordBoundary: false,
27
- style
28
- });
29
- table.push(...rows);
30
- return table.toString();
31
- }
32
- export function readPath(source, path) {
33
- if (!path)
34
- return source;
35
- return path.split(".").reduce((current, key) => {
36
- if (typeof current !== "object" || current === null)
37
- return undefined;
38
- return current[key];
39
- }, source);
40
- }
41
- export function display(value, expanded = false) {
42
- if (value === null || value === undefined || value === "")
43
- return "—";
44
- if (typeof value === "boolean")
45
- return value ? "yes" : "no";
46
- if (typeof value === "string" || typeof value === "number" || typeof value === "bigint")
47
- return String(value);
48
- if (Array.isArray(value) && !expanded)
49
- return value.length ? value.map(item => display(item)).join(", ") : "—";
50
- return JSON.stringify(value, null, expanded ? 2 : undefined);
51
- }
52
- function createTable(fields, rows, colWidths) {
53
- const table = new Table({
54
- head: fields.map(field => field.label),
55
- ...(colWidths ? { colWidths } : {}),
56
- wordWrap: true,
57
- wrapOnWordBoundary: false,
58
- style
59
- });
60
- table.push(...rows.map(row => fields.map(field => display(readPath(row, field.path)))));
61
- return table;
62
- }
63
- function allocateWidths(width, fields) {
64
- const minimums = fields.map(field => minimumColumnWidth(field));
65
- const available = width - fields.length - 1;
66
- const remaining = available - minimums.reduce((total, current) => total + current, 0);
67
- const weights = fields.map(field => field.width ?? 1);
68
- const totalWeight = weights.reduce((total, current) => total + current, 0);
69
- const widths = minimums.map((minimum, index) => minimum + Math.floor(remaining * weights[index] / totalWeight));
70
- let remainder = available - widths.reduce((total, current) => total + current, 0);
71
- for (let index = 0; remainder > 0; index = (index + 1) % widths.length) {
72
- widths[index] = widths[index] + 1;
73
- remainder--;
74
- }
75
- return widths;
76
- }
77
- function minimumTableWidth(fields) {
78
- return fields.reduce((total, field) => total + minimumColumnWidth(field), fields.length + 1);
79
- }
80
- function minimumColumnWidth(field) {
81
- return Math.max(6, stringWidth(field.label) + 2);
82
- }
83
- function terminalWidth() {
84
- const configured = Number(process.env.COLUMNS);
85
- if (Number.isFinite(configured) && configured > 0)
86
- return Math.floor(configured);
87
- return process.stdout.columns ?? 80;
88
- }