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