@scalar/cli 2.8.0 → 2.11.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/README.md +84 -1076
- package/chunks/action-25QMCP5G.js +122 -0
- package/chunks/{action-354TUG4H.js → action-2VF6LODL.js} +20 -16
- package/chunks/{action-XIUO64C7.js → action-5I4XDPPG.js} +20 -14
- package/chunks/action-6M5PTDF6.js +100 -0
- package/chunks/{action-NVI5DWFP.js → action-73ELLN3T.js} +8 -11
- package/chunks/{action-Y6NXJQ4H.js → action-7H3AWCHX.js} +21 -16
- package/chunks/{action-LLH4QPXM.js → action-BRSLSOE5.js} +19 -18
- package/chunks/{action-EOAVVL52.js → action-CQQCKSNS.js} +17 -22
- package/chunks/action-D5QWDNQ2.js +65 -0
- package/chunks/{action-Y7OUGD56.js → action-DQDHBOLJ.js} +34 -31
- package/chunks/{action-5SK5NE7E.js → action-EYPYQQVM.js} +18 -23
- package/chunks/{action-YRX6SN5F.js → action-FMA5ECUA.js} +12 -10
- package/chunks/{action-7PEQXDWT.js → action-GXDJLF2G.js} +134 -25
- package/chunks/action-HUICEXJZ.js +75 -0
- package/chunks/action-IH6G77C5.js +38 -0
- package/chunks/{action-H3RTILLM.js → action-IIQMZVRJ.js} +1 -1
- package/chunks/action-IQM54ITT.js +164 -0
- package/chunks/{action-UIKH4SZX.js → action-J5TO3UJW.js} +32 -26
- package/chunks/{action-H6OUJWWM.js → action-KC3ZCNDR.js} +17 -22
- package/chunks/{action-6BYGBXRC.js → action-L7TMS3Q3.js} +44 -37
- package/chunks/{action-GWXLHL2Z.js → action-LAAHRDSR.js} +5 -4
- package/chunks/{action-FCAYFPVR.js → action-LR75GHBA.js} +14 -11
- package/chunks/action-MJMLQFLT.js +1552 -0
- package/chunks/action-NHU4CUKT.js +130 -0
- package/chunks/action-NKTFNFU7.js +64 -0
- package/chunks/{action-F7A2K74G.js → action-NMW5WPD2.js} +12 -16
- package/chunks/{action-VOFDW3U2.js → action-OTPXODUE.js} +8 -7
- package/chunks/{action-43YBNBDR.js → action-RPCDNGCI.js} +54 -39
- package/chunks/{action-QQZLPI42.js → action-RQCXSJPZ.js} +55 -27
- package/chunks/action-SOYSVG67.js +147 -0
- package/chunks/action-Y7EBKCUU.js +16 -0
- package/chunks/{action-WFDNRA7D.js → action-YN4TE7TG.js} +24 -23
- package/chunks/{action-AQRPFQKI.js → action-ZGNVWTHZ.js} +14 -12
- package/chunks/action-ZKKRPLDK.js +64 -0
- package/chunks/{action-HT2DJ34Z.js → action-ZUZL7R3H.js} +20 -15
- package/chunks/{actions-OGIVBQC7.js → actions-S6K76HCW.js} +46 -19
- package/chunks/{agent-ASPV3R5U.js → agent-IRNEV4K5.js} +46 -9
- package/chunks/{asyncapi-QNFKXHEI.js → asyncapi-WQPIQMEZ.js} +15 -10
- package/chunks/{build.action-NM6CAE5F.js → build.action-CLBVKFWD.js} +28 -24
- package/chunks/chunk-25XERWCE.js +1058 -0
- package/chunks/chunk-3RIUDHLG.js +467 -0
- package/chunks/{chunk-MLSZVVTT.js → chunk-3TFOA64C.js} +19 -8
- package/chunks/{chunk-HGOD6THU.js → chunk-4JKXZ5CF.js} +12 -25
- package/chunks/{chunk-C2KAWRIX.js → chunk-5ENKYZA4.js} +1 -1
- package/chunks/{chunk-W24BETFG.js → chunk-5L7V7RCH.js} +10 -10
- package/chunks/chunk-6PSYZO3U.js +24 -0
- package/chunks/{chunk-IMG35UXX.js → chunk-ALYM4ZB2.js} +1 -1
- package/chunks/chunk-AVZFSWPD.js +37 -0
- package/chunks/{chunk-5UHLAJQD.js → chunk-BQYVSPAI.js} +36 -10
- package/chunks/{chunk-XXSQUBXS.js → chunk-CSSTCHHF.js} +6212 -4642
- package/chunks/chunk-DFOZG7ZV.js +15 -0
- package/chunks/{chunk-22HYZ7LE.js → chunk-DQD2753S.js} +3 -3
- package/chunks/{action-F2ZJNURT.js → chunk-EBNFCIKS.js} +7 -10
- package/chunks/{chunk-EXY3ZTV4.js → chunk-F3OPMYME.js} +143 -301
- package/chunks/{chunk-FDC2IESH.js → chunk-FG5AOTDN.js} +8519 -14702
- package/chunks/chunk-GKCVATQJ.js +92 -0
- package/chunks/{chunk-PH3WFNXJ.js → chunk-GMHIK5K2.js} +1 -1
- package/chunks/{chunk-GTV2BVXV.js → chunk-GYR5E6RB.js} +2 -2
- package/chunks/{chunk-OJ2EWIJH.js → chunk-HZN6IIPZ.js} +11 -6
- package/chunks/{chunk-IKT5F47M.js → chunk-I57ID5K7.js} +24 -11
- package/chunks/{chunk-BPGFSSUH.js → chunk-KOD2HX5I.js} +1 -1
- package/chunks/{chunk-L3UXDCBI.js → chunk-LOLVJNI5.js} +4 -4
- package/chunks/{chunk-KCCFN4F7.js → chunk-MN2AFJXM.js} +36 -29
- package/chunks/{chunk-UXJ753NV.js → chunk-N5CJ5MTY.js} +5 -13
- package/chunks/chunk-NAC63XJF.js +10 -0
- package/chunks/{chunk-2OCWX42S.js → chunk-NWJ37GI2.js} +166 -22
- package/chunks/{chunk-3ZJYGGAA.js → chunk-ORCUZITN.js} +1 -1
- package/chunks/chunk-QMLRYD76.js +24 -0
- package/chunks/{chunk-KKRGBXCE.js → chunk-SEURG74P.js} +303 -209
- package/chunks/{chunk-R5LK6VPY.js → chunk-SOV4POMS.js} +370 -264
- package/chunks/chunk-T34TL6KL.js +222 -0
- package/chunks/{chunk-5DEU2DVL.js → chunk-U6VE6JOS.js} +3 -15
- package/chunks/{chunk-YILQODZF.js → chunk-UFSFY7Z4.js} +23 -20
- package/chunks/{chunk-6YPQGVF4.js → chunk-ULRJZXMS.js} +1 -1
- package/chunks/chunk-US54KYOJ.js +131 -0
- package/chunks/chunk-V6LUKXBV.js +37 -0
- package/chunks/{chunk-5JLVQVKO.js → chunk-VRZSDUZK.js} +190 -152
- package/chunks/chunk-VUXPDHTQ.js +22 -0
- package/chunks/chunk-XP5UM7SF.js +21 -0
- package/chunks/chunk-Y6XGC4K5.js +311 -0
- package/chunks/{create.action-FUQ2BVJA.js → create.action-ITEOQ644.js} +34 -30
- package/chunks/{delete.action-47E66R3I.js → delete.action-77MFPLUN.js} +30 -26
- package/chunks/{delete.action-BTDFH7WY.js → delete.action-C6VX4S5Q.js} +30 -26
- package/chunks/{get.action-XC7KC2JO.js → get.action-3BP4FHZC.js} +20 -14
- package/chunks/get.action-LNBOWUVE.js +95 -0
- package/chunks/list.action-6CRFQPJT.js +156 -0
- package/chunks/list.action-KR5YIDR4.js +126 -0
- package/chunks/{publish.action-OS27XOX4.js → publish.action-YBORRPBM.js} +49 -42
- package/chunks/query-WKATAJJ6.js +129 -0
- package/chunks/scripts-6CI6U32J.js +102 -0
- package/chunks/{update.action-AEIBLCWD.js → update.action-O7TSXDGV.js} +34 -27
- package/chunks/{update.action-ZMS4CQ3T.js → update.action-QZI7M2MV.js} +34 -27
- package/index.js +579 -382
- package/package.json +15 -14
- package/skills/scalar-cli/SKILL.md +52 -46
- package/template.md +71 -136
- package/chunks/action-CA4QYPI6.js +0 -125
- package/chunks/action-JAHFRYWZ.js +0 -423
- package/chunks/action-KTYOCA2V.js +0 -229
- package/chunks/action-LEUD5P2U.js +0 -92
- package/chunks/action-LXGXKXZZ.js +0 -72
- package/chunks/action-W3C53GPH.js +0 -54
- package/chunks/action-YLF2G4G5.js +0 -37
- package/chunks/chunk-6XWCMJDB.js +0 -404
- package/chunks/chunk-K74E42RV.js +0 -7311
- package/chunks/chunk-QVQ4PNVL.js +0 -610
- package/chunks/chunk-XEDGMZJD.js +0 -366
- package/chunks/list.action-LXKEUYKO.js +0 -116
- package/chunks/list.action-OFGLMRE7.js +0 -95
- package/docs.html +0 -6245
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
BaseCollections
|
|
4
|
+
} from "./chunk-NWJ37GI2.js";
|
|
5
|
+
import {
|
|
6
|
+
getDatabaseClient
|
|
7
|
+
} from "./chunk-U6VE6JOS.js";
|
|
8
|
+
import "./chunk-SEURG74P.js";
|
|
9
|
+
import "./chunk-3TFOA64C.js";
|
|
10
|
+
import "./chunk-5ENKYZA4.js";
|
|
11
|
+
import "./chunk-Y6XGC4K5.js";
|
|
12
|
+
import "./chunk-T34TL6KL.js";
|
|
13
|
+
import "./chunk-V6LUKXBV.js";
|
|
14
|
+
import "./chunk-VUXPDHTQ.js";
|
|
15
|
+
import {
|
|
16
|
+
getAuthData
|
|
17
|
+
} from "./chunk-3RIUDHLG.js";
|
|
18
|
+
import "./chunk-N5CJ5MTY.js";
|
|
19
|
+
import "./chunk-US54KYOJ.js";
|
|
20
|
+
import {
|
|
21
|
+
teamSchema
|
|
22
|
+
} from "./chunk-BQYVSPAI.js";
|
|
23
|
+
import "./chunk-VRZSDUZK.js";
|
|
24
|
+
import "./chunk-4ORL4MST.js";
|
|
25
|
+
import "./chunk-MN2AFJXM.js";
|
|
26
|
+
import {
|
|
27
|
+
output
|
|
28
|
+
} from "./chunk-T5HJUAWB.js";
|
|
29
|
+
import "./chunk-25XERWCE.js";
|
|
30
|
+
import "./chunk-AVZFSWPD.js";
|
|
31
|
+
import "./chunk-I57ID5K7.js";
|
|
32
|
+
import "./chunk-3MZYUBJ6.js";
|
|
33
|
+
|
|
34
|
+
// src/domains/auth/whoami/action.ts
|
|
35
|
+
import as from "ansis";
|
|
36
|
+
async function whoamiAction(options = {}) {
|
|
37
|
+
const auth = await getAuthData();
|
|
38
|
+
const team = await getDatabaseClient().then(
|
|
39
|
+
(client) => client.getOne({
|
|
40
|
+
collectionPath: BaseCollections.Teams,
|
|
41
|
+
query: { uid: auth.teamUid },
|
|
42
|
+
schema: teamSchema
|
|
43
|
+
})
|
|
44
|
+
).catch(() => null);
|
|
45
|
+
const details = {
|
|
46
|
+
email: auth.email,
|
|
47
|
+
team: {
|
|
48
|
+
uid: auth.teamUid,
|
|
49
|
+
name: team && !team.error ? team.data.name : null
|
|
50
|
+
},
|
|
51
|
+
role: auth.role ?? null,
|
|
52
|
+
authentication: "refreshToken" in auth ? "browser_session" : "personal_token"
|
|
53
|
+
};
|
|
54
|
+
if (options.json) {
|
|
55
|
+
process.stdout.write(`${JSON.stringify(details, null, 2)}
|
|
56
|
+
`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
output.info().line(`User: ${as.cyan(details.email ?? "Unknown")}`).line(`Team: ${details.team.name ?? "Unavailable"}`).line(`Team ID: ${details.team.uid}`).line(`Role: ${as.cyan(details.role ?? "Unknown")}`).line(
|
|
60
|
+
`Authentication: ${details.authentication === "browser_session" ? "Browser session" : "Personal token"}`
|
|
61
|
+
).print();
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
whoamiAction
|
|
65
|
+
};
|
|
@@ -6,37 +6,38 @@ import {
|
|
|
6
6
|
findConfig,
|
|
7
7
|
getCurrentFolderName,
|
|
8
8
|
scalarConfigSchema
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-CSSTCHHF.js";
|
|
10
10
|
import {
|
|
11
11
|
apiService
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
17
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-F3OPMYME.js";
|
|
13
|
+
import "./chunk-FG5AOTDN.js";
|
|
14
|
+
import "./chunk-SEURG74P.js";
|
|
15
|
+
import "./chunk-3TFOA64C.js";
|
|
16
|
+
import "./chunk-5ENKYZA4.js";
|
|
17
|
+
import "./chunk-Y6XGC4K5.js";
|
|
18
|
+
import "./chunk-SOV4POMS.js";
|
|
19
|
+
import "./chunk-T34TL6KL.js";
|
|
18
20
|
import {
|
|
19
21
|
getMetadata
|
|
20
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-3RIUDHLG.js";
|
|
21
23
|
import {
|
|
22
24
|
config
|
|
23
|
-
} from "./chunk-
|
|
24
|
-
import "./chunk-
|
|
25
|
-
import "./chunk-
|
|
25
|
+
} from "./chunk-N5CJ5MTY.js";
|
|
26
|
+
import "./chunk-US54KYOJ.js";
|
|
27
|
+
import "./chunk-BQYVSPAI.js";
|
|
28
|
+
import "./chunk-VRZSDUZK.js";
|
|
26
29
|
import {
|
|
27
30
|
requireInteractive
|
|
28
31
|
} from "./chunk-EGOXR5FB.js";
|
|
29
|
-
import "./chunk-
|
|
30
|
-
import "./chunk-KCCFN4F7.js";
|
|
31
|
-
import "./chunk-6XWCMJDB.js";
|
|
32
|
-
import "./chunk-4ORL4MST.js";
|
|
32
|
+
import "./chunk-MN2AFJXM.js";
|
|
33
33
|
import {
|
|
34
34
|
output
|
|
35
35
|
} from "./chunk-T5HJUAWB.js";
|
|
36
|
-
import "./chunk-
|
|
36
|
+
import "./chunk-25XERWCE.js";
|
|
37
|
+
import "./chunk-AVZFSWPD.js";
|
|
37
38
|
import {
|
|
38
39
|
slugify
|
|
39
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-I57ID5K7.js";
|
|
40
41
|
import "./chunk-3MZYUBJ6.js";
|
|
41
42
|
|
|
42
43
|
// src/domains/project/init/action.ts
|
|
@@ -2003,21 +2004,21 @@ var __default = {
|
|
|
2003
2004
|
// src/domains/project/init/quickstart.ts
|
|
2004
2005
|
var quickstartMarkdown = `# Quickstart
|
|
2005
2006
|
|
|
2006
|
-
## 1. Preview
|
|
2007
|
+
## 1. Preview your documentation
|
|
2007
2008
|
|
|
2008
|
-
Run a local development server to see your changes
|
|
2009
|
+
Run a local development server to see your changes as you edit:
|
|
2009
2010
|
|
|
2010
2011
|
\`\`\`bash
|
|
2011
2012
|
npx @scalar/cli project preview
|
|
2012
2013
|
\`\`\`
|
|
2013
2014
|
|
|
2014
|
-
|
|
2015
|
+
The preview uses port 7970 by default and selects another port if it is unavailable. Open the URL printed by the command to see your changes.
|
|
2015
2016
|
|
|
2016
|
-
## 2. Customize
|
|
2017
|
+
## 2. Customize your documentation
|
|
2017
2018
|
|
|
2018
|
-
Make it yours with themes, custom CSS, and
|
|
2019
|
+
Make it yours with themes, custom CSS, and Markdown. Configure your documentation structure, navigation, and styling through \`scalar.config.json\`.
|
|
2019
2020
|
|
|
2020
|
-
## 3. Publish
|
|
2021
|
+
## 3. Publish your documentation
|
|
2021
2022
|
|
|
2022
2023
|
First, authenticate with your Scalar account:
|
|
2023
2024
|
|
|
@@ -2028,12 +2029,12 @@ npx @scalar/cli auth login
|
|
|
2028
2029
|
Then publish your documentation:
|
|
2029
2030
|
|
|
2030
2031
|
\`\`\`bash
|
|
2031
|
-
npx @scalar/cli project publish --slug
|
|
2032
|
+
npx @scalar/cli project publish --slug <project-slug>
|
|
2032
2033
|
\`\`\`
|
|
2033
2034
|
|
|
2034
|
-
|
|
2035
|
+
The command prints the deployment URL when publishing completes.
|
|
2035
2036
|
|
|
2036
|
-
##
|
|
2037
|
+
## Get help
|
|
2037
2038
|
|
|
2038
2039
|
Check whether your \`scalar.config.json\` is valid:
|
|
2039
2040
|
|
|
@@ -2063,12 +2064,12 @@ async function initAction({
|
|
|
2063
2064
|
}) {
|
|
2064
2065
|
const configFile = findConfig() || CONFIG_FILE_DEFAULT;
|
|
2065
2066
|
const nextSteps = () => {
|
|
2066
|
-
output.info().line("
|
|
2067
|
+
output.info().line("Next steps:").line(
|
|
2067
2068
|
` ${as.cyan("scalar project preview")} to preview your project locally`
|
|
2068
2069
|
).line(
|
|
2069
2070
|
` ${as.cyan("scalar project check-config")} to validate your scalar.config.json file`
|
|
2070
2071
|
).line(
|
|
2071
|
-
` ${as.cyan("scalar project publish --slug")} ${as.gray("
|
|
2072
|
+
` ${as.cyan("scalar project publish --slug")} ${as.gray("<project-slug>")} to publish your project`
|
|
2072
2073
|
).line(
|
|
2073
2074
|
as.white(
|
|
2074
2075
|
`Run ${as.magenta("scalar --help")} to see all available commands.`
|
|
@@ -2093,7 +2094,7 @@ async function initAction({
|
|
|
2093
2094
|
);
|
|
2094
2095
|
}
|
|
2095
2096
|
const shouldOverwriteExisting = force ?? await confirm({
|
|
2096
|
-
message: "
|
|
2097
|
+
message: "Overwrite the existing configuration file?",
|
|
2097
2098
|
initialValue: false
|
|
2098
2099
|
});
|
|
2099
2100
|
if (isCancel(shouldOverwriteExisting)) {
|
|
@@ -2147,7 +2148,7 @@ async function initAction({
|
|
|
2147
2148
|
}
|
|
2148
2149
|
while (true) {
|
|
2149
2150
|
const response = suppliedSubdomain ?? await text({
|
|
2150
|
-
message: "
|
|
2151
|
+
message: "Enter the project name",
|
|
2151
2152
|
defaultValue: folderName,
|
|
2152
2153
|
placeholder: folderName
|
|
2153
2154
|
});
|
|
@@ -2168,7 +2169,9 @@ async function initAction({
|
|
|
2168
2169
|
if (apiClient) {
|
|
2169
2170
|
const result = await apiClient.publish.getDomainAvailability(`${slug}.${config.publishTld}`).catch(() => null);
|
|
2170
2171
|
if (!result || result.error) {
|
|
2171
|
-
return output.error().message(
|
|
2172
|
+
return output.error().message(
|
|
2173
|
+
"Could not check subdomain availability. Check your connection and authentication before running the command again."
|
|
2174
|
+
).exit("error");
|
|
2172
2175
|
}
|
|
2173
2176
|
if (!result.data.available) {
|
|
2174
2177
|
const message = `Subdomain "${slug}" is already taken. Choose another name.`;
|
|
@@ -4,58 +4,53 @@ import {
|
|
|
4
4
|
} from "./chunk-KHDYYVYF.js";
|
|
5
5
|
import {
|
|
6
6
|
getFileOrUrl,
|
|
7
|
+
isDocument
|
|
8
|
+
} from "./chunk-4JKXZ5CF.js";
|
|
9
|
+
import {
|
|
7
10
|
isAsyncApiDocument,
|
|
8
|
-
isDocument,
|
|
9
11
|
safeNormalize
|
|
10
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-QMLRYD76.js";
|
|
11
13
|
import {
|
|
12
14
|
requireInteractive
|
|
13
15
|
} from "./chunk-EGOXR5FB.js";
|
|
14
|
-
import {
|
|
15
|
-
require_dist
|
|
16
|
-
} from "./chunk-K74E42RV.js";
|
|
17
|
-
import "./chunk-KCCFN4F7.js";
|
|
18
|
-
import "./chunk-6XWCMJDB.js";
|
|
19
16
|
import {
|
|
20
17
|
isUrl,
|
|
21
18
|
isYamlFileName
|
|
22
19
|
} from "./chunk-4ORL4MST.js";
|
|
20
|
+
import "./chunk-MN2AFJXM.js";
|
|
23
21
|
import {
|
|
24
22
|
output
|
|
25
23
|
} from "./chunk-T5HJUAWB.js";
|
|
26
|
-
import "./chunk-
|
|
27
|
-
import "./chunk-
|
|
28
|
-
import
|
|
29
|
-
|
|
30
|
-
} from "./chunk-3MZYUBJ6.js";
|
|
24
|
+
import "./chunk-25XERWCE.js";
|
|
25
|
+
import "./chunk-AVZFSWPD.js";
|
|
26
|
+
import "./chunk-I57ID5K7.js";
|
|
27
|
+
import "./chunk-3MZYUBJ6.js";
|
|
31
28
|
|
|
32
29
|
// src/domains/document/upgrade/action.ts
|
|
33
|
-
var import_yaml = __toESM(require_dist(), 1);
|
|
34
30
|
import fs from "node:fs/promises";
|
|
35
31
|
import { confirm } from "@clack/prompts";
|
|
36
32
|
import as from "ansis";
|
|
33
|
+
import YAML from "yaml";
|
|
37
34
|
import { upgrade as upgradeAsyncApi } from "@scalar/asyncapi-upgrader";
|
|
38
35
|
import { upgrade } from "@scalar/openapi-upgrader";
|
|
39
36
|
async function upgradeAction(input, { output: outputFilePath }) {
|
|
40
37
|
if (!input) {
|
|
41
|
-
return output.error().title("Missing input").message("
|
|
38
|
+
return output.error().title("Missing input").message("Provide a file path or URL to upgrade.").exit("error");
|
|
42
39
|
}
|
|
43
40
|
const isUrlInput = isUrl(input);
|
|
44
41
|
if (!outputFilePath) {
|
|
45
42
|
if (isUrlInput) {
|
|
46
|
-
return output.error().message(
|
|
47
|
-
"Please provide an output file using the -o flag when upgrading from a URL."
|
|
48
|
-
).exit("error");
|
|
43
|
+
return output.error().message("URL input requires an output file. Use `--output <file>`.").exit("error");
|
|
49
44
|
}
|
|
50
45
|
requireInteractive(
|
|
51
46
|
"Pass --output to upgrade a document in non-interactive mode."
|
|
52
47
|
);
|
|
53
48
|
const shouldContinue = await confirm({
|
|
54
|
-
message:
|
|
49
|
+
message: `No output file was specified. Overwrite "${input}"?`,
|
|
55
50
|
initialValue: false
|
|
56
51
|
});
|
|
57
52
|
if (shouldContinue !== true) {
|
|
58
|
-
return output.error().message("Operation cancelled
|
|
53
|
+
return output.error().message("Operation cancelled.").exit("error");
|
|
59
54
|
}
|
|
60
55
|
}
|
|
61
56
|
const outputFileName = outputFilePath ?? input;
|
|
@@ -63,7 +58,7 @@ async function upgradeAction(input, { output: outputFilePath }) {
|
|
|
63
58
|
const document = safeNormalize(content);
|
|
64
59
|
if (!isDocument(document)) {
|
|
65
60
|
return output.error().title("Invalid input").message(
|
|
66
|
-
"Could not read a document from the input.
|
|
61
|
+
"Could not read a document from the input. Provide a valid JSON or YAML file."
|
|
67
62
|
).exit("error");
|
|
68
63
|
}
|
|
69
64
|
const isAsyncApi = isAsyncApiDocument(document);
|
|
@@ -73,14 +68,14 @@ async function upgradeAction(input, { output: outputFilePath }) {
|
|
|
73
68
|
const isYaml = isYamlFileName(outputFileName);
|
|
74
69
|
await fs.writeFile(
|
|
75
70
|
outputFileName,
|
|
76
|
-
isYaml ?
|
|
71
|
+
isYaml ? YAML.stringify(upgraded) : JSON.stringify(upgraded, null, 2)
|
|
77
72
|
);
|
|
78
73
|
const specification = isAsyncApi ? "AsyncAPI" : "OpenAPI";
|
|
79
74
|
const version = upgraded[isAsyncApi ? "asyncapi" : "openapi"];
|
|
80
75
|
const versionSuffix = typeof version === "string" ? ` to version ${version}` : "";
|
|
81
76
|
output.info().message(
|
|
82
|
-
`${as.green(
|
|
83
|
-
).print();
|
|
77
|
+
`${as.green(`${specification} description upgraded${versionSuffix}`)} (${as.white(`${as.bold(`${executionTimeMs.toFixed(2)}`)} ms`)})`
|
|
78
|
+
).line(`Written to ${as.cyan(outputFileName)}`).print();
|
|
84
79
|
}
|
|
85
80
|
export {
|
|
86
81
|
upgradeAction
|
|
@@ -3,22 +3,24 @@ import {
|
|
|
3
3
|
measureTime
|
|
4
4
|
} from "./chunk-KHDYYVYF.js";
|
|
5
5
|
import {
|
|
6
|
-
isAsyncApiDocument,
|
|
7
6
|
isDocument
|
|
8
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-4JKXZ5CF.js";
|
|
8
|
+
import {
|
|
9
|
+
isAsyncApiDocument
|
|
10
|
+
} from "./chunk-QMLRYD76.js";
|
|
9
11
|
import {
|
|
10
12
|
requireInteractive
|
|
11
13
|
} from "./chunk-EGOXR5FB.js";
|
|
12
|
-
import "./chunk-KCCFN4F7.js";
|
|
13
|
-
import "./chunk-6XWCMJDB.js";
|
|
14
14
|
import {
|
|
15
15
|
isUrl
|
|
16
16
|
} from "./chunk-4ORL4MST.js";
|
|
17
|
+
import "./chunk-MN2AFJXM.js";
|
|
17
18
|
import {
|
|
18
19
|
output
|
|
19
20
|
} from "./chunk-T5HJUAWB.js";
|
|
20
|
-
import "./chunk-
|
|
21
|
-
import "./chunk-
|
|
21
|
+
import "./chunk-25XERWCE.js";
|
|
22
|
+
import "./chunk-AVZFSWPD.js";
|
|
23
|
+
import "./chunk-I57ID5K7.js";
|
|
22
24
|
import "./chunk-3MZYUBJ6.js";
|
|
23
25
|
|
|
24
26
|
// src/domains/document/split/action.ts
|
|
@@ -186,7 +188,7 @@ async function splitAsyncApi(document, outputPath) {
|
|
|
186
188
|
// src/domains/document/split/action.ts
|
|
187
189
|
async function splitAction(input, { output: __outputPath }) {
|
|
188
190
|
if (!input) {
|
|
189
|
-
return output.error().title("Missing input").message("
|
|
191
|
+
return output.error().title("Missing input").message("Provide a file path or URL to split.").exit("error");
|
|
190
192
|
}
|
|
191
193
|
const getOutputPath = async () => {
|
|
192
194
|
if (__outputPath !== void 0 && typeof __outputPath === "string") {
|
|
@@ -201,7 +203,7 @@ async function splitAction(input, { output: __outputPath }) {
|
|
|
201
203
|
placeholder: "./assets"
|
|
202
204
|
});
|
|
203
205
|
if (typeof outputPath2 !== "string") {
|
|
204
|
-
return output.error().message("Operation cancelled
|
|
206
|
+
return output.error().message("Operation cancelled.").exit("error");
|
|
205
207
|
}
|
|
206
208
|
return outputPath2;
|
|
207
209
|
};
|
|
@@ -217,7 +219,7 @@ async function splitAction(input, { output: __outputPath }) {
|
|
|
217
219
|
}).catch(() => null);
|
|
218
220
|
if (!isDocument(document)) {
|
|
219
221
|
return output.error().title("Invalid input").message(
|
|
220
|
-
"Could not read an OpenAPI or AsyncAPI document from the input.
|
|
222
|
+
"Could not read an OpenAPI or AsyncAPI document from the input. Provide a valid JSON or YAML file."
|
|
221
223
|
).exit("error");
|
|
222
224
|
}
|
|
223
225
|
const { executionTimeMs } = await measureTime(async () => {
|
|
@@ -243,7 +245,7 @@ async function splitAction(input, { output: __outputPath }) {
|
|
|
243
245
|
);
|
|
244
246
|
await fs2.rm(workspaceFilePath);
|
|
245
247
|
});
|
|
246
|
-
output.info().line().title(as.green("
|
|
248
|
+
output.info().line().title(as.green("API description split")).line().message(`Written to ${as.blue(outputPath)}`).line(`Completed (${as.yellow(executionTimeMs.toFixed(2))} ms)`).line("").print();
|
|
247
249
|
}
|
|
248
250
|
export {
|
|
249
251
|
splitAction
|
|
@@ -2,38 +2,38 @@ import { createRequire as $$cR } from "node:module"; const require = $$cR(import
|
|
|
2
2
|
import {
|
|
3
3
|
measureTime
|
|
4
4
|
} from "./chunk-KHDYYVYF.js";
|
|
5
|
+
import {
|
|
6
|
+
isDocument
|
|
7
|
+
} from "./chunk-4JKXZ5CF.js";
|
|
5
8
|
import {
|
|
6
9
|
isAsyncApiDocument,
|
|
7
|
-
isDocument,
|
|
8
10
|
safeNormalize
|
|
9
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-QMLRYD76.js";
|
|
10
12
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import "./chunk-6XWCMJDB.js";
|
|
13
|
+
err,
|
|
14
|
+
ok
|
|
15
|
+
} from "./chunk-5ENKYZA4.js";
|
|
15
16
|
import {
|
|
16
17
|
isYamlFileName
|
|
17
18
|
} from "./chunk-4ORL4MST.js";
|
|
19
|
+
import "./chunk-MN2AFJXM.js";
|
|
18
20
|
import {
|
|
19
21
|
output
|
|
20
22
|
} from "./chunk-T5HJUAWB.js";
|
|
21
|
-
import "./chunk-
|
|
23
|
+
import "./chunk-25XERWCE.js";
|
|
24
|
+
import "./chunk-AVZFSWPD.js";
|
|
22
25
|
import {
|
|
23
26
|
external_exports
|
|
24
|
-
} from "./chunk-
|
|
25
|
-
import
|
|
26
|
-
__toESM
|
|
27
|
-
} from "./chunk-3MZYUBJ6.js";
|
|
27
|
+
} from "./chunk-I57ID5K7.js";
|
|
28
|
+
import "./chunk-3MZYUBJ6.js";
|
|
28
29
|
|
|
29
30
|
// src/domains/document/join/action.ts
|
|
30
|
-
var import_yaml = __toESM(require_dist(), 1);
|
|
31
31
|
import fs from "node:fs/promises";
|
|
32
32
|
import path from "node:path";
|
|
33
33
|
import as from "ansis";
|
|
34
|
-
import
|
|
34
|
+
import YAML from "yaml";
|
|
35
|
+
import { bundle as bundle2 } from "@scalar/json-magic/bundle";
|
|
35
36
|
import { fetchUrls, readFiles } from "@scalar/json-magic/bundle/plugins/node";
|
|
36
|
-
import { join } from "@scalar/openapi-parser";
|
|
37
37
|
|
|
38
38
|
// src/domains/document/join/helpers.ts
|
|
39
39
|
import { getValueByPath as getValueByPathWithContext } from "@scalar/json-magic/helpers/get-value-by-path";
|
|
@@ -171,6 +171,111 @@ var joinAsyncApi = (inputs, prefixes) => {
|
|
|
171
171
|
return conflicts.length ? { ok: false, conflicts } : { ok: true, document: result };
|
|
172
172
|
};
|
|
173
173
|
|
|
174
|
+
// ../../node_modules/.pnpm/@scalar+helpers@0.16.1/node_modules/@scalar/helpers/dist/object/prevent-pollution.js
|
|
175
|
+
var PROTOTYPE_POLLUTION_KEYS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
176
|
+
var isPollutionKey = (key) => PROTOTYPE_POLLUTION_KEYS.has(key);
|
|
177
|
+
|
|
178
|
+
// src/domains/document/join/openapi.ts
|
|
179
|
+
import { bundle } from "@scalar/json-magic/bundle";
|
|
180
|
+
import { join } from "@scalar/json-magic/join";
|
|
181
|
+
import { upgrade as upgrade2 } from "@scalar/openapi-upgrader";
|
|
182
|
+
var omitEmptySection = (value) => {
|
|
183
|
+
if (Array.isArray(value)) return value.length ? value : void 0;
|
|
184
|
+
if (isDocument(value)) return Object.keys(value).length ? value : void 0;
|
|
185
|
+
return value ?? void 0;
|
|
186
|
+
};
|
|
187
|
+
var prefixComponents = async (document, prefix) => {
|
|
188
|
+
await bundle(document, {
|
|
189
|
+
treeShake: false,
|
|
190
|
+
urlMap: false,
|
|
191
|
+
plugins: [
|
|
192
|
+
{
|
|
193
|
+
type: "lifecycle",
|
|
194
|
+
onBeforeNodeProcess: (node) => {
|
|
195
|
+
const ref = node.$ref;
|
|
196
|
+
if (typeof ref !== "string" || !ref.startsWith("#/components/"))
|
|
197
|
+
return;
|
|
198
|
+
const parts = ref.split("/");
|
|
199
|
+
if (parts.length < 4) return;
|
|
200
|
+
parts[3] = `${prefix}${parts[3]}`;
|
|
201
|
+
node.$ref = parts.join("/");
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
type: "lifecycle",
|
|
206
|
+
onBeforeNodeProcess: (node, context) => {
|
|
207
|
+
if (context.path.length !== 2 || context.path[0] !== "components")
|
|
208
|
+
return;
|
|
209
|
+
for (const key of Object.keys(node)) {
|
|
210
|
+
const value = node[key];
|
|
211
|
+
delete node[key];
|
|
212
|
+
const name = `${prefix}${key}`;
|
|
213
|
+
if (!isPollutionKey(key) && !isPollutionKey(name))
|
|
214
|
+
node[name] = value;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
var joinOpenApi = async (inputs, prefixes) => {
|
|
222
|
+
const documents = await Promise.all(
|
|
223
|
+
inputs.map(async (input, index) => {
|
|
224
|
+
const document = upgrade2(structuredClone(input), "3.1");
|
|
225
|
+
await prefixComponents(document, prefixes[index] ?? "");
|
|
226
|
+
return {
|
|
227
|
+
...document,
|
|
228
|
+
info: isDocument(document.info) ? document.info : {},
|
|
229
|
+
paths: document.paths ?? {},
|
|
230
|
+
webhooks: document.webhooks ?? {},
|
|
231
|
+
components: document.components ?? {},
|
|
232
|
+
tags: document.tags ?? [],
|
|
233
|
+
servers: document.servers ?? []
|
|
234
|
+
};
|
|
235
|
+
})
|
|
236
|
+
);
|
|
237
|
+
const result = join(documents.reverse(), {
|
|
238
|
+
strategy: ({ path: path2, current }) => {
|
|
239
|
+
const [field] = path2;
|
|
240
|
+
if (isPollutionKey(path2.at(-1) ?? "") && (field === "info" || field === "components" || path2.length === 2))
|
|
241
|
+
return "skip";
|
|
242
|
+
if (field === "info") return "merge-by-index";
|
|
243
|
+
if (field === "tags") return { uniqueBy: "name" };
|
|
244
|
+
if (field === "servers") return { uniqueBy: "url" };
|
|
245
|
+
if (field === "paths" || field === "webhooks" || field === "components") {
|
|
246
|
+
if (path2.length < 3) return "merge";
|
|
247
|
+
return field === "components" && !current ? "replace" : "conflict";
|
|
248
|
+
}
|
|
249
|
+
return "replace";
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
if (!result.ok) {
|
|
253
|
+
const conflicts = [];
|
|
254
|
+
for (const field of ["paths", "webhooks", "components"]) {
|
|
255
|
+
for (const { path: path2 } of result.conflicts) {
|
|
256
|
+
if (path2[0] !== field) continue;
|
|
257
|
+
conflicts.push(
|
|
258
|
+
field === "components" ? { type: "component", componentType: path2[1], name: path2[2] } : {
|
|
259
|
+
type: field === "paths" ? "path" : "webhook",
|
|
260
|
+
path: path2[1],
|
|
261
|
+
method: path2[2]
|
|
262
|
+
}
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return err(conflicts);
|
|
267
|
+
}
|
|
268
|
+
return ok({
|
|
269
|
+
...result.document,
|
|
270
|
+
info: result.document.info ?? {},
|
|
271
|
+
paths: result.document.paths ?? {},
|
|
272
|
+
webhooks: omitEmptySection(result.document.webhooks),
|
|
273
|
+
tags: omitEmptySection(result.document.tags),
|
|
274
|
+
servers: omitEmptySection(result.document.servers),
|
|
275
|
+
components: omitEmptySection(result.document.components)
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
|
|
174
279
|
// src/domains/document/join/action.ts
|
|
175
280
|
var formatErrorMessage = (conflicts) => {
|
|
176
281
|
return conflicts.map((conflict) => {
|
|
@@ -196,14 +301,16 @@ async function joinAction(rawInput, rawOpt) {
|
|
|
196
301
|
}).safeParse(rawOpt);
|
|
197
302
|
if (optsError) {
|
|
198
303
|
return output.error().title("Invalid options").line("").line(
|
|
199
|
-
optsError.issues.map(
|
|
304
|
+
optsError.issues.map(
|
|
305
|
+
(e) => e.path[0] === "output" ? "Provide an output file with --output <file>." : `${e.message} (option: ${e.path.join(".")})`
|
|
306
|
+
).join("\n")
|
|
200
307
|
).line("").exit("error");
|
|
201
308
|
}
|
|
202
309
|
const files = (await Promise.all(input.map((file) => fs.readFile(file, "utf-8")))).map((it) => {
|
|
203
310
|
const document = safeNormalize(it);
|
|
204
311
|
if (!isDocument(document)) {
|
|
205
312
|
return output.error().title("Invalid input").message(
|
|
206
|
-
"Could not read an API document from one of the input files.
|
|
313
|
+
"Could not read an API document from one of the input files. Provide valid JSON or YAML files."
|
|
207
314
|
).exit("error");
|
|
208
315
|
}
|
|
209
316
|
return document;
|
|
@@ -215,35 +322,37 @@ async function joinAction(rawInput, rawOpt) {
|
|
|
215
322
|
const specification = asyncApiCount ? "AsyncAPI" : "OpenAPI";
|
|
216
323
|
const documents = asyncApiCount ? await Promise.all(
|
|
217
324
|
input.map(async (file) => {
|
|
218
|
-
const document = await
|
|
325
|
+
const document = await bundle2(path.resolve(file), {
|
|
219
326
|
plugins: [readFiles(), fetchUrls()],
|
|
220
327
|
treeShake: false
|
|
221
328
|
});
|
|
222
329
|
if (!isDocument(document)) {
|
|
223
330
|
return output.error().title("Invalid input").message(
|
|
224
|
-
"Could not read an API document from one of the input files.
|
|
331
|
+
"Could not read an API document from one of the input files. Provide valid JSON or YAML files."
|
|
225
332
|
).exit("error");
|
|
226
333
|
}
|
|
227
334
|
return document;
|
|
228
335
|
})
|
|
229
336
|
) : files;
|
|
230
337
|
const prefixes = opts.prefixComponentsWithPathValue ? getPrefixes(files, opts.prefixComponentsWithPathValue) : [];
|
|
231
|
-
const { executionTimeMs, result } = await measureTime(
|
|
232
|
-
|
|
233
|
-
|
|
338
|
+
const { executionTimeMs, result } = await measureTime(async () => {
|
|
339
|
+
if (!asyncApiCount) return joinOpenApi(files, prefixes);
|
|
340
|
+
const joined = joinAsyncApi(documents, prefixes);
|
|
341
|
+
return joined.ok ? ok(joined.document) : err(joined.conflicts);
|
|
342
|
+
});
|
|
234
343
|
if (!result.ok) {
|
|
235
344
|
return output.error().title(`Failed to join ${specification} documents`).line().line(`Conflicts:
|
|
236
|
-
${formatErrorMessage(result.
|
|
345
|
+
${formatErrorMessage(result.error).join("\n")}`).line().exit("error");
|
|
237
346
|
}
|
|
238
347
|
const isYaml = isYamlFileName(opts.output);
|
|
239
348
|
await fs.writeFile(
|
|
240
349
|
opts.output,
|
|
241
|
-
isYaml ?
|
|
350
|
+
isYaml ? YAML.stringify(result.data) : JSON.stringify(result.data, null, 2),
|
|
242
351
|
"utf8"
|
|
243
352
|
);
|
|
244
353
|
output.info().message(
|
|
245
|
-
`${as.green(
|
|
246
|
-
).print();
|
|
354
|
+
`${as.green(`${specification} descriptions joined`)} (${as.white(`${as.bold(`${Math.round(executionTimeMs)}`)} ms`)})`
|
|
355
|
+
).line(`Written to ${as.cyan(opts.output)}`).print();
|
|
247
356
|
}
|
|
248
357
|
export {
|
|
249
358
|
joinAction
|