mirror of
https://github.com/ritz078/transform.git
synced 2026-11-21 08:33:55 +03:00
1 parent
a11f71758a
commit
217b9978cd
7 files changed
+134
-4
No files matched your search
@@ -53,6 +53,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
|
||||
|
||||
<!-- markdownlint-enable -->
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
|
||||
+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,13 +80,16 @@
|
||||
"snack-sdk": "^2.3.1",
|
||||
"stringify-object": "^3.3.0",
|
||||
"svg-to-dataurl": "^1.0.0",
|
||||
"tempy": "^0.3.0",
|
||||
"svgo": "^1.3.2",
|
||||
"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.7.2"
|
||||
},
|
||||
"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,38 @@
|
||||
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),
|
||||
// @ts-ignore
|
||||
createFormatter(config)
|
||||
);
|
||||
const schema = generator.createSchema("*");
|
||||
|
||||
fs.unlink(filePath, () => {});
|
||||
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."
|
||||
/>
|
||||
)
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -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: "",
|
||||
|
||||
@@ -2614,6 +2614,10 @@ commander@~2.8.1:
|
||||
dependencies:
|
||||
graceful-readlink ">= 1.0.0"
|
||||
|
||||
commander@~4.0.1:
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-4.0.1.tgz#b67622721785993182e807f4883633e6401ba53c"
|
||||
|
||||
common-tags@1.8.0:
|
||||
version "1.8.0"
|
||||
resolved "https://registry.yarnpkg.com/common-tags/-/common-tags-1.8.0.tgz#8e3153e542d4a39e9b10554434afaaf98956a937"
|
||||
@@ -4353,6 +4357,17 @@ glob@7.1.4, glob@^7.0.0, glob@^7.0.3, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4:
|
||||
once "^1.3.0"
|
||||
path-is-absolute "^1.0.0"
|
||||
|
||||
glob@~7.1.6:
|
||||
version "7.1.6"
|
||||
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
|
||||
dependencies:
|
||||
fs.realpath "^1.0.0"
|
||||
inflight "^1.0.4"
|
||||
inherits "2"
|
||||
minimatch "^3.0.4"
|
||||
once "^1.3.0"
|
||||
path-is-absolute "^1.0.0"
|
||||
|
||||
global-dirs@^0.1.0:
|
||||
version "0.1.1"
|
||||
resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-0.1.1.tgz#b319c0dd4607f353f3be9cca4c72fc148c49f445"
|
||||
@@ -5462,6 +5477,12 @@ json-schema@0.2.3:
|
||||
version "0.2.3"
|
||||
resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13"
|
||||
|
||||
json-stable-stringify@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz#9a759d39c5f2ff503fd5300646ed445f88c4f9af"
|
||||
dependencies:
|
||||
jsonify "~0.0.0"
|
||||
|
||||
json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
|
||||
@@ -8878,6 +8899,14 @@ tempfile@^2.0.0:
|
||||
temp-dir "^1.0.0"
|
||||
uuid "^3.0.1"
|
||||
|
||||
tempy@^0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/tempy/-/tempy-0.3.0.tgz#6f6c5b295695a16130996ad5ab01a8bd726e8bf8"
|
||||
dependencies:
|
||||
temp-dir "^1.0.0"
|
||||
type-fest "^0.3.1"
|
||||
unique-string "^1.0.0"
|
||||
|
||||
term-size@^1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/term-size/-/term-size-1.2.0.tgz#458b83887f288fc56d6fffbfad262e26638efa69"
|
||||
@@ -9093,6 +9122,16 @@ ts-invariant@^0.4.0:
|
||||
dependencies:
|
||||
tslib "^1.9.3"
|
||||
|
||||
ts-json-schema-generator@^0.58.1:
|
||||
version "0.58.1"
|
||||
resolved "https://registry.yarnpkg.com/ts-json-schema-generator/-/ts-json-schema-generator-0.58.1.tgz#41bce930e53422723646f0b037f33b1b4c8a42d5"
|
||||
dependencies:
|
||||
"@types/json-schema" "^7.0.3"
|
||||
commander "~4.0.1"
|
||||
glob "~7.1.6"
|
||||
json-stable-stringify "^1.0.1"
|
||||
typescript "~3.7.3"
|
||||
|
||||
ts-pnp@^1.1.2:
|
||||
version "1.1.4"
|
||||
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.1.4.tgz#ae27126960ebaefb874c6d7fa4729729ab200d90"
|
||||
@@ -9121,6 +9160,10 @@ type-check@~0.3.2:
|
||||
dependencies:
|
||||
prelude-ls "~1.1.2"
|
||||
|
||||
type-fest@^0.3.1:
|
||||
version "0.3.1"
|
||||
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.3.1.tgz#63d00d204e059474fe5e1b7c011112bbd1dc29e1"
|
||||
|
||||
type-fest@^0.4.1:
|
||||
version "0.4.1"
|
||||
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.4.1.tgz#8bdf77743385d8a4f13ba95f610f5ccd68c728f8"
|
||||
@@ -9162,7 +9205,7 @@ typescript@^2.3.2:
|
||||
version "2.9.2"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c"
|
||||
|
||||
typescript@^3.4:
|
||||
typescript@^3.4, typescript@~3.7.3:
|
||||
version "3.7.4"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.4.tgz#1743a5ec5fef6a1fa9f3e4708e33c81c73876c19"
|
||||
|
||||
|
||||
Reference in new issue
Block a user