Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
writtenFiles += 1;
}
} else {
let output;
const context = compileToLegacyIR(schema, document, options);
switch (target) {
case "json":
output = serializeToJSON(context);
break;
case "scala":
output = generateScalaSource(context);
}
if (outputPath) {
fs.writeFileSync(outputPath, output);
writtenFiles += 1;
} else {
console.log(output);
}
}
return writtenFiles;
}
fs.mkdirSync(dir);
}
}
const outFilePath = path.join(dir, fileName);
outFiles[outFilePath] = {
output: content({ outputPath: outFilePath, globalSourcePath })
.fileContents
};
});
writeGeneratedFiles(outFiles, path.resolve("."));
writtenFiles += Object.keys(outFiles).length;
} else {
fs.writeFileSync(
outputPath,
generatedFiles.map(o => o.content().fileContents).join("\n") +
"\n" +
generatedGlobalFile.fileContents
);
writtenFiles += 1;
}
} else {
let output;
const context = compileToLegacyIR(schema, document, options);
switch (target) {
case "json":
output = serializeToJSON(context);
break;
case "scala":
const suppressSwiftMultilineStringLiterals = Boolean(
options.suppressSwiftMultilineStringLiterals
);
const generator = generateSwiftSource(
context,
outputIndividualFiles,
suppressSwiftMultilineStringLiterals,
only
);
if (outputIndividualFiles) {
writeGeneratedFiles(generator.generatedFiles, outputPath, "\n");
writtenFiles += Object.keys(generator.generatedFiles).length;
} else {
fs.writeFileSync(outputPath, generator.output.concat("\n"));
writtenFiles += 1;
}
if (options.generateOperationIds) {
writeOperationIdsMap(context);
writtenFiles += 1;
}
} else if (target === "flow") {
const context = compileToIR(schema, document, options);
const { generatedFiles, common } = generateFlowSource(context);
const outFiles: {
[fileName: string]: BasicGeneratedFile;
} = {};
if (nextToSources) {
function writeGeneratedFiles(
generatedFiles: { [fileName: string]: BasicGeneratedFile },
outputDirectory: string,
terminator: string = ""
) {
for (const [fileName, generatedFile] of Object.entries(generatedFiles)) {
fs.writeFileSync(
path.join(outputDirectory, fileName),
generatedFile.output.concat(terminator)
);
}
}
function writeOperationIdsMap(context: CompilerContext) {
let operationIdsMap: { [id: string]: OperationIdsMap } = {};
Object.keys(context.operations)
.map(k => context.operations[k])
.forEach(operation => {
operationIdsMap[operation.operationId!] = {
name: operation.operationName,
source: operation.source
};
});
fs.writeFileSync(
context.options.operationIdsPath,
JSON.stringify(operationIdsMap, null, 2)
);
}