Skip to content

Commit 0b00659

Browse files
committed
🎨 Apply prettier
1 parent bb4d11f commit 0b00659

File tree

6 files changed

+80
-80
lines changed

6 files changed

+80
-80
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dev": "ts-node --files src/cli",
1010
"prepack": "npm run build",
1111
"test": "jest",
12-
"lint:fix": "prettier --write src/**"
12+
"fmt": "prettier --write src/**"
1313
},
1414
"bin": "dist/cli.js",
1515
"files": [

src/__tests__/diff.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe("getDiff", () => {
1010
const introspectionQueryBody = JSON.stringify({
1111
query: print(parse(getIntrospectionQuery({ descriptions: true }))),
1212
variables: {},
13-
operationName: "IntrospectionQuery"
13+
operationName: "IntrospectionQuery",
1414
});
1515

1616
it("fetches remote schema successfully", async () => {
@@ -38,8 +38,8 @@ describe("getDiff", () => {
3838
testRemoteSchemaLocation,
3939
{
4040
headers: {
41-
Test: "test"
42-
}
41+
Test: "test",
42+
},
4343
}
4444
);
4545
expect(result).toBeUndefined();
@@ -62,14 +62,14 @@ describe("getDiff", () => {
6262
{
6363
leftSchema: {
6464
headers: {
65-
Test: "left"
66-
}
65+
Test: "left",
66+
},
6767
},
6868
rightSchema: {
6969
headers: {
70-
Test: "right"
71-
}
72-
}
70+
Test: "right",
71+
},
72+
},
7373
}
7474
);
7575
expect(result).toBeUndefined();
@@ -93,18 +93,18 @@ describe("getDiff", () => {
9393
testRemoteRightSchemaLocation,
9494
{
9595
headers: {
96-
Global: "merged"
96+
Global: "merged",
9797
},
9898
leftSchema: {
9999
headers: {
100-
Test: "left"
101-
}
100+
Test: "left",
101+
},
102102
},
103103
rightSchema: {
104104
headers: {
105-
Test: "right"
106-
}
107-
}
105+
Test: "right",
106+
},
107+
},
108108
}
109109
);
110110
expect(result).toBeUndefined();
@@ -205,8 +205,8 @@ describe("getDiff", () => {
205205
expect(result.dangerousChanges).toEqual([
206206
{
207207
description: "SECOND_VALUE was added to enum type TestEnum.",
208-
type: "VALUE_ADDED_TO_ENUM"
209-
}
208+
type: "VALUE_ADDED_TO_ENUM",
209+
},
210210
]);
211211
}
212212
});
@@ -223,8 +223,8 @@ describe("getDiff", () => {
223223
expect(result.breakingChanges).toEqual([
224224
{
225225
description: "Query.test changed type from String to Int.",
226-
type: "FIELD_CHANGED_KIND"
227-
}
226+
type: "FIELD_CHANGED_KIND",
227+
},
228228
]);
229229
}
230230
});

src/cli.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env node
22

3-
import meow from 'meow';
4-
import chalk from 'chalk';
5-
import { createHtmlOutput } from './html';
6-
import { getDiff, Headers } from './diff';
3+
import meow from "meow";
4+
import chalk from "chalk";
5+
import { createHtmlOutput } from "./html";
6+
import { getDiff, Headers } from "./diff";
77

