@sanity/runtime-cli 1.2.0 → 1.3.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.
Files changed (32) hide show
  1. package/README.md +42 -16
  2. package/dist/actions/blueprints/logs.d.ts +7 -0
  3. package/dist/actions/blueprints/logs.js +79 -0
  4. package/dist/actions/blueprints/operations.d.ts +18 -0
  5. package/dist/actions/blueprints/operations.js +52 -0
  6. package/dist/actions/blueprints/read-blueprint.d.ts +6 -1
  7. package/dist/actions/blueprints/read-blueprint.js +35 -9
  8. package/dist/actions/blueprints/stacks.d.ts +33 -5
  9. package/dist/actions/blueprints/stacks.js +53 -17
  10. package/dist/actions/blueprints/stash-asset.d.ts +4 -1
  11. package/dist/actions/blueprints/stash-asset.js +12 -7
  12. package/dist/actions/functions/dev.js +1 -2
  13. package/dist/actions/functions/invoke.js +8 -5
  14. package/dist/commands/blueprints/deploy.js +29 -35
  15. package/dist/commands/blueprints/info.js +45 -39
  16. package/dist/commands/blueprints/logs.d.ts +10 -0
  17. package/dist/commands/blueprints/logs.js +166 -0
  18. package/dist/commands/blueprints/plan.js +10 -23
  19. package/dist/config.js +2 -2
  20. package/dist/server/app.d.ts +1 -2
  21. package/dist/server/app.js +62 -32
  22. package/dist/server/static/vendor/vendor.bundle.js +30 -8
  23. package/dist/utils/display/blueprints-formatting.d.ts +4 -0
  24. package/dist/utils/display/blueprints-formatting.js +42 -0
  25. package/dist/utils/display/colors.d.ts +6 -0
  26. package/dist/utils/display/colors.js +18 -0
  27. package/dist/utils/display/dates.d.ts +2 -0
  28. package/dist/utils/display/dates.js +26 -0
  29. package/dist/utils/invoke-local.js +1 -5
  30. package/dist/utils/types.d.ts +22 -3
  31. package/oclif.manifest.json +45 -1
  32. package/package.json +6 -4
