@osdk/create-app 2.1.1 → 2.2.0-beta.10

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 (41) hide show
  1. package/CHANGELOG.md +26 -14
  2. package/README.md +4 -5
  3. package/build/esm/{esm-ZDKAQEHX.js → esm-D3MFKIK5.js} +5 -8
  4. package/build/esm/esm-D3MFKIK5.js.map +1 -0
  5. package/build/esm/{esm-HA4JIHHL.js → esm-EWF64ZOH.js} +10 -7
  6. package/build/esm/esm-EWF64ZOH.js.map +1 -0
  7. package/build/esm/{esm-XWXVWZDN.js → esm-HPYM2Y43.js} +10 -7
  8. package/build/esm/esm-HPYM2Y43.js.map +1 -0
  9. package/build/esm/{esm-ZXMFAUNZ.js → esm-IRYTK2SN.js} +10 -7
  10. package/build/esm/esm-IRYTK2SN.js.map +1 -0
  11. package/build/esm/{esm-BFQ5RNHV.js → esm-QGTNZWRA.js} +4 -4
  12. package/build/esm/{esm-BFQ5RNHV.js.map → esm-QGTNZWRA.js.map} +1 -1
  13. package/build/esm/{esm-YVNV3MQG.js → esm-RVZ3BRIG.js} +10 -7
  14. package/build/esm/esm-RVZ3BRIG.js.map +1 -0
  15. package/build/esm/{esm-EXZTN5HA.js → esm-SHZQJOYD.js} +5 -8
  16. package/build/esm/esm-SHZQJOYD.js.map +1 -0
  17. package/build/esm/{esm-FZSV3C5D.js → esm-TYOQYEDZ.js} +5 -8
  18. package/build/esm/esm-TYOQYEDZ.js.map +1 -0
  19. package/build/esm/{esm-WPYEYT7F.js → esm-VZPD4V7P.js} +5 -8
  20. package/build/esm/esm-VZPD4V7P.js.map +1 -0
  21. package/build/esm/index.js +131 -112
  22. package/build/esm/index.js.map +1 -1
  23. package/build/types/consola.d.ts.map +1 -1
  24. package/build/types/generate/generateEnv.d.ts.map +1 -1
  25. package/build/types/prompts/promptScopes.test.d.ts +1 -0
  26. package/build/types/prompts/promptScopes.test.d.ts.map +1 -0
  27. package/build/types/prompts/promptTemplate.d.ts +2 -0
  28. package/build/types/prompts/promptTemplate.d.ts.map +1 -1
  29. package/package.json +14 -16
  30. package/build/esm/esm-4SFFV2ZK.js +0 -421
  31. package/build/esm/esm-4SFFV2ZK.js.map +0 -1
  32. package/build/esm/esm-EXZTN5HA.js.map +0 -1
  33. package/build/esm/esm-FZSV3C5D.js.map +0 -1
  34. package/build/esm/esm-HA4JIHHL.js.map +0 -1
  35. package/build/esm/esm-NFVUE2AE.js +0 -394
  36. package/build/esm/esm-NFVUE2AE.js.map +0 -1
  37. package/build/esm/esm-WPYEYT7F.js.map +0 -1
  38. package/build/esm/esm-XWXVWZDN.js.map +0 -1
  39. package/build/esm/esm-YVNV3MQG.js.map +0 -1
  40. package/build/esm/esm-ZDKAQEHX.js.map +0 -1
  41. package/build/esm/esm-ZXMFAUNZ.js.map +0 -1
@@ -2,18 +2,21 @@ import yargs from 'yargs';
2
2
  import { hideBin } from 'yargs/helpers';
3
3
  import { createConsola, consola as consola$1 } from 'consola';
4
4
  import { colorize } from 'consola/utils';
5
- import fs2 from 'fs';
6
- import path2 from 'path';
5
+ import fs2 from 'node:fs';
6
+ import path2 from 'node:path';
7
7
  import { findUpSync } from 'find-up';
8
8
  import Handlebars from 'handlebars';
9
- import { fileURLToPath } from 'url';
9
+ import { fileURLToPath } from 'node:url';
10
10
 
11
11
  // src/cli.ts
