diff --git a/.eslintignore b/.eslintignore index 990412f38..a4962f609 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,4 +3,4 @@ /test-harness/tests/ /packages/*/dist /packages/*/CHANGELOG.md -packages/cli/src/formatters/html/templates.ts +packages/formatters/src/html/templates.ts diff --git a/.gitignore b/.gitignore index 5ef457b59..e796c1f4b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ node_modules !.yarn/sdks !.yarn/versions -packages/cli/src/formatters/html/templates.ts +packages/formatters/src/html/templates.ts packages/cli/binaries /test-harness/tmp/ /test-harness/tests/ diff --git a/jest.config.mjs b/jest.config.mjs index ba162d2ec..1b23888fc 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -101,6 +101,14 @@ export default { }, testMatch: ['/packages/runtime/src/**/__tests__/*.{test,spec}.ts'], }, + { + ...projectDefault, + displayName: { + name: '@stoplight/spectral-formatters', + color: 'magenta', + }, + testMatch: ['/packages/formatters/src/**/__tests__/*.{test,spec}.ts'], + }, ], collectCoverageFrom: ['/packages/*/src/**/*.ts', '!/packages/*/src/**/__*__/**/*.ts'], }; diff --git a/karma.conf.ts b/karma.conf.ts index 802b77af0..89f9af299 100644 --- a/karma.conf.ts +++ b/karma.conf.ts @@ -18,7 +18,12 @@ module.exports = (config: Config): void => { files: ['./__karma__/jest.ts', './test-utils/*.ts', 'packages/*/src/**/*.ts'], // list of files / patterns to exclude - exclude: ['packages/cli/**', 'packages/ruleset-bundler/src/plugins/commonjs.ts', '**/*.jest.test.ts'], + exclude: [ + 'packages/cli/**', + 'packages/formatters/**', + 'packages/ruleset-bundler/src/plugins/commonjs.ts', + '**/*.jest.test.ts', + ], // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor diff --git a/packages/cli/package.json b/packages/cli/package.json index 912b21ccc..1c381e942 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -27,9 +27,6 @@ "build.binary": "pkg . --output ./binaries/spectral", "build.windows": "pkg . --targets windows --out-path ./binaries", "build.nix": "pkg . --targets linux,macos,alpine --out-path ./binaries", - "pretest": "yarn prebuild", - "prelint": "yarn prebuild", - "prebuild": "node scripts/bundle-html-templates.mjs", "cli": "node -r ts-node/register/transpile-only -r tsconfig-paths/register src/index.ts", "cli:debug": "node -r ts-node/register/transpile-only -r tsconfig-paths/register --inspect-brk src/index.ts", "release": "semantic-release -e semantic-release-monorepo" @@ -38,6 +35,7 @@ "@stoplight/json": "~3.20.1", "@stoplight/path": "1.3.2", "@stoplight/spectral-core": "^1.15.1", + "@stoplight/spectral-formatters": "^1.0.0", "@stoplight/spectral-parsers": "^1.0.2", "@stoplight/spectral-ref-resolver": "^1.0.2", "@stoplight/spectral-ruleset-bundler": "^1.4.0", @@ -46,14 +44,11 @@ "@stoplight/spectral-runtime": "^1.1.2", "@stoplight/types": "^13.6.0", "chalk": "4.1.2", - "cliui": "7.0.4", "fast-glob": "~3.2.12", "lodash": "~4.17.21", "pony-cause": "^1.0.0", "proxy-agent": "5.0.0", "stacktracey": "^2.1.7", - "strip-ansi": "6.0", - "text-table": "0.2", "tslib": "^2.3.0", "yargs": "17.3.1" }, @@ -61,12 +56,8 @@ "@types/es-aggregate-error": "^1.0.2", "@types/xml2js": "^0.4.9", "@types/yargs": "^17.0.8", - "ast-types": "^0.14.2", - "astring": "^1.8.4", - "eol": "0.9.1", "es-aggregate-error": "^1.0.7", "nock": "^13.1.3", - "node-html-parser": "^4.1.5", "pkg": "^5.8.0", "xml2js": "^0.5.0" }, diff --git a/packages/cli/src/services/__tests__/output.test.ts b/packages/cli/src/services/__tests__/output.test.ts index c9f08e305..ead9c63b6 100644 --- a/packages/cli/src/services/__tests__/output.test.ts +++ b/packages/cli/src/services/__tests__/output.test.ts @@ -1,11 +1,11 @@ import { DiagnosticSeverity } from '@stoplight/types'; import * as fs from 'fs'; import * as process from 'process'; -import * as formatters from '../../formatters'; +import * as formatters from '@stoplight/spectral-formatters'; import { OutputFormat } from '../config'; import { formatOutput, writeOutput } from '../output'; -jest.mock('../../formatters'); +jest.mock('@stoplight/spectral-formatters'); jest.mock('fs', () => ({ readFileSync: jest.requireActual('fs').readFileSync, promises: { diff --git a/packages/cli/src/services/output.ts b/packages/cli/src/services/output.ts index f8dde0597..a7bb0f0ea 100644 --- a/packages/cli/src/services/output.ts +++ b/packages/cli/src/services/output.ts @@ -1,8 +1,8 @@ import * as process from 'process'; import { IRuleResult } from '@stoplight/spectral-core'; import { promises as fs } from 'fs'; -import { html, json, junit, stylish, teamcity, text, pretty } from '../formatters'; -import { Formatter, FormatterOptions } from '../formatters/types'; +import { html, json, junit, stylish, teamcity, text, pretty } from '@stoplight/spectral-formatters'; +import type { Formatter, FormatterOptions } from '@stoplight/spectral-formatters'; import type { OutputFormat } from './config'; const formatters: Record = { diff --git a/packages/cli/tsconfig.build.json b/packages/cli/tsconfig.build.json index 1e8a26961..5ccfb47c2 100644 --- a/packages/cli/tsconfig.build.json +++ b/packages/cli/tsconfig.build.json @@ -8,11 +8,12 @@ "tsBuildInfoFile": ".cache/.tsbuildinfo" }, "references": [ - { "path": "../core/tsconfig.build.json" }, - { "path": "../parsers/tsconfig.build.json" }, - { "path": "../ref-resolver/tsconfig.build.json" }, - { "path": "../ruleset-bundler/tsconfig.build.json" }, - { "path": "../ruleset-migrator/tsconfig.build.json" }, - { "path": "../runtime/tsconfig.build.json" }, + { "path": "../core/tsconfig.build.json" }, + { "path": "../formatters/tsconfig.build.json" }, + { "path": "../parsers/tsconfig.build.json" }, + { "path": "../ref-resolver/tsconfig.build.json" }, + { "path": "../ruleset-bundler/tsconfig.build.json" }, + { "path": "../ruleset-migrator/tsconfig.build.json" }, + { "path": "../runtime/tsconfig.build.json" } ] } diff --git a/packages/formatters/CHANGELOG.md b/packages/formatters/CHANGELOG.md new file mode 100644 index 000000000..e69de29bb diff --git a/packages/formatters/LICENSE b/packages/formatters/LICENSE new file mode 100644 index 000000000..ba50e461e --- /dev/null +++ b/packages/formatters/LICENSE @@ -0,0 +1,190 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + Copyright 2018 Stoplight, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/formatters/README.md b/packages/formatters/README.md new file mode 100644 index 000000000..e1f9b4825 --- /dev/null +++ b/packages/formatters/README.md @@ -0,0 +1,19 @@ +# @stoplight/spectral-formatters + +This project exposes the available formatters from the CLI for users that perform custom validation through Javascript. + +## Usage + +```ts +import { pretty } from "@stoplight/spectral-formatters"; + +const spectral = new Spectral(); +// ... +const result = await spectral.run(document); + +// You can also filter the results here. +const output = pretty(result); + +console.error(output); +// ... +``` diff --git a/packages/formatters/package.json b/packages/formatters/package.json new file mode 100644 index 000000000..7f3c83299 --- /dev/null +++ b/packages/formatters/package.json @@ -0,0 +1,48 @@ +{ + "name": "@stoplight/spectral-formatters", + "version": "1.0.0", + "homepage": "https://github.com/stoplightio/spectral", + "bugs": "https://github.com/stoplightio/spectral/issues", + "author": "Stoplight ", + "engines": { + "node": "^12.20 || >=14.13" + }, + "license": "Apache-2.0", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "files": [ + "/dist" + ], + "repository": { + "type": "git", + "url": "https://github.com/stoplightio/spectral.git" + }, + "scripts": { + "release": "semantic-release -e semantic-release-monorepo", + "pretest": "yarn prebuild", + "prelint": "yarn prebuild", + "prebuild": "node scripts/bundle-html-templates.mjs" + }, + "dependencies": { + "@stoplight/path": "^2.0.0", + "@stoplight/spectral-core": "^1.15.1", + "@stoplight/spectral-functions": "^1.0.0", + "@stoplight/spectral-runtime": "^1.1.0", + "@stoplight/types": "^13.15.0", + "@stoplight/yaml": "~4.2.3", + "chalk": "4.1.2", + "cliui": "7.0.4", + "eol": "0.9.1", + "lodash": "^4.17.21", + "strip-ansi": "6.0", + "text-table": "^0.2.0", + "tslib": "^2.5.0" + }, + "devDependencies": { + "ast-types": "^0.14.2", + "astring": "^1.8.4", + "eol": "0.9.1", + "node-html-parser": "^4.1.5", + "xml2js": "^0.5.0" + } +} \ No newline at end of file diff --git a/packages/cli/scripts/bundle-html-templates.mjs b/packages/formatters/scripts/bundle-html-templates.mjs similarity index 81% rename from packages/cli/scripts/bundle-html-templates.mjs rename to packages/formatters/scripts/bundle-html-templates.mjs index 05b9fefb5..c54bdcac3 100644 --- a/packages/cli/scripts/bundle-html-templates.mjs +++ b/packages/formatters/scripts/bundle-html-templates.mjs @@ -10,7 +10,7 @@ import fg from 'fast-glob'; const cwd = path.join(path.dirname(fileURLToPath(import.meta.url)), '..'); -fg('src/formatters/html/*.html', { cwd, absolute: true }) +fg('src/html/*.html', { cwd, absolute: true }) .then(files => Promise.all( files.map(async file => ({ file: path.basename(file), content: eol.lf(await fs.readFile(file, 'utf8')) })), @@ -21,5 +21,5 @@ fg('src/formatters/html/*.html', { cwd, absolute: true }) b.objectExpression(items.map(({ file, content }) => b.property('init', b.literal(file), b.literal(content)))), ); - await fs.writeFile(path.join(cwd, 'src/formatters/html/templates.ts'), astring.generate(root)); + await fs.writeFile(path.join(cwd, 'src/html/templates.ts'), astring.generate(root)); }); diff --git a/packages/cli/src/formatters/__tests__/__fixtures__/errors-with-special-xml-strings.json b/packages/formatters/src/__tests__/__fixtures__/errors-with-special-xml-strings.json similarity index 100% rename from packages/cli/src/formatters/__tests__/__fixtures__/errors-with-special-xml-strings.json rename to packages/formatters/src/__tests__/__fixtures__/errors-with-special-xml-strings.json diff --git a/packages/cli/src/formatters/__tests__/__fixtures__/mixed-errors-with-different-paths.json b/packages/formatters/src/__tests__/__fixtures__/mixed-errors-with-different-paths.json similarity index 100% rename from packages/cli/src/formatters/__tests__/__fixtures__/mixed-errors-with-different-paths.json rename to packages/formatters/src/__tests__/__fixtures__/mixed-errors-with-different-paths.json diff --git a/packages/cli/src/formatters/__tests__/__fixtures__/mixed-errors.json b/packages/formatters/src/__tests__/__fixtures__/mixed-errors.json similarity index 100% rename from packages/cli/src/formatters/__tests__/__fixtures__/mixed-errors.json rename to packages/formatters/src/__tests__/__fixtures__/mixed-errors.json diff --git a/packages/cli/src/formatters/__tests__/__fixtures__/oas3-schema-errors.json b/packages/formatters/src/__tests__/__fixtures__/oas3-schema-errors.json similarity index 100% rename from packages/cli/src/formatters/__tests__/__fixtures__/oas3-schema-errors.json rename to packages/formatters/src/__tests__/__fixtures__/oas3-schema-errors.json diff --git a/packages/cli/src/formatters/__tests__/html.test.ts b/packages/formatters/src/__tests__/html.test.ts similarity index 100% rename from packages/cli/src/formatters/__tests__/html.test.ts rename to packages/formatters/src/__tests__/html.test.ts diff --git a/packages/cli/src/formatters/__tests__/json.test.ts b/packages/formatters/src/__tests__/json.test.ts similarity index 100% rename from packages/cli/src/formatters/__tests__/json.test.ts rename to packages/formatters/src/__tests__/json.test.ts diff --git a/packages/cli/src/formatters/__tests__/junit.test.ts b/packages/formatters/src/__tests__/junit.test.ts similarity index 100% rename from packages/cli/src/formatters/__tests__/junit.test.ts rename to packages/formatters/src/__tests__/junit.test.ts diff --git a/packages/cli/src/formatters/__tests__/pretty.test.ts b/packages/formatters/src/__tests__/pretty.test.ts similarity index 100% rename from packages/cli/src/formatters/__tests__/pretty.test.ts rename to packages/formatters/src/__tests__/pretty.test.ts diff --git a/packages/cli/src/formatters/__tests__/stylish.test.ts b/packages/formatters/src/__tests__/stylish.test.ts similarity index 100% rename from packages/cli/src/formatters/__tests__/stylish.test.ts rename to packages/formatters/src/__tests__/stylish.test.ts diff --git a/packages/cli/src/formatters/__tests__/teamcity.test.ts b/packages/formatters/src/__tests__/teamcity.test.ts similarity index 100% rename from packages/cli/src/formatters/__tests__/teamcity.test.ts rename to packages/formatters/src/__tests__/teamcity.test.ts diff --git a/packages/cli/src/formatters/__tests__/text.test.ts b/packages/formatters/src/__tests__/text.test.ts similarity index 100% rename from packages/cli/src/formatters/__tests__/text.test.ts rename to packages/formatters/src/__tests__/text.test.ts diff --git a/packages/cli/src/formatters/html/html-template-message.html b/packages/formatters/src/html/html-template-message.html similarity index 100% rename from packages/cli/src/formatters/html/html-template-message.html rename to packages/formatters/src/html/html-template-message.html diff --git a/packages/cli/src/formatters/html/html-template-page.html b/packages/formatters/src/html/html-template-page.html similarity index 100% rename from packages/cli/src/formatters/html/html-template-page.html rename to packages/formatters/src/html/html-template-page.html diff --git a/packages/cli/src/formatters/html/html-template-result.html b/packages/formatters/src/html/html-template-result.html similarity index 100% rename from packages/cli/src/formatters/html/html-template-result.html rename to packages/formatters/src/html/html-template-result.html diff --git a/packages/cli/src/formatters/html/index.ts b/packages/formatters/src/html/index.ts similarity index 100% rename from packages/cli/src/formatters/html/index.ts rename to packages/formatters/src/html/index.ts diff --git a/packages/cli/src/formatters/index.ts b/packages/formatters/src/index.ts similarity index 87% rename from packages/cli/src/formatters/index.ts rename to packages/formatters/src/index.ts index 1a50c90d0..4c5cbfd79 100644 --- a/packages/cli/src/formatters/index.ts +++ b/packages/formatters/src/index.ts @@ -5,3 +5,4 @@ export * from './html'; export * from './text'; export * from './teamcity'; export * from './pretty'; +export * from './types'; diff --git a/packages/cli/src/formatters/json.ts b/packages/formatters/src/json.ts similarity index 100% rename from packages/cli/src/formatters/json.ts rename to packages/formatters/src/json.ts diff --git a/packages/cli/src/formatters/junit.ts b/packages/formatters/src/junit.ts similarity index 100% rename from packages/cli/src/formatters/junit.ts rename to packages/formatters/src/junit.ts diff --git a/packages/cli/src/formatters/pretty.ts b/packages/formatters/src/pretty.ts similarity index 100% rename from packages/cli/src/formatters/pretty.ts rename to packages/formatters/src/pretty.ts diff --git a/packages/cli/src/formatters/stylish.ts b/packages/formatters/src/stylish.ts similarity index 100% rename from packages/cli/src/formatters/stylish.ts rename to packages/formatters/src/stylish.ts diff --git a/packages/cli/src/formatters/teamcity.ts b/packages/formatters/src/teamcity.ts similarity index 100% rename from packages/cli/src/formatters/teamcity.ts rename to packages/formatters/src/teamcity.ts diff --git a/packages/cli/src/formatters/text.ts b/packages/formatters/src/text.ts similarity index 100% rename from packages/cli/src/formatters/text.ts rename to packages/formatters/src/text.ts diff --git a/packages/cli/src/formatters/types.ts b/packages/formatters/src/types.ts similarity index 100% rename from packages/cli/src/formatters/types.ts rename to packages/formatters/src/types.ts diff --git a/packages/cli/src/formatters/utils/getColorForSeverity.ts b/packages/formatters/src/utils/getColorForSeverity.ts similarity index 100% rename from packages/cli/src/formatters/utils/getColorForSeverity.ts rename to packages/formatters/src/utils/getColorForSeverity.ts diff --git a/packages/cli/src/formatters/utils/getHighestSeverity.ts b/packages/formatters/src/utils/getHighestSeverity.ts similarity index 100% rename from packages/cli/src/formatters/utils/getHighestSeverity.ts rename to packages/formatters/src/utils/getHighestSeverity.ts diff --git a/packages/cli/src/formatters/utils/getSeverityName.ts b/packages/formatters/src/utils/getSeverityName.ts similarity index 100% rename from packages/cli/src/formatters/utils/getSeverityName.ts rename to packages/formatters/src/utils/getSeverityName.ts diff --git a/packages/cli/src/formatters/utils/getSummary.ts b/packages/formatters/src/utils/getSummary.ts similarity index 100% rename from packages/cli/src/formatters/utils/getSummary.ts rename to packages/formatters/src/utils/getSummary.ts diff --git a/packages/cli/src/formatters/utils/groupBySeverity.ts b/packages/formatters/src/utils/groupBySeverity.ts similarity index 100% rename from packages/cli/src/formatters/utils/groupBySeverity.ts rename to packages/formatters/src/utils/groupBySeverity.ts diff --git a/packages/cli/src/formatters/utils/groupBySource.ts b/packages/formatters/src/utils/groupBySource.ts similarity index 100% rename from packages/cli/src/formatters/utils/groupBySource.ts rename to packages/formatters/src/utils/groupBySource.ts diff --git a/packages/cli/src/formatters/utils/index.ts b/packages/formatters/src/utils/index.ts similarity index 100% rename from packages/cli/src/formatters/utils/index.ts rename to packages/formatters/src/utils/index.ts diff --git a/packages/cli/src/formatters/utils/pluralize.ts b/packages/formatters/src/utils/pluralize.ts similarity index 100% rename from packages/cli/src/formatters/utils/pluralize.ts rename to packages/formatters/src/utils/pluralize.ts diff --git a/packages/cli/src/formatters/utils/xmlEscape.ts b/packages/formatters/src/utils/xmlEscape.ts similarity index 100% rename from packages/cli/src/formatters/utils/xmlEscape.ts rename to packages/formatters/src/utils/xmlEscape.ts diff --git a/packages/formatters/tsconfig.build.json b/packages/formatters/tsconfig.build.json new file mode 100644 index 000000000..fd2267897 --- /dev/null +++ b/packages/formatters/tsconfig.build.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.json", + "include": ["src"], + "compilerOptions": { + "composite": true, + "rootDir": "src", + "outDir": "dist", + "tsBuildInfoFile": ".cache/.tsbuildinfo" + }, + "references": [{ "path": "../core/tsconfig.build.json" }] +} diff --git a/tsconfig.build.json b/tsconfig.build.json index 23d50a91c..5e0e7c473 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -14,6 +14,9 @@ { "path": "./packages/formats/tsconfig.build.json" }, + { + "path": "./packages/formatters/tsconfig.build.json" + }, { "path": "./packages/functions/tsconfig.build.json" }, @@ -34,6 +37,6 @@ }, { "path": "./packages/runtime/tsconfig.build.json" - }, + } ] } diff --git a/tsconfig.json b/tsconfig.json index 8f7094cec..23da7f880 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "@stoplight/spectral-core/ruleset": ["packages/core/src/ruleset/index.ts"], "@stoplight/spectral-core/ruleset/validation": ["packages/core/src/ruleset/validation/index.ts"], "@stoplight/spectral-formats": ["packages/formats/src/index.ts"], + "@stoplight/spectral-formatters": ["packages/formatters/src/index.ts"], "@stoplight/spectral-functions": ["packages/functions/src/index.ts"], "@stoplight/spectral-parsers": ["packages/parsers/src/index.ts"], "@stoplight/spectral-ref-resolver": ["packages/ref-resolver/src/index.ts"], diff --git a/yarn.lock b/yarn.lock index 2e5c5fd2a..f536f500e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2493,6 +2493,13 @@ __metadata: languageName: node linkType: hard +"@stoplight/path@npm:^2.0.0": + version: 2.0.0 + resolution: "@stoplight/path@npm:2.0.0" + checksum: b55071d28fb1eed573039054ae72384f3dc2440f17cf34a872c118c49c88746c578c3d5f672caddb859a0ec99b82a143654cac13c91a2d8f74b0937dcfe4535a + languageName: node + linkType: hard + "@stoplight/spectral-cli@workspace:packages/cli": version: 0.0.0-use.local resolution: "@stoplight/spectral-cli@workspace:packages/cli" @@ -2500,6 +2507,7 @@ __metadata: "@stoplight/json": ~3.20.1 "@stoplight/path": 1.3.2 "@stoplight/spectral-core": ^1.15.1 + "@stoplight/spectral-formatters": ^1.0.0 "@stoplight/spectral-parsers": ^1.0.2 "@stoplight/spectral-ref-resolver": ^1.0.2 "@stoplight/spectral-ruleset-bundler": ^1.4.0 @@ -2510,22 +2518,15 @@ __metadata: "@types/es-aggregate-error": ^1.0.2 "@types/xml2js": ^0.4.9 "@types/yargs": ^17.0.8 - ast-types: ^0.14.2 - astring: ^1.8.4 chalk: 4.1.2 - cliui: 7.0.4 - eol: 0.9.1 es-aggregate-error: ^1.0.7 fast-glob: ~3.2.12 lodash: ~4.17.21 nock: ^13.1.3 - node-html-parser: ^4.1.5 pkg: ^5.8.0 pony-cause: ^1.0.0 proxy-agent: 5.0.0 stacktracey: ^2.1.7 - strip-ansi: 6.0 - text-table: 0.2 tslib: ^2.3.0 xml2js: ^0.5.0 yargs: 17.3.1 @@ -2580,6 +2581,30 @@ __metadata: languageName: unknown linkType: soft +"@stoplight/spectral-formatters@^1.0.0, @stoplight/spectral-formatters@workspace:packages/formatters": + version: 0.0.0-use.local + resolution: "@stoplight/spectral-formatters@workspace:packages/formatters" + dependencies: + "@stoplight/path": ^2.0.0 + "@stoplight/spectral-core": ^1.15.1 + "@stoplight/spectral-functions": ^1.0.0 + "@stoplight/spectral-runtime": ^1.1.0 + "@stoplight/types": ^13.15.0 + "@stoplight/yaml": ~4.2.3 + ast-types: ^0.14.2 + astring: ^1.8.4 + chalk: 4.1.2 + cliui: 7 + eol: 0.9.1 + lodash: ^4.17.21 + node-html-parser: ^4.1.5 + strip-ansi: 6.0 + text-table: ^0.2.0 + tslib: ^2.5.0 + xml2js: ^0.5.0 + languageName: unknown + linkType: soft + "@stoplight/spectral-functions@*, @stoplight/spectral-functions@>=1, @stoplight/spectral-functions@^1.0.0, @stoplight/spectral-functions@^1.5.1, @stoplight/spectral-functions@workspace:packages/functions": version: 0.0.0-use.local resolution: "@stoplight/spectral-functions@workspace:packages/functions" @@ -2725,6 +2750,16 @@ __metadata: languageName: node linkType: hard +"@stoplight/types@npm:^13.15.0": + version: 13.15.0 + resolution: "@stoplight/types@npm:13.15.0" + dependencies: + "@types/json-schema": ^7.0.4 + utility-types: ^3.10.0 + checksum: 839f0bbedb791bd6792ef22b6a821ca504b14b705927f7c510c4cdcc591eddc8818c82b8857129501aa809d6f369b82e4487bfe18dfc5ce00e28317ecad2df9a + languageName: node + linkType: hard + "@stoplight/types@npm:~13.6.0": version: 13.6.0 resolution: "@stoplight/types@npm:13.6.0" @@ -4514,7 +4549,7 @@ __metadata: languageName: node linkType: hard -"cliui@npm:7.0.4, cliui@npm:^7.0.2": +"cliui@npm:7, cliui@npm:^7.0.2": version: 7.0.4 resolution: "cliui@npm:7.0.4" dependencies: @@ -12410,7 +12445,7 @@ __metadata: languageName: node linkType: hard -"text-table@npm:0.2, text-table@npm:^0.2.0, text-table@npm:~0.2.0": +"text-table@npm:^0.2.0, text-table@npm:~0.2.0": version: 0.2.0 resolution: "text-table@npm:0.2.0" checksum: b6937a38c80c7f84d9c11dd75e49d5c44f71d95e810a3250bd1f1797fc7117c57698204adf676b71497acc205d769d65c16ae8fa10afad832ae1322630aef10a @@ -12697,6 +12732,13 @@ __metadata: languageName: node linkType: hard +"tslib@npm:^2.5.0": + version: 2.5.0 + resolution: "tslib@npm:2.5.0" + checksum: ae3ed5f9ce29932d049908ebfdf21b3a003a85653a9a140d614da6b767a93ef94f460e52c3d787f0e4f383546981713f165037dc2274df212ea9f8a4541004e1 + languageName: node + linkType: hard + "tsutils@npm:^3.21.0": version: 3.21.0 resolution: "tsutils@npm:3.21.0"