Skip to content

Commit

Permalink
chore: Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Sep 4, 2024
1 parent c4c076a commit 28eba68
Show file tree
Hide file tree
Showing 34 changed files with 307 additions and 412 deletions.
5 changes: 4 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ node_modules
/dist
/build
/cache
/coverage
/coverage

/src/__tests__
/jest.snapshots.js
4 changes: 4 additions & 0 deletions esbuild/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
extends: require.resolve('@diplodoc/lint/eslint-config/node'),
root: true,
};
42 changes: 42 additions & 0 deletions esbuild/esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const esbuild = require('esbuild');
const {sassPlugin} = require('esbuild-sass-plugin');
const external = Object.keys(require('../package.json').peerDependencies || {});

[
{minify: false, outfile: 'build/plugin/index.js'},
{minify: true, outfile: 'build/plugin/index.min.js'},
{minify: true, format: 'cjs', outfile: 'build/plugin/cjs/index.min.js'},
].forEach((options) =>
esbuild.build({
tsconfig: './tsconfig.json',
packages: 'external',
platform: 'node',
format: 'esm',
mainFields: ['module', 'main'],
target: 'es2016',
bundle: true,
sourcemap: true,
entryPoints: ['src/plugin/index.ts'],
...options,
}),
);

[
{minify: false, outfile: 'build/runtime/index.js'},
{minify: true, outfile: 'build/runtime/index.min.js'},
{minify: true, format: 'cjs', outfile: 'build/runtime/cjs/index.min.js'},
].forEach((options) =>
esbuild.build({
tsconfig: './tsconfig.json',
platform: 'neutral',
mainFields: ['module', 'main'],
target: 'es2016',
format: 'esm',
bundle: true,
sourcemap: true,
entryPoints: ['src/runtime/index.tsx'],
external,
plugins: [sassPlugin()],
...options,
}),
);
27 changes: 27 additions & 0 deletions esbuild/includer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const glob = require('glob');
const path = require('node:path');
const esbuild = require('esbuild');

const IN_PATH = path.resolve('src', 'includer').replace(/\\/g, '/');
const OUT_PATH = 'build/includer';
const FORMATS = ['cjs', 'esm'];

const tsFiles = glob.sync(`${IN_PATH}/**/*.ts`);

const build = (files, format) =>
Promise.all(
files.map((name) => {
const newFilePath = path.resolve(OUT_PATH, format, name.substring(IN_PATH.length + 1));
const jsFile = newFilePath.replace('.ts', '.js');

return esbuild.build({
format,
target: 'es2016',
entryPoints: [name],
outfile: jsFile,
packages: 'external',
});
}),
);

Promise.all(FORMATS.map((format) => build(tsFiles, format)));
38 changes: 18 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@
},
"exports": {
".": {
"require": "./plugin/cjs/index.min.js",
"production": "./plugin/index.min.js",
"development": "./plugin/index.js",
"default": "./plugin/index.min.js"
"require": "./build/plugin/cjs/index.min.js",
"production": "./build/plugin/index.min.js",
"development": "./build/plugin/index.js",
"default": "./build/plugin/index.min.js"
},
"./includer": {
"require": "./includer/cjs/index.js",
"default": "./includer/esm/index.js",
"types": "./includer/index.d.ts"
"require": "./build/includer/cjs/index.js",
"default": "./build/includer/esm/index.js",
"types": "./build/includer/index.d.ts"
},
"./runtime": {
"require": "./runtime/cjs/index.min.js",
"production": "./runtime/index.min.js",
"development": "./runtime/index.js",
"default": "./runtime/index.min.js"
"require": "./build/runtime/cjs/index.min.js",
"production": "./build/runtime/index.min.js",
"development": "./build/runtime/index.js",
"default": "./build/runtime/index.min.js"
},
"./runtime/styles": {
"production": "./runtime/index.min.css",
"development": "./runtime/index.css",
"default": "./runtime/index.min.css"
"production": "./build/runtime/index.min.css",
"development": "./build/runtime/index.css",
"default": "./build/runtime/index.min.css"
}
},
"scripts": {
"prebuild": "rm -rf plugin includer runtime",
"build": "run-p build:*",
"build:plugin": "node build/esbuild.js",
"build:includer": "node build/includer.js",
"build:declarations": "tsc --emitDeclarationOnly --outDir .",
"build:plugin": "node esbuild/esbuild.js",
"build:includer": "node esbuild/includer.js",
"build:declarations": "tsc --emitDeclarationOnly --outDir ./build",
"prepublishOnly": "npm run build",
"test": "jest",
"typecheck": "tsc --noEmit",
Expand All @@ -47,9 +47,7 @@
"prepare": "husky"
},
"files": [
"plugin",
"runtime",
"includer"
"build"
],
"peerDependencies": {
"@gravity-ui/uikit": "^6.0.0",
Expand Down
31 changes: 15 additions & 16 deletions src/includer/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
import RefsService from './services/refs';
import ArgvService from './services/argv';

import assert from 'assert';
import {dirname, join, resolve} from 'path';
import {mkdir, writeFile} from 'fs/promises';
import {readFileSync} from 'fs';
import {matchFilter} from './utils';

import {dump} from 'js-yaml';
import SwaggerParser from '@apidevtools/swagger-parser';

import {matchFilter} from './utils';
import parsers from './parsers';
import generators from './ui';

import SwaggerParser from '@apidevtools/swagger-parser';

import ArgvService from './services/argv';
import RefsService from './services/refs';
import {
LEADING_PAGE_MODES,
LEADING_PAGE_NAME_DEFAULT,
LeadingPageMode,
SPEC_RENDER_MODES,
SPEC_RENDER_MODE_DEFAULT,
} from './constants';

import {
Endpoint,
IncluderFunctionParams,
Info,
OpenAPISpec,
OpenApiIncluderParams,
OpenJSONSchema,
Refs,
Specification,
V3Endpoint,
V3Info,
YfmPreset,
YfmToc,
YfmTocItem,
Expand Down Expand Up @@ -247,7 +242,7 @@ async function generateContent(params: GenerateContentParams): Promise<void> {

const results: EndpointRoute[] = [];

const info: Info = parsers.info(data);
const info: V3Info = parsers.info(data);
let spec = parsers.paths(data, parsers.tags(data));

if (noindex) {
Expand Down Expand Up @@ -307,14 +302,18 @@ async function generateContent(params: GenerateContentParams): Promise<void> {
}
}

function handleEndpointIncluder(endpoint: Endpoint, pathPrefix: string, sandbox?: {host?: string}) {
function handleEndpointIncluder(
endpoint: V3Endpoint,
pathPrefix: string,
sandbox?: {host?: string},
) {
const path = join(pathPrefix, mdPath(endpoint));
const content = generators.endpoint(endpoint, sandbox);

return {path, content};
}

function handleEndpointRender(endpoint: Endpoint, pathPrefix?: string): YfmToc {
function handleEndpointRender(endpoint: V3Endpoint, pathPrefix?: string): YfmToc {
let path = mdPath(endpoint);
if (pathPrefix) {
path = join(pathPrefix, path);
Expand Down Expand Up @@ -358,11 +357,11 @@ function filterUsefullContent(
};
}

export function sectionName(e: Endpoint): string {
export function sectionName(e: V3Endpoint): string {
return e.summary ?? e.operationId ?? `${e.method} ${e.path}`;
}

export function mdPath(e: Endpoint): string {
export function mdPath(e: V3Endpoint): string {
return `${e.id}.md`;
}

Expand Down
Loading

0 comments on commit 28eba68

Please sign in to comment.