@sanity/runtime-cli 1.5.0 → 1.6.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/README.md CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @sanity/runtime-cli
20
20
  $ sanity COMMAND
21
21
  running command...
22
22
  $ sanity (--version)
23
- @sanity/runtime-cli/1.5.0 linux-x64 node-v22.14.0
23
+ @sanity/runtime-cli/1.6.0 linux-x64 node-v22.14.0
24
24
  $ sanity --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity COMMAND
@@ -65,7 +65,7 @@ EXAMPLES
65
65
  $ sanity blueprints deploy
66
66
  ```
67
67
 
68
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v1.5.0/src/commands/blueprints/deploy.ts)_
68
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v1.6.0/src/commands/blueprints/deploy.ts)_
69
69
 
70
70
  ## `sanity blueprints info`
71
71
 
@@ -87,7 +87,7 @@ EXAMPLES
87
87
  $ sanity blueprints info --id abc123
88
88
  ```
89
89
 
90
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v1.5.0/src/commands/blueprints/info.ts)_
90
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v1.6.0/src/commands/blueprints/info.ts)_
91
91
 
92
92
  ## `sanity blueprints logs`
93
93
 
@@ -109,7 +109,7 @@ EXAMPLES
109
109
  $ sanity blueprints logs --watch
110
110
  ```
111
111
 
112
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v1.5.0/src/commands/blueprints/logs.ts)_
112
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v1.6.0/src/commands/blueprints/logs.ts)_
113
113
 
114
114
  ## `sanity blueprints plan`
115
115
 
@@ -126,7 +126,7 @@ EXAMPLES
126
126
  $ sanity blueprints plan
127
127
  ```
128
128
 
129
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v1.5.0/src/commands/blueprints/plan.ts)_
129
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v1.6.0/src/commands/blueprints/plan.ts)_
130
130
 
131
131
  ## `sanity blueprints stacks`
132
132
 
@@ -143,7 +143,7 @@ EXAMPLES
143
143
  $ sanity blueprints stacks
144
144
  ```
145
145
 
146
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v1.5.0/src/commands/blueprints/stacks.ts)_
146
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v1.6.0/src/commands/blueprints/stacks.ts)_
147
147
 
148
148
  ## `sanity functions dev`
149
149
 
@@ -163,7 +163,7 @@ EXAMPLES
163
163
  $ sanity functions dev --port 8974
164
164
  ```
165
165
 
166
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v1.5.0/src/commands/functions/dev.ts)_
166
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v1.6.0/src/commands/functions/dev.ts)_
167
167
 
168
168
  ## `sanity functions invoke ID`
169
169
 
@@ -189,7 +189,7 @@ EXAMPLES
189
189
  $ sanity functions invoke <ID> --file 'payload.json'
190
190
  ```
191
191
 
192
- _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v1.5.0/src/commands/functions/invoke.ts)_
192
+ _See code: [src/commands/functions/invoke.ts](https://github.com/sanity-io/runtime-cli/blob/v1.6.0/src/commands/functions/invoke.ts)_
193
193
 
194
194
  ## `sanity functions logs ID`
195
195
 
@@ -209,7 +209,7 @@ EXAMPLES
209
209
  $ sanity functions logs <ID>
210
210
  ```
211
211
 
212
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v1.5.0/src/commands/functions/logs.ts)_
212
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v1.6.0/src/commands/functions/logs.ts)_
213
213
 
214
214
  ## `sanity functions test PATH`
215
215
 
@@ -238,7 +238,7 @@ EXAMPLES
238
238
  $ sanity functions test ./test.ts --data '{ "id": 1 }' --timeout 60
