@scalar/cli 2.10.0 → 2.12.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 -1289
- package/chunks/action-2OPUQFUY.js +164 -0
- package/chunks/{action-4GZI2M5B.js → action-36LZ6XXE.js} +19 -17
- package/chunks/{action-KDUFU7TZ.js → action-3XMTJJRT.js} +19 -16
- package/chunks/{action-R4PGILN4.js → action-6CLEENBI.js} +47 -36
- package/chunks/{action-ZFI77WA5.js → action-7HXYZPOT.js} +10 -10
- package/chunks/{action-X7BA7PQQ.js → action-AC5ENU6Z.js} +20 -18
- package/chunks/{action-PPTFYZWD.js → action-ADGLTNFC.js} +28 -22
- package/chunks/{action-7XOHYWYM.js → action-AOKHLTZ6.js} +25 -21
- package/chunks/{action-XOADBXSX.js → action-AVSJ3AJY.js} +17 -16
- package/chunks/{action-GFLRD7LO.js → action-D3IVCY24.js} +8 -8
- package/chunks/action-EBZJS367.js +130 -0
- package/chunks/{action-ZKA3RR3S.js → action-EZXHSAJ2.js} +18 -17
- package/chunks/{action-5LF4XYHX.js → action-FDTVHVHF.js} +12 -12
- package/chunks/{action-JEYDBB3P.js → action-FUO5F7NV.js} +15 -15
- package/chunks/{action-DKDRAIKV.js → action-HA3CMV3P.js} +13 -15
- package/chunks/{action-YSVTZVKV.js → action-IG3BK2LF.js} +37 -26
- package/chunks/{action-H3RTILLM.js → action-IIQMZVRJ.js} +1 -1
- package/chunks/{action-DTEO4YNX.js → action-JT6C472I.js} +13 -11
- package/chunks/{action-UUL6SWV4.js → action-KDT6H6ML.js} +12 -14
- package/chunks/{action-PAM2EZ22.js → action-KJDIJQ3A.js} +8 -7
- package/chunks/{action-HT42NUUX.js → action-NF5E7JKA.js} +40 -38
- package/chunks/{action-EAUTQ77U.js → action-NIZBME45.js} +26 -24
- package/chunks/{action-CB55NWAU.js → action-O757TFA2.js} +9 -9
- package/chunks/{action-XLE37MZL.js → action-ONR7QSN7.js} +23 -22
- package/chunks/{action-5RL4NWUZ.js → action-QM2BMMHG.js} +33 -30
- package/chunks/{action-GWYYTUTM.js → action-QVTAZCKY.js} +5 -5
- package/chunks/action-SLB52XRG.js +65 -0
- package/chunks/{action-CABLS46Q.js → action-UTFRCKGE.js} +11 -11
- package/chunks/{action-4W5GUGEG.js → action-VESBFIP3.js} +20 -19
- package/chunks/{action-657A4K2D.js → action-VGFAIFYE.js} +26 -23
- package/chunks/action-WCU5O2VT.js +100 -0
- package/chunks/{action-TOBU74JH.js → action-XS5EESHW.js} +51 -27
- package/chunks/action-XVNRZ5VX.js +38 -0
- package/chunks/action-Y7EBKCUU.js +16 -0
- package/chunks/{action-5N3P43MD.js → action-YWQ2OKS3.js} +16 -15
- package/chunks/{actions-3SAMH7A5.js → actions-6QG7LH7P.js} +23 -20
- package/chunks/{agent-2ESZI7NO.js → agent-ONXROEAE.js} +44 -9
- package/chunks/{asyncapi-4HGVM3PR.js → asyncapi-7IFXAIE3.js} +13 -12
- package/chunks/{build.action-VBGFGACM.js → build.action-FI4OWY3T.js} +28 -26
- package/chunks/{chunk-ZGNDXPLU.js → chunk-26VIHQGL.js} +3 -3
- package/chunks/{chunk-JXGF5EHC.js → chunk-3HCEUGOE.js} +42 -13
- package/chunks/{chunk-G4HRW2FZ.js → chunk-5TNKTLQP.js} +370 -254
- package/chunks/{chunk-XAGJJNQW.js → chunk-BB6WWG25.js} +10 -10
- package/chunks/{chunk-K2HIB5BA.js → chunk-BCFUMXMC.js} +3 -3
- package/chunks/{action-F2ZJNURT.js → chunk-EBNFCIKS.js} +7 -10
- package/chunks/{chunk-MC4EMNOR.js → chunk-EJSGWV2K.js} +7 -6
- package/chunks/{chunk-GYRQPDTK.js → chunk-FJCOYEKT.js} +139 -3
- package/chunks/{chunk-ZKJPLWRJ.js → chunk-HU47OMI4.js} +4 -4
- package/chunks/{chunk-VVRUSQCY.js → chunk-I57ID5K7.js} +13 -0
- package/chunks/{chunk-43WALAW3.js → chunk-JLNHOA5Z.js} +64 -115
- package/chunks/{chunk-5SMP756H.js → chunk-LCSU43NJ.js} +2 -2
- package/chunks/{chunk-KHF2QXBG.js → chunk-N645RGAB.js} +1853 -683
- package/chunks/{chunk-3ZJYGGAA.js → chunk-ORCUZITN.js} +1 -1
- package/chunks/{chunk-H467HDVV.js → chunk-PERC34BV.js} +1 -1
- package/chunks/chunk-Q26DFKTY.js +37 -0
- package/chunks/{chunk-MMWSCTDB.js → chunk-QJQTSRU4.js} +19 -19
- package/chunks/{chunk-WDIWLXLV.js → chunk-RLBS4HJT.js} +3 -3
- package/chunks/{chunk-ATNTXKMS.js → chunk-RNZVZMYC.js} +198 -42
- package/chunks/{chunk-IPZP3VRA.js → chunk-RYWXF3LO.js} +12 -21
- package/chunks/{chunk-CWVYOXXM.js → chunk-SNOAL2C5.js} +11 -7
- package/chunks/{chunk-UDBSV3CK.js → chunk-T3R66THO.js} +6085 -4167
- package/chunks/{chunk-VYFGRLVQ.js → chunk-U73OW57G.js} +1 -1
- package/chunks/chunk-U764PQUA.js +1034 -0
- package/chunks/{chunk-KZNRQVMY.js → chunk-UAFCSWQ6.js} +1 -1
- package/chunks/{chunk-WB6PWTMU.js → chunk-UBLFIMUA.js} +1 -1
- package/chunks/{chunk-WIEXQUTD.js → chunk-UODTHS76.js} +1 -1
- package/chunks/chunk-V3MYP5SQ.js +247 -0
- package/chunks/{chunk-36LXIJIZ.js → chunk-V6LUKXBV.js} +1 -16
- package/chunks/{chunk-6M7TL2G2.js → chunk-VRZSDUZK.js} +45 -5
- package/chunks/{chunk-GLWTVLKM.js → chunk-VUNOOPEG.js} +9 -2
- package/chunks/chunk-VUXPDHTQ.js +22 -0
- package/chunks/{chunk-DHZW7Q7U.js → chunk-VVQOFG76.js} +2 -4
- package/chunks/chunk-XP5UM7SF.js +21 -0
- package/chunks/{chunk-ZYBLQ5CT.js → chunk-Y6C3H27E.js} +9 -4
- package/chunks/{chunk-35Z7VTJT.js → chunk-YTFFBGNQ.js} +52 -38
- package/chunks/{chunk-BIMLCGKS.js → chunk-ZNLMQKDU.js} +1 -1
- package/chunks/{create.action-DBNIS665.js → create.action-PPMZEMZL.js} +34 -32
- package/chunks/{delete.action-GBOZC45K.js → delete.action-GDOHATRZ.js} +30 -28
- package/chunks/{delete.action-K7BLK7DK.js → delete.action-VAHKEHEU.js} +29 -27
- package/chunks/{get.action-QHKMYZBK.js → get.action-UXFTGO7W.js} +24 -20
- package/chunks/{get.action-N3JOY3OU.js → get.action-XON3EZDT.js} +16 -15
- package/chunks/{list.action-TJCS6UEY.js → list.action-24F5WDGR.js} +37 -26
- package/chunks/{list.action-6SSO3JVN.js → list.action-OQEAEJ5U.js} +39 -29
- package/chunks/{publish.action-T24VHRMR.js → publish.action-G7FPDRBZ.js} +45 -43
- package/chunks/{scripts-VIBLGKYG.js → scripts-6CI6U32J.js} +1 -1
- package/chunks/{update.action-VOE6PH5F.js → update.action-IFIFXZWA.js} +29 -27
- package/chunks/{update.action-OGYNBXRU.js → update.action-MJDHVVR3.js} +30 -28
- package/index.js +290 -284
- package/package.json +2 -2
- package/skills/scalar-cli/SKILL.md +49 -49
- package/template.md +68 -252
- package/chunks/action-FBRY5JKU.js +0 -37
- package/chunks/action-LYCNT3KA.js +0 -73
- package/chunks/action-OJ2NK25F.js +0 -121
- package/chunks/action-U2L5DCFG.js +0 -91
- package/chunks/chunk-MNNGUUKJ.js +0 -405
- package/chunks/chunk-ZGVZU6L2.js +0 -422
- package/docs.html +0 -6977
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
isAsyncApiContent
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-PERC34BV.js";
|
|
5
5
|
import {
|
|
6
6
|
err,
|
|
7
7
|
ok
|
|
8
8
|
} from "./chunk-5ENKYZA4.js";
|
|
9
9
|
import {
|
|
10
10
|
package_default
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-VVQOFG76.js";
|
|
12
|
+
import "./chunk-VUNOOPEG.js";
|
|
13
|
+
import "./chunk-U764PQUA.js";
|
|
14
|
+
import "./chunk-Q26DFKTY.js";
|
|
15
|
+
import "./chunk-I57ID5K7.js";
|
|
16
16
|
import "./chunk-3MZYUBJ6.js";
|
|
17
17
|
|
|
18
18
|
// src/domains/document/lint/action.ts
|
|
@@ -26,12 +26,14 @@ var ASYNCAPI_RULESET = `extends: spectral:asyncapi
|
|
|
26
26
|
rules: {}`;
|
|
27
27
|
|
|
28
28
|
// ../../packages/api-document-lint/dist/default-ruleset.js
|
|
29
|
+
import { parse as parseYaml } from "yaml";
|
|
29
30
|
function isAsyncApiContent2(content) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return
|
|
31
|
+
try {
|
|
32
|
+
const document = parseYaml(content);
|
|
33
|
+
return typeof document === "object" && document !== null && !Array.isArray(document) && Object.hasOwn(document, "asyncapi");
|
|
34
|
+
} catch {
|
|
35
|
+
return false;
|
|
33
36
|
}
|
|
34
|
-
return head.split("\n").some((line) => /^asyncapi\s*:/.test(line.trimStart()));
|
|
35
37
|
}
|
|
36
38
|
function defaultRulesetFor(content) {
|
|
37
39
|
return isAsyncApiContent2(content) ? ASYNCAPI_RULESET : DEFAULT_RULESET;
|
|
@@ -329,12 +331,16 @@ function parseReport(report) {
|
|
|
329
331
|
}
|
|
330
332
|
|
|
331
333
|
// ../../packages/api-document-lint/dist/select-engine.js
|
|
332
|
-
import { parse as
|
|
333
|
-
function selectEngine(ruleset) {
|
|
334
|
+
import { parse as parseYaml2 } from "yaml";
|
|
335
|
+
function selectEngine(ruleset, document) {
|
|
336
|
+
const parsedDocument = document ? parseYamlObject(document) : null;
|
|
337
|
+
if (typeof parsedDocument?.asyncapi === "string" && parsedDocument.asyncapi.startsWith("2.")) {
|
|
338
|
+
return "spectral";
|
|
339
|
+
}
|
|
334
340
|
if (!ruleset || ruleset.trim().length === 0) {
|
|
335
341
|
return "vacuum";
|
|
336
342
|
}
|
|
337
|
-
const parsed =
|
|
343
|
+
const parsed = parseYamlObject(ruleset);
|
|
338
344
|
if (parsed === null) {
|
|
339
345
|
return "spectral";
|
|
340
346
|
}
|
|
@@ -356,9 +362,9 @@ function hasRuleCustomizations(ruleset) {
|
|
|
356
362
|
function isRecord(value) {
|
|
357
363
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
358
364
|
}
|
|
359
|
-
function
|
|
365
|
+
function parseYamlObject(source) {
|
|
360
366
|
try {
|
|
361
|
-
const value =
|
|
367
|
+
const value = parseYaml2(source);
|
|
362
368
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
363
369
|
return value;
|
|
364
370
|
}
|
|
@@ -391,7 +397,7 @@ function isBuiltInRuleset(entry) {
|
|
|
391
397
|
async function lint(input, options = {}) {
|
|
392
398
|
const ruleset = input.ruleset && input.ruleset.trim().length > 0 ? input.ruleset : defaultRulesetFor(input.document);
|
|
393
399
|
const resolved = { ...input, ruleset };
|
|
394
|
-
const engine = selectEngine(ruleset);
|
|
400
|
+
const engine = selectEngine(ruleset, input.document);
|
|
395
401
|
const diagnostics = engine === "vacuum" ? await runVacuum(resolved, options) : await runSpectral(resolved);
|
|
396
402
|
if (!diagnostics.ok) {
|
|
397
403
|
return diagnostics;
|
|
@@ -1328,9 +1334,7 @@ ${coloredStatus}`;
|
|
|
1328
1334
|
return color ? text2 : stripVTControlCharacters(text2);
|
|
1329
1335
|
}
|
|
1330
1336
|
const lines = [
|
|
1331
|
-
totals.errors ? as2.red("\u2716
|
|
1332
|
-
${as2.green("\u2714 No issues found!")}
|
|
1333
|
-
`
|
|
1337
|
+
diagnostics.length ? (totals.errors ? as2.red : as2.yellow)("\u2716 Lint issues found:") : as2.green("\u2714 No lint issues found.")
|
|
1334
1338
|
];
|
|
1335
1339
|
for (const diagnostic of selected) {
|
|
1336
1340
|
lines.push(
|
|
@@ -1346,7 +1350,8 @@ ${as2.green("\u2714 No issues found!")}
|
|
|
1346
1350
|
as2.gray("---")
|
|
1347
1351
|
);
|
|
1348
1352
|
}
|
|
1349
|
-
if (ignored)
|
|
1353
|
+
if (ignored)
|
|
1354
|
+
lines.push(`${ignored} ${ignored === 1 ? "finding" : "findings"} ignored.`);
|
|
1350
1355
|
const text = `${lines.join("\n")}
|
|
1351
1356
|
`;
|
|
1352
1357
|
return color ? text : stripVTControlCharacters(text);
|
|
@@ -1431,7 +1436,7 @@ function fail(message) {
|
|
|
1431
1436
|
}
|
|
1432
1437
|
async function lintAction(inputArgument, options) {
|
|
1433
1438
|
if (!inputArgument) {
|
|
1434
|
-
fail("
|
|
1439
|
+
fail("Missing input\n\nProvide an API description file path or URL.\n");
|
|
1435
1440
|
return;
|
|
1436
1441
|
}
|
|
1437
1442
|
try {
|
|
@@ -1478,7 +1483,8 @@ async function runLint(inputArgument, options) {
|
|
|
1478
1483
|
ruleset: ruleset.data,
|
|
1479
1484
|
source
|
|
1480
1485
|
});
|
|
1481
|
-
if (!result.ok)
|
|
1486
|
+
if (!result.ok)
|
|
1487
|
+
return fail(`Could not lint the API description
|
|
1482
1488
|
|
|
1483
1489
|
${result.error}`);
|
|
1484
1490
|
const diagnostics = addRelatedLocations(
|
|
@@ -2,26 +2,26 @@ 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 "./chunk-
|
|
6
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-SNOAL2C5.js";
|
|
6
|
+
import "./chunk-PERC34BV.js";
|
|
7
7
|
import {
|
|
8
8
|
DEFAULT_FETCH_CONCURRENCY
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-EJSGWV2K.js";
|
|
10
10
|
import "./chunk-DFOZG7ZV.js";
|
|
11
11
|
import {
|
|
12
12
|
requireInteractive
|
|
13
13
|
} from "./chunk-EGOXR5FB.js";
|
|
14
|
-
import "./chunk-GLWTVLKM.js";
|
|
15
14
|
import {
|
|
16
15
|
isUrl,
|
|
17
16
|
isYamlFileName
|
|
18
17
|
} from "./chunk-4ORL4MST.js";
|
|
19
|
-
import "./chunk-
|
|
18
|
+
import "./chunk-VUNOOPEG.js";
|
|
20
19
|
import {
|
|
21
20
|
output
|
|
22
21
|
} from "./chunk-T5HJUAWB.js";
|
|
23
|
-
import "./chunk-
|
|
24
|
-
import "./chunk-
|
|
22
|
+
import "./chunk-U764PQUA.js";
|
|
23
|
+
import "./chunk-Q26DFKTY.js";
|
|
24
|
+
import "./chunk-I57ID5K7.js";
|
|
25
25
|
import "./chunk-3MZYUBJ6.js";
|
|
26
26
|
|
|
27
27
|
// src/domains/document/bundle/action.ts
|
|
@@ -40,28 +40,27 @@ async function bundleAction(input, {
|
|
|
40
40
|
fetchLimit
|
|
41
41
|
}) {
|
|
42
42
|
if (!input) {
|
|
43
|
-
return output.error().title("Missing input").message("
|
|
43
|
+
return output.error().title("Missing input").message("Provide a file path or URL to bundle.").exit("error");
|
|
44
44
|
}
|
|
45
45
|
const isUrlInput = isUrl(input);
|
|
46
46
|
if (!outputFilePath) {
|
|
47
47
|
if (isUrlInput) {
|
|
48
|
-
return output.error().message(
|
|
49
|
-
"Please provide an output file using the -o flag when bundling from a URL."
|
|
50
|
-
).exit("error");
|
|
48
|
+
return output.error().message("URL input requires an output file. Use `--output <file>`.").exit("error");
|
|
51
49
|
}
|
|
52
50
|
requireInteractive(
|
|
53
51
|
"Pass --output to bundle a document in non-interactive mode."
|
|
54
52
|
);
|
|
55
53
|
const shouldContinue = await confirm({
|
|
56
|
-
message:
|
|
54
|
+
message: `No output file was specified. Overwrite "${input}"?`,
|
|
57
55
|
initialValue: false
|
|
58
56
|
});
|
|
59
57
|
if (shouldContinue !== true) {
|
|
60
|
-
return output.error().message("Operation cancelled
|
|
58
|
+
return output.error().message("Operation cancelled.").exit("error");
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
61
|
const outputFileName = outputFilePath ?? input;
|
|
64
|
-
const
|
|
62
|
+
const isStdout = outputFilePath === "-";
|
|
63
|
+
const isYaml = isStdout || isYamlFileName(outputFileName);
|
|
65
64
|
const resolvedInput = isUrlInput ? input : path.resolve(cwd(), input);
|
|
66
65
|
const { result, executionTimeMs } = await measureTime(
|
|
67
66
|
() => bundle(resolvedInput, {
|
|
@@ -75,14 +74,19 @@ async function bundleAction(input, {
|
|
|
75
74
|
urlMap: !!urlMap
|
|
76
75
|
})
|
|
77
76
|
);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
const serialized = isYaml ? YAML.stringify(result) : JSON.stringify(result);
|
|
78
|
+
if (isStdout) {
|
|
79
|
+
process.stdout.write(serialized);
|
|
80
|
+
process.stderr.write(
|
|
81
|
+
`API description bundled (${Math.round(executionTimeMs)} ms)
|
|
82
|
+
`
|
|
83
|
+
);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
await fs.writeFile(outputFileName, serialized, "utf8");
|
|
83
87
|
output.info().message(
|
|
84
|
-
`${as.green("
|
|
85
|
-
).print();
|
|
88
|
+
`${as.green("API description bundled")} (${as.white(`${as.bold(`${Math.round(executionTimeMs)}`)} ms`)})`
|
|
89
|
+
).line(`Written to ${as.cyan(outputFileName)}`).print();
|
|
86
90
|
}
|
|
87
91
|
export {
|
|
88
92
|
bundleAction
|
|
@@ -4,33 +4,34 @@ import {
|
|
|
4
4
|
isDocument,
|
|
5
5
|
loadOpenApiDocument,
|
|
6
6
|
printSpecificationBanner
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-SNOAL2C5.js";
|
|
8
8
|
import {
|
|
9
9
|
isAsyncApiDocument,
|
|
10
10
|
safeNormalize
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-PERC34BV.js";
|
|
12
12
|
import {
|
|
13
13
|
err,
|
|
14
14
|
ok
|
|
15
15
|
} from "./chunk-5ENKYZA4.js";
|
|
16
16
|
import {
|
|
17
17
|
watchFile
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import "./chunk-
|
|
20
|
-
import "./chunk-
|
|
21
|
-
import "./chunk-
|
|
22
|
-
import "./chunk-
|
|
23
|
-
import "./chunk-
|
|
24
|
-
import "./chunk-
|
|
18
|
+
} from "./chunk-V6LUKXBV.js";
|
|
19
|
+
import "./chunk-VUXPDHTQ.js";
|
|
20
|
+
import "./chunk-YTFFBGNQ.js";
|
|
21
|
+
import "./chunk-UBLFIMUA.js";
|
|
22
|
+
import "./chunk-VVQOFG76.js";
|
|
23
|
+
import "./chunk-FJCOYEKT.js";
|
|
24
|
+
import "./chunk-VRZSDUZK.js";
|
|
25
25
|
import {
|
|
26
26
|
isUrl
|
|
27
27
|
} from "./chunk-4ORL4MST.js";
|
|
28
|
-
import "./chunk-
|
|
28
|
+
import "./chunk-VUNOOPEG.js";
|
|
29
29
|
import {
|
|
30
30
|
output
|
|
31
31
|
} from "./chunk-T5HJUAWB.js";
|
|
32
|
-
import "./chunk-
|
|
33
|
-
import "./chunk-
|
|
32
|
+
import "./chunk-U764PQUA.js";
|
|
33
|
+
import "./chunk-Q26DFKTY.js";
|
|
34
|
+
import "./chunk-I57ID5K7.js";
|
|
34
35
|
import "./chunk-3MZYUBJ6.js";
|
|
35
36
|
|
|
36
37
|
// src/domains/document/serve/action.ts
|
|
@@ -108,7 +109,7 @@ var loadServeDocument = async (input) => {
|
|
|
108
109
|
}
|
|
109
110
|
const result = validate(document);
|
|
110
111
|
if (!result.valid) {
|
|
111
|
-
output.warn().title("
|
|
112
|
+
output.warn().title("API description does not match the AsyncAPI specification").print();
|
|
112
113
|
for (const error of result.errors ?? []) {
|
|
113
114
|
output.warn().title(error.message ?? "Invalid AsyncAPI document").print();
|
|
114
115
|
}
|
|
@@ -129,7 +130,7 @@ async function serveAction(inputArgument, {
|
|
|
129
130
|
config
|
|
130
131
|
}) {
|
|
131
132
|
if (!inputArgument) {
|
|
132
|
-
return output.error().title("Invalid argument").message("
|
|
133
|
+
return output.error().title("Invalid argument").message("Provide a file path or URL.").exit("error");
|
|
133
134
|
}
|
|
134
135
|
const configuration = await loadServeConfig(config);
|
|
135
136
|
if (!configuration.ok) {
|
|
@@ -142,7 +143,7 @@ async function serveAction(inputArgument, {
|
|
|
142
143
|
let { specification } = result;
|
|
143
144
|
printServeBanner(result);
|
|
144
145
|
if (!isAsyncApiDocument(specification) && Object.keys(specification.paths ?? {}).length === 0) {
|
|
145
|
-
output.warn().title("
|
|
146
|
+
output.warn().title("No paths found in the OpenAPI description").print();
|
|
146
147
|
}
|
|
147
148
|
const app = new Hono();
|
|
148
149
|
app.get("/", (c) => {
|
|
@@ -186,7 +187,7 @@ async function serveAction(inputArgument, {
|
|
|
186
187
|
},
|
|
187
188
|
(info) => {
|
|
188
189
|
output.info().line(
|
|
189
|
-
`${as.green.bold("\u279C API Reference
|
|
190
|
+
`${as.green.bold("\u279C API Reference server")} ${as.white(
|
|
190
191
|
"listening on"
|
|
191
192
|
)} ${as.cyan(`http://localhost:${info.port}`)}`
|
|
192
193
|
).print();
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
getFileOrUrl
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-GLWTVLKM.js";
|
|
4
|
+
} from "./chunk-SNOAL2C5.js";
|
|
5
|
+
import "./chunk-PERC34BV.js";
|
|
7
6
|
import "./chunk-4ORL4MST.js";
|
|
8
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-VUNOOPEG.js";
|
|
9
8
|
import {
|
|
10
9
|
output
|
|
11
10
|
} from "./chunk-T5HJUAWB.js";
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-U764PQUA.js";
|
|
12
|
+
import "./chunk-Q26DFKTY.js";
|
|
13
|
+
import "./chunk-I57ID5K7.js";
|
|
14
14
|
import "./chunk-3MZYUBJ6.js";
|
|
15
15
|
|
|
16
16
|
// src/domains/document/markdown/action.ts
|
|
@@ -20,7 +20,7 @@ import { createMarkdownFromOpenApi } from "@scalar/openapi-to-markdown";
|
|
|
20
20
|
async function markdownAction(inputArgument, { output: outputPath }) {
|
|
21
21
|
const startTime = performance.now();
|
|
22
22
|
if (!inputArgument) {
|
|
23
|
-
return output.error().title("Invalid argument").message("
|
|
23
|
+
return output.error().title("Invalid argument").message("Provide a file path or URL.").exit("error");
|
|
24
24
|
}
|
|
25
25
|
const specification = await getFileOrUrl(inputArgument);
|
|
26
26
|
const markdown = await createMarkdownFromOpenApi(specification);
|
|
@@ -29,7 +29,7 @@ async function markdownAction(inputArgument, { output: outputPath }) {
|
|
|
29
29
|
const endTime = performance.now();
|
|
30
30
|
output.info().line(
|
|
31
31
|
`${as.green("Markdown generated")} ${as.grey(
|
|
32
|
-
`
|
|
32
|
+
`(${as.white(`${as.bold(`${Math.round(endTime - startTime)}`)} ms`)})`
|
|
33
33
|
)}`
|
|
34
34
|
).line(`Written to ${as.cyan(outputPath)}`).print();
|
|
35
35
|
return;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
createError,
|
|
4
|
+
displayError
|
|
5
|
+
} from "./chunk-ORCUZITN.js";
|
|
6
|
+
import {
|
|
7
|
+
readAndParseConfig,
|
|
8
|
+
renderConfigError
|
|
9
|
+
} from "./chunk-BB6WWG25.js";
|
|
10
|
+
import {
|
|
11
|
+
CONFIG_FILE_DEFAULT,
|
|
12
|
+
expandFolderGuides,
|
|
13
|
+
findConfig,
|
|
14
|
+
legacyTo2_0_0
|
|
15
|
+
} from "./chunk-T3R66THO.js";
|
|
16
|
+
import "./chunk-5ENKYZA4.js";
|
|
17
|
+
import {
|
|
18
|
+
ConfigVersion
|
|
19
|
+
} from "./chunk-VRZSDUZK.js";
|
|
20
|
+
import {
|
|
21
|
+
output
|
|
22
|
+
} from "./chunk-T5HJUAWB.js";
|
|
23
|
+
import "./chunk-I57ID5K7.js";
|
|
24
|
+
import "./chunk-3MZYUBJ6.js";
|
|
25
|
+
|
|
26
|
+
// src/domains/project/upgrade/action.ts
|
|
27
|
+
import { spawnSync } from "node:child_process";
|
|
28
|
+
import { existsSync } from "node:fs";
|
|
29
|
+
import fs from "node:fs/promises";
|
|
30
|
+
import path from "node:path";
|
|
31
|
+
import { text } from "@clack/prompts";
|
|
32
|
+
import as from "ansis";
|
|
33
|
+
import { n } from "neverpanic";
|
|
34
|
+
async function upgradeAction(__configPath) {
|
|
35
|
+
const configPath = __configPath || findConfig() || await text({
|
|
36
|
+
message: "Where is your configuration file located?",
|
|
37
|
+
defaultValue: CONFIG_FILE_DEFAULT,
|
|
38
|
+
placeholder: CONFIG_FILE_DEFAULT
|
|
39
|
+
});
|
|
40
|
+
const parseConfigResult = readAndParseConfig(configPath);
|
|
41
|
+
if (!parseConfigResult.success) {
|
|
42
|
+
renderConfigError(parseConfigResult.error);
|
|
43
|
+
}
|
|
44
|
+
if (parseConfigResult.success) {
|
|
45
|
+
output.info().line(
|
|
46
|
+
`${as.green("[SUCCESS]")} ${as.green("Configuration is valid:")} ${as.green(parseConfigResult.filePath)}`
|
|
47
|
+
).print();
|
|
48
|
+
}
|
|
49
|
+
const { config } = parseConfigResult;
|
|
50
|
+
if (config.version === ConfigVersion.V2) {
|
|
51
|
+
return output.info().title("Your Scalar configuration is already upgraded").message(
|
|
52
|
+
"You are already on the latest Scalar docs version. No further action required."
|
|
53
|
+
).exit("success");
|
|
54
|
+
}
|
|
55
|
+
const projectRootDir = path.resolve(
|
|
56
|
+
path.dirname(parseConfigResult.filePath),
|
|
57
|
+
config.root ?? "./"
|
|
58
|
+
);
|
|
59
|
+
const publishedFiles = listGitFiles(projectRootDir);
|
|
60
|
+
const expandedConfigResult = await n.fromUnsafe(
|
|
61
|
+
() => expandFolderGuides(config, async (folderPath) => {
|
|
62
|
+
const entries = await fs.readdir(
|
|
63
|
+
path.join(projectRootDir, folderPath),
|
|
64
|
+
{
|
|
65
|
+
withFileTypes: true
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
return entries.filter((entry) => entry.isFile() || entry.isDirectory()).map((entry) => ({
|
|
69
|
+
name: entry.name,
|
|
70
|
+
type: entry.isFile() ? "file" : "dir",
|
|
71
|
+
path: path.posix.join(folderPath, entry.name)
|
|
72
|
+
})).filter(
|
|
73
|
+
(entry) => entry.type === "dir" || !publishedFiles || entry.path.startsWith("..") || publishedFiles.has(entry.path)
|
|
74
|
+
);
|
|
75
|
+
}),
|
|
76
|
+
(originalError) => createError("FAILED_TO_EXPAND_FOLDER_GUIDES", originalError)
|
|
77
|
+
);
|
|
78
|
+
if (!expandedConfigResult.success) {
|
|
79
|
+
return output.error().title("Could not read the folders of your folder-based guides.").message(expandedConfigResult.error.code).message(displayError(expandedConfigResult.error.detail)).exit("error");
|
|
80
|
+
}
|
|
81
|
+
const upgradedConfigResult = n.fromUnsafe(
|
|
82
|
+
() => legacyTo2_0_0(expandedConfigResult.data, {
|
|
83
|
+
isPathTaken: (filePath) => existsSync(path.join(projectRootDir, filePath))
|
|
84
|
+
}),
|
|
85
|
+
(originalError) => createError("FAILED_TO_UPGRADE_CONFIG_V1", originalError)
|
|
86
|
+
);
|
|
87
|
+
if (!upgradedConfigResult.success) {
|
|
88
|
+
return output.error().title("Could not upgrade the configuration").message(upgradedConfigResult.error.code).message(displayError(upgradedConfigResult.error.detail)).exit("error");
|
|
89
|
+
}
|
|
90
|
+
const { upgradedConfig, sideFiles, dropped } = upgradedConfigResult.data;
|
|
91
|
+
for (const sideFile of sideFiles) {
|
|
92
|
+
const writeSideFileResult = await n.fromUnsafe(
|
|
93
|
+
() => fs.writeFile(
|
|
94
|
+
path.join(projectRootDir, sideFile.path),
|
|
95
|
+
sideFile.content,
|
|
96
|
+
{ flag: "wx" }
|
|
97
|
+
),
|
|
98
|
+
(originalError) => createError("FAILED_TO_WRITE_UPGRADED_SIDE_FILE", originalError)
|
|
99
|
+
);
|
|
100
|
+
if (!writeSideFileResult.success) {
|
|
101
|
+
return output.error().title(`Could not save ${sideFile.path}`).message(writeSideFileResult.error.code).message(displayError(writeSideFileResult.error.detail)).exit("error");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (dropped.length) {
|
|
105
|
+
output.warn().title("Some settings have no V2 equivalent and were not carried over:").message(dropped.join(", ")).print();
|
|
106
|
+
}
|
|
107
|
+
const writeUpgradedConfigResult = await n.fromUnsafe(
|
|
108
|
+
() => fs.writeFile(
|
|
109
|
+
parseConfigResult.filePath,
|
|
110
|
+
JSON.stringify(upgradedConfig, null, 2)
|
|
111
|
+
),
|
|
112
|
+
(originalError) => createError("FAILED_TO_WRITE_UPGRADED_CONFIG", originalError)
|
|
113
|
+
);
|
|
114
|
+
if (!writeUpgradedConfigResult.success) {
|
|
115
|
+
return output.error().title("Could not save the upgraded configuration").message(writeUpgradedConfigResult.error.code).message(displayError(writeUpgradedConfigResult.error.detail)).exit("error");
|
|
116
|
+
}
|
|
117
|
+
return output.info().title("Scalar Docs configuration upgraded").message("Run `scalar project preview` to preview your project.").exit("success");
|
|
118
|
+
}
|
|
119
|
+
function listGitFiles(projectRootDir) {
|
|
120
|
+
const result = spawnSync(
|
|
121
|
+
"git",
|
|
122
|
+
["ls-files", "--cached", "--others", "--exclude-standard", "-z"],
|
|
123
|
+
{ cwd: projectRootDir, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 }
|
|
124
|
+
);
|
|
125
|
+
if (result.status !== 0) return null;
|
|
126
|
+
return new Set(result.stdout.split("\0").filter(Boolean));
|
|
127
|
+
}
|
|
128
|
+
export {
|
|
129
|
+
upgradeAction
|
|
130
|
+
};
|
|
@@ -3,28 +3,29 @@ import {
|
|
|
3
3
|
getFileOrUrl,
|
|
4
4
|
loadOpenApiDocument,
|
|
5
5
|
printSpecificationBanner
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-SNOAL2C5.js";
|
|
7
7
|
import {
|
|
8
8
|
isAsyncApiContent
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-PERC34BV.js";
|
|
10
10
|
import {
|
|
11
11
|
watchFile
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
17
|
-
import "./chunk-
|
|
18
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-V6LUKXBV.js";
|
|
13
|
+
import "./chunk-VUXPDHTQ.js";
|
|
14
|
+
import "./chunk-YTFFBGNQ.js";
|
|
15
|
+
import "./chunk-UBLFIMUA.js";
|
|
16
|
+
import "./chunk-VVQOFG76.js";
|
|
17
|
+
import "./chunk-FJCOYEKT.js";
|
|
18
|
+
import "./chunk-VRZSDUZK.js";
|
|
19
19
|
import {
|
|
20
20
|
isUrl
|
|
21
21
|
} from "./chunk-4ORL4MST.js";
|
|
22
|
-
import "./chunk-
|
|
22
|
+
import "./chunk-VUNOOPEG.js";
|
|
23
23
|
import {
|
|
24
24
|
output
|
|
25
25
|
} from "./chunk-T5HJUAWB.js";
|
|
26
|
-
import "./chunk-
|
|
27
|
-
import "./chunk-
|
|
26
|
+
import "./chunk-U764PQUA.js";
|
|
27
|
+
import "./chunk-Q26DFKTY.js";
|
|
28
|
+
import "./chunk-I57ID5K7.js";
|
|
28
29
|
import "./chunk-3MZYUBJ6.js";
|
|
29
30
|
|
|
30
31
|
// src/domains/document/mock/action.ts
|
|
@@ -54,7 +55,7 @@ var bootServer = async ({
|
|
|
54
55
|
treeShake: false
|
|
55
56
|
}).then((bundled) => createMockServer({ document: bundled, onRequest })).catch(
|
|
56
57
|
(error) => output.error().title(
|
|
57
|
-
`Could not start
|
|
58
|
+
`Could not start Mock Server: ${error instanceof Error ? error.message : String(error)}`
|
|
58
59
|
).exit("error")
|
|
59
60
|
);
|
|
60
61
|
return serve(
|
|
@@ -72,9 +73,9 @@ var bootServer = async ({
|
|
|
72
73
|
);
|
|
73
74
|
};
|
|
74
75
|
var printAvailablePaths = (specification) => {
|
|
75
|
-
output.info().message(as.white.bold("Available
|
|
76
|
+
output.info().message(as.white.bold("Available paths")).print();
|
|
76
77
|
if (specification?.paths === void 0 || Object.keys(specification?.paths).length === 0) {
|
|
77
|
-
output.warn().title(as.grey("
|
|
78
|
+
output.warn().title(as.grey("No paths found in the OpenAPI description")).print();
|
|
78
79
|
}
|
|
79
80
|
for (const path3 in specification?.paths ?? []) {
|
|
80
81
|
if (specification?.paths?.[path3] === void 0) {
|
|
@@ -115,7 +116,7 @@ function getMethodColor(method) {
|
|
|
115
116
|
async function mockAction(fileArgument, { watch, once, port }) {
|
|
116
117
|
const content = await getFileOrUrl(fileArgument);
|
|
117
118
|
if (isAsyncApiContent(content)) {
|
|
118
|
-
const { mockAsyncApi } = await import("./asyncapi-
|
|
119
|
+
const { mockAsyncApi } = await import("./asyncapi-7IFXAIE3.js");
|
|
119
120
|
return mockAsyncApi(fileArgument, { watch, once, port });
|
|
120
121
|
}
|
|
121
122
|
const origin = isUrl(fileArgument) ? fileArgument : path2.resolve(fileArgument);
|
|
@@ -154,7 +155,7 @@ async function mockAction(fileArgument, { watch, once, port }) {
|
|
|
154
155
|
});
|
|
155
156
|
}
|
|
156
157
|
if (!specification) {
|
|
157
|
-
output.warn().title("
|
|
158
|
+
output.warn().title("No paths found in the OpenAPI description").print();
|
|
158
159
|
return;
|
|
159
160
|
}
|
|
160
161
|
printAvailablePaths(specification);
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
getFileOrUrl
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-SNOAL2C5.js";
|
|
5
5
|
import {
|
|
6
6
|
isAsyncApiContent
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-PERC34BV.js";
|
|
8
8
|
import {
|
|
9
9
|
config
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import "./chunk-GLWTVLKM.js";
|
|
10
|
+
} from "./chunk-UBLFIMUA.js";
|
|
11
|
+
import "./chunk-VVQOFG76.js";
|
|
13
12
|
import "./chunk-4ORL4MST.js";
|
|
14
|
-
import "./chunk-
|
|
13
|
+
import "./chunk-VUNOOPEG.js";
|
|
15
14
|
import {
|
|
16
15
|
output
|
|
17
16
|
} from "./chunk-T5HJUAWB.js";
|
|
18
|
-
import "./chunk-
|
|
19
|
-
import "./chunk-
|
|
17
|
+
import "./chunk-U764PQUA.js";
|
|
18
|
+
import "./chunk-Q26DFKTY.js";
|
|
19
|
+
import "./chunk-I57ID5K7.js";
|
|
20
20
|
import "./chunk-3MZYUBJ6.js";
|
|
21
21
|
|
|
22
22
|
// src/domains/document/share/action.ts
|
|
23
23
|
import as from "ansis";
|
|
24
24
|
async function shareAction(fileArgument, { token }) {
|
|
25
25
|
if (!fileArgument) {
|
|
26
|
-
return output.error().title("Invalid argument").message("
|
|
26
|
+
return output.error().title("Invalid argument").message("Provide a file path or URL.").exit("error");
|
|
27
27
|
}
|
|
28
28
|
const content = await getFileOrUrl(fileArgument);
|
|
29
29
|
const specification = isAsyncApiContent(content) ? "AsyncAPI" : "OpenAPI";
|
|
@@ -54,7 +54,7 @@ async function shareAction(fileArgument, { token }) {
|
|
|
54
54
|
}
|
|
55
55
|
const { id, token: newToken } = data;
|
|
56
56
|
const link = (pathname) => new URL(pathname, sandboxUrl).toString();
|
|
57
|
-
output.info().line(as.green.bold(`Your ${specification}
|
|
57
|
+
output.info().line(as.green.bold(`Your ${specification} description is public.`)).line().table(
|
|
58
58
|
[
|
|
59
59
|
[
|
|
60
60
|
`${as.green("\u279C")} ${as.white.bold("API Reference:")}`,
|
|
@@ -76,10 +76,10 @@ async function shareAction(fileArgument, { token }) {
|
|
|
76
76
|
],
|
|
77
77
|
{ padding: 1 }
|
|
78
78
|
).line().line("Use the token to update the existing sandbox:").line().line(
|
|
79
|
-
`${as.grey("$")} ${as.white.bold("scalar document share --token=")}${as.cyan.bold(`${newToken}`)} `
|
|
79
|
+
`${as.grey("$")} ${as.white.bold("scalar document share <file> --token=")}${as.cyan.bold(`${newToken}`)} `
|
|
80
80
|
).line().print();
|
|
81
81
|
}).catch((error) => {
|
|
82
|
-
output.error().title("
|
|
82
|
+
output.error().title("Could not share the API description").message(`Details: ${error}`).exit("error");
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
export {
|