This commit is contained in:
Mark Probst 2018-03-15 15:21:15 -07:00
Родитель f6fa99329b
Коммит a8830c4443
3 изменённых файлов: 39 добавлений и 8 удалений

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

@ -121,6 +121,8 @@ export class TypeGraph {
private _parents: Set<Type>[] | undefined = undefined;
private _printOnRewrite: boolean = false;
constructor(typeBuilder: TypeBuilder, private readonly _haveProvenanceAttributes: boolean) {
this._typeBuilder = typeBuilder;
}
@ -214,6 +216,10 @@ export class TypeGraph {
}).reduce<Set<TypeRef>>((a, b) => a.union(b));
}
setPrintOnRewrite(): void {
this._printOnRewrite = true;
}
// Each array in `replacementGroups` is a bunch of types to be replaced by a
// single new type. `replacer` is a function that takes a group and a
// TypeBuilder, and builds a new type with that builder that replaces the group.
@ -250,8 +256,11 @@ export class TypeGraph {
}
}
// console.log(`\n# ${title}`);
// this.printGraph();
if (this._printOnRewrite) {
newGraph.setPrintOnRewrite();
console.log(`\n# ${title}`);
newGraph.printGraph();
}
return newGraph;
}

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

@ -65,6 +65,7 @@ export interface CLIOptions {
help: boolean;
quiet: boolean;
version: boolean;
debug?: string;
}
async function sourceFromFileOrUrlArray(name: string, filesOrUrls: string[]): Promise<JSONTypeSource> {
@ -241,7 +242,8 @@ function inferOptions(opts: Partial<CLIOptions>): CLIOptions {
graphqlIntrospect: opts.graphqlIntrospect,
graphqlServerHeader: opts.graphqlServerHeader,
addSchemaTopLevel: opts.addSchemaTopLevel,
template: opts.template
template: opts.template,
debug: opts.debug
};
/* tslint:enable */
}
@ -372,6 +374,12 @@ const optionDefinitions: OptionDefinition[] = [
type: Boolean,
description: "Don't show issues in the generated code."
},
{
name: "debug",
type: String,
typeLabel: "OPTIONS",
description: "Comma separated debug options: print-graph"
},
{
name: "help",
alias: "h",
@ -644,6 +652,12 @@ export async function main(args: string[] | Partial<CLIOptions>) {
handlebarsTemplate = fs.readFileSync(options.template, "utf8");
}
let debugPrintGraph = false;
if (options.debug !== undefined) {
assert(options.debug === "print-graph", "The --debug option must be \"print-graph\"");
debugPrintGraph = true;
}
let run = new Run({
lang: options.lang,
sources,
@ -660,7 +674,8 @@ export async function main(args: string[] | Partial<CLIOptions>) {
handlebarsTemplate,
findSimilarClassesSchemaURI: options.findSimilarClassesSchema,
outputFilename: options.out !== undefined ? path.basename(options.out) : undefined,
schemaStore: new FetchingJSONSchemaStore()
schemaStore: new FetchingJSONSchemaStore(),
debugPrintGraph
});
const resultsByFilename = await run.run();

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

@ -97,6 +97,7 @@ export interface Options {
indentation: string | undefined;
outputFilename: string;
schemaStore: JSONSchemaStore | undefined;
debugPrintGraph: boolean | undefined;
}
const defaultOptions: Options = {
@ -116,7 +117,8 @@ const defaultOptions: Options = {
rendererOptions: {},
indentation: undefined,
outputFilename: "stdout",
schemaStore: undefined
schemaStore: undefined,
debugPrintGraph: false
};
type InputData = {
@ -224,7 +226,10 @@ export class Run {
}
let graph = typeBuilder.finish();
// graph.printGraph();
if (this._options.debugPrintGraph) {
graph.setPrintOnRewrite();
graph.printGraph();
}
if (haveSchemas) {
let intersectionsDone = false;
@ -272,8 +277,10 @@ export class Run {
graph = graph.garbageCollect(this._options.alphabetizeProperties);
gatherNames(graph);
// graph.printGraph();
if (this._options.debugPrintGraph) {
console.log("\n# gather names");
graph.printGraph();
}
return graph;
}