Split off GraphQL input into its own package

This commit is contained in:
Mark Probst 2018-05-14 07:34:18 -07:00
Родитель a682b71de3
Коммит bd8b702561
12 изменённых файлов: 175 добавлений и 103 удалений

85
build/build-utils.js Normal file
Просмотреть файл

@ -0,0 +1,85 @@
"use strict";
const fs = require("fs");
const path = require("path");
const spawnSync = require("child_process").spawnSync;
function mapFile(source, destination, transform) {
const content = fs.readFileSync(source, "utf8");
fs.writeFileSync(destination, transform(content));
}
function writePackage(pkg, core) {
pkg["dependencies"]["quicktype-core"] = core;
fs.writeFileSync("package.json", JSON.stringify(pkg, undefined, 4));
}
function run(cmd, args) {
const result = spawnSync(cmd, args, { stdio: "inherit" });
if (result.error) {
console.log(result.error);
process.exit(1);
}
}
function copyFile(src, dst) {
run("cp", [src, dst]);
}
function endsWith(str, suffix) {
if (str.length < suffix.length) return false;
return str.substr(str.length - suffix.length) === suffix;
}
function replaceAll(content, from, to) {
for (;;) {
const newContent = content.replace(from, to);
if (content === newContent) return content;
content = newContent;
}
}
function ignoreExceptions(f) {
try {
f();
} catch (e) {}
}
function buildPackage(srcDir, coreVersion, publish) {
try {
const pkg = JSON.parse(fs.readFileSync("./package.in.json", "utf8"));
if (!fs.existsSync("src")) {
run("mkdir", ["src"]);
}
for (const fn of fs.readdirSync(srcDir).filter(fn => endsWith(fn, ".ts"))) {
const dstPath = path.join("src", fn);
copyFile(path.join(srcDir, fn), dstPath);
mapFile(dstPath, dstPath, content =>
replaceAll(
content,
'} from "../quicktype-core',
'} from "quicktype-core'
)
);
}
copyFile(path.join(srcDir, "tsconfig.json"), "./");
writePackage(pkg, "file:../quicktype-core");
run("npm", ["install"]);
if (publish) {
writePackage(pkg, coreVersion);
run("npm", ["publish"]);
}
} catch (e) {
console.log(e);
process.exit(1);
} finally {
ignoreExceptions(() => fs.unlinkSync("package.json"));
ignoreExceptions(() => fs.unlinkSync("tsconfig.json"));
ignoreExceptions(() => run("rm", ["-rf", "src"]));
}
}
module.exports = { buildPackage };

Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "quicktype-core",
"version": "0.0.8",
"version": "1.0.0",
"description": "EXPERIMENTAL: The quicktype engine as a library",
"license": "Apache-2.0",
"main": "dist/index.js",
@ -10,8 +10,7 @@
"clean": "rm -rf dist node_modules *~",
"prepare": "npm run build",
"build": "cd ../../src/quicktype-core ; tsc",
"tslint":
"cd ../../src/quicktype-core ; tslint --project . --exclude 'get-stream/**'"
"tslint": "cd ../../src/quicktype-core ; tslint --project . --exclude 'get-stream/**'"
},
"dependencies": {
"@types/urijs": "github:quicktype/types-urijs",
@ -22,8 +21,7 @@
"stream-json": "0.5.2",
"string-to-stream": "^1.1.0",
"unicode-properties": "github:quicktype/unicode-properties#dist",
"urijs": "^1.19.1",
"graphql": "^0.11.7"
"urijs": "^1.19.1"
},
"devDependencies": {
"@types/js-base64": "^2.3.1",
@ -34,5 +32,7 @@
"typescript": "~2.8.3",
"tslint": "^5.9.1"
},
"files": ["dist/**"]
"files": [
"dist/**"
]
}

Просмотреть файл

@ -0,0 +1,5 @@
"use strict";
const buildPackage = require("../build-utils").buildPackage;
buildPackage("../../src/quicktype-graphql-input", "^1.0.0", false);

Просмотреть файл

