@sanity/runtime-cli 8.1.4 → 8.1.6

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-run COMMAND
21
21
  running command...
22
22
  $ sanity-run (--version)
23
- @sanity/runtime-cli/8.1.4 linux-x64 node-v22.16.0
23
+ @sanity/runtime-cli/8.1.6 linux-x64 node-v22.16.0
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -86,7 +86,7 @@ EXAMPLES
86
86
  $ sanity-run blueprints add function --name my-function --fn-type document-publish --lang js
87
87
  ```
88
88
 
89
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/blueprints/add.ts)_
89
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/add.ts)_
90
90
 
91
91
  ## `sanity-run blueprints config`
92
92
 
@@ -117,7 +117,7 @@ EXAMPLES
117
117
  $ sanity-run blueprints config --edit --project-id <projectId> --stack-id <stackId>
118
118
  ```
119
119
 
120
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/blueprints/config.ts)_
120
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/config.ts)_
121
121
 
122
122
  ## `sanity-run blueprints deploy`
123
123
 
@@ -139,7 +139,7 @@ EXAMPLES
139
139
  $ sanity-run blueprints deploy --no-wait
140
140
  ```
141
141
 
142
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/blueprints/deploy.ts)_
142
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/deploy.ts)_
143
143
 
144
144
  ## `sanity-run blueprints destroy`
145
145
 
@@ -164,7 +164,7 @@ EXAMPLES
164
164
  $ sanity-run blueprints destroy --stack-id <stackId> --project-id <projectId> --force --no-wait
165
165
  ```
166
166
 
167
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/blueprints/destroy.ts)_
167
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/destroy.ts)_
168
168
 
169
169
  ## `sanity-run blueprints info`
170
170
 
@@ -186,7 +186,7 @@ EXAMPLES
186
186
  $ sanity-run blueprints info --stack-id <stackId>
187
187
  ```
188
188
 
189
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/blueprints/info.ts)_
189
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/info.ts)_
190
190
 
191
191
  ## `sanity-run blueprints init [DIR]`
192
192
 
@@ -224,7 +224,7 @@ EXAMPLES
224
224
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
225
225
  ```
226
226
 
227
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/blueprints/init.ts)_
227
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/init.ts)_
228
228
 
229
229
  ## `sanity-run blueprints logs`
230
230
 
@@ -246,7 +246,7 @@ EXAMPLES
246
246
  $ sanity-run blueprints logs --watch
247
247
  ```
248
248
 
249
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/blueprints/logs.ts)_
249
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/logs.ts)_
250
250
 
251
251
  ## `sanity-run blueprints plan`
252
252
 
@@ -263,7 +263,7 @@ EXAMPLES
263
263
  $ sanity-run blueprints plan
264
264
  ```
265
265
 
266
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/blueprints/plan.ts)_
266
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/plan.ts)_
267
267
 
268
268
  ## `sanity-run blueprints stacks`
269
269
 
@@ -285,7 +285,7 @@ EXAMPLES
285
285
  $ sanity-run blueprints stacks --project-id <projectId>
286
286
  ```
287
287
 
288
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/blueprints/stacks.ts)_
288
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/blueprints/stacks.ts)_
289
289
 
290
290
  ## `sanity-run functions dev`
291
291
 
@@ -305,7 +305,7 @@ EXAMPLES
305
305
  $ sanity-run functions dev --port 8974
306
306
  ```
307
307
 
308
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/functions/dev.ts)_
308
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/functions/dev.ts)_
309
309
 
310
310
  ## `sanity-run functions env add NAME KEY VALUE`
311
311
 
@@ -327,7 +327,7 @@ EXAMPLES
327
327
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
328
328
  ```
329
329
 
330
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/functions/env/add.ts)_
330
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/functions/env/add.ts)_
331
331
 
332
332
  ## `sanity-run functions env list NAME`
333
333
 
@@ -347,7 +347,7 @@ EXAMPLES
347
347
  $ sanity-run functions env list MyFunction
348
348
  ```
349
349
 
350
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/functions/env/list.ts)_
350
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/functions/env/list.ts)_
351
351
 
