@osdk/create-app 0.0.1 → 0.2.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 (38) hide show
  1. package/build/js/index.cjs +326 -198
  2. package/build/js/index.cjs.map +1 -1
  3. package/build/js/index.mjs +324 -196
  4. package/build/js/index.mjs.map +1 -1
  5. package/build/types/generate/generateEnv.d.ts +11 -0
  6. package/build/types/generate/generateEnv.test.d.ts +1 -0
  7. package/build/types/generate/generateFoundryConfigJson.d.ts +5 -0
  8. package/build/types/generate/generateFoundryConfigJson.test.d.ts +1 -0
  9. package/build/types/generate/generateNpmRc.d.ts +4 -0
  10. package/build/types/generate/generateNpmRc.test.d.ts +1 -0
  11. package/build/types/prompts/promptApplicationRid.d.ts +3 -0
  12. package/build/types/prompts/promptApplicationRid.test.d.ts +1 -0
  13. package/build/types/prompts/promptApplicationUrl.d.ts +4 -0
  14. package/build/types/prompts/promptApplicationUrl.test.d.ts +1 -0
  15. package/build/types/prompts/promptClientId.d.ts +3 -0
  16. package/build/types/prompts/promptClientId.test.d.ts +1 -0
  17. package/build/types/prompts/promptFoundryUrl.d.ts +3 -0
  18. package/build/types/prompts/promptFoundryUrl.test.d.ts +1 -0
  19. package/build/types/prompts/promptOsdkPackage.d.ts +3 -0
  20. package/build/types/prompts/promptOsdkPackage.test.d.ts +1 -0
  21. package/build/types/prompts/promptOsdkRegistryUrl.d.ts +3 -0
  22. package/build/types/prompts/promptOsdkRegistryUrl.test.d.ts +1 -0
  23. package/build/types/prompts/promptOverwrite.d.ts +4 -0
  24. package/build/types/prompts/promptOverwrite.test.d.ts +1 -0
  25. package/build/types/prompts/promptProject.d.ts +3 -0
  26. package/build/types/prompts/promptProject.test.d.ts +1 -0
  27. package/build/types/prompts/promptTemplate.d.ts +4 -0
  28. package/build/types/prompts/promptTemplate.test.d.ts +1 -0
  29. package/build/types/templates.d.ts +5 -0
  30. package/changelog/0.1.0/pr-31.v2.yml +5 -0
  31. package/changelog/0.1.0/pr-32.v2.yml +5 -0
  32. package/changelog/0.2.0/pr-40.v2.yml +5 -0
  33. package/changelog/0.2.0/pr-44.v2.yml +5 -0
  34. package/package.json +1 -1
  35. /package/build/types/{__tests__/cli.test.d.ts → cli.test.d.ts} +0 -0
  36. /package/changelog/{@unreleased → 0.1.0}/pr-26.v2.yml +0 -0
  37. /package/changelog/{@unreleased → 0.1.0}/pr-27.v2.yml +0 -0
  38. /package/changelog/{@unreleased → 0.1.0}/pr-33.v2.yml +0 -0
@@ -1,7 +1,7 @@
1
1
  import { findUpSync } from 'find-up';
2
2
  import Handlebars from 'handlebars';
3
- import fs from 'fs';
4
- import path from 'path';
3
+ import fs2 from 'fs';
4
+ import path2 from 'path';
5
5
  import { fileURLToPath } from 'url';
6
6
  import yargs from 'yargs';
7
7
  import { hideBin } from 'yargs/helpers';
@@ -20,6 +20,74 @@ var consola = createConsola({
20
20
  return response;
21
21
  }
22
22
  });
