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