@ -0,0 +1,26 @@
{
"name": "quicktype-typescript-input",
"version": "0.0.1",
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": "https://github.com/quicktype/quicktype",
"scripts": {
"clean": "rm -rf dist node_modules *~",
"prepare": "npm run build",
"build": "tsc",
"tslint": "tslint --project ."
},
"dependencies": {
"quicktype-core": "^0.0.5",
"immutable": "^4.0.0-rc.9",
"typescript": "~2.8.3",
"typescript-json-schema":
"quicktype/typescript-json-schema#d16083d29c8b6702c666a981fa6b21113300c059"
},
"devDependencies": {
"@types/node": "^8.10.10",
"tslint": "^5.9.1"
},
"files": ["dist/**"]
}

Просмотреть файл

@ -1,76 +1,5 @@
"use strict";
const fs = require("fs");
const path = require("path");
const spawnSync = require("child_process").spawnSync;
const buildPackage = require("../build-utils").buildPackage;
const pkg = require("./package.in.json");
function mapFile(source, destination, transform) {
const content = fs.readFileSync(source, "utf8");
fs.writeFileSync(destination, transform(content));
}
function writePackage(core) {
pkg["dependencies"]["quicktype-core"] = core;
fs.writeFileSync("package.json", JSON.stringify(pkg, undefined, 4));
}
function run(cmd, args) {
const result = spawnSync(cmd, args, { stdio: "inherit" });
if (result.error) {
console.log(result.error);
process.exit(1);
}
}
function copyFile(src, dst) {
run("cp", [src, dst]);
}
function endsWith(str, suffix) {
if (str.length < suffix.length) return false;
return str.substr(str.length - suffix.length) === suffix;
}
function replaceAll(content, from, to) {
for (;;) {
const newContent = content.replace(from, to);
if (content === newContent) return content;
content = newContent;
}
}
function ignoreExceptions(f) {
try {
f();
} catch (e) {}
}
try {
if (!fs.existsSync("src")) {
run("mkdir", ["src"]);
}
const srcDir = "../../src/quicktype-typescript-input";
for (const fn of fs.readdirSync(srcDir).filter(fn => endsWith(fn, ".ts"))) {
const dstPath = path.join("src", fn);
copyFile(path.join(srcDir, fn), dstPath);
mapFile(dstPath, dstPath, content =>
replaceAll(content, '} from "../quicktype-core', '} from "quicktype-core')
);
}
copyFile(path.join(srcDir, "tsconfig.json"), "./");
writePackage("file:../quicktype-core");
run("npm", ["install"]);
// writePackage("^0.0.6");
// run("npm", ["publish"]);
} catch (e) {
console.log(e);
process.exit(1);
} finally {
ignoreExceptions(() => fs.unlinkSync("package.json"));
ignoreExceptions(() => fs.unlinkSync("tsconfig.json"));
ignoreExceptions(() => run("rm", ["-rf", "src"]));
}
buildPackage("../../src/quicktype-typescript-input", "^1.0.0", false);

Просмотреть файл

@ -1,5 +1,5 @@
{
"name": "quicktype-typescript-input",
"name": "quicktype-graphql-input",
"version": "0.0.1",
"license": "Apache-2.0",
"main": "dist/index.js",
@ -12,14 +12,13 @@
"tslint": "tslint --project ."
},
"dependencies": {
"quicktype-core": "^0.0.5",
"quicktype-core": "^1.0.0",
"immutable": "^4.0.0-rc.9",
"typescript": "~2.8.3",
"typescript-json-schema":
"quicktype/typescript-json-schema#d16083d29c8b6702c666a981fa6b21113300c059"
"graphql": "^0.11.7"
},
"devDependencies": {
"@types/node": "^8.10.10",
"typescript": "~2.8.3",
"tslint": "^5.9.1"
},
"files": ["dist/**"]

Просмотреть файл