23
+
24
+ // src/generate/generateEnv.ts
25
+ function generateEnvDevelopment({
26
+ envPrefix,
27
+ foundryUrl,
28
+ clientId
29
+ }) {
30
+ return generateEnv({
31
+ envPrefix,
32
+ foundryUrl,
33
+ applicationUrl: "http://localhost:8080",
34
+ clientId
35
+ });
36
+ }
37
+ function generateEnvProduction({
38
+ envPrefix,
39
+ foundryUrl,
40
+ applicationUrl,
41
+ clientId
42
+ }) {
43
+ return generateEnv({
44
+ envPrefix,
45
+ foundryUrl,
46
+ applicationUrl: applicationUrl ?? "<Fill in the domain at which you deploy your application>",
47
+ clientId
48
+ });
49
+ }
50
+ function generateEnv({
51
+ envPrefix,
52
+ foundryUrl,
53
+ applicationUrl,
54
+ clientId
55
+ }) {
56
+ return `${envPrefix}FOUNDRY_API_URL=${foundryUrl}
57
+ ${envPrefix}FOUNDRY_REDIRECT_URL=${applicationUrl}/auth/callback
58
+ ${envPrefix}FOUNDRY_CLIENT_ID=${clientId}
59
+ `;
60
+ }
61
+
62
+ // src/generate/generateFoundryConfigJson.ts
63
+ function generateFoundryConfigJson({
64
+ foundryUrl,
65
+ application,
66
+ directory
67
+ }) {
68
+ return JSON.stringify({
69
+ foundryUrl,
70
+ site: {
71
+ application,
72
+ directory,
73
+ autoVersion: {
74
+ type: "git-describe",
75
+ tagPrefix: ""
76
+ }
77
+ }
78
+ }, null, 2) + "\n";
79
+ }
80
+
81
+ // src/generate/generateNpmRc.ts
82
+ function generateNpmRc({
83
+ osdkPackage,
84
+ osdkRegistryUrl
85
+ }) {
86
+ const withoutProtocol = osdkRegistryUrl.replace(/^https:\/\//, "");
87
+ return `//${withoutProtocol}:_authToken=\${FOUNDRY_TOKEN}
88
+ ${osdkPackage.split("/")[0]}:registry=${osdkRegistryUrl}
89
+ `;
90
+ }
23
91
  function green(text) {
24
92
  return colorize("green", text);
25
93
  }
@@ -27,24 +95,223 @@ function italic(text) {
27
95
  return colorize("italic", text);
28
96
  }
29
97
 
98
+ // src/prompts/promptApplicationRid.ts
99
+ async function promptApplicationRid({
100
+ application
101
+ }) {
102
+ while (application == null || !/^ri\.third-party-applications\.[^.]+\.application\.[^.]+$/.test(application)) {
103
+ if (application != null) {
104
+ consola.fail("Please enter a valid application resource identifier (rid)");
105
+ }
106
+ application = await consola.prompt(`Enter the application resource identifier (rid) for your application from Developer Console:
107
+ ${italic("(Example ri.third-party-applications.main.application.1c66b352-4e00-40d2-995d-061c9d533ace)")}`, {
108
+ type: "text"
109
+ });
110
+ }
111
+ return application;
112
+ }
113
+
114
+ // src/prompts/promptApplicationUrl.ts
115
+ async function promptApplicationUrl({
116
+ skipApplicationUrl,
117
+ applicationUrl
118
+ }) {
119
+ if (skipApplicationUrl) {
120
+ return void 0;
121
+ }
122
+ if (applicationUrl == null) {
123
+ const skip = await consola.prompt(
124
+ `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.`,
125
+ {
126
+ type: "select",
127
+ options: [{
128
+ label: "Yes, prefill it for me",
129
+ value: "yes"
130
+ }, {
131
+ label: "No, I will fill it in myself later",
132
+ value: "no"
133
+ }]
134
+ }
135
+ // Types for "select" are wrong the value is returned rather than the option object
136
+ // https://github.com/unjs/consola/pull/238
137
+ );
138
+ if (skip === "no") {
139
+ return void 0;
140
+ }
141
+ }
142
+ while (applicationUrl == null || !/^https?:\/\//.test(applicationUrl)) {
143
+ if (applicationUrl != null) {
144
+ consola.fail("Please enter a valid application URL");
145
+ }
146
+ applicationUrl = await consola.prompt(`Enter the URL your production application will be hosted on:
147
+ ${italic("(Example https://myapp.example.palantirfoundry.com/)")}`, {
148
+ type: "text"
149
+ });
150
+ }
151
+ return applicationUrl.replace(/\/$/, "");
152
+ }
153
+
154
+ // src/prompts/promptClientId.ts
155
+ async function promptClientId({
156
+ clientId
157
+ }) {
158
+ while (clientId == null || !/^[0-9a-f]+$/.test(clientId)) {
159
+ if (clientId != null) {
160
+ consola.fail("Please enter a valid OAuth client ID");
161
+ }
162
+ clientId = await consola.prompt(`Enter the OAuth client ID for your application from Developer Console:
163
+ ${italic("(Example 2650385ab6c5e0df3b44aff776b00a42)")}`, {
164
+ type: "text"
165
+ });
166
+ }
167
+ return clientId;
168
+ }
169
+
170
+ // src/prompts/promptFoundryUrl.ts
171
+ async function promptFoundryUrl({
172
+ foundryUrl
173
+ }) {
174
+ while (foundryUrl == null || !foundryUrl.startsWith("https://")) {
175
+ if (foundryUrl != null) {
176
+ consola.fail("Please enter a valid Foundry URL");
177
+ }
178
+ foundryUrl = await consola.prompt(`Enter the URL for your Foundry stack:
179
+ ${italic("(Example https://example.palantirfoundry.com/)")}`, {
180
+ type: "text"
181
+ });
182
+ }
183
+ return foundryUrl.replace(/\/$/, "");
184
+ }
185
+
186
+ // src/prompts/promptOsdkPackage.ts
187
+ async function promptOsdkPackage({
188
+ osdkPackage
189
+ }) {
190
+ while (osdkPackage == null || !/^@[a-z0-9-]+\/sdk$/.test(osdkPackage)) {
191
+ if (osdkPackage != null) {
192
+ consola.fail("Please enter a valid OSDK package name");
193
+ }
194
+ osdkPackage = await consola.prompt(`Enter the OSDK package name for your application from Developer Console:
195
+ ${italic("(Example @my-app/sdk)")}`, {
196
+ type: "text"
197
+ });
198
+ }
199
+ return osdkPackage;
200
+ }
201
+
202
+ // src/prompts/promptOsdkRegistryUrl.ts
203
+ async function promptOsdkRegistryUrl({
204
+ osdkRegistryUrl
205
+ }) {
206
+ while (osdkRegistryUrl == null || !/^https:\/\/[^/]+\/artifacts\/api\/repositories\/ri\.artifacts\.[^/]+\/contents\/release\/npm\/?$/.test(osdkRegistryUrl)) {
207
+ if (osdkRegistryUrl != null) {
208
+ consola.fail("Please enter a valid NPM registry URL to install your OSDK package");
209
+ }
210
+ osdkRegistryUrl = await consola.prompt(`Enter the NPM registry URL to install your OSDK package from Developer Console:
211
+ ${italic("(Example https://example.palantirfoundry.com/artifacts/api/repositories/ri.artifacts.main.repository.a4a7fe1c-486f-4226-b706-7b90005f527d/contents/release/npm)")}`, {
212
+ type: "text"
213
+ });
214
+ }
215
+ return osdkRegistryUrl.replace(/\/$/, "");
216
+ }
217
+ async function promptOverwrite({
218
+ project,
219
+ overwrite
220
+ }) {
221
+ if (overwrite != null) {
222
+ return overwrite;
223
+ }
224
+ if (!fs2.existsSync(path2.join(process.cwd(), project))) {
225
+ return true;
226
+ }
227
+ const result = await consola.prompt(
228
+ `The directory ${green(project)} already exists do you want to overwrite or ignore it?`,
229
+ {
230
+ type: "select",
231
+ options: [{
232
+ label: "Remove existing files and continue",
233
+ value: "overwrite"
234
+ }, {
235
+ label: "Ignore files and continue",
236
+ value: "ignore"
237
+ }, {
238
+ label: "Cancel",
239
+ value: "cancel"
240
+ }]
241
+ }
242
+ // Types for "select" are wrong the value is returned rather than the option object
243
+ // https://github.com/unjs/consola/pull/238
244
+ );
245
+ switch (result) {
246
+ case "overwrite":
247
+ return true;
248
+ case "ignore":
249
+ return false;
250
+ case "cancel":
251
+ consola.fail("Operation cancelled");
252
+ process.exit(0);
253
+ }
254
+ }
255
+
256
+ // src/prompts/promptProject.ts
257
+ async function promptProject({
258
+ project
259
+ }) {
260
+ while (project == null || !/^[a-zA-Z0-9-_]+$/.test(project)) {
261
+ if (project != null) {
262
+ consola.fail("Project name can only contain alphanumeric characters, hyphens and underscores");
263
+ }
264
+ project = await consola.prompt("Project name:", {
265
+ type: "text",
266
+ placeholder: "my-osdk-app",
267
+ default: "my-osdk-app"
268
+ });
269
+ }
270
+ return project;
271
+ }
272
+
30
273
  // src/templates.ts
31
274
  var TEMPLATES = [{
32
275
  id: "template-react",
33
276
  label: "React",
34
- envPrefix: "VITE_"
277
+ envPrefix: "VITE_",
278
+ buildDirectory: "./dist"
35
279
  }, {
36
280
  id: "template-vue",
37
281
  label: "Vue",
38
- envPrefix: "VITE_"
282
+ envPrefix: "VITE_",
283
+ buildDirectory: "./dist"
39
284
  }, {
40
285
  id: "template-next-static-export",
41
286
  label: "Next (static export)",
42
- envPrefix: "NEXT_PUBLIC_"
287
+ envPrefix: "NEXT_PUBLIC_",
288
+ buildDirectory: "./out"
43
289
  }];
44
290
 
291
+ // src/prompts/promptTemplate.ts
292
+ async function promptTemplate(parsed) {
293
+ let template = TEMPLATES.find((t) => t.id === parsed.template);
294
+ if (template == null) {
295
+ const templateId = await consola.prompt(parsed.template != null ? `The provided template ${green(parsed.template)} is invalid please select a framework:` : "Select a framework:", {
296
+ type: "select",
297
+ options: TEMPLATES.map((template2) => ({
298
+ value: template2.id,
299
+ label: template2.label
300
+ }))
301
+ // Types for "select" are wrong the value is returned rather than the option object
302
+ // https://github.com/unjs/consola/pull/238
303
+ });
304
+ template = TEMPLATES.find((t) => t.id === templateId);
305
+ if (template == null) {
306
+ throw new Error(`Template ${templateId} should be found`);
307
+ }
308
+ }
309
+ return template;
310
+ }
311
+
45
312
  // src/cli.ts
46
313
  async function cli(args = process.argv) {
47
- const base = yargs(hideBin(args)).version("0.0.1").strict().help().command("$0 [project] [--<option>]", "Create a new OSDK application based on framework templates. Information may be provided through arguments to skip interactive prompts.", (yargs2) => yargs2.positional("project", {
314
+ const base = yargs(hideBin(args)).version("0.2.0").strict().help().command("$0 [project] [--<option>]", "Create a new OSDK application based on framework templates. Information may be provided through arguments to skip interactive prompts.", (yargs2) => yargs2.positional("project", {
48
315
  type: "string",
49
316
  describe: "Project name to create"
50
317
  }).option("overwrite", {
@@ -62,6 +329,9 @@ async function cli(args = process.argv) {
62
329
  }).option("skip-application-url", {
63
330
  type: "boolean",
64
331
  describe: "Skip filling in URL the production application will be hosted on"
332
+ }).option("application", {
333
+ type: "string",
334
+ describe: "Application resource identifier (rid)"
65
335
  }).option("client-id", {
66
336
  type: "string",
67
337
  describe: "OAuth client ID for application"
@@ -74,25 +344,29 @@ async function cli(args = process.argv) {
74
344
  }));
75
345
  const parsed = base.parseSync();
76
346
  const project = await promptProject(parsed);
77
- const overwrite = await promptOverwrite(parsed, project);
347
+ const overwrite = await promptOverwrite({
348
+ ...parsed,
349
+ project
350
+ });
78
351
  const template = await promptTemplate(parsed);
79
352
  const foundryUrl = await promptFoundryUrl(parsed);
80
353
  const applicationUrl = await promptApplicationUrl(parsed);
354
+ const application = await promptApplicationRid(parsed);
81
355
  const clientId = await promptClientId(parsed);
82
356
  const osdkPackage = await promptOsdkPackage(parsed);
83
357
  const osdkRegistryUrl = await promptOsdkRegistryUrl(parsed);
84
358
  consola.log("");
85
359
  consola.start(`Creating project ${green(project)} using template ${green(template.id)}`);
86
360
  const cwd = process.cwd();
87
- const root = path.join(cwd, project);
88
- if (fs.existsSync(root)) {
361
+ const root = path2.join(cwd, project);
362
+ if (fs2.existsSync(root)) {
89
363
  if (overwrite) {
90
364
  consola.info(`Overwriting existing project directory`);
91
- fs.rmSync(root, {
365
+ fs2.rmSync(root, {
92
366
  recursive: true,
93
367
  force: true
94
368
  });
95
- fs.mkdirSync(root, {
369
+ fs2.mkdirSync(root, {
96
370
  recursive: true
97
371
  });
98
372
  } else {
@@ -100,26 +374,30 @@ async function cli(args = process.argv) {
100
374
  }
101
375
  } else {
102
376
  consola.info(`Creating project directory`);
103
- fs.mkdirSync(root, {
377
+ fs2.mkdirSync(root, {
104
378
  recursive: true
105
379
  });
106
380
  }
107
381
  consola.info(`Copying files into project directory`);
108
382
  const templatesDir = findUpSync("templates", {
109
- cwd: path.dirname(fileURLToPath(import.meta.url)),
383
+ cwd: path2.dirname(fileURLToPath(import.meta.url)),
110
384
  type: "directory"
111
385
  });
112
386
  if (templatesDir == null) {
113
387
  throw new Error(`Could not find templates directory`);
114
388
  }
115
- const templateDir = path.resolve(templatesDir, template.id);
116
- fs.cpSync(templateDir, root, {
389
+ const templateDir = path2.resolve(templatesDir, template.id);
390
+ fs2.cpSync(templateDir, root, {
117
391
  recursive: true
118
392
  });
393
+ const templateContext = {
394
+ project,
395
+ osdkPackage
396
+ };
119
397
  const templateHbs = function(dir) {
120
- fs.readdirSync(dir).forEach(function(file) {
398
+ fs2.readdirSync(dir).forEach(function(file) {
121
399
  file = dir + "/" + file;
122
- const stat = fs.statSync(file);
400
+ const stat = fs2.statSync(file);
123
401
  if (stat.isDirectory()) {
124
402
  templateHbs(file);
125
403
  return;
@@ -127,37 +405,43 @@ async function cli(args = process.argv) {
127
405
  if (!file.endsWith(".hbs")) {
128
406
  return;
129
407
  }
130
- const hbsContext = {
131
- project,
132
- osdkPackage
133
- };
134
- const templated = Handlebars.compile(fs.readFileSync(file, "utf-8"))(hbsContext);
135
- fs.writeFileSync(file.replace(/.hbs$/, ""), templated);
136
- fs.rmSync(file);
408
+ const templated = Handlebars.compile(fs2.readFileSync(file, "utf-8"))(templateContext);
409
+ fs2.writeFileSync(file.replace(/.hbs$/, ""), templated);
410
+ fs2.rmSync(file);
137
411
  });
138
412
  };
139
413
  templateHbs(root);
140
- const npmRc = `//${osdkRegistryUrl.replace(/^https:\/\//, "")}:_authToken=\${FOUNDRY_SDK_AUTH_TOKEN}
141
- ${osdkPackage.split("/")[0]}:registry=${osdkRegistryUrl}
142
- `;
143
- fs.writeFileSync(path.join(root, ".npmrc"), npmRc);
144
- const envDevelopment = `${template.envPrefix}FOUNDRY_API_URL=${foundryUrl}
145
- ${template.envPrefix}FOUNDRY_REDIRECT_URL=http://localhost:8080/auth/callback
146
- ${template.envPrefix}FOUNDRY_CLIENT_ID=${clientId}
147
- `;
148
- fs.writeFileSync(path.join(root, ".env.development"), envDevelopment);
149
- const envProduction = `${template.envPrefix}FOUNDRY_API_URL=${foundryUrl}
150
- ${template.envPrefix}FOUNDRY_REDIRECT_URL=${applicationUrl != null ? applicationUrl : "<Fill in the domain at which you deploy your application>"}/auth/callback
151
- ${template.envPrefix}FOUNDRY_CLIENT_ID=${clientId}
152
- `;
153
- fs.writeFileSync(path.join(root, ".env.production"), envProduction);
414
+ const npmRc = generateNpmRc({
415
+ osdkPackage,
416
+ osdkRegistryUrl
417
+ });
418
+ fs2.writeFileSync(path2.join(root, ".npmrc"), npmRc);
419
+ const envDevelopment = generateEnvDevelopment({
420
+ envPrefix: template.envPrefix,
421
+ foundryUrl,
422
+ clientId
423
+ });
424
+ fs2.writeFileSync(path2.join(root, ".env.development"), envDevelopment);
425
+ const envProduction = generateEnvProduction({
426
+ envPrefix: template.envPrefix,
427
+ foundryUrl,
428
+ applicationUrl,
429
+ clientId
430
+ });
431
+ fs2.writeFileSync(path2.join(root, ".env.production"), envProduction);
432
+ const foundryConfigJson = generateFoundryConfigJson({
433
+ foundryUrl,
434
+ application,
435
+ directory: template.buildDirectory
436
+ });
437
+ fs2.writeFileSync(path2.join(root, "foundry.config.json"), foundryConfigJson);
154
438
  consola.success("Success");
155
- const cdRelative = path.relative(cwd, root);
439
+ const cdRelative = path2.relative(cwd, root);
156
440
  consola.box({
157
441
  message: `Done! Run the following commands to get started:
158
442
 
159
443
  \`cd ${cdRelative}\`
160
- \`export FOUNDRY_SDK_AUTH_TOKEN=<token>\`
444
+ \`export FOUNDRY_TOKEN=<token>\`
161
445
  \`npm install\`
162
446
  \`npm run dev\``,
163
447
  style: {
@@ -167,162 +451,6 @@ ${template.envPrefix}FOUNDRY_CLIENT_ID=${clientId}
167
451
  }
168
452
  });
169
453
  }
170
- async function promptProject(parsed) {
171
- let project = parsed.project;
172
- while (project == null || !/^[a-zA-Z0-9-_]+$/.test(project)) {
173
- if (project != null) {
174
- consola.fail("Project name can only contain alphanumeric characters, hyphens and underscores");
175
- }
176
- project = await consola.prompt("Project name:", {
177
- type: "text",
178
- placeholder: "my-osdk-app",
179
- default: "my-osdk-app"
180
- });
181
- }
182
- return project;
183
- }
184
- async function promptOverwrite(parsed, project) {
185
- if (!fs.existsSync(path.join(process.cwd(), project))) {
186
- return true;
187
- }
188
- if (parsed.overwrite != null) {
189
- return parsed.overwrite;
190
- }
191
- const result = await consola.prompt(
192
- `The directory ${green(project)} already exists do you want to overwrite or ignore it?`,
193
- {
194
- type: "select",
195
- options: [{
196
- label: "Remove existing files and continue",
197
- value: "overwrite"
198
- }, {
199
- label: "Ignore files and continue",
200
- value: "ignore"
201
- }, {
202
- label: "Cancel",
203
- value: "cancel"
204
- }]
205
- }
206
- // Types for "select" are wrong the value is returned rather than the option object
207
- // https://github.com/unjs/consola/pull/238
208
- );
209
- switch (result) {
210
- case "overwrite":
211
- return true;
212
- case "ignore":
213
- return false;
214
- case "cancel":
215
- consola.fail("Operation cancelled");
216
- process.exit(0);
217
- }
218
- }
219
- async function promptTemplate(parsed) {
220
- let template = TEMPLATES.find((t) => t.id === parsed.template);
221
- if (template == null) {
222
- const templateId = await consola.prompt(parsed.template != null ? `The provided template ${green(parsed.template)} is invalid please select a framework:` : "Select a framework:", {
223
- type: "select",
224
- options: TEMPLATES.map((template2) => ({
225
- value: template2.id,
226
- label: template2.label
227
- }))
228
- // Types for "select" are wrong the value is returned rather than the option object
229
- // https://github.com/unjs/consola/pull/238
230
- });
231
- template = TEMPLATES.find((t) => t.id === templateId);
232
- if (template == null) {
233
- throw new Error(`Template ${templateId} should be found`);
234
- }
235
- }
236
- return template;
237
- }
238
- async function promptFoundryUrl(parsed) {
239
- let foundryUrl = parsed.foundryUrl;
240
- while (foundryUrl == null || !foundryUrl.startsWith("https://")) {
241
- if (foundryUrl != null) {
242
- consola.fail("Please enter a valid Foundry URL");
243
- }
244
- foundryUrl = await consola.prompt(`Enter the URL for your Foundry stack:
245
- ${italic("(Example https://example.palantirfoundry.com/)")}`, {
246
- type: "text"
247
- });
248
- }
249
- return foundryUrl.replace(/\/$/, "");
250
- }
251
- async function promptApplicationUrl(parsed) {
252
- if (parsed.skipApplicationUrl) {
253
- return void 0;
254
- }
255
- let applicationUrl = parsed.applicationUrl;
256
- if (applicationUrl == null) {
257
- const skip = await consola.prompt(
258
- `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.`,
259
- {
260
- type: "select",
261
- options: [{
262
- label: "Yes, prefill it for me",
263
- value: "yes"
264
- }, {
265
- label: "No, I will fill it in myself later",
266
- value: "no"
267
- }]
268
- }
269
- // Types for "select" are wrong the value is returned rather than the option object
270
- // https://github.com/unjs/consola/pull/238
271
- );
272
- if (skip === "no") {
273
- return void 0;
274
- }
275
- }
276
- while (applicationUrl == null || !/^https?:\/\//.test(applicationUrl)) {
277
- if (applicationUrl != null) {
278
- consola.fail("Please enter a valid application URL");
279
- }
280
- applicationUrl = await consola.prompt(`Enter the URL your production application will be hosted on:
281
- ${italic("(Example https://myapp.example.palantirfoundry.com/)")}`, {
282
- type: "text"
283
- });
284
- }
285
- return applicationUrl.replace(/\/$/, "");
286
- }
287
- async function promptClientId(parsed) {
288
- let clientId = parsed.clientId;
289
- while (clientId == null || !/^[0-9a-f]+$/.test(clientId)) {
290
- if (clientId != null) {
291
- consola.fail("Please enter a valid OAuth client ID");
292
- }
293
- clientId = await consola.prompt(`Enter the OAuth client ID for your application from Developer Console:
294
- ${italic("(Example 2650385ab6c5e0df3b44aff776b00a42)")}`, {
295
- type: "text"
296
- });
297
- }
298
- return clientId;
299
- }
300
- async function promptOsdkPackage(parsed) {
301
- let osdkPackage = parsed.osdkPackage;
302
- while (osdkPackage == null || !/^@[a-z0-9-]+\/sdk$/.test(osdkPackage)) {
303
- if (osdkPackage != null) {
304
- consola.fail("Please enter a valid OSDK package name");
305
- }
306
- osdkPackage = await consola.prompt(`Enter the OSDK package name for your application from Developer Console:
307
- ${italic("(Example @my-app/sdk)")}`, {
308
- type: "text"
309
- });
310
- }
311
- return osdkPackage;
312
- }
313
- async function promptOsdkRegistryUrl(parsed) {
314
- let osdkRegistryUrl = parsed.osdkRegistryUrl;
315
- while (osdkRegistryUrl == null || !/^https:\/\/[^/]+\/artifacts\/api\/repositories\/ri\.artifacts\.[^/]+\/contents\/release\/npm\/?$/.test(osdkRegistryUrl)) {
316
- if (osdkRegistryUrl != null) {
317
- consola.fail("Please enter a valid NPM registry URL to install your OSDK package");
318
- }
319
- osdkRegistryUrl = await consola.prompt(`Enter the NPM registry URL to install your OSDK package from Developer Console:
320
- ${italic("(Example https://example.palantirfoundry.com/artifacts/api/repositories/ri.artifacts.main.repository.a4a7fe1c-486f-4226-b706-7b90005f527d/contents/release/npm)")}`, {
321
- type: "text"
322
- });
323
- }
324
- return osdkRegistryUrl.replace(/\/$/, "");
325
- }
326
454
 
327
455
  export { cli };
328
456
  //# sourceMappingURL=out.js.map