352
352
  ## `sanity-run functions env remove NAME KEY`
353
353
 
@@ -368,7 +368,7 @@ EXAMPLES
368
368
  $ sanity-run functions env remove MyFunction API_URL
369
369
  ```
370
370
 
371
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/functions/env/remove.ts)_
371
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/functions/env/remove.ts)_
372
372
 
373
373
  ## `sanity-run functions logs NAME`
374
374
 
@@ -402,7 +402,7 @@ EXAMPLES
402
402
  $ sanity-run functions logs <name> --delete
403
403
  ```
404
404
 
405
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/functions/logs.ts)_
405
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/functions/logs.ts)_
406
406
 
407
407
  ## `sanity-run functions test NAME`
408
408
 
@@ -435,7 +435,7 @@ EXAMPLES
435
435
  $ sanity-run functions test <name> --data '{ "id": 1 }' --timeout 60
436
436
  ```
437
437
 
438
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.4/src/commands/functions/test.ts)_
438
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v8.1.6/src/commands/functions/test.ts)_
439
439
 
440
440
  ## `sanity-run help [COMMAND]`
441
441
 
@@ -200,7 +200,7 @@ export async function writeOrUpdateNodeDependency({ blueprintFilePath, dependenc
200
200
  const packageJsonPath = join(dir, 'package.json');
201
201
  const packageExists = existsSync(packageJsonPath);
202
202
  if (!packageExists) {
203
- writeFileSync(packageJsonPath, JSON.stringify({ devDependencies: { [dependency]: version } }, null, 2));
203
+ writeFileSync(packageJsonPath, JSON.stringify({ type: 'module', devDependencies: { [dependency]: version } }, null, 2));
204
204
  return;
205
205
  }
206
206
  const packageJson = readFileSync(packageJsonPath, 'utf8');
@@ -10,7 +10,6 @@ import { check, indent, warn } from '../../utils/display/presenters.js';
10
10
  import { validateFunctionName } from '../../utils/validate/resource.js';
11
11
  const FUNCTION_BLUEPRINT_RESOURCE_TEMPLATE = `
