@scalar/cli 0.2.141 → 0.2.143
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/dist/commands/bundle/BundleCommand.js +38 -0
- package/dist/commands/format/FormatCommand.js +44 -0
- package/dist/commands/init/InitCommand.js +145 -0
- package/dist/commands/mock/MockCommand.js +124 -0
- package/dist/commands/serve/ServeCommand.js +89 -0
- package/dist/commands/share/ShareCommand.js +58 -0
- package/dist/commands/validate/ValidateCommand.js +47 -0
- package/dist/commands/void/VoidCommand.js +38 -0
- package/dist/index.js +11 -962
- package/dist/package.json.js +3 -0
- package/dist/src/commands/bundle/BundleCommand.d.ts +3 -0
- package/dist/src/commands/bundle/BundleCommand.d.ts.map +1 -0
- package/dist/src/commands/format/FormatCommand.d.ts +3 -0
- package/dist/src/commands/format/FormatCommand.d.ts.map +1 -0
- package/dist/src/commands/format/format.test.d.ts +2 -0
- package/dist/src/commands/format/format.test.d.ts.map +1 -0
- package/dist/src/commands/index.d.ts +9 -0
- package/dist/src/commands/index.d.ts.map +1 -0
- package/dist/src/commands/init/InitCommand.d.ts +33 -0
- package/dist/src/commands/init/InitCommand.d.ts.map +1 -0
- package/dist/src/commands/init/init.test.d.ts +2 -0
- package/dist/src/commands/init/init.test.d.ts.map +1 -0
- package/dist/src/commands/mock/MockCommand.d.ts +3 -0
- package/dist/src/commands/mock/MockCommand.d.ts.map +1 -0
- package/dist/src/commands/mock/mock.test.d.ts +2 -0
- package/dist/src/commands/mock/mock.test.d.ts.map +1 -0
- package/dist/src/commands/serve/ServeCommand.d.ts +3 -0
- package/dist/src/commands/serve/ServeCommand.d.ts.map +1 -0
- package/dist/src/commands/share/ShareCommand.d.ts +3 -0
- package/dist/src/commands/share/ShareCommand.d.ts.map +1 -0
- package/dist/src/commands/validate/ValidateCommand.d.ts +6 -0
- package/dist/src/commands/validate/ValidateCommand.d.ts.map +1 -0
- package/dist/src/commands/validate/validate.test.d.ts +2 -0
- package/dist/src/commands/validate/validate.test.d.ts.map +1 -0
- package/dist/src/commands/void/VoidCommand.d.ts +3 -0
- package/dist/src/commands/void/VoidCommand.d.ts.map +1 -0
- package/dist/src/commands/void/void.test.d.ts +2 -0
- package/dist/src/commands/void/void.test.d.ts.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/options/version/version.test.d.ts +2 -0
- package/dist/src/options/version/version.test.d.ts.map +1 -0
- package/dist/src/utils/getFileOrUrl.d.ts +5 -0
- package/dist/src/utils/getFileOrUrl.d.ts.map +1 -0
- package/dist/src/utils/getHtmlDocument.d.ts +3 -0
- package/dist/src/utils/getHtmlDocument.d.ts.map +1 -0
- package/dist/src/utils/getMethodColor.d.ts +3 -0
- package/dist/src/utils/getMethodColor.d.ts.map +1 -0
- package/dist/src/utils/getOperationByMethodAndPath.d.ts +3 -0
- package/dist/src/utils/getOperationByMethodAndPath.d.ts.map +1 -0
- package/dist/src/utils/getOperationByMethodAndPath.test.d.ts +2 -0
- package/dist/src/utils/getOperationByMethodAndPath.test.d.ts.map +1 -0
- package/dist/src/utils/index.d.ts +9 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/isUrl.d.ts +5 -0
- package/dist/src/utils/isUrl.d.ts.map +1 -0
- package/dist/src/utils/isYamlFileName.d.ts +5 -0
- package/dist/src/utils/isYamlFileName.d.ts.map +1 -0
- package/dist/src/utils/loadOpenApiFile.d.ts +11 -0
- package/dist/src/utils/loadOpenApiFile.d.ts.map +1 -0
- package/dist/src/utils/printSpecificationBanner.d.ts +6 -0
- package/dist/src/utils/printSpecificationBanner.d.ts.map +1 -0
- package/dist/src/utils/readFile.d.ts +2 -0
- package/dist/src/utils/readFile.d.ts.map +1 -0
- package/dist/src/utils/useGivenFileOrConfiguration.d.ts +3 -0
- package/dist/src/utils/useGivenFileOrConfiguration.d.ts.map +1 -0
- package/dist/src/utils/watchFile.d.ts +7 -0
- package/dist/src/utils/watchFile.d.ts.map +1 -0
- package/dist/tests/invoke-cli.d.ts +12 -0
- package/dist/tests/invoke-cli.d.ts.map +1 -0
- package/dist/tests/matcher.d.ts +10 -0
- package/dist/tests/matcher.d.ts.map +1 -0
- package/dist/utils/getFileOrUrl.js +23 -0
- package/dist/utils/getHtmlDocument.js +37 -0
- package/dist/utils/getMethodColor.js +12 -0
- package/dist/utils/isUrl.js +9 -0
- package/dist/utils/isYamlFileName.js +13 -0
- package/dist/utils/loadOpenApiFile.js +41 -0
- package/dist/utils/printSpecificationBanner.js +19 -0
- package/dist/utils/readFile.js +16 -0
- package/dist/utils/useGivenFileOrConfiguration.js +31 -0
- package/dist/utils/watchFile.js +33 -0
- package/package.json +18 -9
- package/dist/package.json +0 -64
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BundleCommand.d.ts","sourceRoot":"","sources":["../../../../src/commands/bundle/BundleCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAMnC,wBAAgB,aAAa,YAkD5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormatCommand.d.ts","sourceRoot":"","sources":["../../../../src/commands/format/FormatCommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AASnC,wBAAgB,aAAa,YAqD5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.test.d.ts","sourceRoot":"","sources":["../../../../src/commands/format/format.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './bundle/BundleCommand';
|
|
2
|
+
export * from './format/FormatCommand';
|
|
3
|
+
export * from './init/InitCommand';
|
|
4
|
+
export * from './mock/MockCommand';
|
|
5
|
+
export * from './serve/ServeCommand';
|
|
6
|
+
export * from './share/ShareCommand';
|
|
7
|
+
export * from './validate/ValidateCommand';
|
|
8
|
+
export * from './void/VoidCommand';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* Scalar configuration file (scalar.config.json)
|
|
4
|
+
*/
|
|
5
|
+
export type ScalarConfigurationFile = {
|
|
6
|
+
subdomain: string;
|
|
7
|
+
references: ScalarReferenceEntry[];
|
|
8
|
+
guides: ScalarGuideEntry[];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Entry for an API reference
|
|
12
|
+
*/
|
|
13
|
+
export type ScalarReferenceEntry = {
|
|
14
|
+
name: string;
|
|
15
|
+
path: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Entry for the guide
|
|
19
|
+
*/
|
|
20
|
+
export type ScalarGuideEntry = {
|
|
21
|
+
name: string;
|
|
22
|
+
sidebar: ScalarSidebarEntry[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Entry for the sidebar (folder or page)
|
|
26
|
+
*/
|
|
27
|
+
export type ScalarSidebarEntry = {
|
|
28
|
+
path?: string;
|
|
29
|
+
type: 'folder' | 'page';
|
|
30
|
+
items?: ScalarSidebarEntry[];
|
|
31
|
+
};
|
|
32
|
+
export declare function InitCommand(): Command;
|
|
33
|
+
//# sourceMappingURL=InitCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InitCommand.d.ts","sourceRoot":"","sources":["../../../../src/commands/init/InitCommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAQnC;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,oBAAoB,EAAE,CAAA;IAClC,MAAM,EAAE,gBAAgB,EAAE,CAAA;CAC3B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,kBAAkB,EAAE,CAAA;CAC9B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAA;IACvB,KAAK,CAAC,EAAE,kBAAkB,EAAE,CAAA;CAC7B,CAAA;AAED,wBAAgB,WAAW,YAgM1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.test.d.ts","sourceRoot":"","sources":["../../../../src/commands/init/init.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockCommand.d.ts","sourceRoot":"","sources":["../../../../src/commands/mock/MockCommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAYnC,wBAAgB,WAAW,YAoG1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock.test.d.ts","sourceRoot":"","sources":["../../../../src/commands/mock/mock.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServeCommand.d.ts","sourceRoot":"","sources":["../../../../src/commands/serve/ServeCommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAanC,wBAAgB,YAAY,YAoH3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShareCommand.d.ts","sourceRoot":"","sources":["../../../../src/commands/share/ShareCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAKnC,wBAAgB,YAAY,YA+E3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidateCommand.d.ts","sourceRoot":"","sources":["../../../../src/commands/validate/ValidateCommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAMnC;;GAEG;AACH,wBAAgB,eAAe,YA6D9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.test.d.ts","sourceRoot":"","sources":["../../../../src/commands/validate/validate.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VoidCommand.d.ts","sourceRoot":"","sources":["../../../../src/commands/void/VoidCommand.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGnC,wBAAgB,WAAW,YAiC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"void.test.d.ts","sourceRoot":"","sources":["../../../../src/commands/void/void.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.test.d.ts","sourceRoot":"","sources":["../../../../src/options/version/version.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFileOrUrl.d.ts","sourceRoot":"","sources":["../../../src/utils/getFileOrUrl.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAqBjE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHtmlDocument.d.ts","sourceRoot":"","sources":["../../../src/utils/getHtmlDocument.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAErD,wBAAgB,eAAe,CAC7B,aAAa,EAAE,OAAO,CAAC,QAAQ,EAC/B,KAAK,UAAQ,UAuCd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMethodColor.d.ts","sourceRoot":"","sources":["../../../src/utils/getMethodColor.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAClB,OAAO,GACP,KAAK,GACL,OAAO,GACP,QAAQ,GACR,MAAM,GACN,SAAS,GACT,MAAM,GACN,OAAO,GACP,MAAM,GACN,MAAM,CAAA;AAEV,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GASQ,UAAU,CAC9D"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { OpenAPI, OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-parser';
|
|
2
|
+
export declare function getOperationByMethodAndPath(schema: OpenAPI.Document, method: string, path: string): OpenAPIV2.PathItemObject<{}> | OpenAPIV3.PathItemObject<{}> | OpenAPIV3_1.PathItemObject<{}> | null;
|
|
3
|
+
//# sourceMappingURL=getOperationByMethodAndPath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOperationByMethodAndPath.d.ts","sourceRoot":"","sources":["../../../src/utils/getOperationByMethodAndPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,SAAS,EACT,SAAS,EACT,WAAW,EACZ,MAAM,wBAAwB,CAAA;AAS/B,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,OAAO,CAAC,QAAQ,EACxB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,uGAsCb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOperationByMethodAndPath.test.d.ts","sourceRoot":"","sources":["../../../src/utils/getOperationByMethodAndPath.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './getFileOrUrl';
|
|
2
|
+
export * from './getHtmlDocument';
|
|
3
|
+
export * from './getMethodColor';
|
|
4
|
+
export * from './getOperationByMethodAndPath';
|
|
5
|
+
export * from './loadOpenApiFile';
|
|
6
|
+
export * from './readFile';
|
|
7
|
+
export * from './useGivenFileOrConfiguration';
|
|
8
|
+
export * from './watchFile';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,+BAA+B,CAAA;AAC7C,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isUrl.d.ts","sourceRoot":"","sources":["../../../src/utils/isUrl.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAK3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isYamlFileName.d.ts","sourceRoot":"","sources":["../../../src/utils/isYamlFileName.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,WAM9C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function loadOpenApiFile(input: string): Promise<import("@scalar/openapi-parser").ValidateResult | {
|
|
2
|
+
valid: boolean;
|
|
3
|
+
version: undefined;
|
|
4
|
+
specification: undefined;
|
|
5
|
+
schema: undefined;
|
|
6
|
+
errors: {
|
|
7
|
+
error: any;
|
|
8
|
+
path: string;
|
|
9
|
+
}[];
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=loadOpenApiFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadOpenApiFile.d.ts","sourceRoot":"","sources":["../../../src/utils/loadOpenApiFile.ts"],"names":[],"mappings":"AAKA,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM;;;;;;;;;GAmDlD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printSpecificationBanner.d.ts","sourceRoot":"","sources":["../../../src/utils/printSpecificationBanner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAGrD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAA;CAC1B,QA8BA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readFile.d.ts","sourceRoot":"","sources":["../../../src/utils/readFile.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,sBAYpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGivenFileOrConfiguration.d.ts","sourceRoot":"","sources":["../../../src/utils/useGivenFileOrConfiguration.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,uBAAuB,CAAA;AAE/C,wBAAgB,2BAA2B,CAAC,IAAI,CAAC,EAAE,MAAM,OAiCxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watchFile.d.ts","sourceRoot":"","sources":["../../../src/utils/watchFile.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,IAAI,EACpB,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,iBAiClC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createLogsMatcher } from './matcher';
|
|
2
|
+
type CreateLogsMatcherReturn = ReturnType<typeof createLogsMatcher>;
|
|
3
|
+
export type InvokeResult = [
|
|
4
|
+
exitCode: number,
|
|
5
|
+
logsMatcher: CreateLogsMatcherReturn
|
|
6
|
+
];
|
|
7
|
+
export declare function ScalarCli(): {
|
|
8
|
+
setCwd: (_cwd: string) => any;
|
|
9
|
+
invoke: (args: Array<string>) => InvokeResult;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=invoke-cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoke-cli.d.ts","sourceRoot":"","sources":["../../tests/invoke-cli.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAI7C,KAAK,uBAAuB,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAA;AACnE,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,MAAM;IAChB,WAAW,EAAE,uBAAuB;CACrC,CAAA;AAED,wBAAgB,SAAS;mBAIN,MAAM;mBAIN,KAAK,CAAC,MAAM,CAAC,KAAG,YAAY;EAkC9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matcher.d.ts","sourceRoot":"","sources":["../../tests/matcher.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM;;;yBAOzB,MAAM;;6BAEJ,MAAM;;;EAI9B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import kleur from 'kleur';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { isUrl } from './isUrl.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Pass a file path or URL and get the content of the file.
|
|
7
|
+
*/
|
|
8
|
+
async function getFileOrUrl(input) {
|
|
9
|
+
if (isUrl(input)) {
|
|
10
|
+
const response = await fetch(input);
|
|
11
|
+
if (!response.ok) {
|
|
12
|
+
console.error(kleur.bold().red('[ERROR]'), kleur.bold().red('Failed to fetch OpenAPI specification from URL.'));
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
return await response.text();
|
|
16
|
+
}
|
|
17
|
+
if (!fs.existsSync(input)) {
|
|
18
|
+
throw new Error('File not found');
|
|
19
|
+
}
|
|
20
|
+
return fs.readFileSync(input, 'utf-8');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { getFileOrUrl };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
function getHtmlDocument(specification, watch = false) {
|
|
2
|
+
return `<!doctype html>
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<title>Scalar API Reference</title>
|
|
6
|
+
<meta charset="utf-8" />
|
|
7
|
+
<meta
|
|
8
|
+
name="viewport"
|
|
9
|
+
content="width=device-width, initial-scale=1" />
|
|
10
|
+
<style>
|
|
11
|
+
body {
|
|
12
|
+
margin: 0;
|
|
13
|
+
}
|
|
14
|
+
</style>
|
|
15
|
+
${watch
|
|
16
|
+
? `
|
|
17
|
+
<script>
|
|
18
|
+
const evtSource = new EventSource('__watcher');
|
|
19
|
+
evtSource.onmessage = (event) => {
|
|
20
|
+
console.log(\`message: \${event.data}\`);
|
|
21
|
+
window.location.reload();
|
|
22
|
+
};
|
|
23
|
+
</script>
|
|
24
|
+
`
|
|
25
|
+
: ''}
|
|
26
|
+
</head>
|
|
27
|
+
<body>
|
|
28
|
+
<script
|
|
29
|
+
id="api-reference"
|
|
30
|
+
type="application/json"
|
|
31
|
+
data-proxy-url="https://proxy.scalar.com">${JSON.stringify(specification)}</script>
|
|
32
|
+
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
|
33
|
+
</body>
|
|
34
|
+
</html>`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { getHtmlDocument };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isUrl } from './isUrl.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* True for all files ending with .yml or .yaml (case-insensitive).
|
|
5
|
+
*/
|
|
6
|
+
function isYamlFileName(fileName) {
|
|
7
|
+
if (isUrl(fileName)) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return /\.ya?ml$/i.test(fileName);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { isYamlFileName };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { load, validate } from '@scalar/openapi-parser';
|
|
2
|
+
import kleur from 'kleur';
|
|
3
|
+
import { getFileOrUrl } from './getFileOrUrl.js';
|
|
4
|
+
|
|
5
|
+
async function loadOpenApiFile(input) {
|
|
6
|
+
const specification = await getFileOrUrl(input);
|
|
7
|
+
try {
|
|
8
|
+
const { filesystem } = await load(specification);
|
|
9
|
+
const result = await validate(filesystem);
|
|
10
|
+
// Invalid specification
|
|
11
|
+
if (!result.valid) {
|
|
12
|
+
console.warn(kleur.bold().yellow('[WARN]'), kleur.bold().yellow('File doesn’t match the OpenAPI specification.'));
|
|
13
|
+
console.log();
|
|
14
|
+
// Output errors
|
|
15
|
+
result.errors?.forEach((error) => {
|
|
16
|
+
console.warn(kleur.bold().yellow('[WARN]'), kleur.yellow(error.error), kleur.yellow(`(${error.path})`));
|
|
17
|
+
});
|
|
18
|
+
console.log();
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.warn(kleur.bold().red('[ERROR]'), error ? kleur.red(error.toString()) : 'Unknown error.');
|
|
25
|
+
console.log();
|
|
26
|
+
return {
|
|
27
|
+
valid: false,
|
|
28
|
+
version: undefined,
|
|
29
|
+
specification: undefined,
|
|
30
|
+
schema: undefined,
|
|
31
|
+
errors: [
|
|
32
|
+
{
|
|
33
|
+
error: error?.message,
|
|
34
|
+
path: '',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { loadOpenApiFile };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import kleur from 'kleur';
|
|
2
|
+
|
|
3
|
+
function printSpecificationBanner(result) {
|
|
4
|
+
const { version, schema } = result;
|
|
5
|
+
if (!schema?.info?.title || !version) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
// Version
|
|
9
|
+
console.log(kleur.bold().white('[INFO]'), kleur.bold().white(schema?.info?.title), kleur.grey(`(OpenAPI v${version})`));
|
|
10
|
+
// Count number of paths
|
|
11
|
+
const pathsCount = Object.keys(schema.paths ?? {}).length;
|
|
12
|
+
// Count number of operations
|
|
13
|
+
const operationsCount = Object.values(schema.paths ?? {}).reduce((acc, path) => acc + Object.keys(path).length, 0);
|
|
14
|
+
// Statistics
|
|
15
|
+
console.log(kleur.bold().white('[INFO]'), kleur.grey(`${pathsCount} paths, ${operationsCount} operations`));
|
|
16
|
+
console.log();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { printSpecificationBanner };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
|
|
3
|
+
function readFile(file) {
|
|
4
|
+
try {
|
|
5
|
+
if (fs.existsSync(file) === false) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
return fs.readFileSync(file, 'utf8');
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
console.error(err);
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { readFile };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import kleur from 'kleur';
|
|
2
|
+
import { readFile } from './readFile.js';
|
|
3
|
+
|
|
4
|
+
const CONFIG_FILE = 'scalar.config.json';
|
|
5
|
+
function useGivenFileOrConfiguration(file) {
|
|
6
|
+
// If a specific file is given, use it.
|
|
7
|
+
if (file) {
|
|
8
|
+
return file;
|
|
9
|
+
}
|
|
10
|
+
// Try to load the configuration
|
|
11
|
+
try {
|
|
12
|
+
const content = readFile(CONFIG_FILE);
|
|
13
|
+
if (!content) {
|
|
14
|
+
throw new Error('No configuration file found.');
|
|
15
|
+
}
|
|
16
|
+
const configuration = JSON.parse(content);
|
|
17
|
+
if (configuration?.reference?.file) {
|
|
18
|
+
return configuration.reference.file;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// Do nothing
|
|
23
|
+
}
|
|
24
|
+
console.error(kleur.red('No file provided.'));
|
|
25
|
+
console.log();
|
|
26
|
+
console.log(kleur.white('Try `scalar init` or add the file as an argument. Read `scalar --help` for more information.'));
|
|
27
|
+
console.log();
|
|
28
|
+
return process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { CONFIG_FILE, useGivenFileOrConfiguration };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import watcher from '@parcel/watcher';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { isUrl } from './isUrl.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Watch a foobar for changes and call a callback when it does.
|
|
8
|
+
*/
|
|
9
|
+
async function watchFile(file, callback, options) {
|
|
10
|
+
// Poll URLs
|
|
11
|
+
if (isUrl(file)) {
|
|
12
|
+
setInterval(callback, 5000);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const absoluteFilePath = path.join(process.cwd(), file);
|
|
16
|
+
// Check if file exists
|
|
17
|
+
if (!fs.existsSync(absoluteFilePath)) {
|
|
18
|
+
throw new Error(`File ${absoluteFilePath} does not exist`);
|
|
19
|
+
}
|
|
20
|
+
// Watch the file for changes
|
|
21
|
+
console.log(`[INFO] Watch ${file}`);
|
|
22
|
+
// Get path where the file is located
|
|
23
|
+
const directory = path.dirname(absoluteFilePath);
|
|
24
|
+
// Start the watcher
|
|
25
|
+
await watcher.subscribe(directory, (err, events) => {
|
|
26
|
+
// Match the file path
|
|
27
|
+
if (events.some((event) => event.path === absoluteFilePath)) {
|
|
28
|
+
callback();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { watchFile };
|