@osdk/create-app 0.0.1 → 0.1.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/build/js/index.cjs +274 -194
- package/build/js/index.cjs.map +1 -1
- package/build/js/index.mjs +272 -192
- package/build/js/index.mjs.map +1 -1
- package/build/types/generate/generateEnv.d.ts +11 -0
- package/build/types/generate/generateEnv.test.d.ts +1 -0
- package/build/types/generate/generateNpmRc.d.ts +4 -0
- package/build/types/generate/generateNpmRc.test.d.ts +1 -0
- package/build/types/prompts/promptApplicationUrl.d.ts +4 -0
- package/build/types/prompts/promptApplicationUrl.test.d.ts +1 -0
- package/build/types/prompts/promptClientId.d.ts +3 -0
- package/build/types/prompts/promptClientId.test.d.ts +1 -0
- package/build/types/prompts/promptFoundryUrl.d.ts +3 -0
- package/build/types/prompts/promptFoundryUrl.test.d.ts +1 -0
- package/build/types/prompts/promptOsdkPackage.d.ts +3 -0
- package/build/types/prompts/promptOsdkPackage.test.d.ts +1 -0
- package/build/types/prompts/promptOsdkRegistryUrl.d.ts +3 -0
- package/build/types/prompts/promptOsdkRegistryUrl.test.d.ts +1 -0
- package/build/types/prompts/promptOverwrite.d.ts +4 -0
- package/build/types/prompts/promptOverwrite.test.d.ts +1 -0
- package/build/types/prompts/promptProject.d.ts +3 -0
- package/build/types/prompts/promptProject.test.d.ts +1 -0
- package/build/types/prompts/promptTemplate.d.ts +4 -0
- package/build/types/prompts/promptTemplate.test.d.ts +1 -0
- package/build/types/templates.d.ts +4 -0
- package/changelog/0.1.0/pr-31.v2.yml +5 -0
- package/changelog/0.1.0/pr-32.v2.yml +5 -0
- package/package.json +1 -1
- /package/build/types/{__tests__/cli.test.d.ts → cli.test.d.ts} +0 -0
- /package/changelog/{@unreleased → 0.1.0}/pr-26.v2.yml +0 -0
- /package/changelog/{@unreleased → 0.1.0}/pr-27.v2.yml +0 -0
- /package/changelog/{@unreleased → 0.1.0}/pr-33.v2.yml +0 -0
package/build/js/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { findUpSync } from 'find-up';
|
|
2
2
|
import Handlebars from 'handlebars';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
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,55 @@ 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/generateNpmRc.ts
|
|
63
|
+
function generateNpmRc({
|
|
64
|
+
osdkPackage,
|
|
65
|
+
osdkRegistryUrl
|
|
66
|
+
}) {
|
|
67
|
+
const withoutProtocol = osdkRegistryUrl.replace(/^https:\/\//, "");
|
|
68
|
+
return `//${withoutProtocol}:_authToken=\${FOUNDRY_SDK_AUTH_TOKEN}
|
|
69
|
+
${osdkPackage.split("/")[0]}:registry=${osdkRegistryUrl}
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
23
72
|
function green(text) {
|
|
24
73
|
return colorize("green", text);
|
|
25
74
|
}
|
|
@@ -27,6 +76,165 @@ function italic(text) {
|
|
|
27
76
|
return colorize("italic", text);
|
|
28
77
|
}
|
|
29
78
|
|
|
79
|
+
// src/prompts/promptApplicationUrl.ts
|
|
80
|
+
async function promptApplicationUrl({
|
|
81
|
+
skipApplicationUrl,
|
|
82
|
+
applicationUrl
|
|
83
|
+
}) {
|
|
84
|
+
if (skipApplicationUrl) {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
if (applicationUrl == null) {
|
|
88
|
+
const skip = await consola.prompt(
|
|
89
|
+
`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.`,
|
|
90
|
+
{
|
|
91
|
+
type: "select",
|
|
92
|
+
options: [{
|
|
93
|
+
label: "Yes, prefill it for me",
|
|
94
|
+
value: "yes"
|
|
95
|
+
}, {
|
|
96
|
+
label: "No, I will fill it in myself later",
|
|
97
|
+
value: "no"
|
|
98
|
+
}]
|
|
99
|
+
}
|
|
100
|
+
// Types for "select" are wrong the value is returned rather than the option object
|
|
101
|
+
// https://github.com/unjs/consola/pull/238
|
|
102
|
+
);
|
|
103
|
+
if (skip === "no") {
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
while (applicationUrl == null || !/^https?:\/\//.test(applicationUrl)) {
|
|
108
|
+
if (applicationUrl != null) {
|
|
109
|
+
consola.fail("Please enter a valid application URL");
|
|
110
|
+
}
|
|
111
|
+
applicationUrl = await consola.prompt(`Enter the URL your production application will be hosted on:
|
|
112
|
+
${italic("(Example https://myapp.example.palantirfoundry.com/)")}`, {
|
|
113
|
+
type: "text"
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return applicationUrl.replace(/\/$/, "");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/prompts/promptClientId.ts
|
|
120
|
+
async function promptClientId({
|
|
121
|
+
clientId
|
|
122
|
+
}) {
|
|
123
|
+
while (clientId == null || !/^[0-9a-f]+$/.test(clientId)) {
|
|
124
|
+
if (clientId != null) {
|
|
125
|
+
consola.fail("Please enter a valid OAuth client ID");
|
|
126
|
+
}
|
|
127
|
+
clientId = await consola.prompt(`Enter the OAuth client ID for your application from Developer Console:
|
|
128
|
+
${italic("(Example 2650385ab6c5e0df3b44aff776b00a42)")}`, {
|
|
129
|
+
type: "text"
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return clientId;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/prompts/promptFoundryUrl.ts
|
|
136
|
+
async function promptFoundryUrl({
|
|
137
|
+
foundryUrl
|
|
138
|
+
}) {
|
|
139
|
+
while (foundryUrl == null || !foundryUrl.startsWith("https://")) {
|
|
140
|
+
if (foundryUrl != null) {
|
|
141
|
+
consola.fail("Please enter a valid Foundry URL");
|
|
142
|
+
}
|
|
143
|
+
foundryUrl = await consola.prompt(`Enter the URL for your Foundry stack:
|
|
144
|
+
${italic("(Example https://example.palantirfoundry.com/)")}`, {
|
|
145
|
+
type: "text"
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return foundryUrl.replace(/\/$/, "");
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// src/prompts/promptOsdkPackage.ts
|
|
152
|
+
async function promptOsdkPackage({
|
|
153
|
+
osdkPackage
|
|
154
|
+
}) {
|
|
155
|
+
while (osdkPackage == null || !/^@[a-z0-9-]+\/sdk$/.test(osdkPackage)) {
|
|
156
|
+
if (osdkPackage != null) {
|
|
157
|
+
consola.fail("Please enter a valid OSDK package name");
|
|
158
|
+
}
|
|
159
|
+
osdkPackage = await consola.prompt(`Enter the OSDK package name for your application from Developer Console:
|
|
160
|
+
${italic("(Example @my-app/sdk)")}`, {
|
|
161
|
+
type: "text"
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return osdkPackage;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/prompts/promptOsdkRegistryUrl.ts
|
|
168
|
+
async function promptOsdkRegistryUrl({
|
|
169
|
+
osdkRegistryUrl
|
|
170
|
+
}) {
|
|
171
|
+
while (osdkRegistryUrl == null || !/^https:\/\/[^/]+\/artifacts\/api\/repositories\/ri\.artifacts\.[^/]+\/contents\/release\/npm\/?$/.test(osdkRegistryUrl)) {
|
|
172
|
+
if (osdkRegistryUrl != null) {
|
|
173
|
+
consola.fail("Please enter a valid NPM registry URL to install your OSDK package");
|
|
174
|
+
}
|
|
175
|
+
osdkRegistryUrl = await consola.prompt(`Enter the NPM registry URL to install your OSDK package from Developer Console:
|
|
176
|
+
${italic("(Example https://example.palantirfoundry.com/artifacts/api/repositories/ri.artifacts.main.repository.a4a7fe1c-486f-4226-b706-7b90005f527d/contents/release/npm)")}`, {
|
|
177
|
+
type: "text"
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return osdkRegistryUrl.replace(/\/$/, "");
|
|
181
|
+
}
|
|
182
|
+
async function promptOverwrite({
|
|
183
|
+
project,
|
|
184
|
+
overwrite
|
|
185
|
+
}) {
|
|
186
|
+
if (overwrite != null) {
|
|
187
|
+
return overwrite;
|
|
188
|
+
}
|
|
189
|
+
if (!fs2.existsSync(path2.join(process.cwd(), project))) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
const result = await consola.prompt(
|
|
193
|
+
`The directory ${green(project)} already exists do you want to overwrite or ignore it?`,
|
|
194
|
+
{
|
|
195
|
+
type: "select",
|
|
196
|
+
options: [{
|
|
197
|
+
label: "Remove existing files and continue",
|
|
198
|
+
value: "overwrite"
|
|
199
|
+
}, {
|
|
200
|
+
label: "Ignore files and continue",
|
|
201
|
+
value: "ignore"
|
|
202
|
+
}, {
|
|
203
|
+
label: "Cancel",
|
|
204
|
+
value: "cancel"
|
|
205
|
+
}]
|
|
206
|
+
}
|
|
207
|
+
// Types for "select" are wrong the value is returned rather than the option object
|
|
208
|
+
// https://github.com/unjs/consola/pull/238
|
|
209
|
+
);
|
|
210
|
+
switch (result) {
|
|
211
|
+
case "overwrite":
|
|
212
|
+
return true;
|
|
213
|
+
case "ignore":
|
|
214
|
+
return false;
|
|
215
|
+
case "cancel":
|
|
216
|
+
consola.fail("Operation cancelled");
|
|
217
|
+
process.exit(0);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/prompts/promptProject.ts
|
|
222
|
+
async function promptProject({
|
|
223
|
+
project
|
|
224
|
+
}) {
|
|
225
|
+
while (project == null || !/^[a-zA-Z0-9-_]+$/.test(project)) {
|
|
226
|
+
if (project != null) {
|
|
227
|
+
consola.fail("Project name can only contain alphanumeric characters, hyphens and underscores");
|
|
228
|
+
}
|
|
229
|
+
project = await consola.prompt("Project name:", {
|
|
230
|
+
type: "text",
|
|
231
|
+
placeholder: "my-osdk-app",
|
|
232
|
+
default: "my-osdk-app"
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
return project;
|
|
236
|
+
}
|
|
237
|
+
|
|
30
238
|
// src/templates.ts
|
|
31
239
|
var TEMPLATES = [{
|
|
32
240
|
id: "template-react",
|
|
@@ -42,9 +250,30 @@ var TEMPLATES = [{
|
|
|
42
250
|
envPrefix: "NEXT_PUBLIC_"
|
|
43
251
|
}];
|
|
44
252
|
|
|
253
|
+
// src/prompts/promptTemplate.ts
|
|
254
|
+
async function promptTemplate(parsed) {
|
|
255
|
+
let template = TEMPLATES.find((t) => t.id === parsed.template);
|
|
256
|
+
if (template == null) {
|
|
257
|
+
const templateId = await consola.prompt(parsed.template != null ? `The provided template ${green(parsed.template)} is invalid please select a framework:` : "Select a framework:", {
|
|
258
|
+
type: "select",
|
|
259
|
+
options: TEMPLATES.map((template2) => ({
|
|
260
|
+
value: template2.id,
|
|
261
|
+
label: template2.label
|
|
262
|
+
}))
|
|
263
|
+
// Types for "select" are wrong the value is returned rather than the option object
|
|
264
|
+
// https://github.com/unjs/consola/pull/238
|
|
265
|
+
});
|
|
266
|
+
template = TEMPLATES.find((t) => t.id === templateId);
|
|
267
|
+
if (template == null) {
|
|
268
|
+
throw new Error(`Template ${templateId} should be found`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return template;
|
|
272
|
+
}
|
|
273
|
+
|
|
45
274
|
// src/cli.ts
|
|
46
275
|
async function cli(args = process.argv) {
|
|
47
|
-
const base = yargs(hideBin(args)).version("0.0
|
|
276
|
+
const base = yargs(hideBin(args)).version("0.1.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
277
|
type: "string",
|
|
49
278
|
describe: "Project name to create"
|
|
50
279
|
}).option("overwrite", {
|
|
@@ -74,7 +303,10 @@ async function cli(args = process.argv) {
|
|
|
74
303
|
}));
|
|
75
304
|
const parsed = base.parseSync();
|
|
76
305
|
const project = await promptProject(parsed);
|
|
77
|
-
const overwrite = await promptOverwrite(
|
|
306
|
+
const overwrite = await promptOverwrite({
|
|
307
|
+
...parsed,
|
|
308
|
+
project
|
|
309
|
+
});
|
|
78
310
|
const template = await promptTemplate(parsed);
|
|
79
311
|
const foundryUrl = await promptFoundryUrl(parsed);
|
|
80
312
|
const applicationUrl = await promptApplicationUrl(parsed);
|
|
@@ -84,15 +316,15 @@ async function cli(args = process.argv) {
|
|
|
84
316
|
consola.log("");
|
|
85
317
|
consola.start(`Creating project ${green(project)} using template ${green(template.id)}`);
|
|
86
318
|
const cwd = process.cwd();
|
|
87
|
-
const root =
|
|
88
|
-
if (
|
|
319
|
+
const root = path2.join(cwd, project);
|
|
320
|
+
if (fs2.existsSync(root)) {
|
|
89
321
|
if (overwrite) {
|
|
90
322
|
consola.info(`Overwriting existing project directory`);
|
|
91
|
-
|
|
323
|
+
fs2.rmSync(root, {
|
|
92
324
|
recursive: true,
|
|
93
325
|
force: true
|
|
94
326
|
});
|
|
95
|
-
|
|
327
|
+
fs2.mkdirSync(root, {
|
|
96
328
|
recursive: true
|
|
97
329
|
});
|
|
98
330
|
} else {
|
|
@@ -100,26 +332,30 @@ async function cli(args = process.argv) {
|
|
|
100
332
|
}
|
|
101
333
|
} else {
|
|
102
334
|
consola.info(`Creating project directory`);
|
|
103
|
-
|
|
335
|
+
fs2.mkdirSync(root, {
|
|
104
336
|
recursive: true
|
|
105
337
|
});
|
|
106
338
|
}
|
|
107
339
|
consola.info(`Copying files into project directory`);
|
|
108
340
|
const templatesDir = findUpSync("templates", {
|
|
109
|
-
cwd:
|
|
341
|
+
cwd: path2.dirname(fileURLToPath(import.meta.url)),
|
|
110
342
|
type: "directory"
|
|
111
343
|
});
|
|
112
344
|
if (templatesDir == null) {
|
|
113
345
|
throw new Error(`Could not find templates directory`);
|
|
114
346
|
}
|
|
115
|
-
const templateDir =
|
|
116
|
-
|
|
347
|
+
const templateDir = path2.resolve(templatesDir, template.id);
|
|
348
|
+
fs2.cpSync(templateDir, root, {
|
|
117
349
|
recursive: true
|
|
118
350
|
});
|
|
351
|
+
const templateContext = {
|
|
352
|
+
project,
|
|
353
|
+
osdkPackage
|
|
354
|
+
};
|
|
119
355
|
const templateHbs = function(dir) {
|
|
120
|
-
|
|
356
|
+
fs2.readdirSync(dir).forEach(function(file) {
|
|
121
357
|
file = dir + "/" + file;
|
|
122
|
-
const stat =
|
|
358
|
+
const stat = fs2.statSync(file);
|
|
123
359
|
if (stat.isDirectory()) {
|
|
124
360
|
templateHbs(file);
|
|
125
361
|
return;
|
|
@@ -127,32 +363,32 @@ async function cli(args = process.argv) {
|
|
|
127
363
|
if (!file.endsWith(".hbs")) {
|
|
128
364
|
return;
|
|
129
365
|
}
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
const templated = Handlebars.compile(fs.readFileSync(file, "utf-8"))(hbsContext);
|
|
135
|
-
fs.writeFileSync(file.replace(/.hbs$/, ""), templated);
|
|
136
|
-
fs.rmSync(file);
|
|
366
|
+
const templated = Handlebars.compile(fs2.readFileSync(file, "utf-8"))(templateContext);
|
|
367
|
+
fs2.writeFileSync(file.replace(/.hbs$/, ""), templated);
|
|
368
|
+
fs2.rmSync(file);
|
|
137
369
|
});
|
|
138
370
|
};
|
|
139
371
|
templateHbs(root);
|
|
140
|
-
const npmRc =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
372
|
+
const npmRc = generateNpmRc({
|
|
373
|
+
osdkPackage,
|
|
374
|
+
osdkRegistryUrl
|
|
375
|
+
});
|
|
376
|
+
fs2.writeFileSync(path2.join(root, ".npmrc"), npmRc);
|
|
377
|
+
const envDevelopment = generateEnvDevelopment({
|
|
378
|
+
envPrefix: template.envPrefix,
|
|
379
|
+
foundryUrl,
|
|
380
|
+
clientId
|
|
381
|
+
});
|
|
382
|
+
fs2.writeFileSync(path2.join(root, ".env.development"), envDevelopment);
|
|
383
|
+
const envProduction = generateEnvProduction({
|
|
384
|
+
envPrefix: template.envPrefix,
|
|
385
|
+
foundryUrl,
|
|
386
|
+
applicationUrl,
|
|
387
|
+
clientId
|
|
388
|
+
});
|
|
389
|
+
fs2.writeFileSync(path2.join(root, ".env.production"), envProduction);
|
|
154
390
|
consola.success("Success");
|
|
155
|
-
const cdRelative =
|
|
391
|
+
const cdRelative = path2.relative(cwd, root);
|
|
156
392
|
consola.box({
|
|
157
393
|
message: `Done! Run the following commands to get started:
|
|
158
394
|
|
|
@@ -167,162 +403,6 @@ ${template.envPrefix}FOUNDRY_CLIENT_ID=${clientId}
|
|
|
167
403
|
}
|
|
168
404
|
});
|
|
169
405
|
}
|
|
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
406
|
|
|
327
407
|
export { cli };
|
|
328
408
|
//# sourceMappingURL=out.js.map
|