@@ -0,0 +1,42 @@
1
+ import { blue, bold, boldnblue, green, yellow } from './colors.js';
2
+ export function formatTitle(title, name) {
3
+ return `${boldnblue(title)} ${bold(`"${name}"`)}`;
4
+ }
5
+ export function formatStacksList(stacks) {
6
+ if (!stacks || stacks.length === 0) {
7
+ return 'No stacks found';
8
+ }
9
+ let result = '\nFound Stacks:\n';
10
+ for (const name of stacks) {
11
+ result += ` ${name}\n`;
12
+ }
13
+ return result;
14
+ }
15
+ export function formatResourceTree(resources, logger) {
16
+ if (!resources || resources.length === 0) {
17
+ logger(' No resources in this stack');
18
+ return;
19
+ }
20
+ logger(`${blue('Stack Resources')} [${resources.length}]`);
21
+ const functionResources = resources.filter((r) => r.kind === 'function');
22
+ const otherResources = resources.filter((r) => r.kind !== 'function');
23
+ const hasOtherResources = otherResources.length > 0;
24
+ if (functionResources.length > 0) {
25
+ logger(` ${hasOtherResources ? '├─' : '└─'} ${bold('Functions')} [${functionResources.length}]`);
26
+ for (const [i, fn] of functionResources.entries()) {
27
+ const isLast = i === functionResources.length - 1;
28
+ const prefix = hasOtherResources ? '│' : ' ';
29
+ const connector = isLast ? '└─' : '├─';
30
+ const name = green(fn.displayName || fn.name);
31
+ const externalId = fn.externalId ? `Fn<${yellow(fn.externalId)}>` : '';
32
+ logger(` ${prefix} ${connector} "${name}" ${externalId}`);
33
+ }
34
+ }
35
+ if (hasOtherResources) {
36
+ logger(` └─ ${bold('Other Resources')} [${otherResources.length}]`);
37
+ for (const [i, other] of otherResources.entries()) {
38
+ const isLast = i === otherResources.length - 1;
39
+ logger(` ${isLast ? '└─' : '├─'} "${yellow(other.displayName || other.name || other.src)}"`);
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,6 @@
1
+ export declare function bold(str: string): string;
2
+ export declare function blue(str: string): string;
3
+ export declare function green(str: string): string;
4
+ export declare function red(str: string): string;
5
+ export declare function yellow(str: string): string;
6
+ export declare function boldnblue(str: string): string;
@@ -0,0 +1,18 @@
1
+ export function bold(str) {
2
+ return `\x1b[1m${str}\x1b[0m`;
3
+ }
4
+ export function blue(str) {
5
+ return `\x1b[34m${str}\x1b[0m`;
6
+ }
7
+ export function green(str) {
8
+ return `\x1b[32m${str}\x1b[0m`;
9
+ }
10
+ export function red(str) {
11
+ return `\x1b[31m${str}\x1b[0m`;
12
+ }
13
+ export function yellow(str) {
14
+ return `\x1b[33m${str}\x1b[0m`;
15
+ }
16
+ export function boldnblue(str) {
17
+ return bold(blue(str));
18
+ }
@@ -0,0 +1,2 @@
1
+ export declare function formatDate(dateString: string): string;
2
+ export declare function formatDuration(startDate: string, endDate: string): string;
@@ -0,0 +1,26 @@
1
+ export function formatDate(dateString) {
2
+ const date = new Date(dateString);
3
+ return date.toLocaleString();
4
+ }
5
+ export function formatDuration(startDate, endDate) {
6
+ const start = new Date(startDate).getTime();
7
+ const end = new Date(endDate).getTime();
8
+ if (start > end) {
9
+ return 'Invalid duration';
10
+ }
11
+ const durationMs = end - start;
12
+ if (durationMs < 1000) {
13
+ return `${durationMs}ms`;
14
+ }
15
+ if (durationMs < 60000) {
16
+ return `${Math.round(durationMs / 1000)}s`;
17
+ }
18
+ if (durationMs < 3600000) {
19
+ const minutes = Math.floor(durationMs / 60000);
20
+ const seconds = Math.floor((durationMs % 60000) / 1000);
21
+ return `${minutes}m ${seconds}s`;
22
+ }
23
+ const hours = Math.floor(durationMs / 3600000);
24
+ const minutes = Math.floor((durationMs % 3600000) / 60000);
25
+ return `${hours}h ${minutes}m`;
26
+ }
@@ -1,12 +1,8 @@
1
1
  import { spawn } from 'node:child_process';
2
- import { join } from 'node:path';
3
2
  import { cwd } from 'node:process';
4
3
  import { setTimeout } from 'node:timers';
5
- import isDependency from './is-dependency.js';
6
4
  function getChildProcessWrapperPath() {
7
- return isDependency('./utils/child-process-wrapper.js')
8
- ? join(cwd(), './node_modules/@sanity/runtime-cli/dist/utils/child-process-wrapper.js')
9
- : join(cwd(), './src/utils/child-process-wrapper.js');
5
+ return new URL('./child-process-wrapper.js', import.meta.url).pathname;
10
6
  }
11
7
  export default async function invoke(srcPath, payload, timeout = 5) {
12
8
  return new Promise((resolve, reject) => {
@@ -48,17 +48,36 @@ export interface BlueprintJob {
48
48
  * @internal
49
49
  */
50
50
  export interface BlueprintResource {
51
+ id: string;
52
+ displayName: string;
51
53
  name: string;
52
54
  kind: string;
53
55
  src: string;
54
- assetId: string;
56
+ externalId: string;
55
57
  }
56
58
  /**
57
59
  * @internal
58
60
  */
61
+ export interface BlueprintOperation {
62
+ id: string;
63
+ status: string;
64
+ createdAt?: string;
65
+ completedAt?: string;
66
+ }
59
67
  export interface BlueprintStack {
68
+ id: string;
60
69
  name: string;
61
- kind: string;
62
- src: string;
70
+ displayName: string;
71
+ resources: Array<BlueprintResource>;
72
+ createdAt?: string;
73
+ updatedAt?: string;
74
+ recentOperation?: BlueprintOperation;
75
+ }
76
+ /**
77
+ * @internal
78
+ */
79
+ export interface BlueprintLog {
80
+ timestamp: string;
81
+ message: string;
63
82
  }
64
83
  export {};
@@ -48,6 +48,50 @@
48
48
  "info.js"
49
49
  ]
50
50
  },
51
+ "blueprints:logs": {
52
+ "aliases": [],
53
+ "args": {},
54
+ "description": "Display logs for a Blueprint stack",
55
+ "examples": [
56
+ "<%= config.bin %> <%= command.id %>",
57
+ "<%= config.bin %> <%= command.id %> --stack-id <stack-id>",
58
+ "<%= config.bin %> <%= command.id %> --watch"
59
+ ],
60
+ "flags": {
61
+ "stack-id": {
62
+ "char": "s",
63
+ "description": "Stack ID to fetch logs for (optional if running in a blueprint directory)",
64
+ "name": "stack-id",
65
+ "required": false,
66
+ "hasDynamicHelp": false,
67
+ "multiple": false,
68
+ "type": "option"
69
+ },
70
+ "watch": {
71
+ "char": "w",
72
+ "description": "Watch for new logs (streaming mode)",
73
+ "name": "watch",
74
+ "required": false,
75
+ "allowNo": false,
76
+ "type": "boolean"
77
+ }
78
+ },
79
+ "hasDynamicHelp": false,
80
+ "hiddenAliases": [],
81
+ "id": "blueprints:logs",
82
+ "pluginAlias": "@sanity/runtime-cli",
83
+ "pluginName": "@sanity/runtime-cli",
84
+ "pluginType": "core",
85
+ "strict": true,
86
+ "enableJsonFlag": false,
87
+ "isESM": true,
88
+ "relativePath": [
89
+ "dist",
90
+ "commands",
91
+ "blueprints",
92
+ "logs.js"
93
+ ]
94
+ },
51
95
  "blueprints:plan": {
52
96
  "aliases": [],
53
97
  "args": {},
@@ -247,5 +291,5 @@
247
291
  ]
248
292
  }
249
293
  },
250
- "version": "1.2.0"
294
+ "version": "1.3.0"
251
295
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sanity/runtime-cli",
3
3
  "description": "A new CLI generated with oclif",
4
- "version": "1.2.0",
4
+ "version": "1.3.0",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",
@@ -22,7 +22,8 @@
22
22
  "sanity": "./bin/run.js"
23
23
  },
24
24
  "scripts": {
25
- "build": "rollup -c && shx rm -rf dist && tsc -b && npm run build:static",
25
+ "build": "rollup -c && npm run build:bin && npm run build:static",
26
+ "build:bin": "shx rm -rf dist && tsc -b",
26
27
  "build:static": "npm run copy:wrapper && npm run copy:server",
27
28
  "copy:server": "shx cp -r ./src/server/static ./dist/server/static",
28
29
  "copy:wrapper": "shx cp ./src/utils/child-process-wrapper.js ./dist/utils/child-process-wrapper.js",
@@ -35,12 +36,12 @@
35
36
  "version": "oclif readme && git add README.md"
36
37
  },
37
38
  "dependencies": {
38
- "@hono/node-server": "^1.13.8",
39
39
  "@oclif/core": "^4",
40
40
  "@oclif/plugin-help": "^6",
41
41
  "@oclif/plugin-plugins": "^5",
42
- "hono": "^4.7.2",
42
+ "eventsource": "^3.0.5",
43
43
  "jszip": "^3.10.1",
44
+ "mime-types": "^2.1.35",
44
45
  "xdg-basedir": "^5.1.0"
45
46
  },
46
47
  "devDependencies": {
@@ -52,6 +53,7 @@
52
53
  "@oclif/test": "^4",
53
54
  "@rollup/plugin-node-resolve": "^16.0.0",
54
55
  "@types/chai": "^5",
56
+ "@types/mime-types": "^2.1.4",
55
57
  "@types/mocha": "^10",
56
58
  "@types/node": "^20",
57
59
  "chai": "^5",