Skip to content

Commit 34ad760

Browse files
committed
[TS] Elimate newlines at beginning of file and add newline at end of file
1 parent 6570f72 commit 34ad760

4 files changed

Lines changed: 287 additions & 358 deletions

File tree

packages/apollo-cli/src/commands/codegen/__tests__/__snapshots__/generate.test.ts.snap

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,7 @@ public final class SimpleQueryQuery: GraphQLQuery {
311311
`;
312312

313313
exports[`successful codegen infers TypeScript target and writes types 1`] = `
314-
"
315-
316-
/* tslint:disable */
314+
"/* tslint:disable */
317315
// This file was automatically generated and should not be edited.
318316
319317
// ====================================================
@@ -333,13 +331,12 @@ export interface SimpleQuery {
333331
334332
//==============================================================
335333
// END Enums and Input Objects
336-
//=============================================================="
334+
//==============================================================
335+
"
337336
`;
338337

339338
exports[`successful codegen infers TypeScript target and writes types for query with client-side data 1`] = `
340-
"
341-
342-
/* tslint:disable */
339+
"/* tslint:disable */
343340
// This file was automatically generated and should not be edited.
344341
345342
// ====================================================
@@ -376,13 +373,12 @@ export interface SimpleQuery {
376373
377374
//==============================================================
378375
// END Enums and Input Objects
379-
//=============================================================="
376+
//==============================================================
377+
"
380378
`;
381379

382380
exports[`successful codegen infers TypeScript target and writes types for query with client-side data with schema in a JS file 1`] = `
383-
"
384-
385-
/* tslint:disable */
381+
"/* tslint:disable */
386382
// This file was automatically generated and should not be edited.
387383
388384
// ====================================================
@@ -419,13 +415,12 @@ export interface SimpleQuery {
419415
420416
//==============================================================
421417
// END Enums and Input Objects
422-
//=============================================================="
418+
//==============================================================
419+
"
423420
`;
424421

425422
exports[`successful codegen infers TypeScript target and writes types for query with client-side data with schema in a JS file from config 1`] = `
426-
"
427-
428-
/* tslint:disable */
423+
"/* tslint:disable */
429424
// This file was automatically generated and should not be edited.
430425
431426
// ====================================================
@@ -462,13 +457,12 @@ export interface SimpleQuery {
462457
463458
//==============================================================
464459
// END Enums and Input Objects
465-
//=============================================================="
460+
//==============================================================
461+
"
466462
`;
467463

468464
exports[`successful codegen infers TypeScript target and writes types for query with only client-side data 1`] = `
469-
"
470-
471-
/* tslint:disable */
465+
"/* tslint:disable */
472466
// This file was automatically generated and should not be edited.
473467
474468
// ====================================================
@@ -493,7 +487,8 @@ export interface SimpleQuery {
493487
494488
//==============================================================
495489
// END Enums and Input Objects
496-
//=============================================================="
490+
//==============================================================
491+
"
497492
`;
498493

499494
exports[`successful codegen writes Flow types into a __generated__ directory next to sources when no output is set 1`] = `
@@ -581,9 +576,7 @@ export type SimpleQuery = {
581576
`;
582577

583578
exports[`successful codegen writes TypeScript types into a __generated__ directory next to sources when no output is set 1`] = `
584-
"
585-
586-
/* tslint:disable */
579+
"/* tslint:disable */
587580
// This file was automatically generated and should not be edited.
588581
589582
// ====================================================
@@ -592,13 +585,12 @@ exports[`successful codegen writes TypeScript types into a __generated__ directo
592585
593586
export interface SimpleQuery {
594587
hello: string;
595-
}"
588+
}
589+
"
596590
`;
597591

598592
exports[`successful codegen writes TypeScript types into a __generated__ directory next to sources when no output is set 2`] = `
599-
"
600-
601-
/* tslint:disable */
593+
"/* tslint:disable */
602594
// This file was automatically generated and should not be edited.
603595
604596
//==============================================================
@@ -607,13 +599,12 @@ exports[`successful codegen writes TypeScript types into a __generated__ directo
607599
608600
//==============================================================
609601
// END Enums and Input Objects
610-
//=============================================================="
602+
//==============================================================
603+
"
611604
`;
612605

613606
exports[`successful codegen writes TypeScript types next to sources when output is set to empty string 1`] = `
614-
"
615-
616-
/* tslint:disable */
607+
"/* tslint:disable */
617608
// This file was automatically generated and should not be edited.
618609
619610
// ====================================================
@@ -622,13 +613,12 @@ exports[`successful codegen writes TypeScript types next to sources when output
622613
623614
export interface SimpleQuery {
624615
hello: string;
625-
}"
616+
}
617+
"
626618
`;
627619

628620
exports[`successful codegen writes TypeScript types next to sources when output is set to empty string 2`] = `
629-
"
630-
631-
/* tslint:disable */
621+
"/* tslint:disable */
632622
// This file was automatically generated and should not be edited.
633623
634624
//==============================================================
@@ -637,13 +627,12 @@ exports[`successful codegen writes TypeScript types next to sources when output
637627
638628
//==============================================================
639629
// END Enums and Input Objects
640-
//=============================================================="
630+
//==============================================================
631+
"
641632
`;
642633

643634
exports[`successful codegen writes TypeScript types to a custom directory next to sources when output is set 1`] = `
644-
"
645-
646-
/* tslint:disable */
635+
"/* tslint:disable */
647636
// This file was automatically generated and should not be edited.
648637
649638
// ====================================================
@@ -652,13 +641,12 @@ exports[`successful codegen writes TypeScript types to a custom directory next t
652641
653642
export interface SimpleQuery {
654643
hello: string;
655-
}"
644+
}
645+
"
656646
`;
657647

658648
exports[`successful codegen writes TypeScript types to a custom directory next to sources when output is set 2`] = `
659-
"
660-
661-
/* tslint:disable */
649+
"/* tslint:disable */
662650
// This file was automatically generated and should not be edited.
663651
664652
//==============================================================
@@ -667,7 +655,8 @@ exports[`successful codegen writes TypeScript types to a custom directory next t
667655
668656
//==============================================================
669657
// END Enums and Input Objects
670-
//=============================================================="
658+
//==============================================================
659+
"
671660
`;
672661

673662
exports[`successful codegen writes exact Flow types when the flag is set 1`] = `

packages/apollo-cli/src/generate.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,29 @@ import * as path from "path";
33

44
import { loadAndMergeQueryDocuments } from "apollo-codegen-core/lib/loading";
55
import { validateQueryDocument } from "./validation";
6-
import { compileToIR, CompilerContext, CompilerOptions } from "apollo-codegen-core/lib/compiler";
7-
import { compileToLegacyIR, CompilerOptions as LegacyCompilerOptions } from "apollo-codegen-core/lib/compiler/legacyIR";
6+
import {
7+
compileToIR,
8+
CompilerContext,
9+
CompilerOptions
10+
} from "apollo-codegen-core/lib/compiler";
11+
import {
12+
compileToLegacyIR,
13+
CompilerOptions as LegacyCompilerOptions
14+
} from "apollo-codegen-core/lib/compiler/legacyIR";
815
import serializeToJSON from "apollo-codegen-core/lib/serializeToJSON";
916
import { BasicGeneratedFile } from "apollo-codegen-core/lib/utilities/CodeGenerator";
1017

1118
import { generateSource as generateSwiftSource } from "apollo-codegen-swift";
1219
import { generateSource as generateTypescriptLegacySource } from "apollo-codegen-typescript-legacy";
1320
import { generateSource as generateFlowLegacySource } from "apollo-codegen-flow-legacy";
1421
import { generateSource as generateFlowSource } from "apollo-codegen-flow";
15-
import { generateLocalSource as generateTypescriptLocalSource, generateGlobalSource as generateTypescriptGlobalSource } from "apollo-codegen-typescript";
22+
import {
23+
generateLocalSource as generateTypescriptLocalSource,
24+
generateGlobalSource as generateTypescriptGlobalSource
25+
} from "apollo-codegen-typescript";
1626
import { generateSource as generateScalaSource } from "apollo-codegen-scala";
1727
import { GraphQLSchema } from "graphql";
18-
import { FlowCompilerOptions } from '../../apollo-codegen-flow/lib/language';
28+
import { FlowCompilerOptions } from "../../apollo-codegen-flow/lib/language";
1929

2030
export type TargetType =
2131
| "json"
@@ -28,7 +38,9 @@ export type TargetType =
2838
| "typescript"
2939
| "ts";
3040

31-
export type GenerationOptions = CompilerOptions & LegacyCompilerOptions & FlowCompilerOptions;
41+
export type GenerationOptions = CompilerOptions &
42+
LegacyCompilerOptions &
43+
FlowCompilerOptions;
3244

3345
export default function generate(
3446
inputPaths: string[],
@@ -46,7 +58,7 @@ export default function generate(
4658

4759
validateQueryDocument(schema, document);
4860

49-
if (outputPath.split('.').length <= 1 && !fs.existsSync(outputPath)) {
61+
if (outputPath.split(".").length <= 1 && !fs.existsSync(outputPath)) {
5062
fs.mkdirSync(outputPath);
5163
}
5264

@@ -95,9 +107,10 @@ export default function generate(
95107
writeGeneratedFiles(outFiles, path.resolve("."));
96108

97109
writtenFiles += Object.keys(outFiles).length;
98-
}
99-
100-
else if (fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory()) {
110+
} else if (
111+
fs.existsSync(outputPath) &&
112+
fs.statSync(outputPath).isDirectory()
113+
) {
101114
generatedFiles.forEach(({ fileName, content }) => {
102115
outFiles[fileName] = {
103116
output: content.fileContents + common
@@ -107,9 +120,7 @@ export default function generate(
107120
writeGeneratedFiles(outFiles, outputPath);
108121

109122
writtenFiles += Object.keys(outFiles).length;
110-
}
111-
112-
else {
123+
} else {
113124
fs.writeFileSync(
114125
outputPath,
115126
generatedFiles.map(o => o.content.fileContents).join("\n") + common
@@ -126,19 +137,22 @@ export default function generate(
126137
[fileName: string]: BasicGeneratedFile;
127138
} = {};
128139

129-
if (nextToSources || (fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory())) {
140+
if (
141+
nextToSources ||
142+
(fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory())
143+
) {
130144
if (nextToSources && !fs.existsSync(outputPath)) {
131145
fs.mkdirSync(outputPath);
132146
}
133147

134148
const globalSourcePath = path.join(outputPath, "globalTypes.ts");
135149
outFiles[globalSourcePath] = {
136-
output: generatedGlobalFile.fileContents,
150+
output: generatedGlobalFile.fileContents
137151
};
138152

139153
generatedFiles.forEach(({ sourcePath, fileName, content }) => {
140154
let dir = outputPath;
141-
if (nextToSources) {
155+
if (nextToSources) {
142156
dir = path.join(path.dirname(sourcePath), dir);
143157
if (!fs.existsSync(dir)) {
144158
fs.mkdirSync(dir);
@@ -147,7 +161,8 @@ export default function generate(
147161

148162
const outFilePath = path.join(dir, fileName);
149163
outFiles[outFilePath] = {
150-
output: content({ outputPath: outFilePath, globalSourcePath }).fileContents,
164+
output: content({ outputPath: outFilePath, globalSourcePath })
165+
.fileContents
151166
};
152167
});
153168

@@ -158,7 +173,8 @@ export default function generate(
158173
fs.writeFileSync(
159174
outputPath,
160175
generatedFiles.map(o => o.content().fileContents).join("\n") +
161-
generatedGlobalFile.fileContents,
176+
"\n" +
177+
generatedGlobalFile.fileContents
162178
);
163179

164180
writtenFiles += 1;

0 commit comments

Comments
 (0)