12
12
  export default defineBlueprint({
13
- // ...
14
13
  resources: [
15
14
  // ...
16
15
  defineDocumentFunction({name: '{{fnName}}'}), // ← add this line
@@ -162,11 +161,11 @@ export async function blueprintAddCore(options) {
162
161
  log(`\n${chalk.bold('Add the Resource to your Blueprint:')}`);
163
162
  switch (blueprint.fileInfo.extension) {
164
163
  case '.ts':
165
- log(highlight(FUNCTION_BLUEPRINT_RESOURCE_TEMPLATE.replace('{{fnName}}', fnName)));
166
- break;
167
164
  case '.js':
165
+ case '.mjs': {
168
166
  log(highlight(FUNCTION_BLUEPRINT_RESOURCE_TEMPLATE.replace('{{fnName}}', fnName)));
169
167
  break;
168
+ }
170
169
  default:
171
170
  log(highlight(JSON.stringify(resource, null, 2)));
172
171
  break;
@@ -1,4 +1,4 @@
1
- import { existsSync } from 'node:fs';
1
+ import { existsSync, readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import chalk from 'chalk';
4
4
  import inquirer from 'inquirer';
@@ -15,8 +15,8 @@ export async function blueprintInitCore(options) {
15
15
  const { dir: flagDir, example: flagExample, 'blueprint-type': flagBlueprintType, 'project-id': flagProjectId, 'stack-id': flagStackId, 'stack-name': flagStackName, } = flags;
16
16
  const { dir: argDir } = args;
17
17
  const providedDir = argDir || flagDir;
18
- const dir = providedDir || '.';
19
- const existingBlueprint = findBlueprintFile(dir);
18
+ const blueprintDir = providedDir || '.';
19
+ const existingBlueprint = findBlueprintFile(blueprintDir);
20
20
  if (existingBlueprint) {
21
21
  return { success: false, error: 'Existing Blueprint found.' };
22
22
  }
@@ -40,7 +40,7 @@ export async function blueprintInitCore(options) {
40
40
  });
41
41
  // * 4. download and write example to disk
42
42
  // take into account optional providedDir
43
- const exampleDir = join(dir, providedDir ? '' : flagExample);
43
+ const exampleDir = join(blueprintDir, providedDir ? '' : flagExample);
44
44
  if (existsSync(exampleDir)) {
45
45
  return { success: false, error: `Example directory "${exampleDir}" already exists.` };
46
46
  }
@@ -72,10 +72,25 @@ export async function blueprintInitCore(options) {
72
72
  }
73
73
  return { success: true };
74
74
  }
75
- const blueprintExtension = flagBlueprintType || (await promptForBlueprintType());
75
+ let blueprintExtension = flagBlueprintType || (await promptForBlueprintType());
76
76
  if (!blueprintExtension) {
77
77
  return { success: false, error: 'Blueprint type is required.' };
78
78
  }
79
+ if (blueprintExtension === 'js') {
80
+ const packageJsonPath = join(blueprintDir, 'package.json');
81
+ const packageExists = existsSync(packageJsonPath);
82
+ if (packageExists) {
83
+ // if package.json#type is not module, set blueprintExtension to mjs
84
+ try {
85
+ const packageJson = readFileSync(packageJsonPath, 'utf8');
86
+ const packageJsonObject = JSON.parse(packageJson);
87
+ if (packageJsonObject.type !== 'module') {
88
+ blueprintExtension = 'mjs';
89
+ }
90
+ }
91
+ catch { } // not our concern
92
+ }
93
+ }
79
94
  let projectId = flagProjectId;
80
95
  let stackId = flagStackId;
81
96
  if (!projectId) {
@@ -104,21 +119,21 @@ export async function blueprintInitCore(options) {
104
119
  stackId = await promptForStackId({ projectId, token });
105
120
  }
106
121
  }
107
- const fileName = `sanity.blueprint.${blueprintExtension}`;
108
- const filePath = join(dir, fileName);
109
- writeBlueprintToDisk({ blueprintFilePath: filePath });
122
+ const blueprintFileName = `sanity.blueprint.${blueprintExtension}`;
123
+ const blueprintFilePath = join(blueprintDir, blueprintFileName);
124
+ writeBlueprintToDisk({ blueprintFilePath });
110
125
  if (providedDir)
111
126
  log(check(`${chalk.bold('New folder created:')} ${providedDir}/`));
112
- log(check(`${chalk.bold('Created Blueprint:')} ${providedDir ?? '.'}/${fileName}`));
113
- writeConfigFile({ blueprintFilePath: filePath, projectId, stackId });
127
+ log(check(`${chalk.bold('Created Blueprint:')} ${providedDir ?? '.'}/${blueprintFileName}`));
128
+ writeConfigFile({ blueprintFilePath, projectId, stackId });
114
129
  log(check(`${chalk.bold('Added configuration:')} ${providedDir ?? '.'}/${BLUEPRINT_DIR}/${BLUEPRINT_CONFIG_FILE}`));
115
- writeGitignoreFile({ blueprintFilePath: filePath });
130
+ writeGitignoreFile({ blueprintFilePath });
116
131
  log(check(`${chalk.bold('Added .gitignore:')} ${providedDir ?? '.'}/.gitignore`));
117
132
  if (blueprintExtension !== 'json') {
118
133
  try {
119
134
  // check for || create package.json and add @sanity/blueprints to dependencies
120
135
  await writeOrUpdateNodeDependency({
121
- blueprintFilePath: filePath,
136
+ blueprintFilePath,
122
137
  dependency: '@sanity/blueprints',
123
138
  });
124
139
  log(check(`${chalk.bold('Added dependency:')} @sanity/blueprints`));
@@ -871,5 +871,5 @@
871
871
  ]
872
872
  }
873
873
  },
874
- "version": "8.1.4"
874
+ "version": "8.1.6"
875
875
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sanity/runtime-cli",
3
3
  "description": "Sanity's Runtime CLI for Blueprints and Functions",
4
- "version": "8.1.4",
4
+ "version": "8.1.6",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",