12
+ var cancelSymbol = Symbol.for("cancel");
12
13
  var consola = createConsola({
13
- // https://github.com/unjs/consola/issues/251
14
- async prompt(...params) {
15
- const response = await consola$1.prompt(...params);
16
- if (typeof response === "symbol" && response.toString() === "Symbol(clack:cancel)") {
14
+ async prompt(message, opts) {
15
+ const response = await consola$1.prompt(message, {
16
+ ...opts,
17
+ cancel: opts?.cancel ?? "symbol"
18
+ });
19
+ if (response === cancelSymbol) {
17
20
  consola$1.fail("Operation cancelled");
18
21
  process.exit(0);
19
22
  }
@@ -52,21 +55,16 @@ async function promptApplicationUrl({
52
55
  return undefined;
53
56
  }
54
57
  if (applicationUrl == null) {
55
- const skip = await consola.prompt(
56
- `Do you know the URL your production application will be hosted on? This is required to create a production build of your application with the correct OAuth redirect URL.`,
57
- {
58
- type: "select",
59
- options: [{
60
- label: "Yes, let me fill it here",
61
- value: "yes"
62
- }, {
63
- label: "No, I will fill it in later following the instructions in the generated README",
64
- value: "no"
65
- }]
66
- }
67
- // Types for "select" are wrong the value is returned rather than the option object
68
- // https://github.com/unjs/consola/pull/238
69
- );
58
+ const skip = await consola.prompt(`Do you know the URL your production application will be hosted on? This is required to create a production build of your application with the correct OAuth redirect URL.`, {
59
+ type: "select",
60
+ options: [{
61
+ label: "Yes, let me fill it here",
62
+ value: "yes"
63
+ }, {
64
+ label: "No, I will fill it in later following the instructions in the generated README",
65
+ value: "no"
66
+ }]
67
+ });
70
68
  if (skip === "no") {
71
69
  return undefined;
72
70
  }
@@ -170,24 +168,19 @@ async function promptOverwrite({
170
168
  if (!fs2.existsSync(path2.join(process.cwd(), project))) {
171
169
  return true;
172
170
  }
173
- const result = await consola.prompt(
174
- `The directory ${green(project)} already exists do you want to overwrite or ignore it?`,
175
- {
176
- type: "select",
177
- options: [{
178
- label: "Remove existing files and continue",
179
- value: "overwrite"
180
- }, {
181
- label: "Ignore files and continue",
182
- value: "ignore"
183
- }, {
184
- label: "Cancel",
185
- value: "cancel"
186
- }]
187
- }
188
- // Types for "select" are wrong the value is returned rather than the option object
189
- // https://github.com/unjs/consola/pull/238
190
- );
171
+ const result = await consola.prompt(`The directory ${green(project)} already exists do you want to overwrite or ignore it?`, {
172
+ type: "select",
173
+ options: [{
174
+ label: "Remove existing files and continue",
175
+ value: "overwrite"
176
+ }, {
177
+ label: "Ignore files and continue",
178
+ value: "ignore"
179
+ }, {
180
+ label: "Cancel",
181
+ value: "cancel"
182
+ }]
183
+ });
191
184
  switch (result) {
192
185
  case "overwrite":
193
186
  return true;
@@ -221,18 +214,17 @@ var scopeNameRegex = /^[a-zA-Z-_:]+$/;
221
214
  async function promptScopes({
222
215
  scopes
223
216
  }) {
224
- if (scopes == null) {
225
- return undefined;
226
- }
227
217
  while (true) {
228
- const invalidScopes = scopes.filter((scope) => !scopeNameRegex.test(scope));
229
- const allValidScopes = invalidScopes.length === 0;
230
- if (allValidScopes) {
231
- break;
218
+ if (scopes != null) {
219
+ const invalidScopes = scopes.filter((scope) => !scopeNameRegex.test(scope));
220
+ const allValidScopes = invalidScopes.length === 0;
221
+ if (allValidScopes) {
222
+ break;
223
+ }
224
+ const joinedInvalidScopes = invalidScopes.join(", ");
225
+ consola.fail(`Scopes [ ${joinedInvalidScopes} ] are invalid. Scope names can only contain letters, hyphens, underscores, and colons`);
232
226
  }
233
- const joinedInvalidScopes = invalidScopes.join(", ");
234
- consola.fail(`Scopes [ ${joinedInvalidScopes} ] are invalid. Scope names can only contain letters, hyphens, underscores, and colons`);
235
- const stringScopes = await consola.prompt("Scopes:", {
227
+ const stringScopes = await consola.prompt("Enter the scopes to request during OAuth:", {
236
228
  type: "text",
237
229
  placeholder: "api:read-data api:write-data",
238
230
  default: "api:read-data api:write-data"
@@ -264,18 +256,13 @@ async function promptSdkVersion({
264
256
  }
265
257
  if (template.files[sdkVersion] == null) {
266
258
  consola.fail(`The ${template.label} template does not support a "${sdkVersion}" SDK version.`);
267
- sdkVersion = await consola.prompt(
268
- `Please choose which version of the OSDK you'd like to use for the ${template.label} template:`,
269
- {
270
- type: "select",
271
- options: Object.keys(template.files).reverse().map((sdkVersion2) => ({
272
- label: sdkVersion2,
273
- value: sdkVersion2
274
- }))
275
- }
276
- // Types for "select" are wrong the value is returned rather than the option object
277
- // https://github.com/unjs/consola/pull/238
278
- );
259
+ sdkVersion = await consola.prompt(`Please choose which version of the OSDK you'd like to use for the ${template.label} template:`, {
260
+ type: "select",
261
+ options: Object.keys(template.files).reverse().map((sdkVersion2) => ({
262
+ label: sdkVersion2,
263
+ value: sdkVersion2
264
+ }))
265
+ });
279
266
  }
280
267
  return sdkVersion;
281
268
  }
@@ -291,9 +278,10 @@ var TEMPLATES = [
291
278
  label: "React",
292
279
  envPrefix: "VITE_",
293
280
  buildDirectory: "./dist",
281
+ hidden: false,
294
282
  files: {
295
- "1.x": getPackageFiles(import('./esm-ZXMFAUNZ.js')),
296
- "2.x": getPackageFiles(import('./esm-FZSV3C5D.js'))
283
+ "1.x": getPackageFiles(import('./esm-IRYTK2SN.js')),
284
+ "2.x": getPackageFiles(import('./esm-TYOQYEDZ.js'))
297
285
  }
298
286
  },
299
287
  // Expo
@@ -302,8 +290,9 @@ var TEMPLATES = [
302
290
  label: "Expo",
303
291
  envPrefix: "EXPO_PUBLIC_",
304
292
  buildDirectory: "./dist",
293
+ hidden: false,
305
294
  files: {
306
- "2.x": getPackageFiles(import('./esm-BFQ5RNHV.js'))
295
+ "2.x": getPackageFiles(import('./esm-QGTNZWRA.js'))
307
296
  }
308
297
  },
309
298
  // Vue
@@ -312,20 +301,10 @@ var TEMPLATES = [
312
301
  label: "Vue",
313
302
  envPrefix: "VITE_",
314
303
  buildDirectory: "./dist",
304
+ hidden: false,
315
305
  files: {
316
- "1.x": getPackageFiles(import('./esm-HA4JIHHL.js')),
317
- "2.x": getPackageFiles(import('./esm-EXZTN5HA.js'))
318
- }
319
- },
320
- // Next (static export)
321
- {
322
- id: "template-next-static-export",
323
- label: "Next (static export)",
324
- envPrefix: "NEXT_PUBLIC_",
325
- buildDirectory: "./out",
326
- files: {
327
- "1.x": getPackageFiles(import('./esm-NFVUE2AE.js')),
328
- "2.x": getPackageFiles(import('./esm-4SFFV2ZK.js'))
306
+ "1.x": getPackageFiles(import('./esm-EWF64ZOH.js')),
307
+ "2.x": getPackageFiles(import('./esm-SHZQJOYD.js'))
329
308
  }
330
309
  },
331
310
  // Tutorial: To do App
@@ -334,9 +313,10 @@ var TEMPLATES = [
334
313
  label: "Tutorial: To do App",
335
314
  envPrefix: "VITE_",
336
315
  buildDirectory: "./dist",
316
+ hidden: true,
337
317
  files: {
338
- "1.x": getPackageFiles(import('./esm-XWXVWZDN.js')),
339
- "2.x": getPackageFiles(import('./esm-WPYEYT7F.js'))
318
+ "1.x": getPackageFiles(import('./esm-HPYM2Y43.js')),
319
+ "2.x": getPackageFiles(import('./esm-VZPD4V7P.js'))
340
320
  }
341
321
  },
342
322
  // Tutorial: To do AIP App
@@ -345,30 +325,26 @@ var TEMPLATES = [
345
325
  label: "Tutorial: To do AIP App",
346
326
  envPrefix: "VITE_",
347
327
  buildDirectory: "./dist",
328
+ hidden: true,
348
329
  files: {
349
- "1.x": getPackageFiles(import('./esm-YVNV3MQG.js')),
350
- "2.x": getPackageFiles(import('./esm-ZDKAQEHX.js'))
330
+ "1.x": getPackageFiles(import('./esm-RVZ3BRIG.js')),
331
+ "2.x": getPackageFiles(import('./esm-D3MFKIK5.js'))
351
332
  }
352
333
  }
353
334
  ];
354
335
 
355
336
  // src/prompts/promptTemplate.ts
356
337
  async function promptTemplate(parsed) {
357
- let useBeta = parsed.beta ?? false;
338
+ const useBeta = parsed.beta ?? false;
358
339
  let template = TEMPLATES.find((t) => t.id === parsed.template || t.id === `template-${parsed.template}`);
359
340
  if (template == null) {
360
- const availableTemplates = TEMPLATES.filter((template2) => !template2.hidden && (useBeta ? template2.isBeta === true : !template2.isBeta));
361
- if (availableTemplates.length === 0) {
362
- throw new Error("No available templates found for the selected options.");
363
- }
341
+ const availableTemplates = getAvailableTemplatesOrThrow(useBeta);
364
342
  const templateId = await consola.prompt(parsed.template != null ? `The provided template ${green(parsed.template)} is invalid please select a framework:` : "Select a framework:", {
365
343
  type: "select",
366
344
  options: availableTemplates.map((template2) => ({
367
345
  value: template2.id,
368
346
  label: template2.label
369
347
  }))
370
- // Types for "select" are wrong the value is returned rather than the option object
371
- // https://github.com/unjs/consola/pull/238
372
348
  });
373
349
  template = TEMPLATES.find((t) => t.id === templateId);
374
350
  if (template == null) {
@@ -377,6 +353,13 @@ async function promptTemplate(parsed) {
377
353
  }
378
354
  return template;
379
355
  }
356
+ function getAvailableTemplatesOrThrow(useBeta) {
357
+ const availableTemplates = TEMPLATES.filter((template) => !template.hidden && (useBeta ? template.isBeta === true : !template.isBeta));
358
+ if (availableTemplates.length === 0) {
359
+ throw new Error("No available templates found for the selected options.");
360
+ }
361
+ return availableTemplates;
362
+ }
380
363
 
381
364
  // ../generator-utils/build/esm/changeVersionPrefix.js
382
365
  function changeVersionPrefix(version, prefix) {
@@ -400,12 +383,36 @@ function generateEnvDevelopment({
400
383
  clientId,
401
384
  corsProxy
402
385
  }) {
403
- return generateEnv({
404
- envPrefix,
405
- foundryUrl: corsProxy ? "http://localhost:8080" : foundryUrl,
406
- applicationUrl: "http://localhost:8080",
407
- clientId
408
- });
386
+ const foundryApiUrl = corsProxy ? "http://localhost:8080" : foundryUrl;
387
+ const applicationUrl = "http://localhost:8080";
388
+ return `# This env file is intended for developing on your local computer.
389
+ # To set up development in Foundry's Code Workspaces, see .env.code-workspaces.
390
+ # To deploy your application to production, see .env.production.
391
+ # Note that .env.code-workspaces is only present for projects that were set up
392
+ # using the "Bootstrap in Foundry" option in Developer Console.
393
+
394
+
395
+ # This URL is the URL your users will be redirected back to after signing in.
396
+ # This URL must exactly match one of the URLs listed in the "OAuth & scopes"
397
+ # page of Developer Console.
398
+ #
399
+ # If your application in development is not hosted on port 8080, you will need
400
+ # to change this URL here and in Developer Console.
401
+
402
+ ${envPrefix}FOUNDRY_REDIRECT_URL=${applicationUrl}/auth/callback
403
+
404
+
405
+ # This URL is the Foundry host that your OSDK will use. It typically does not
406
+ # need to be changed.
407
+
408
+ ${envPrefix}FOUNDRY_API_URL=${foundryApiUrl}
409
+
410
+
411
+ # This client ID must match the client ID given on the "OAuth & scopes" page of
412
+ # Developer Console. It typically does not need to be changed.
413
+
414
+ ${envPrefix}FOUNDRY_CLIENT_ID=${clientId}
415
+ `;
409
416
  }
410
417
  function generateEnvProduction({
411
418
  envPrefix,
@@ -413,21 +420,33 @@ function generateEnvProduction({
413
420
  applicationUrl,
414
421
  clientId
415
422
  }) {
416
- return generateEnv({
417
- envPrefix,
418
- foundryUrl,
419
- applicationUrl,
420
- clientId
421
- });
422
- }
423
- function generateEnv({
424
- envPrefix,
425
- foundryUrl,
426
- applicationUrl,
427
- clientId
428
- }) {
429
- return `${envPrefix}FOUNDRY_API_URL=${foundryUrl}
430
- ${applicationUrl == null ? "# " : ""}${envPrefix}FOUNDRY_REDIRECT_URL=${applicationUrl ?? "<Fill in the domain at which you deploy your application>"}/auth/callback
423
+ const applicationUrlOrDefault = applicationUrl ?? "<Fill in the domain at which you deploy your application>";
424
+ return `# This env file is intended for deploying your application to production.
425
+ # To set up development on your local computer, see .env.development.
426
+ # To set up development in Foundry's Code Workspaces, see .env.code-workspaces.
427
+ # Note that .env.code-workspaces is only present for projects that were set up
428
+ # using the "Bootstrap in Foundry" option in Developer Console.
429
+
430
+
431
+ # This URL is the URL your users will be redirected back to after signing in.
432
+ # This URL must exactly match one of the URLs listed in the "OAuth & scopes"
433
+ # page of Developer Console.
434
+ #
435
+ # If you change where your application is hosted, you will need to change this
436
+ # URL here and in Developer Console.
437
+
438
+ ${applicationUrl == null ? "# " : ""}${envPrefix}FOUNDRY_REDIRECT_URL=${applicationUrlOrDefault}/auth/callback
439
+
440
+
441
+ # This URL is the Foundry host that your OSDK will use. It typically does not
442
+ # need to be changed.
443
+
444
+ ${envPrefix}FOUNDRY_API_URL=${foundryUrl}
445
+
446
+
447
+ # This client ID must match the client ID given on the "OAuth & scopes" page of
448
+ # Developer Console. It typically does not need to be changed.
449
+
431
450
  ${envPrefix}FOUNDRY_CLIENT_ID=${clientId}
432
451
  `;
433
452
  }
@@ -519,7 +538,7 @@ async function run({
519
538
  cwd: fileURLToPath(import.meta.url)
520
539
  });
521
540
  ourPackageJsonPath ? JSON.parse(fs2.readFileSync(ourPackageJsonPath, "utf-8")).version : undefined;
522
- const clientVersion = "2.1.1";
541
+ const clientVersion = "2.2.0-beta.10";
523
542
  const templateContext = {
524
543
  project,
525
544
  foundryUrl,
@@ -593,7 +612,7 @@ async function run({
593
612
 
594
613
  // src/cli.ts
595
614
  async function cli(args = process.argv) {
596
- const base = yargs(hideBin(args)).version("2.1.1").wrap(Math.min(150, yargs().terminalWidth())).strict().help().command("$0 [project] [--<option>]", "Create a new OSDK application based on framework templates. Information may be provided through options to skip interactive prompts.", (yargs2) => yargs2.positional("project", {
615
+ const base = yargs(hideBin(args)).version("2.2.0-beta.10").wrap(Math.min(150, yargs().terminalWidth())).strict().help().command("$0 [project] [--<option>]", "Create a new OSDK application based on framework templates. Information may be provided through options to skip interactive prompts.", (yargs2) => yargs2.positional("project", {
597
616
  type: "string",
598
617
  describe: "Project name to create"
599
618
  }).option("overwrite", {