Skip to content

Commit

Permalink
chore: add apidom-converter package scaffolding (#3699)
Browse files Browse the repository at this point in the history
Refs #3698
  • Loading branch information
char0n authored Jan 18, 2024
1 parent 945ad4d commit d390f96
Show file tree
Hide file tree
Showing 19 changed files with 294 additions and 45 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ You can install ApiDOM packages using [npm CLI](https://docs.npmjs.com/cli):

```sh
$ npm install @swagger-api/apidom-ast
$ npm install @swagger-api/apidom-converter
$ npm install @swagger-api/apidom-core
$ npm install @swagger-api/apidom-error
$ npm install @swagger-api/apidom-json-path
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"clean": "lerna run clean",
"test": "lerna run test",
"link": "npm link --workspaces",
"unlink": "npm unlink --global @swagger-api/apidom-ast @swagger-api/apidom-core @swagger-api/apidom-error @swagger-api/apidom-json-path @swagger-api/apidom-json-pointer @swagger-api/apidom-json-pointer-relative @swagger-api/apidom-parser-adapter-json @swagger-api/apidom-ns-api-design-systems @swagger-api/apidom-ns-asyncapi-2 @swagger-api/apidom-ns-json-schema-draft-4 @swagger-api/apidom-ns-json-schema-draft-6 @swagger-api/apidom-ns-json-schema-draft-7 @swagger-api/apidom-ns-openapi-2 @swagger-api/apidom-ns-openapi-3-0 @swagger-api/apidom-ns-openapi-3-1 @swagger-api/apidom-parser-adapter-yaml-1-2 @swagger-api/apidom-parser-adapter-asyncapi-yaml-2 @swagger-api/apidom-parser-adapter-openapi-yaml-2 @swagger-api/apidom-parser-adapter-openapi-yaml-3-0 @swagger-api/apidom-parser-adapter-openapi-yaml-3-1 @swagger-api/apidom-parser @swagger-api/apidom-parser-adapter-api-design-systems-json @swagger-api/apidom-parser-adapter-api-design-systems-yaml @swagger-api/apidom-parser-adapter-asyncapi-json-2 @swagger-api/apidom-ls @swagger-api/apidom-reference @swagger-api/apidom-parser-adapter-openapi-json-2 @swagger-api/apidom-parser-adapter-openapi-json-3-0 @swagger-api/apidom-parser-adapter-openapi-json-3-1 @swagger-api/apidom-parser-adapter-workflows-json-1 @swagger-api/apidom-parser-adapter-workflows-yaml-1 @swagger-api/apidom-playground",
"unlink": "npm unlink --global @swagger-api/apidom-ast @swagger-api/apidom-converter @swagger-api/apidom-core @swagger-api/apidom-error @swagger-api/apidom-json-path @swagger-api/apidom-json-pointer @swagger-api/apidom-json-pointer-relative @swagger-api/apidom-parser-adapter-json @swagger-api/apidom-ns-api-design-systems @swagger-api/apidom-ns-asyncapi-2 @swagger-api/apidom-ns-json-schema-draft-4 @swagger-api/apidom-ns-json-schema-draft-6 @swagger-api/apidom-ns-json-schema-draft-7 @swagger-api/apidom-ns-openapi-2 @swagger-api/apidom-ns-openapi-3-0 @swagger-api/apidom-ns-openapi-3-1 @swagger-api/apidom-parser-adapter-yaml-1-2 @swagger-api/apidom-parser-adapter-asyncapi-yaml-2 @swagger-api/apidom-parser-adapter-openapi-yaml-2 @swagger-api/apidom-parser-adapter-openapi-yaml-3-0 @swagger-api/apidom-parser-adapter-openapi-yaml-3-1 @swagger-api/apidom-parser @swagger-api/apidom-parser-adapter-api-design-systems-json @swagger-api/apidom-parser-adapter-api-design-systems-yaml @swagger-api/apidom-parser-adapter-asyncapi-json-2 @swagger-api/apidom-ls @swagger-api/apidom-reference @swagger-api/apidom-parser-adapter-openapi-json-2 @swagger-api/apidom-parser-adapter-openapi-json-3-0 @swagger-api/apidom-parser-adapter-openapi-json-3-1 @swagger-api/apidom-parser-adapter-workflows-json-1 @swagger-api/apidom-parser-adapter-workflows-yaml-1 @swagger-api/apidom-playground",
"prepare": "chmod +x ./node_modules/husky/lib/bin.js && husky install"
},
"repository": {
Expand Down
9 changes: 9 additions & 0 deletions packages/apidom-converter/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/dist
/es
/cjs
/types
/config
/.eslintrc.js
/.nyc_output
/node_modules
/**/*.js
6 changes: 6 additions & 0 deletions packages/apidom-converter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/dist
/es
/cjs
/types
/NOTICE
/swagger-api-apidom-converter-*.tgz
5 changes: 5 additions & 0 deletions packages/apidom-converter/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recursive": true,
"spec": "test/**/*.ts",
"file": ["test/mocha-bootstrap.cjs"]
}
2 changes: 2 additions & 0 deletions packages/apidom-converter/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
save-prefix="="
save=false
11 changes: 11 additions & 0 deletions packages/apidom-converter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @swagger-api/apidom-converter

`apidom-converter` is a package that facilitates conversion of API specifications.

## Installation

You can install this package via [npm CLI](https://docs.npmjs.com/cli) by running the following command:

```sh
$ npm install @swagger-api/apidom-converter
```
12 changes: 12 additions & 0 deletions packages/apidom-converter/config/rollup/types.dist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import dts from 'rollup-plugin-dts';

const config = [
{
input: './types/index.d.ts',
output: [{ file: 'types/dist.d.ts', format: 'es' }],
plugins: [dts()],
external: ['Function/Curry'],
},
];

export default config;
70 changes: 70 additions & 0 deletions packages/apidom-converter/config/webpack/browser.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import path from 'node:path';
import { nonMinimizeTrait, minimizeTrait } from './traits.config.js';

const browser = {
mode: 'production',
entry: ['./src/index.ts'],
target: 'web',
performance: {
maxEntrypointSize: 1100000,
maxAssetSize: 1100000,
},
output: {
path: path.resolve('./dist'),
filename: 'apidom-converter.browser.js',
libraryTarget: 'umd',
library: 'apidomConverter',
},
resolve: {
extensions: ['.ts', '.mjs', '.js', '.json'],
},
module: {
rules: [
{
test: /\.(ts|js)?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
babelrc: true,
rootMode: 'upward',
},
},
},
],
},
...nonMinimizeTrait,
};

const browserMin = {
mode: 'production',
entry: ['./src/index.ts'],
target: 'web',
output: {
path: path.resolve('./dist'),
filename: 'apidom-converter.browser.min.js',
libraryTarget: 'umd',
library: 'apidomConverter',
},
resolve: {
extensions: ['.ts', '.mjs', '.js', '.json'],
},
module: {
rules: [
{
test: /\.(ts|js)?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
babelrc: true,
rootMode: 'upward',
},
},
},
],
},
...minimizeTrait,
};

export default [browser, browserMin];
32 changes: 32 additions & 0 deletions packages/apidom-converter/config/webpack/traits.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import webpack from 'webpack';
import TerserPlugin from 'terser-webpack-plugin';

export const nonMinimizeTrait = {
optimization: {
minimize: false,
usedExports: false,
concatenateModules: false,
},
};

export const minimizeTrait = {
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: true,
}),
],
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
warnings: false,
},
output: {
comments: false,
},
},
}),
],
},
};
12 changes: 12 additions & 0 deletions packages/apidom-converter/declaration.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"exclude": [
"test/**/*"
],
"compilerOptions": {
"declaration": true,
"declarationDir": "types",
"noEmit": false,
"emitDeclarationOnly": true
}
}
54 changes: 54 additions & 0 deletions packages/apidom-converter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@swagger-api/apidom-converter",
"version": "0.92.0",
"description": "Tool for converting API specifications.",
"private": true,
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"type": "module",
"unpkg": "./dist/apidom-converter.browser.min.js",
"main": "./cjs/index.cjs",
"exports": {
"types": "./types/dist.d.ts",
"import": "./es/index.mjs",
"require": "./cjs/index.cjs"
},
"types": "./types/dist.d.ts",
"scripts": {
"build": "npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser",
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward'",
"build:cjs": "cross-env BABEL_ENV=cjs babel src --out-dir cjs --extensions '.ts' --out-file-extension '.cjs' --root-mode 'upward'",
"build:umd:browser": "cross-env BABEL_ENV=browser webpack --config config/webpack/browser.config.js --progress",
"lint": "eslint ./",
"lint:fix": "eslint ./ --fix",
"clean": "rimraf ./es ./cjs ./dist ./types",
"typescript:check-types": "tsc --noEmit",
"typescript:declaration": "copyfiles -u 1 'src/**/*.d.ts' ./types && tsc -p declaration.tsconfig.json && rollup -c config/rollup/types.dist.js",
"test": "cross-env NODE_ENV=test BABEL_ENV=cjs mocha",
"test:update-snapshots": "cross-env UPDATE_SNAPSHOT=1 BABEL_ENV=cjs mocha",
"prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .",
"postpack": "rimraf NOTICE LICENSES"
},
"repository": {
"type": "git",
"url": "git+https://github.com/swagger-api/apidom.git"
},
"author": "Vladimír Gorej",
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime-corejs3": "^7.20.7"
},
"files": [
"cjs/",
"dist/",
"es/",
"types/dist.d.ts",
"types/minim.d.ts",
"LICENSES",
"NOTICE",
"README.md",
"CHANGELOG.md"
]
}
3 changes: 3 additions & 0 deletions packages/apidom-converter/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const foo = Symbol('foo');

export default foo;
40 changes: 40 additions & 0 deletions packages/apidom-converter/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"env": {
"mocha": true
},
"globals": {
"document": true
},
"plugins": [
"mocha"
],
"rules": {
"no-void": 0,
"no-underscore-dangle": 0,
"func-names": 0,
"prefer-arrow-callback": 0,
"no-array-constructor": 0,
"prefer-rest-params": 0,
"no-new-wrappers": 0,
"mocha/no-skipped-tests": 2,
"mocha/handle-done-callback": 2,
"mocha/valid-suite-description": 2,
"mocha/no-mocha-arrows": 2,
"mocha/no-hooks-for-single-case": 2,
"mocha/no-sibling-hooks": 2,
"mocha/no-top-level-hooks": 2,
"mocha/no-identical-title": 2,
"mocha/no-nested-tests": 2,
"mocha/no-exclusive-tests": 2,
"max-classes-per-file": 0
},
"overrides": [{
"files": ["mocha-bootstrap.cjs"],
"parserOptions": {
"sourceType": "script"
},
"rules": {
"@typescript-eslint/no-var-requires": 0
}
}]
}
7 changes: 7 additions & 0 deletions packages/apidom-converter/test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { assert } from 'chai';

describe('apidom-converter', function () {
it('initial test', async function () {
assert.strictEqual(true, true);
});
});
11 changes: 11 additions & 0 deletions packages/apidom-converter/test/mocha-bootstrap.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require('@babel/register')({ extensions: ['.js', '.ts'], rootMode: 'upward' });

const chai = require('chai');
const { jestSnapshotPlugin, addSerializer } = require('mocha-chai-jest-snapshot');

const jestApiDOMSerializer = require('../../../scripts/jest-serializer-apidom.cjs');
const jestStringSerializer = require('../../../scripts/jest-serializer-string.cjs');

chai.use(jestSnapshotPlugin());
addSerializer(jestApiDOMSerializer);
addSerializer(jestStringSerializer);
7 changes: 7 additions & 0 deletions packages/apidom-converter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"include": [
"src/**/*",
"test/**/*"
]
}
44 changes: 0 additions & 44 deletions ti-15770.log

This file was deleted.

0 comments on commit d390f96

Please sign in to comment.