1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | 'use strict';
|
19 |
|
20 | export type FormatModule = ({|
|
21 | moduleName: string,
|
22 | documentType: 'ConcreteBatch' | 'ConcreteFragment',
|
23 | docText: ?string,
|
24 | concreteText: string,
|
25 | flowText: ?string,
|
26 | hash: ?string,
|
27 | devTextGenerator: (objectName: string) => string,
|
28 | relayRuntimeModule: string,
|
29 | |}) => string;
|
30 |
|
31 | const formatGeneratedModule: FormatModule = ({
|
32 | moduleName,
|
33 | documentType,
|
34 | docText,
|
35 | concreteText,
|
36 | flowText,
|
37 | hash,
|
38 | devTextGenerator,
|
39 | relayRuntimeModule,
|
40 | }) => {
|
41 | const objectName = documentType === 'ConcreteBatch' ? 'batch' : 'fragment';
|
42 | const docTextComment = docText ? '\n/*\n' + docText.trim() + '\n*/\n' : '';
|
43 | const hashText = hash ? `\n * ${hash}` : '';
|
44 |
|
45 | return `/**
|
46 | * ${'@'}flow${hashText}
|
47 | */
|
48 |
|
49 | /* eslint-disable */
|
50 |
|
51 | 'use strict';
|
52 |
|
53 | /*::
|
54 | import type {${documentType}} from '${relayRuntimeModule}';
|
55 | ${flowText || ''}
|
56 | */
|
57 |
|
58 | ${docTextComment}
|
59 | const ${objectName} /*: ${documentType}*/ = ${concreteText};
|
60 |
|
61 | module.exports = ${objectName};
|
62 | `;
|
63 | };
|
64 |
|
65 | module.exports = formatGeneratedModule;
|