88
const cli = meow(
99
`
@@ -29,46 +29,46 @@ const cli = meow(
2929
{
3030
flags: {
3131
"fail-on-dangerous-changes": {
32-
type: "boolean"
32+
type: "boolean",
3333
},
3434
"fail-on-breaking-changes": {
35-
type: "boolean"
35+
type: "boolean",
3636
},
3737
"fail-on-all-changes": {
38-
type: "boolean"
38+
type: "boolean",
3939
},
4040
"use-colors": {
41-
type: "boolean"
41+
type: "boolean",
4242
},
4343
"create-html-output": {
44-
type: "boolean"
44+
type: "boolean",
4545
},
4646
"html-output-directory": {
4747
type: "string",
48-
default: "schemaDiff"
48+
default: "schemaDiff",
4949
},
5050
header: {
5151
type: "string",
52-
alias: "H"
52+
alias: "H",
5353
},
5454
"left-schema-header": {
55-
type: "string"
55+
type: "string",
5656
},
5757
"right-schema-header": {
58-
type: "string"
58+
type: "string",
5959
},
6060
"sort-schema": {
6161
type: "boolean",
62-
alias: "s"
63-
}
64-
}
62+
alias: "s",
63+
},
64+
},
6565
}
6666
);
6767

6868
function parseHeaders(headerInput?: string | string[]): Headers | undefined {
6969
let headers: string[][];
7070
const parseHeader = (header: string): string[] =>
71-
header.split(':').map((val: string) => val.trim());
71+
header.split(":").map((val: string) => val.trim());
7272

7373
if (!headerInput) return;
7474

@@ -81,7 +81,7 @@ function parseHeaders(headerInput?: string | string[]): Headers | undefined {
8181
return headers.reduce(
8282
(result, [key, value]) => ({
8383
...result,
84-
...(key && value && { [key]: value })
84+
...(key && value && { [key]: value }),
8585
}),
8686
{}
8787
);
@@ -91,7 +91,7 @@ const [leftSchemaLocation, rightSchemaLocation]: string[] = cli.input;
9191
const {
9292
header,
9393
leftSchemaHeader,
94-
rightSchemaHeader
94+
rightSchemaHeader,
9595
}: {
9696
header?: string | string[];
9797
leftSchemaHeader?: string | string[];
@@ -100,10 +100,10 @@ const {
100100

101101
if (!leftSchemaLocation || !rightSchemaLocation) {
102102
console.error(
103-
chalk.red('ERROR: Schema locations missing!\n\n'),
103+
chalk.red("ERROR: Schema locations missing!\n\n"),
104104
chalk.gray(
105-
'Usage\n' +
106-
' $ graphql-schema-diff <leftSchemaLocation> <rightSchemaLocation>'
105+
"Usage\n" +
106+
" $ graphql-schema-diff <leftSchemaLocation> <rightSchemaLocation>"
107107
)
108108
);
109109
process.exit(1);
@@ -112,16 +112,16 @@ if (!leftSchemaLocation || !rightSchemaLocation) {
112112
getDiff(leftSchemaLocation, rightSchemaLocation, {
113113
headers: parseHeaders(header),
114114
leftSchema: {
115-
headers: parseHeaders(leftSchemaHeader)
115+
headers: parseHeaders(leftSchemaHeader),
116116
},
117117
rightSchema: {
118-
headers: parseHeaders(rightSchemaHeader)
118+
headers: parseHeaders(rightSchemaHeader),
119119
},
120-
sortSchema: cli.flags.sortSchema as boolean
120+
sortSchema: cli.flags.sortSchema as boolean,
121121
})
122-
.then(async result => {
122+
.then(async (result) => {
123123
if (result === undefined) {
124-
console.warn(chalk.green('✔ No changes'));
124+
console.warn(chalk.green("✔ No changes"));
125125
return;
126126
}
127127

@@ -135,10 +135,10 @@ getDiff(leftSchemaLocation, rightSchemaLocation, {
135135
}
136136

137137
if (hasDangerousChanges) {
138-
console.warn(chalk.yellow.bold.underline('Dangerous changes'));
138+
console.warn(chalk.yellow.bold.underline("Dangerous changes"));
139139

140140
for (const change of result.dangerousChanges) {
141-
console.warn(chalk.yellow('' + change.description));
141+
console.warn(chalk.yellow("" + change.description));
142142
}
143143
}
144144

@@ -147,16 +147,16 @@ getDiff(leftSchemaLocation, rightSchemaLocation, {
147147
}
148148

149149
if (hasBreakingChanges) {
150-
console.warn(chalk.red.bold.underline('BREAKING CHANGES'));
150+
console.warn(chalk.red.bold.underline("BREAKING CHANGES"));
151151

152152
for (const change of result.breakingChanges) {
153-
console.warn(chalk.red('' + change.description));
153+
console.warn(chalk.red("" + change.description));
154154
}
155155
}
156156

157157
if (cli.flags.createHtmlOutput) {
158158
await createHtmlOutput(result.diffNoColor, {
159-
outputDirectory: cli.flags.htmlOutputDirectory as string | undefined
159+
outputDirectory: cli.flags.htmlOutputDirectory as string | undefined,
160160
});
161161
}
162162

@@ -169,7 +169,7 @@ getDiff(leftSchemaLocation, rightSchemaLocation, {
169169
return;
170170
}
171171
})
172-
.catch(err => {
172+
.catch((err) => {
173173
console.error(chalk.red(`\nERROR: ${err.message}`));
174174
process.exit(1);
175175
});

src/diff.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
findBreakingChanges,
44
findDangerousChanges,
55
DangerousChange,
6-
BreakingChange
6+
BreakingChange,
77
} from "graphql";
88
import { lexicographicSortSchema } from "graphql/utilities";
99
import disparity from "disparity";
@@ -40,26 +40,26 @@ export async function getDiff(
4040
const leftSchemaOptions = {
4141
headers: {
4242
...options.headers,
43-
...(options.leftSchema && options.leftSchema.headers)
43+
...(options.leftSchema && options.leftSchema.headers),
4444
},
45-
skipGraphQLImport: false
45+
skipGraphQLImport: false,
4646
};
4747
const rightSchemaOptions = {
4848
headers: {
4949
...options.headers,
50-
...(options.rightSchema && options.rightSchema.headers)
50+
...(options.rightSchema && options.rightSchema.headers),
5151
},
52-
skipGraphQLImport: false
52+
skipGraphQLImport: false,
5353
};
5454
let [leftSchema, rightSchema] = await Promise.all([
5555
loadSchema(leftSchemaLocation, {
5656
loaders: [new UrlLoader(), new JsonFileLoader(), new GraphQLFileLoader()],
57-
...leftSchemaOptions
57+
...leftSchemaOptions,
5858
}),
5959
loadSchema(rightSchemaLocation, {
6060
loaders: [new UrlLoader(), new JsonFileLoader(), new GraphQLFileLoader()],
61-
...rightSchemaOptions
62-
})
61+
...rightSchemaOptions,
62+
}),
6363
]);
6464

6565
if (!leftSchema || !rightSchema) {
@@ -69,24 +69,24 @@ export async function getDiff(
6969
if (options.sortSchema) {
7070
[leftSchema, rightSchema] = [
7171
lexicographicSortSchema(leftSchema),
72-
lexicographicSortSchema(rightSchema)
72+
lexicographicSortSchema(rightSchema),
7373
];
7474
}
7575

7676
const [leftSchemaSDL, rightSchemaSDL] = [
7777
printSchema(leftSchema),
78-
printSchema(rightSchema)
78+
printSchema(rightSchema),
7979
];
8080

8181
if (leftSchemaSDL === rightSchemaSDL) {
8282
return;
8383
}
8484

8585
const diff = disparity.unified(leftSchemaSDL, rightSchemaSDL, {
86-
paths: [leftSchemaLocation, rightSchemaLocation]
86+
paths: [leftSchemaLocation, rightSchemaLocation],
8787
});
8888
const diffNoColor = disparity.unifiedNoColor(leftSchemaSDL, rightSchemaSDL, {
89-
paths: [leftSchemaLocation, rightSchemaLocation]
89+
paths: [leftSchemaLocation, rightSchemaLocation],
9090
});
9191
const dangerousChanges = findDangerousChanges(leftSchema, rightSchema);
9292
const breakingChanges = findBreakingChanges(leftSchema, rightSchema);
@@ -95,6 +95,6 @@ export async function getDiff(
9595
diff,
9696
diffNoColor,
9797
dangerousChanges,
98-
breakingChanges
98+
breakingChanges,
9999
};
100100
}

src/html.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import path from 'path';
2-
import fs from 'fs-extra';
3-
import { Diff2Html } from 'diff2html';
1+
import path from "path";
2+
import fs from "fs-extra";
3+
import { Diff2Html } from "diff2html";
44

55
const htmlTemplate = (diffHtml: string): string => `<html>
66
<head>
@@ -27,22 +27,22 @@ export async function createHtmlOutput(
2727
diff: string,
2828
options: Options = {}
2929
): Promise<void> {
30-
const { outputDirectory = 'schemaDiff' } = options;
30+
const { outputDirectory = "schemaDiff" } = options;
3131

3232
const adjustedDiff = diff
33-
.replace(/(---\s.*)\sremoved/, '$1')
34-
.replace(/(\+\+\+\s.*)\sadded/, '$1');
33+
.replace(/(---\s.*)\sremoved/, "$1")
34+
.replace(/(\+\+\+\s.*)\sadded/, "$1");
3535
const diffHtml = Diff2Html.getPrettyHtml(adjustedDiff, {
36-
inputFormat: 'diff',
37-
matching: 'lines',
38-
outputFormat: 'side-by-side',
36+
inputFormat: "diff",
37+
matching: "lines",
38+
outputFormat: "side-by-side",
3939
rawTemplates: {
40-
'tag-file-renamed': ''
41-
}
40+
"tag-file-renamed": "",
41+
},
4242
});
4343
await fs.ensureDir(outputDirectory);
44-
const diff2HtmlPath = path.dirname(require.resolve('diff2html/package.json'));
45-
await fs.copy(path.join(diff2HtmlPath, 'dist'), outputDirectory);
44+
const diff2HtmlPath = path.dirname(require.resolve("diff2html/package.json"));
45+
await fs.copy(path.join(diff2HtmlPath, "dist"), outputDirectory);
4646
const htmlOutput = htmlTemplate(diffHtml);
47-
await fs.writeFile(path.join(outputDirectory, 'index.html'), htmlOutput);
47+
await fs.writeFile(path.join(outputDirectory, "index.html"), htmlOutput);
4848
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { getDiff } from './diff';
1+
export { getDiff } from "./diff";

0 commit comments

Comments
 (0)