@ -45,10 +45,6 @@ function makeDistributedCLIExecutable() {
function main() {
const skipPrereqs = !!process.env.SKIP_INSTALL_PREREQUISITES;
if (!skipPrereqs) {
installPrereqs();
}
buildTypeScript();
makeDistributedCLIExecutable();
}

Просмотреть файл

@ -15,7 +15,6 @@ import {
InputData,
JSONInput,
JSONSchemaInput,
GraphQLInput,
CompressedJSON,
StringInput,
OptionDefinition,
@ -35,6 +34,8 @@ import {
messageAssert,
sourcesFromPostmanCollection
} from "../quicktype-core";
import { schemaForTypeScriptSources } from "../quicktype-typescript-input";
import { GraphQLInput } from "../quicktype-graphql-input";
import { urlsFromURLGrammar } from "./URLGrammar";
import { Readable } from "stream";
@ -50,7 +51,6 @@ import {
} from "./TypeSource";
import { readableFromFileOrURL, readFromFileOrURL, FetchingJSONSchemaStore } from "./NodeIO";
import * as telemetry from "./telemetry";
import { schemaForTypeScriptSources } from "../quicktype-typescript-input";
const commandLineArgs = require("command-line-args");
const getUsage = require("command-line-usage");

Просмотреть файл

@ -9,8 +9,7 @@ export {
languageNamed
} from "./Run";
export { CompressedJSON } from "./input/CompressedJSON";
export { InputData, JSONInput, JSONSourceData, JSONSchemaInput, JSONSchemaSourceData } from "./input/Inputs";
export { GraphQLInput } from "./GraphQL";
export { Input, InputData, JSONInput, JSONSourceData, JSONSchemaInput, JSONSchemaSourceData } from "./input/Inputs";
export { OptionDefinition } from "./RendererOptions";
export { all as defaultTargetLanguages } from "./language/All";
export { Annotation } from "./Source";
@ -27,10 +26,17 @@ export {
checkStringMap,
checkArray,
inflateBase64,
StringInput
StringInput,
toString
} from "./support/Support";
export { getStream } from "./get-stream/index";
export { train as trainMarkovChain } from "./MarkovChain";
export { QuickTypeError, messageError, messageAssert } from "./Messages";
export { UnionType, ClassProperty, TypeKind } from "./Type";
export { JSONSchemaStore, JSONSchema } from "./input/JSONSchemaStore";
export { sourcesFromPostmanCollection } from "./input/PostmanCollection";
export { TypeBuilder, TypeRef } from "./TypeBuilder";
export { TypeAttributes, emptyTypeAttributes } from "./TypeAttributes";
export { TypeNames, makeNamesTypeAttributes, namesTypeAttributeKind } from "./TypeNames";
export { StringTypes } from "./StringTypes";
export { removeNullFromUnion } from "./TypeUtils";

Просмотреть файл

@ -2,9 +2,6 @@
import { List, Map, OrderedSet, OrderedMap } from "immutable";
import { UnionType, ClassProperty } from "./Type";
import { removeNullFromUnion } from "./TypeUtils";
import { GraphQLSchema, TypeKind } from "./GraphQLSchema";
import {
DocumentNode,
SelectionSetNode,
@ -14,14 +11,29 @@ import {
DirectiveNode,
FieldNode
} from "graphql/language/ast";
import { assertNever, panic, toString, StringInput } from "./support/Support";
import { TypeBuilder, TypeRef } from "./TypeBuilder";
import * as graphql from "graphql/language";
import { TypeNames, makeNamesTypeAttributes, namesTypeAttributeKind } from "./TypeNames";
import { TypeAttributes, emptyTypeAttributes } from "./TypeAttributes";
import { messageAssert } from "./Messages";
import { StringTypes } from "./StringTypes";
import { Input } from "./input/Inputs";
import {
UnionType,
ClassProperty,
removeNullFromUnion,
assertNever,
panic,
toString,
StringInput,
TypeBuilder,
TypeRef,
TypeNames,
makeNamesTypeAttributes,
namesTypeAttributeKind,
messageAssert,
TypeAttributes,
emptyTypeAttributes,
StringTypes,
Input
} from "../quicktype-core";
import { TypeKind, GraphQLSchema } from "./GraphQLSchema";
interface GQLType {
kind: TypeKind;

Просмотреть файл

@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["es2015", "esnext.asynciterable"],
"allowJs": false,
"declaration": true,
"strict": true,
"alwaysStrict": true,
"outDir": "dist",
"noUnusedLocals": true,
"noUnusedParameters": true
}
}