mirror of
https://github.com/ritz078/transform.git
synced 2026-11-21 00:32:56 +03:00
closes #169
This commit is contained in:
1 parent
16cf173411
commit
fea5053ca7
8 files changed
+154
-1491
No files matched your search
@@ -5,3 +5,4 @@ yarn-error.log
|
||||
dist
|
||||
.DS_Store
|
||||
public/static/monaco/*.worker.js.map
|
||||
.tool-versions
|
||||
+1
-3
@@ -296,8 +296,7 @@ export const jsonLdContext = `{
|
||||
"@context": "https://schema.org/"
|
||||
}`;
|
||||
|
||||
export const typescript = `declare module "evergreen-ui" {
|
||||
export interface PaneProps {
|
||||
export const typescript = `export interface PaneProps {
|
||||
elevation?: number;
|
||||
className?: string;
|
||||
css?: any;
|
||||
@@ -323,5 +322,4 @@ export const typescript = `declare module "evergreen-ui" {
|
||||
onClick?: () => void;
|
||||
css?: any;
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -80,12 +80,15 @@
|
||||
"stringify-object": "^3.3.0",
|
||||
"svg-to-dataurl": "^1.0.0",
|
||||
"svgo": "^1.3.0",
|
||||
"tempy": "^0.3.0",
|
||||
"text-encoding-utf-8": "^1.0.2",
|
||||
"transform-json-types": "^0.7.0",
|
||||
"ts-json-schema-generator": "^0.58.1",
|
||||
"xml-js": "^1.6.11",
|
||||
"yaml": "^1.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/helper-create-regexp-features-plugin": "^7.7.4",
|
||||
"@next/bundle-analyzer": "^9.0.2",
|
||||
"@now/node": "^0.12.0",
|
||||
"@types/lodash": "^4.14.135",
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { SchemaGenerator } from "ts-json-schema-generator";
|
||||
import * as ts from "typescript";
|
||||
import { createFormatter } from "ts-json-schema-generator/dist/factory/formatter";
|
||||
import { createParser } from "ts-json-schema-generator/dist/factory/parser";
|
||||
import { createProgram } from "ts-json-schema-generator/dist/factory/program";
|
||||
import { Config } from "ts-json-schema-generator/dist/src/Config";
|
||||
import tempy from "tempy";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
export default (req: NextApiRequest, res: NextApiResponse) => {
|
||||
try {
|
||||
const filePath = tempy.file({ extension: "ts" });
|
||||
fs.writeFileSync(filePath, req.body);
|
||||
const config: Config = {
|
||||
path: path.resolve(filePath),
|
||||
expose: "all",
|
||||
topRef: true,
|
||||
jsDoc: "extended",
|
||||
type: "*"
|
||||
};
|
||||
const program = createProgram(config);
|
||||
|
||||
const generator: SchemaGenerator = new SchemaGenerator(
|
||||
program,
|
||||
createParser(program, config),
|
||||
createFormatter(config)
|
||||
);
|
||||
const schema = generator.createSchema("*");
|
||||
res.status(200).send(schema);
|
||||
} catch (e) {
|
||||
res.status(500).send(e.message);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
import ConversionPanel from "@components/ConversionPanel";
|
||||
import * as React from "react";
|
||||
import { useCallback } from "react";
|
||||
import request from "@utils/request";
|
||||
import { Alert } from "evergreen-ui";
|
||||
|
||||
export default function() {
|
||||
const transformer = useCallback(
|
||||
({ value }) => request("/api/typescript-to-json-schema", value),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<ConversionPanel
|
||||
transformer={transformer}
|
||||
editorTitle="TypeScript"
|
||||
editorLanguage="typescript"
|
||||
resultTitle="JSON Schema"
|
||||
resultLanguage={"json"}
|
||||
resultEditorProps={{
|
||||
topNotifications: () => (
|
||||
<Alert
|
||||
backgroundColor="#e7f7ff"
|
||||
title="This code is converted on the server."
|
||||
/>
|
||||
)
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -8417,7 +8417,7 @@ self.onmessage = function (e) {
|
||||
/*!***************************************************************************************************************!*\
|
||||
!*** ./node_modules/monaco-editor/esm/vs/language/css/_deps/vscode-css-languageservice/cssLanguageService.js ***!
|
||||
\***************************************************************************************************************/
|
||||
/*! exports provided: Position, Range, Location, LocationLink, Color, ColorInformation, ColorPresentation, FoldingRangeKind, FoldingRange, DiagnosticRelatedInformation, DiagnosticSeverity, Diagnostic, Command, TextEdit, TextDocumentEdit, CreateFile, RenameFile, DeleteFile, WorkspaceEdit, WorkspaceChange, TextDocumentIdentifier, VersionedTextDocumentIdentifier, TextDocumentItem, MarkupKind, MarkupContent, CompletionItemKind, InsertTextFormat, CompletionItem, CompletionList, MarkedString, Hover, ParameterInformation, SignatureInformation, DocumentHighlightKind, DocumentHighlight, SymbolKind, SymbolInformation, DocumentSymbol, CodeActionKind, CodeActionContext, CodeAction, CodeLens, FormattingOptions, DocumentLink, EOL, TextDocument, TextDocumentSaveReason, getCSSLanguageService, getSCSSLanguageService, getLESSLanguageService, SelectionRangeKind */
|
||||
/*! exports provided: getCSSLanguageService, getSCSSLanguageService, getLESSLanguageService, Range, TextEdit, Position, SelectionRangeKind, Location, LocationLink, Color, ColorInformation, ColorPresentation, FoldingRangeKind, FoldingRange, DiagnosticRelatedInformation, DiagnosticSeverity, Diagnostic, Command, TextDocumentEdit, CreateFile, RenameFile, DeleteFile, WorkspaceEdit, WorkspaceChange, TextDocumentIdentifier, VersionedTextDocumentIdentifier, TextDocumentItem, MarkupKind, MarkupContent, CompletionItemKind, InsertTextFormat, CompletionItem, CompletionList, MarkedString, Hover, ParameterInformation, SignatureInformation, DocumentHighlightKind, DocumentHighlight, SymbolKind, SymbolInformation, DocumentSymbol, CodeActionKind, CodeActionContext, CodeAction, CodeLens, FormattingOptions, DocumentLink, EOL, TextDocument, TextDocumentSaveReason */
|
||||
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
@@ -263,6 +263,23 @@ export const categorizedRoutes = [
|
||||
packageUrl: "https://github.com/digitalbazaar/jsonld.js"
|
||||
}))
|
||||
},
|
||||
{
|
||||
category: "TypeScript",
|
||||
content: [
|
||||
{
|
||||
label: "to Flow",
|
||||
path: "/typescript-to-flow",
|
||||
packageName: "flowgen",
|
||||
packageUrl: "https://github.com/joarwilk/flowgen"
|
||||
},
|
||||
{
|
||||
label: "to JSON Schema",
|
||||
path: "/typescript-to-json-schema",
|
||||
packageName: "ts-json-schema-generator",
|
||||
packageUrl: "https://github.com/vega/ts-json-schema-generator"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "Others",
|
||||
iconName: "",
|
||||
|
||||
Reference in new issue
Block a user