1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const types_1 = require("@babel/types");
|
4 | const types_2 = require("./types");
|
5 | const lodash_1 = require("lodash");
|
6 | const paths_1 = require("./paths");
|
7 | const compact_1 = require("./compact");
|
8 | const rawStringIdentifier = (fragmentOrOperationName) => types_1.identifier(lodash_1.camelCase(fragmentOrOperationName + "RawString"));
|
9 | const importDeclarationWithIdentifier = (identifier, source) => types_1.importDeclaration([types_1.importDefaultSpecifier(identifier)], types_1.stringLiteral(source));
|
10 | const rawStringImportDeclaration = (fragmentOrOperationName, source) => importDeclarationWithIdentifier(rawStringIdentifier(fragmentOrOperationName), source);
|
11 | const stringImportDeclaration = (fragmentOrOperationName, source) => importDeclarationWithIdentifier(types_2.stringIdentifier(fragmentOrOperationName), source);
|
12 | const joinedStringDeclaration = (fragmentOrOperationName, fragmentDependencies) => types_1.variableDeclaration("const", [
|
13 | types_1.variableDeclarator(types_2.stringIdentifier(fragmentOrOperationName), types_1.callExpression(types_1.memberExpression(types_1.arrayExpression([
|
14 | rawStringIdentifier(fragmentOrOperationName),
|
15 | ...fragmentDependencies.map(fragment => types_2.stringIdentifier(fragment))
|
16 | ]), types_1.identifier("join")), [types_1.stringLiteral("\n\n")]))
|
17 | ]);
|
18 | const exportedJoinedStringDeclaration = (fragmentOrOperationName, fragmentDependencies) => types_2.exportDeclaration(joinedStringDeclaration(fragmentOrOperationName, fragmentDependencies));
|
19 | const exportedStringDeclaration = (fragmentOrOperationName) => types_2.exportDeclaration(types_1.variableDeclaration("const", [
|
20 | types_1.variableDeclarator(types_2.stringIdentifier(fragmentOrOperationName), rawStringIdentifier(fragmentOrOperationName))
|
21 | ]));
|
22 | exports.default = (fragmentOrOperationName, filePath, outputPath, fragmentDependencies, exportStringDeclaration = false) => compact_1.default((fragmentDependencies.length > 0 || exportStringDeclaration
|
23 | ? rawStringImportDeclaration
|
24 | : stringImportDeclaration)(fragmentOrOperationName, paths_1.relativePath(outputPath, filePath)), fragmentDependencies.length > 0
|
25 | ? (exportStringDeclaration
|
26 | ? exportedJoinedStringDeclaration
|
27 | : joinedStringDeclaration)(fragmentOrOperationName, fragmentDependencies)
|
28 | : exportStringDeclaration &&
|
29 | exportedStringDeclaration(fragmentOrOperationName));
|
30 |
|
\ | No newline at end of file |