UNPKG

1.62 kBJavaScriptView Raw
1/**
2 * Changes have been made to this file.
3 *
4 * devOnlyText have been removed because the variable __DEV__ is not guaranteed
5 * to be available on the consumer end.
6 *
7 * Copyright (c) 2013-present, Facebook, Inc.
8 * All rights reserved.
9 *
10 * This source code is licensed under the BSD-style license found in the
11 * LICENSE file in the root directory of this source tree. An additional grant
12 * of patent rights can be found in the PATENTS file in the same directory.
13 *
14 * @providesModule formatGeneratedModule
15 * @format
16 */
17
18'use strict';
19
20export 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
31const 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 // const devOnlyText = devTextGenerator ? devTextGenerator(objectName) : '';
45 return `/**
46 * ${'@'}flow${hashText}
47 */
48
49/* eslint-disable */
50
51'use strict';
52
53/*::
54import type {${documentType}} from '${relayRuntimeModule}';
55${flowText || ''}
56*/
57
58${docTextComment}
59const ${objectName} /*: ${documentType}*/ = ${concreteText};
60
61module.exports = ${objectName};
62`;
63};
64
65module.exports = formatGeneratedModule;