@jtl-software/create-cloud-app 0.8.3 → 0.9.1
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/README.md +47 -4
- package/dist/index.js +389 -51
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -16,6 +16,30 @@ The CLI has three entry points:
|
|
|
16
16
|
|
|
17
17
|
Registration and listing are two independent resources on two independent files. `register` must happen first — `listing` pushes against the app that `register` created and will fail with a clear error if it hasn't run yet.
|
|
18
18
|
|
|
19
|
+
### Help and version
|
|
20
|
+
|
|
21
|
+
Every command documents its flags:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx @jtl-software/create-cloud-app --help # overview + scaffold flags
|
|
25
|
+
npx @jtl-software/create-cloud-app help register # same as `register --help`
|
|
26
|
+
npx @jtl-software/create-cloud-app listing --help
|
|
27
|
+
npx @jtl-software/create-cloud-app --version
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Running without a terminal (AI agents, scripts)
|
|
31
|
+
|
|
32
|
+
Every prompt has a matching flag. When stdin is not a terminal, the CLI never prompts. Instead it exits with code 1 and names the flags to pass. Pass `--yes` to get the same behavior in a terminal.
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npx @jtl-software/create-cloud-app --name my-app --frontend react --backend node --yes
|
|
36
|
+
cd my-app && npm install
|
|
37
|
+
npm run register -- --yes --tenant my-tenant --new --on-collision overwrite
|
|
38
|
+
npm run listing -- --yes --tenant my-tenant --distribution-type PRIVATE
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`register` and `listing` still need a browser sign-in the first time. After that the cached token is reused and refreshed.
|
|
42
|
+
|
|
19
43
|
### `npm create @jtl-software/cloud-app@latest`
|
|
20
44
|
|
|
21
45
|
Scaffold a new app interactively.
|
|
@@ -28,7 +52,7 @@ You'll be prompted for:
|
|
|
28
52
|
|
|
29
53
|
- **App name**: directory name, package name, and manifest identifier
|
|
30
54
|
- **Description**: placed in the listing
|
|
31
|
-
- **Backend**: Node.js (Express + TypeScript)
|
|
55
|
+
- **Backend**: Node.js (Express + TypeScript), .NET (ASP.NET Core + FastEndpoints) or PHP (Slim 4)
|
|
32
56
|
- **Frontend**: React (Vite + Tailwind + JTL Platform UI)
|
|
33
57
|
|
|
34
58
|
Then:
|
|
@@ -40,6 +64,20 @@ npm run register
|
|
|
40
64
|
npm run dev
|
|
41
65
|
```
|
|
42
66
|
|
|
67
|
+
Pass any of these flags to skip the matching prompt:
|
|
68
|
+
|
|
69
|
+
| Flag | Description |
|
|
70
|
+
| ------------------------------------- | ------------------------------------------------------------------ |
|
|
71
|
+
| `--name <app-name>` | App name and directory. Lowercase letters, numbers and hyphens. |
|
|
72
|
+
| `--description <text>` | Short description. Default `A JTL Platform app`. |
|
|
73
|
+
| `--frontend <react\|none>` | Frontend stack, or `none`. |
|
|
74
|
+
| `--backend <node\|dotnet\|php\|none>` | Backend stack, or `none`. Pick at least one frontend or backend. |
|
|
75
|
+
| `--yes`, `-y` | Never prompt. `--name`, `--frontend` and `--backend` are required. |
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm create @jtl-software/cloud-app@latest -- --name my-app --frontend react --backend node --yes
|
|
79
|
+
```
|
|
80
|
+
|
|
43
81
|
Pass `--legacy` to scaffold the backend for the legacy Ory M2M flow instead of the Zitadel service account (compat testing only, node backend only):
|
|
44
82
|
|
|
45
83
|
```bash
|
|
@@ -75,14 +113,16 @@ Flags:
|
|
|
75
113
|
| `--api-host <url>` | API host. Default `https://api.jtl-cloud.com`. |
|
|
76
114
|
| `--auth-host <url>` | OAuth host. Default `https://id.jtl-cloud.com`. The CLI picks the matching client ID for the known prod/QA/dev hosts. |
|
|
77
115
|
| `--hub-host <url>` | Hub host (used in printed links). Default `https://hub.jtl-cloud.com`. |
|
|
116
|
+
| `--partner-host <url>` | Partner Portal host (used in printed links). Default `https://partner.jtl-cloud.com`. |
|
|
78
117
|
| `--client-id <id>` | Override the OAuth client ID. Only needed for custom auth hosts. |
|
|
79
|
-
| `--scope <scope>` | OAuth scope.
|
|
118
|
+
| `--scope <scope>` | OAuth scope. The default depends on `--auth-host`. |
|
|
80
119
|
| `--reauth` | Skip the cached token and open the browser again. Useful after switching accounts. |
|
|
81
|
-
| `--yes`, `-y` | Non-interactive mode. Auto-confirms prompts and fails if any choice is ambiguous (e.g. multiple tenants match). Required for CI.
|
|
120
|
+
| `--yes`, `-y` | Non-interactive mode. Auto-confirms prompts and fails if any choice is ambiguous (e.g. multiple tenants match). Required for CI and whenever stdin is not a terminal. |
|
|
82
121
|
| `--tenant <id-or-slug>` | Select a tenant by ID or slug (case-insensitive). |
|
|
83
122
|
| `--existing-app-id <id>` | Update the app with this ID instead of prompting. Errors if it doesn't match this manifest's technical name. |
|
|
84
123
|
| `--new` | Force-create a new app even if a matching one exists. Mutually exclusive with `--existing-app-id`. |
|
|
85
124
|
| `--on-collision <overwrite\|print\|cancel>` | What to do when an existing credentials file would be overwritten during provisioning. `print` writes the secret to stdout instead of the file. Required in `--yes` mode if a collision is possible. |
|
|
125
|
+
| `--app-service-path <path>` | App service path segment, for testing a branch deployment (e.g. `app-service-1317`). Default `app-service`. |
|
|
86
126
|
|
|
87
127
|
Tokens are cached under `~/.config/jtl-cli/tokens.json` (mode `0600`). Override the path with the `JTL_CLI_TOKEN_CACHE_FILE` environment variable.
|
|
88
128
|
|
|
@@ -96,7 +136,10 @@ npx @jtl-software/create-cloud-app listing
|
|
|
96
136
|
|
|
97
137
|
Like `register`, it's interactive by default: OAuth login, then a tenant prompt. It also asks two questions about the listing itself — distribution type (`PUBLIC`/`PRIVATE`) and default locale — pre-filled from whatever's already in `listing.json` and written back there once answered, so re-running `listing` later remembers your choice. Unlike `register`, there's no create-vs-update choice or local credential file to write — a listing is always pushed against the app `register` already created, keyed by `technicalName`. If no registered app matches, the command fails with a message telling you to run `register` first.
|
|
98
138
|
|
|
99
|
-
Flags: `--api-host`, `--auth-host`, `--hub-host`, `--client-id`, `--scope`, `--reauth`, `--yes`/`-y`, `--tenant
|
|
139
|
+
Flags: `--api-host`, `--auth-host`, `--hub-host`, `--partner-host`, `--client-id`, `--scope`, `--reauth`, `--yes`/`-y`, `--tenant`. They mean the same as the `register` flags above. There's no `--existing-app-id`, `--new`, or `--on-collision` since listing has nothing to disambiguate or overwrite locally. Two flags answer the listing questions without a prompt and write the value to `listing.json`:
|
|
140
|
+
|
|
141
|
+
- `--distribution-type <PUBLIC|PRIVATE>`
|
|
142
|
+
- `--default-locale <locale>`, e.g. `de-DE`
|
|
100
143
|
|
|
101
144
|
## CI usage: keep your deployed app.json and listing.json in sync with the repo
|
|
102
145
|
|
package/dist/index.js
CHANGED
|
@@ -2,15 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import * as p4 from "@clack/prompts";
|
|
5
|
+
import fs7 from "fs";
|
|
6
|
+
import path7 from "path";
|
|
5
7
|
import pc4 from "picocolors";
|
|
6
8
|
|
|
7
|
-
// src/listing.ts
|
|
8
|
-
import * as p3 from "@clack/prompts";
|
|
9
|
-
import fs3 from "fs";
|
|
10
|
-
import path3 from "path";
|
|
11
|
-
import { parseArgs as parseArgs2 } from "util";
|
|
12
|
-
import pc3 from "picocolors";
|
|
13
|
-
|
|
14
9
|
// src/platform-client.ts
|
|
15
10
|
import * as p from "@clack/prompts";
|
|
16
11
|
import { spawn } from "child_process";
|
|
@@ -388,6 +383,16 @@ async function acquireAccessToken(opts) {
|
|
|
388
383
|
throw err;
|
|
389
384
|
}
|
|
390
385
|
}
|
|
386
|
+
var ApiError = class extends Error {
|
|
387
|
+
constructor(message, status, code) {
|
|
388
|
+
super(message);
|
|
389
|
+
this.status = status;
|
|
390
|
+
this.code = code;
|
|
391
|
+
this.name = "ApiError";
|
|
392
|
+
}
|
|
393
|
+
status;
|
|
394
|
+
code;
|
|
395
|
+
};
|
|
391
396
|
async function apiCall(url, init) {
|
|
392
397
|
const res = await fetch(url, init);
|
|
393
398
|
const text3 = await res.text();
|
|
@@ -399,8 +404,11 @@ async function apiCall(url, init) {
|
|
|
399
404
|
}
|
|
400
405
|
if (!res.ok) {
|
|
401
406
|
const detail = typeof body === "string" ? body : JSON.stringify(body);
|
|
402
|
-
|
|
403
|
-
|
|
407
|
+
const code = typeof body === "object" && body !== null && "code" in body ? String(body.code) : void 0;
|
|
408
|
+
throw new ApiError(
|
|
409
|
+
`${init.method ?? "GET"} ${url} returned ${res.status}: ${detail}`,
|
|
410
|
+
res.status,
|
|
411
|
+
code
|
|
404
412
|
);
|
|
405
413
|
}
|
|
406
414
|
return body;
|
|
@@ -528,6 +536,12 @@ function resolveCommonOptions(values) {
|
|
|
528
536
|
tenant: values.tenant
|
|
529
537
|
};
|
|
530
538
|
}
|
|
539
|
+
function requireTerminalOrYes(opts, isTTY = Boolean(process.stdin.isTTY)) {
|
|
540
|
+
if (opts.yes || isTTY) return;
|
|
541
|
+
bail(
|
|
542
|
+
"no terminal to prompt in. Pass --yes (plus --tenant and the command's other flags) to run without prompts. Run with --help for the flags."
|
|
543
|
+
);
|
|
544
|
+
}
|
|
531
545
|
function ensureContinue(value) {
|
|
532
546
|
if (p.isCancel(value)) {
|
|
533
547
|
bail("Cancelled.");
|
|
@@ -590,6 +604,9 @@ function buildHubAppOverviewUrl(hubHost, tenantSlug) {
|
|
|
590
604
|
function buildPartnerPortalPublishUrl(partnerHost, tenantSlug, publisherId) {
|
|
591
605
|
return `${partnerHost}/${tenantSlug}/${publisherId}/apps/publish`;
|
|
592
606
|
}
|
|
607
|
+
function buildPartnerPortalOnboardingUrl(partnerHost, tenantSlug) {
|
|
608
|
+
return `${partnerHost}/${tenantSlug}/onboarding`;
|
|
609
|
+
}
|
|
593
610
|
function terminalLink(url, text3 = url) {
|
|
594
611
|
const OSC = "\x1B]";
|
|
595
612
|
const ST = "\x1B\\";
|
|
@@ -605,6 +622,191 @@ function printHubLink(hubHost, tenantSlug, appId, isInstalled) {
|
|
|
605
622
|
}
|
|
606
623
|
}
|
|
607
624
|
|
|
625
|
+
// src/help.ts
|
|
626
|
+
var BIN = "create-cloud-app";
|
|
627
|
+
var GLOBAL_FLAGS = [
|
|
628
|
+
{ flag: "-h, --help", description: "Show help for the command." },
|
|
629
|
+
{ flag: "-v, --version", description: "Print the CLI version." }
|
|
630
|
+
];
|
|
631
|
+
var COMMON_FLAGS = [
|
|
632
|
+
{
|
|
633
|
+
flag: "-y, --yes",
|
|
634
|
+
description: "Non-interactive: auto-confirm, and fail with a hint instead of prompting when a choice is ambiguous. Required when stdin is not a terminal."
|
|
635
|
+
},
|
|
636
|
+
{
|
|
637
|
+
flag: "--tenant <id|slug>",
|
|
638
|
+
description: "Tenant to use (case-insensitive slug). Needed with --yes when the account has more than one tenant."
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
flag: "--reauth",
|
|
642
|
+
description: "Ignore the cached token and sign in again in the browser."
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
flag: "--api-host <url>",
|
|
646
|
+
description: `API host. Default ${DEFAULT_API_HOST}.`
|
|
647
|
+
},
|
|
648
|
+
{
|
|
649
|
+
flag: "--auth-host <url>",
|
|
650
|
+
description: `OAuth host. Default ${DEFAULT_AUTH_HOST}.`
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
flag: "--hub-host <url>",
|
|
654
|
+
description: `Hub host for printed links. Default ${DEFAULT_HUB_HOST}.`
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
flag: "--partner-host <url>",
|
|
658
|
+
description: `Partner Portal host for printed links. Default ${DEFAULT_PARTNER_HOST}.`
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
flag: "--client-id <id>",
|
|
662
|
+
description: "OAuth client id. Only needed for an unknown --auth-host."
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
flag: "--scope <scope>",
|
|
666
|
+
description: "OAuth scope. Default depends on --auth-host."
|
|
667
|
+
}
|
|
668
|
+
];
|
|
669
|
+
var AUTH_NOTE = "Sign-in opens a browser once; the token is cached in ~/.config/jtl-cli/tokens.json (override with JTL_CLI_TOKEN_CACHE_FILE).";
|
|
670
|
+
var COMMANDS = {
|
|
671
|
+
scaffold: {
|
|
672
|
+
name: "scaffold",
|
|
673
|
+
usage: `${BIN} [options]`,
|
|
674
|
+
summary: "Scaffold a new app project (default when no command is given).",
|
|
675
|
+
description: "Creates ./<name> with app.json, listing.json and the chosen frontend/backend. Prompts for any value not passed as a flag. With --yes, or when stdin is not a terminal, it never prompts: --name, --frontend and --backend are then required.",
|
|
676
|
+
flags: [
|
|
677
|
+
{
|
|
678
|
+
flag: "--name <app-name>",
|
|
679
|
+
description: "App name and directory. Lowercase letters, numbers and hyphens."
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
flag: "--description <text>",
|
|
683
|
+
description: 'Short description. Default "A JTL Platform app".'
|
|
684
|
+
},
|
|
685
|
+
{
|
|
686
|
+
flag: "--frontend <react|none>",
|
|
687
|
+
description: "Frontend stack, or none."
|
|
688
|
+
},
|
|
689
|
+
{
|
|
690
|
+
flag: "--backend <node|dotnet|php|none>",
|
|
691
|
+
description: "Backend stack, or none. Pick at least one of frontend and backend."
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
flag: "--legacy",
|
|
695
|
+
description: "Scaffold the node backend for the legacy Ory M2M flow (compat testing only)."
|
|
696
|
+
},
|
|
697
|
+
{
|
|
698
|
+
flag: "-y, --yes",
|
|
699
|
+
description: "Never prompt; fail on missing flags instead."
|
|
700
|
+
}
|
|
701
|
+
],
|
|
702
|
+
examples: [
|
|
703
|
+
`${BIN} --name my-app --frontend react --backend node --yes`,
|
|
704
|
+
`npm create @jtl-software/cloud-app@latest -- --name my-app --frontend react --backend none --yes`
|
|
705
|
+
]
|
|
706
|
+
},
|
|
707
|
+
register: {
|
|
708
|
+
name: "register",
|
|
709
|
+
usage: `${BIN} register [options]`,
|
|
710
|
+
summary: "Register or update app.json with the JTL Cloud and write credentials.",
|
|
711
|
+
description: `Run from the project root. Reads app.json, creates or updates the app in the chosen tenant, and writes its credentials to the backend and frontend config. ${AUTH_NOTE}`,
|
|
712
|
+
flags: [
|
|
713
|
+
...COMMON_FLAGS,
|
|
714
|
+
{
|
|
715
|
+
flag: "--existing-app-id <id>",
|
|
716
|
+
description: "Update this app instead of asking. Must match app.json's technicalName."
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
flag: "--new",
|
|
720
|
+
description: "Create a new app even if one matches. Excludes --existing-app-id."
|
|
721
|
+
},
|
|
722
|
+
{
|
|
723
|
+
flag: "--on-collision <overwrite|print|cancel>",
|
|
724
|
+
description: "What to do when a credentials file already has values. Needed with --yes when that can happen."
|
|
725
|
+
},
|
|
726
|
+
{
|
|
727
|
+
flag: "--app-service-path <path>",
|
|
728
|
+
description: "App service path segment, for branch deployments. Default app-service."
|
|
729
|
+
}
|
|
730
|
+
],
|
|
731
|
+
examples: [
|
|
732
|
+
`${BIN} register --yes --tenant my-tenant --new --on-collision overwrite`,
|
|
733
|
+
`${BIN} register --yes --tenant my-tenant --existing-app-id <app-id>`
|
|
734
|
+
]
|
|
735
|
+
},
|
|
736
|
+
listing: {
|
|
737
|
+
name: "listing",
|
|
738
|
+
usage: `${BIN} listing [options]`,
|
|
739
|
+
summary: "Push listing.json as the app's store listing.",
|
|
740
|
+
description: `Run from the project root after register. Reads listing.json and the technicalName from app.json. With --yes, the distribution type and default locale are taken from listing.json (or the flags below). ${AUTH_NOTE}`,
|
|
741
|
+
flags: [
|
|
742
|
+
...COMMON_FLAGS,
|
|
743
|
+
{
|
|
744
|
+
flag: "--distribution-type <PUBLIC|PRIVATE>",
|
|
745
|
+
description: "Set distributionType in listing.json instead of asking."
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
flag: "--default-locale <locale>",
|
|
749
|
+
description: "Set defaultLocale in listing.json instead of asking, e.g. de-DE."
|
|
750
|
+
}
|
|
751
|
+
],
|
|
752
|
+
examples: [
|
|
753
|
+
`${BIN} listing --yes --tenant my-tenant --distribution-type PRIVATE`
|
|
754
|
+
]
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
function flagTable(flags) {
|
|
758
|
+
const width = Math.max(...flags.map((f) => f.flag.length));
|
|
759
|
+
return flags.map((f) => ` ${f.flag.padEnd(width)} ${f.description}`);
|
|
760
|
+
}
|
|
761
|
+
function renderOverview(version) {
|
|
762
|
+
const commands = Object.values(COMMANDS);
|
|
763
|
+
const width = Math.max(...commands.map((c) => c.name.length));
|
|
764
|
+
return [
|
|
765
|
+
`${BIN} ${version}: create, register and publish JTL Platform cloud apps.`,
|
|
766
|
+
"",
|
|
767
|
+
"Usage:",
|
|
768
|
+
` ${BIN} [command] [options]`,
|
|
769
|
+
"",
|
|
770
|
+
"Commands:",
|
|
771
|
+
...commands.map(
|
|
772
|
+
(c) => ` ${(c.name === "scaffold" ? "(none)" : c.name).padEnd(width)} ${c.summary}`
|
|
773
|
+
),
|
|
774
|
+
` ${"help".padEnd(width)} Show help for a command, e.g. \`${BIN} help register\`.`,
|
|
775
|
+
"",
|
|
776
|
+
"Options:",
|
|
777
|
+
...flagTable(GLOBAL_FLAGS),
|
|
778
|
+
"",
|
|
779
|
+
`Run \`${BIN} <command> --help\` for the command's flags.`,
|
|
780
|
+
"Every prompt has a matching flag. register and listing still need a one-time browser sign-in.",
|
|
781
|
+
""
|
|
782
|
+
].join("\n");
|
|
783
|
+
}
|
|
784
|
+
function renderCommandHelp(name) {
|
|
785
|
+
const c = COMMANDS[name];
|
|
786
|
+
return [
|
|
787
|
+
c.summary,
|
|
788
|
+
"",
|
|
789
|
+
"Usage:",
|
|
790
|
+
` ${c.usage}`,
|
|
791
|
+
"",
|
|
792
|
+
c.description,
|
|
793
|
+
"",
|
|
794
|
+
"Options:",
|
|
795
|
+
...flagTable([...c.flags, GLOBAL_FLAGS[0]]),
|
|
796
|
+
"",
|
|
797
|
+
"Examples:",
|
|
798
|
+
...c.examples.map((e) => ` ${e}`),
|
|
799
|
+
""
|
|
800
|
+
].join("\n");
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// src/listing.ts
|
|
804
|
+
import * as p3 from "@clack/prompts";
|
|
805
|
+
import fs3 from "fs";
|
|
806
|
+
import path3 from "path";
|
|
807
|
+
import { parseArgs as parseArgs2 } from "util";
|
|
808
|
+
import pc3 from "picocolors";
|
|
809
|
+
|
|
608
810
|
// src/register.ts
|
|
609
811
|
import * as p2 from "@clack/prompts";
|
|
610
812
|
import fs2 from "fs";
|
|
@@ -884,23 +1086,24 @@ function parseCollisionAction(input) {
|
|
|
884
1086
|
`--on-collision must be one of: overwrite, print, cancel (got "${input}")`
|
|
885
1087
|
);
|
|
886
1088
|
}
|
|
1089
|
+
var REGISTER_ARG_OPTIONS = {
|
|
1090
|
+
...COMMON_ARG_OPTIONS,
|
|
1091
|
+
"existing-app-id": { type: "string" },
|
|
1092
|
+
new: { type: "boolean" },
|
|
1093
|
+
"on-collision": { type: "string" },
|
|
1094
|
+
"app-service-path": { type: "string" }
|
|
1095
|
+
};
|
|
887
1096
|
function resolveOptions(args) {
|
|
888
1097
|
let parsed;
|
|
889
1098
|
try {
|
|
890
1099
|
parsed = parseArgs({
|
|
891
1100
|
args,
|
|
892
|
-
options:
|
|
893
|
-
...COMMON_ARG_OPTIONS,
|
|
894
|
-
"existing-app-id": { type: "string" },
|
|
895
|
-
new: { type: "boolean" },
|
|
896
|
-
"on-collision": { type: "string" },
|
|
897
|
-
"app-service-path": { type: "string" }
|
|
898
|
-
},
|
|
1101
|
+
options: REGISTER_ARG_OPTIONS,
|
|
899
1102
|
strict: true,
|
|
900
1103
|
allowPositionals: false
|
|
901
1104
|
});
|
|
902
1105
|
} catch (err) {
|
|
903
|
-
bail(err.message);
|
|
1106
|
+
bail(`${err.message}. Run with --help for usage.`);
|
|
904
1107
|
}
|
|
905
1108
|
const common = resolveCommonOptions(parsed.values);
|
|
906
1109
|
const existingAppId = parsed.values["existing-app-id"];
|
|
@@ -1032,6 +1235,9 @@ async function updateAppManifest(apiBaseUrl, jwt, tenantId, appId, manifest, app
|
|
|
1032
1235
|
}
|
|
1033
1236
|
);
|
|
1034
1237
|
}
|
|
1238
|
+
function isMissingPublisherError(err) {
|
|
1239
|
+
return err instanceof ApiError && err.status === 404 && (err.code === "PublisherNotFound" || err.code === "EntityNotFound");
|
|
1240
|
+
}
|
|
1035
1241
|
async function createDraftApp(apiBaseUrl, jwt, tenantId, manifest, appServicePath = "app-service") {
|
|
1036
1242
|
const created = await apiCall(
|
|
1037
1243
|
`${apiBaseUrl}/${appServicePath}/store/apps`,
|
|
@@ -1199,6 +1405,7 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1199
1405
|
console.log();
|
|
1200
1406
|
p2.intro(pc2.bgCyan(pc2.black(" register cloud app ")));
|
|
1201
1407
|
const opts = resolveOptions(argv);
|
|
1408
|
+
requireTerminalOrYes(opts);
|
|
1202
1409
|
const backend = detectBackend(root);
|
|
1203
1410
|
p2.note(
|
|
1204
1411
|
[
|
|
@@ -1430,6 +1637,13 @@ async function register(argv = [], runOpts = {}) {
|
|
|
1430
1637
|
spinner4.stop(`Created app ${pc2.cyan(appId)}`);
|
|
1431
1638
|
} catch (err) {
|
|
1432
1639
|
spinner4.stop("Failed to create app");
|
|
1640
|
+
if (isMissingPublisherError(err)) {
|
|
1641
|
+
const url = buildPartnerPortalOnboardingUrl(opts.partner, tenant.slug);
|
|
1642
|
+
p2.note(pc2.cyan(terminalLink(url)), "Register as publisher");
|
|
1643
|
+
bail(
|
|
1644
|
+
`Organization "${tenant.name}" is not registered as a publisher yet. Complete the Partner Portal onboarding for it, then run this command again.`
|
|
1645
|
+
);
|
|
1646
|
+
}
|
|
1433
1647
|
bail(err.message);
|
|
1434
1648
|
}
|
|
1435
1649
|
spinner4.start("Provisioning app");
|
|
@@ -1517,19 +1731,36 @@ async function resolveAppId(apiBaseUrl, jwt, tenantId, technicalName) {
|
|
|
1517
1731
|
}
|
|
1518
1732
|
return matches[0].id;
|
|
1519
1733
|
}
|
|
1734
|
+
var LISTING_ARG_OPTIONS = {
|
|
1735
|
+
...COMMON_ARG_OPTIONS,
|
|
1736
|
+
"distribution-type": { type: "string" },
|
|
1737
|
+
"default-locale": { type: "string" }
|
|
1738
|
+
};
|
|
1520
1739
|
function resolveListingOptions(args) {
|
|
1521
1740
|
let parsed;
|
|
1522
1741
|
try {
|
|
1523
1742
|
parsed = parseArgs2({
|
|
1524
1743
|
args,
|
|
1525
|
-
options:
|
|
1744
|
+
options: LISTING_ARG_OPTIONS,
|
|
1526
1745
|
strict: true,
|
|
1527
1746
|
allowPositionals: false
|
|
1528
1747
|
});
|
|
1529
1748
|
} catch (err) {
|
|
1530
|
-
bail(err.message);
|
|
1749
|
+
bail(`${err.message}. Run with --help for usage.`);
|
|
1531
1750
|
}
|
|
1532
|
-
|
|
1751
|
+
const distributionType = parsed.values["distribution-type"]?.toUpperCase();
|
|
1752
|
+
if (distributionType !== void 0 && distributionType !== "PUBLIC" && distributionType !== "PRIVATE") {
|
|
1753
|
+
bail(
|
|
1754
|
+
`--distribution-type must be PUBLIC or PRIVATE (got "${parsed.values["distribution-type"]}")`
|
|
1755
|
+
);
|
|
1756
|
+
}
|
|
1757
|
+
const defaultLocale = parsed.values["default-locale"];
|
|
1758
|
+
if (defaultLocale === "") bail("--default-locale must not be empty");
|
|
1759
|
+
return {
|
|
1760
|
+
...resolveCommonOptions(parsed.values),
|
|
1761
|
+
distributionType,
|
|
1762
|
+
defaultLocale
|
|
1763
|
+
};
|
|
1533
1764
|
}
|
|
1534
1765
|
async function createAppListing(apiBaseUrl, jwt, tenantId, appId, listing2) {
|
|
1535
1766
|
const created = await apiCall(
|
|
@@ -1610,6 +1841,7 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1610
1841
|
console.log();
|
|
1611
1842
|
p3.intro(pc3.bgCyan(pc3.black(" push app listing ")));
|
|
1612
1843
|
const opts = resolveListingOptions(argv);
|
|
1844
|
+
requireTerminalOrYes(opts);
|
|
1613
1845
|
const technicalName = readTechnicalName(root);
|
|
1614
1846
|
const listingData = readListing(listingPath);
|
|
1615
1847
|
p3.note(
|
|
@@ -1648,14 +1880,8 @@ async function listing(argv = [], runOpts = {}) {
|
|
|
1648
1880
|
bail(err.message);
|
|
1649
1881
|
}
|
|
1650
1882
|
const tenant = await selectTenant(tenants, opts);
|
|
1651
|
-
listingData.distributionType = await resolveDistributionType(
|
|
1652
|
-
|
|
1653
|
-
opts
|
|
1654
|
-
);
|
|
1655
|
-
listingData.defaultLocale = await resolveDefaultLocale(
|
|
1656
|
-
listingData.defaultLocale,
|
|
1657
|
-
opts
|
|
1658
|
-
);
|
|
1883
|
+
listingData.distributionType = opts.distributionType ?? await resolveDistributionType(listingData.distributionType, opts);
|
|
1884
|
+
listingData.defaultLocale = opts.defaultLocale ?? await resolveDefaultLocale(listingData.defaultLocale, opts);
|
|
1659
1885
|
writeListing(listingPath, listingData);
|
|
1660
1886
|
const summary = summarizeListing(listingData);
|
|
1661
1887
|
if (listingData.distributionType === "PUBLIC" && !listingData.pricing?.subscriptionTiers?.length) {
|
|
@@ -2019,6 +2245,82 @@ async function scaffold({
|
|
|
2019
2245
|
);
|
|
2020
2246
|
}
|
|
2021
2247
|
|
|
2248
|
+
// src/scaffold-args.ts
|
|
2249
|
+
import { parseArgs as parseArgs3 } from "util";
|
|
2250
|
+
var SCAFFOLD_ARG_OPTIONS = {
|
|
2251
|
+
name: { type: "string" },
|
|
2252
|
+
description: { type: "string" },
|
|
2253
|
+
frontend: { type: "string" },
|
|
2254
|
+
backend: { type: "string" },
|
|
2255
|
+
legacy: { type: "boolean" },
|
|
2256
|
+
yes: { type: "boolean", short: "y" }
|
|
2257
|
+
};
|
|
2258
|
+
var NONE = "none";
|
|
2259
|
+
function validateAppName(value) {
|
|
2260
|
+
if (!value) return "App name is required";
|
|
2261
|
+
if (!/^[a-z0-9-]+$/.test(value))
|
|
2262
|
+
return "Use lowercase letters, numbers, and hyphens only";
|
|
2263
|
+
}
|
|
2264
|
+
function stackChoices(templates) {
|
|
2265
|
+
return [...templates.map(templateTech), NONE];
|
|
2266
|
+
}
|
|
2267
|
+
function pickTemplate(flag, value, templates) {
|
|
2268
|
+
if (value === void 0) return void 0;
|
|
2269
|
+
if (value === NONE) return null;
|
|
2270
|
+
const match = templates.find((t) => templateTech(t) === value);
|
|
2271
|
+
if (!match) {
|
|
2272
|
+
bail(
|
|
2273
|
+
`--${flag} must be one of: ${stackChoices(templates).join(", ")} (got "${value}")`
|
|
2274
|
+
);
|
|
2275
|
+
}
|
|
2276
|
+
return match;
|
|
2277
|
+
}
|
|
2278
|
+
function resolveScaffoldArgs(args, templates, isTTY = Boolean(process.stdin.isTTY)) {
|
|
2279
|
+
let parsed;
|
|
2280
|
+
try {
|
|
2281
|
+
parsed = parseArgs3({
|
|
2282
|
+
args,
|
|
2283
|
+
options: SCAFFOLD_ARG_OPTIONS,
|
|
2284
|
+
strict: true,
|
|
2285
|
+
allowPositionals: false
|
|
2286
|
+
});
|
|
2287
|
+
} catch (err) {
|
|
2288
|
+
bail(`${err.message}. Run with --help for usage.`);
|
|
2289
|
+
}
|
|
2290
|
+
const v = parsed.values;
|
|
2291
|
+
if (v.name !== void 0) {
|
|
2292
|
+
const invalid = validateAppName(v.name);
|
|
2293
|
+
if (invalid) bail(`--name: ${invalid}`);
|
|
2294
|
+
}
|
|
2295
|
+
const result = {
|
|
2296
|
+
name: v.name,
|
|
2297
|
+
description: v.description,
|
|
2298
|
+
frontend: pickTemplate("frontend", v.frontend, templates.frontends),
|
|
2299
|
+
backend: pickTemplate("backend", v.backend, templates.backends),
|
|
2300
|
+
legacy: v.legacy ?? false,
|
|
2301
|
+
nonInteractive: Boolean(v.yes) || !isTTY
|
|
2302
|
+
};
|
|
2303
|
+
if (result.nonInteractive) {
|
|
2304
|
+
const missing = [
|
|
2305
|
+
result.name === void 0 && "--name <app-name>",
|
|
2306
|
+
result.frontend === void 0 && `--frontend <${stackChoices(templates.frontends).join("|")}>`,
|
|
2307
|
+
result.backend === void 0 && `--backend <${stackChoices(templates.backends).join("|")}>`
|
|
2308
|
+
].filter(Boolean);
|
|
2309
|
+
if (missing.length) {
|
|
2310
|
+
bail(
|
|
2311
|
+
`missing ${missing.join(", ")}. Without a terminal (or with --yes) these must be passed as flags.`
|
|
2312
|
+
);
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
if (result.frontend === null && result.backend === null) {
|
|
2316
|
+
bail("Pick at least a frontend or a backend.");
|
|
2317
|
+
}
|
|
2318
|
+
if (result.legacy && result.backend && templateTech(result.backend) !== "node") {
|
|
2319
|
+
bail("--legacy is only supported for the node backend.");
|
|
2320
|
+
}
|
|
2321
|
+
return result;
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2022
2324
|
// src/templates.ts
|
|
2023
2325
|
import fs5 from "fs";
|
|
2024
2326
|
import path5 from "path";
|
|
@@ -2057,7 +2359,7 @@ import os2 from "os";
|
|
|
2057
2359
|
import path6 from "path";
|
|
2058
2360
|
import { PostHog } from "posthog-node";
|
|
2059
2361
|
var TOKEN = "phc_SkFAxTIa4RUQxotci1Ftdw7xefZK2Ax0LEIGcl8zuD2";
|
|
2060
|
-
var CLI_VERSION = "0.
|
|
2362
|
+
var CLI_VERSION = "0.9.1";
|
|
2061
2363
|
var client = TOKEN ? new PostHog(TOKEN, { host: "https://e.jtl-cloud.com" }) : null;
|
|
2062
2364
|
function telemetryDisabledByEnv() {
|
|
2063
2365
|
const dnt = process.env.DO_NOT_TRACK;
|
|
@@ -2125,7 +2427,7 @@ async function shutdownPostHog() {
|
|
|
2125
2427
|
}
|
|
2126
2428
|
|
|
2127
2429
|
// src/index.ts
|
|
2128
|
-
var
|
|
2430
|
+
var NONE2 = "__none__";
|
|
2129
2431
|
function scaffoldChoice(backend, frontend, legacy) {
|
|
2130
2432
|
const hasBackend = Boolean(backend);
|
|
2131
2433
|
const hasFrontend = Boolean(frontend);
|
|
@@ -2148,14 +2450,14 @@ function templateSelectOptions(templates) {
|
|
|
2148
2450
|
function halfSelectOptions(templates, noneHint) {
|
|
2149
2451
|
return [
|
|
2150
2452
|
...templateSelectOptions(templates),
|
|
2151
|
-
{ value:
|
|
2453
|
+
{ value: NONE2, label: "None", hint: noneHint }
|
|
2152
2454
|
];
|
|
2153
2455
|
}
|
|
2154
2456
|
function cancelScaffold() {
|
|
2155
2457
|
p4.cancel("Cancelled.");
|
|
2156
2458
|
process.exit(0);
|
|
2157
2459
|
}
|
|
2158
|
-
async function runScaffold() {
|
|
2460
|
+
async function runScaffold(argv) {
|
|
2159
2461
|
console.log();
|
|
2160
2462
|
p4.intro(pc4.bgCyan(pc4.black(" create-cloud-app ")));
|
|
2161
2463
|
const templates = discoverTemplates();
|
|
@@ -2166,23 +2468,23 @@ async function runScaffold() {
|
|
|
2166
2468
|
p4.cancel("No templates found. Ensure template packages are installed.");
|
|
2167
2469
|
process.exit(1);
|
|
2168
2470
|
}
|
|
2471
|
+
const args = resolveScaffoldArgs(argv, { frontends, backends });
|
|
2169
2472
|
const answers = await p4.group(
|
|
2170
2473
|
{
|
|
2171
|
-
appName: () => p4.text({
|
|
2474
|
+
appName: () => args.name !== void 0 ? Promise.resolve(args.name) : p4.text({
|
|
2172
2475
|
message: "App name",
|
|
2173
2476
|
placeholder: "my-jtl-app",
|
|
2174
|
-
validate:
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2477
|
+
validate: validateAppName
|
|
2478
|
+
}),
|
|
2479
|
+
description: () => args.description !== void 0 || args.nonInteractive ? Promise.resolve(args.description ?? "") : p4.text({
|
|
2480
|
+
message: "Description",
|
|
2481
|
+
placeholder: "A JTL Platform app"
|
|
2179
2482
|
}),
|
|
2180
|
-
|
|
2181
|
-
frontend: () => p4.select({
|
|
2483
|
+
frontend: () => args.frontend !== void 0 ? Promise.resolve(args.frontend?.packageName ?? NONE2) : p4.select({
|
|
2182
2484
|
message: "Frontend (adds a public client for browser login)",
|
|
2183
2485
|
options: halfSelectOptions(frontends, "no frontend")
|
|
2184
2486
|
}),
|
|
2185
|
-
backend: () => p4.select({
|
|
2487
|
+
backend: () => args.backend !== void 0 ? Promise.resolve(args.backend?.packageName ?? NONE2) : p4.select({
|
|
2186
2488
|
message: "Backend (adds a service account for the JTL API)",
|
|
2187
2489
|
options: halfSelectOptions(backends, "no backend")
|
|
2188
2490
|
})
|
|
@@ -2196,13 +2498,14 @@ async function runScaffold() {
|
|
|
2196
2498
|
(t) => t.packageName === answers.backend
|
|
2197
2499
|
);
|
|
2198
2500
|
if (!selectedFrontend && !selectedBackend) {
|
|
2199
|
-
|
|
2200
|
-
process.exit(1);
|
|
2501
|
+
bail("Pick at least a frontend or a backend.");
|
|
2201
2502
|
}
|
|
2202
|
-
const legacy =
|
|
2503
|
+
const legacy = args.legacy;
|
|
2203
2504
|
if (legacy && selectedBackend && templateTech(selectedBackend) !== "node") {
|
|
2204
|
-
|
|
2205
|
-
|
|
2505
|
+
bail("--legacy is only supported for the node backend.");
|
|
2506
|
+
}
|
|
2507
|
+
if (fs7.existsSync(path7.resolve(process.cwd(), answers.appName))) {
|
|
2508
|
+
bail(`Directory "${answers.appName}" already exists.`);
|
|
2206
2509
|
}
|
|
2207
2510
|
const s = p4.spinner();
|
|
2208
2511
|
s.start("Scaffolding project");
|
|
@@ -2235,7 +2538,10 @@ async function runScaffold() {
|
|
|
2235
2538
|
}
|
|
2236
2539
|
printNextSteps(answers.appName);
|
|
2237
2540
|
p4.outro(pc4.green("Done! Happy building."));
|
|
2238
|
-
return
|
|
2541
|
+
return {
|
|
2542
|
+
...scaffoldChoice(selectedBackend, selectedFrontend, legacy),
|
|
2543
|
+
non_interactive: args.nonInteractive
|
|
2544
|
+
};
|
|
2239
2545
|
}
|
|
2240
2546
|
function printNextSteps(appName) {
|
|
2241
2547
|
p4.note(
|
|
@@ -2249,17 +2555,49 @@ function printNextSteps(appName) {
|
|
|
2249
2555
|
"Next steps"
|
|
2250
2556
|
);
|
|
2251
2557
|
}
|
|
2558
|
+
var SUBCOMMANDS = ["register", "listing"];
|
|
2559
|
+
function handleMeta(argv) {
|
|
2560
|
+
const [first, second] = argv;
|
|
2561
|
+
if (first === "-v" || first === "--version") {
|
|
2562
|
+
console.log(CLI_VERSION);
|
|
2563
|
+
return true;
|
|
2564
|
+
}
|
|
2565
|
+
if (first === "help") {
|
|
2566
|
+
if (second === void 0) console.log(renderOverview(CLI_VERSION));
|
|
2567
|
+
else if (second === "scaffold" || isSubcommand(second))
|
|
2568
|
+
console.log(renderCommandHelp(second));
|
|
2569
|
+
else
|
|
2570
|
+
bail(`unknown command "${second}". Run \`${BIN} --help\` for the list.`);
|
|
2571
|
+
return true;
|
|
2572
|
+
}
|
|
2573
|
+
if (first !== void 0 && !first.startsWith("-") && !isSubcommand(first)) {
|
|
2574
|
+
bail(`unknown command "${first}". Run \`${BIN} --help\` for the list.`);
|
|
2575
|
+
}
|
|
2576
|
+
if (argv.includes("-h") || argv.includes("--help")) {
|
|
2577
|
+
console.log(
|
|
2578
|
+
isSubcommand(first) ? renderCommandHelp(first) : `${renderOverview(CLI_VERSION)}
|
|
2579
|
+
${renderCommandHelp("scaffold")}`
|
|
2580
|
+
);
|
|
2581
|
+
return true;
|
|
2582
|
+
}
|
|
2583
|
+
return false;
|
|
2584
|
+
}
|
|
2585
|
+
function isSubcommand(arg) {
|
|
2586
|
+
return SUBCOMMANDS.includes(arg);
|
|
2587
|
+
}
|
|
2252
2588
|
async function main() {
|
|
2253
|
-
const
|
|
2589
|
+
const argv = process.argv.slice(2);
|
|
2590
|
+
if (handleMeta(argv)) return;
|
|
2591
|
+
const command = isSubcommand(argv[0]) ? argv[0] : "scaffold";
|
|
2254
2592
|
const startedAt = Date.now();
|
|
2255
2593
|
try {
|
|
2256
2594
|
let detail = {};
|
|
2257
2595
|
if (command === "register") {
|
|
2258
|
-
detail = await register(
|
|
2596
|
+
detail = await register(argv.slice(1));
|
|
2259
2597
|
} else if (command === "listing") {
|
|
2260
|
-
await listing(
|
|
2598
|
+
await listing(argv.slice(1));
|
|
2261
2599
|
} else {
|
|
2262
|
-
detail = await runScaffold();
|
|
2600
|
+
detail = await runScaffold(argv);
|
|
2263
2601
|
}
|
|
2264
2602
|
captureCommand(command, {
|
|
2265
2603
|
success: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jtl-software/create-cloud-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI tool for scaffolding JTL Platform cloud apps",
|
|
6
6
|
"bin": {
|
|
@@ -17,20 +17,20 @@
|
|
|
17
17
|
"dev": "tsx src/index.ts"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@clack/prompts": "^1.
|
|
20
|
+
"@clack/prompts": "^1.8.1",
|
|
21
21
|
"@jtl-software/cloud-app-template-backend-dotnet": "0.2.0",
|
|
22
|
-
"@jtl-software/cloud-app-template-backend-node": "0.3.
|
|
22
|
+
"@jtl-software/cloud-app-template-backend-node": "0.3.2",
|
|
23
23
|
"@jtl-software/cloud-app-template-backend-php": "0.3.0",
|
|
24
|
-
"@jtl-software/cloud-app-template-frontend-react": "0.3.
|
|
24
|
+
"@jtl-software/cloud-app-template-frontend-react": "0.3.3",
|
|
25
25
|
"@jtl-software/cloud-app-template-shared": "0.2.0",
|
|
26
26
|
"picocolors": "^1.1.1",
|
|
27
|
-
"posthog-node": "^5.
|
|
27
|
+
"posthog-node": "^5.55.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/node": "^26.
|
|
30
|
+
"@types/node": "^26.6.5",
|
|
31
31
|
"msw": "^2.15.0",
|
|
32
32
|
"tsup": "^8.5.1",
|
|
33
|
-
"tsx": "^4.23.
|
|
33
|
+
"tsx": "^4.23.15",
|
|
34
34
|
"typescript": "^6.0.3"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|