239
239
  ```
240
240
 
241
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v1.5.0/src/commands/functions/test.ts)_
241
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v1.6.0/src/commands/functions/test.ts)_
242
242
 
243
243
  ## `sanity help [COMMAND]`
244
244
 
@@ -14,7 +14,7 @@ export declare function readBlueprintOnDisk({ blueprintPath, getStack, }?: {
14
14
  stackId?: string;
15
15
  deployedStack?: BlueprintStack;
16
16
  }>;
17
- export declare function updateBlueprintMetadata({ blueprintPath, projectId, stackId, }: {
17
+ /** @experimental */ export declare function updateBlueprintMetadata({ blueprintPath, projectId, stackId, }: {
18
18
  blueprintPath?: string;
19
19
  projectId: string;
20
20
  stackId: string;
@@ -1,4 +1,5 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { createRequire } from 'node:module';
2
3
  import { dirname, extname, join } from 'node:path';
3
4
  import { cwd } from 'node:process';
4
5
  import { BlueprintErrorType } from '../../utils/types.js';
@@ -7,10 +8,10 @@ import blueprintParserValidator from '../../utils/vendor/parser-validator.js';
7
8
  import { getStack as getStackById } from './stacks.js';
8
9
  const SUPPORTED_FILE_NAMES_IN_PRIORITY_ORDER = [
9
10
  'blueprint.json',
10
- // 'blueprint.js',
11
- // 'blueprint.mjs',
12
- // 'blueprint.cjs',
13
- // 'blueprint.ts',
11
+ 'blueprint.js',
12
+ 'blueprint.mjs',
13
+ 'blueprint.cjs',
14
+ 'blueprint.ts',
14
15
  ];
15
16
  function findBlueprintFile(blueprintPath) {
16
17
  if (blueprintPath) {
@@ -41,12 +42,12 @@ function readConfigFile(blueprintPath) {
41
42
  }
42
43
  }
43
44
  }
44
- const metadataPath = join(cwd(), '.blueprint', 'config.json');
45
- if (!existsSync(metadataPath))
45
+ const configFilePath = join(cwd(), '.blueprint', 'config.json');
46
+ if (!existsSync(configFilePath))
46
47
  return null;
47
48
  try {
48
- const metadata = JSON.parse(readFileSync(metadataPath, 'utf8'));
49
- return metadata || null;
49
+ const config = JSON.parse(readFileSync(configFilePath, 'utf8'));
50
+ return config || null;
50
51
  }
51
52
  catch (err) {
52
53
  return null;
@@ -59,25 +60,58 @@ export async function readBlueprintOnDisk({ blueprintPath, getStack, } = {}) {
59
60
  throw Error('Could not find Blueprint file! Use the init command.');
60
61
  const { path, fileName, extension } = blueprintFile;
61
62
  let blueprintString;
62
- if (extension === '.json') {
63
- blueprintString = readFileSync(path, 'utf8').toString();
64
- // } else if (extension === '.js' || extension === '.mjs') {
65
- // const blueprintModule = require(path)
66
- // blueprintJson = blueprintModule.default
63
+ let blueprintJson;
64
+ let blueprintModule;
65
+ switch (extension) {
66
+ case '.json': {
67
+ blueprintString = readFileSync(path, 'utf8').toString();
68
+ blueprintJson = JSON.parse(blueprintString);
69
+ break;
70
+ }
71
+ case '.js':
72
+ case '.mjs': {
73
+ const module = await import(path);
74
+ blueprintModule = module.default;
75
+ break;
76
+ }
77
+ case '.cjs': {
78
+ const require = createRequire(import.meta.url);
79
+ blueprintModule = require(path);
80
+ break;
81
+ }
82
+ case '.ts': {
83
+ console.warn('\x1b[2mSupport for Typescript blueprints is experimental.\x1b[0m');
84
+ try {
85
+ const { tsImport } = await import('tsx/esm/api');
86
+ const module = await tsImport(path, dirname(path));
87
+ blueprintModule = module.default;
88
+ }
89
+ catch (err) {
90
+ if (err instanceof Error && err.message.includes('Cannot find module')) {
91
+ throw Error(`TypeScript support requires 'tsx' to be installed. Run: npm install -D tsx`);
92
+ }
93
+ throw err;
94
+ }
95
+ break;
96
+ }
97
+ default:
98
+ throw Error(`Unsupported blueprint file extension: ${extension}`);
67
99
  }
68
- else {
69
- throw Error(`Unsupported blueprint file extension: ${extension}`);
100
+ if (blueprintModule) {
101
+ if (typeof blueprintModule !== 'function')
102
+ throw Error(`Blueprint ${fileName} must export a default function`);
103
+ blueprintJson = blueprintModule();
70
104
  }
71
- const parsed = blueprintParserValidator(JSON.parse(blueprintString));
72
- const { blueprint: parsedBlueprint } = parsed;
73
- const errors = parsed.errors || [];
105
+ const parserResult = blueprintParserValidator(blueprintJson);
106
+ const { blueprint: parsedBlueprint } = parserResult;
107
+ const errors = parserResult.errors || [];
74
108
  // find project and stack IDs from .blueprint/config.json first,
75
109
  // then fallback to metadata in blueprint file,
76
110
  // finally fallback to resources array...
77
111
  let projectId;
78
112
  let stackId;
79
113
  const configIds = readConfigFile(blueprintPath);
80
- const blueprintMetadata = extension === '.json' ? parsedBlueprint.metadata : null;
114
+ const blueprintMetadata = parsedBlueprint.metadata;
81
115
  // find/create project resource
82
116
  if (configIds?.projectId) {
83
117
  projectId = configIds.projectId;
@@ -126,6 +160,7 @@ export async function readBlueprintOnDisk({ blueprintPath, getStack, } = {}) {
126
160
  throw Error(`Unable to parse Blueprint file: ${err}`);
127
161
  }
128
162
  }
163
+ /** @experimental */ // no, that's not a real JSDoc pragma
129
164
  export async function updateBlueprintMetadata({ blueprintPath, projectId, stackId, }) {
130
165
  const blueprintFile = findBlueprintFile(blueprintPath);
131
166
  if (!blueprintFile)
@@ -315,5 +315,5 @@
315
315
  ]
316
316
  }
317
317
  },
318
- "version": "1.5.0"
318
+ "version": "1.6.0"
319
319
  }
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.5.0",
4
+ "version": "1.6.0",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",
@@ -13,6 +13,9 @@
13
13
  "engines": {
14
14
  "node": ">=20.11.0"
15
15
  },
16
+ "optionalPeerDependencies": {
17
+ "tsx": "^4.19.3"
18
+ },
16
19
  "files": [
17
20
  "./bin",
18
21
  "./dist",
@@ -64,6 +67,7 @@
64
67
  "rollup": "^4.36.0",
65
68
  "shx": "^0.4.0",
66
69
  "ts-node": "^10",
70
+ "tsx": "^4.19.3",
67
71
  "typescript": "^5",
68
72
  "vitest": "3.0.8"
69
73
  },